高 等 计 算 机 系 统 结 构 主 存 与 存 储 管 理 系 统 Main Memory & Memory Management ( 第 六 讲 ) 程 旭 2013.4.15
微 处 理 器 - 主 存 (DRAM) 的 延 迟 差 距 Performance (1/latency) Gap grew 50% per year How do architects address this gap? Put small, fast cache memories between CPU and DRAM. Create a memory hierarchy
Memory Hierarchy Take advantage of the principle of locality to: Present as much memory as in the cheapest technology Provide access at speed offered by the fastest technology Processor Datapath Control Registers On-Chip Cache Second Level Cache (SRAM) Main Memory (DRAM/ FLASH/ PCM) Secondary Storage (Disk/ FLASH/ PCM) Tertiary Storage (Tape/ Cloud Storage) Speed (ns): 1s 10s-100s 100s Size (bytes): 100s Ks-Ms Ms 10,000,000s (10s ms) Gs 10,000,000,000s (10s sec) Ts
主 存 系 统 的 性 能 延 迟 (Latency): 主 要 与 Cache Miss Penalty 相 关 访 问 时 间 (access time): time between request and word arrives 周 期 时 间 (cycle time): : time between requests 带 宽 (Bandwidth): 主 要 与 I/O 的 性 能 相 关 带 宽 对 Cache 的 性 能 也 很 重 要 (Large Block Miss Penalty ---- L2 cache) 提 高 带 宽 比 减 低 延 迟 容 易 些 在 系 统 级 ( 板 级 ) 提 高 存 储 系 统 性 能 受 限 制 在 芯 片 内 部 提 高 存 储 系 统 的 性 能
Core Memories (1950s & 60s) The first magnetic core memory, from the IBM 405 Alphabetical Accounting Machine. Core Memory stored data as magnetization in iron rings Iron cores woven into a 2-dimensional mesh of wires Origin of the term Dump Core Rumor that IBM consulted Life Saver company See: http://www.columbia.edu/acis/history/core.html
随 机 存 储 器 (RAM) 技 术 为 什 么 计 算 机 设 计 人 员 需 要 了 解 RAM 技 术? 处 理 器 的 性 能 通 常 受 到 存 储 器 带 宽 的 限 制 随 着 集 成 电 路 密 度 的 增 加, 一 些 存 储 器 将 和 处 理 器 集 成 在 同 一 芯 片 上 - 片 载 存 储 器 来 满 足 特 殊 需 求 - 指 令 cache - 数 据 cache - 写 缓 冲 器 为 什 么 不 用 触 发 器 技 术 来 实 现 RAM? 密 度 :RAM 需 要 更 高 的 密 度
静 态 RAM 单 元 6 管 SRAM 单 元 0 1 word ( 行 选 ) word 0 1 bit bit 写 操 作 : bit 1. 驱 动 位 线 (bit) 2. 选 择 行 读 操 作 : 拉 高 1. 对 两 条 位 线 预 充 电, 使 得 bit Vdd 2. 选 择 行 3. 存 储 单 元 将 一 条 线 拉 为 低 4. 列 上 的 信 号 放 大 器 检 测 bit 和 bit 之 间 的 差 异 bit
典 型 的 SRAM 组 织 : 16 字 4 位 Din 3 Din 2 Din 1 Din 0 Precharge WrEn Wr Driver & Wr Driver & Wr Driver & Wr Driver & - Precharger + - Precharger + - Precharger + - Precharger + SRAM Cell SRAM Cell SRAM Cell SRAM Cell SRAM Cell SRAM Cell SRAM Cell SRAM Cell Word 0 Word 1 Address Decoder A0 A1 A2 A3............ SRAM Cell SRAM Cell SRAM Cell SRAM Cell - Sense Amp + - Sense Amp + - Sense Amp + - Sense Amp + Word 15 Dout 3 Dout 2 Dout 1 Dout 0
寄 存 器 堆 所 用 的 单 端 口 ( 写 ) SRAM 单 元 SelA SelB SelW w b a w 为 了 将 新 值 写 入 存 储 单 元 : 我 们 需 要 同 时 驱 动 两 边 每 次 只 能 写 入 一 个 存 储 字 增 设 另 外 一 对 位 线 (w 和 w) 可 以 同 时 进 行 读 和 写
双 读 端 口 单 写 端 口 的 寄 存 器 堆 : : busw<31> busw<1> busw<0> WrEn - Wr Driver + - Wr Driver + - Wr Driver + SelA0 Register Cell Register Cell Register Cell : : : Register Cell Register Cell Register Cell SelB0 SelW0 SelA31 SelB31 Address Decoder 5 5 5 Ra Rb Rw SelW31 busa<31> busa<1> busa<0> busb<31> busb<1> busb<0>
典 型 SRAM 的 逻 辑 图 A N WE_L OE_L 2 N words x M bit SRAM M D 写 使 能 信 号 通 常 是 低 电 平 有 效 (WE_L) Din 和 Dout 是 结 合 在 一 起 的 : 需 要 一 个 新 的 控 制 信 号 输 出 使 能 信 号 (OE_L) WE_L 有 效 (Low), OE_L 禁 止 (High) - D 为 数 据 输 入 WE_L 禁 止 (High), OE_L 有 效 (Low) - D 为 数 据 输 出 WE_L 和 OE_L 都 有 效 : - 结 果 不 确 定. 千 万 不 要 这 样 做!!!
典 型 的 SRAM 时 序 A N WE_L OE_L 2 N words x M bit SRAM M D Write Timing: Read Timing: D Data In High Z Garbage Data Out Junk Data Out A Write Address Junk Read Address Read Address OE_L WE_L Write Hold Time Write Setup Time Read Access Time Read Access Time
进 一 步 分 析 SRAM 单 元 6 管 SRAM 单 元 word ( 行 选 择 ) word P1 P2 N1 N2 bit bit bit bit 通 常 SRAM 具 有 许 多 存 储 字 ( 行 ) 位 线 (bit lines) 就 很 长, 因 而 也 就 具 有 较 大 的 电 容 晶 体 管 N1 N2 P1 和 P2 就 必 须 非 常 小 晶 体 管 N1 P1 没 有 足 够 的 能 量 来 快 速 驱 动 位 线 (Bit): 需 要 增 设 一 个 信 号 放 大 器 (sense amplifier) 来 比 较 Bit 和 Bit
SRAM 的 问 题 Select = 1 P1 P2 Off On On N1 On Off N2 On 六 个 晶 体 管 需 要 较 多 的 芯 片 面 积 假 设 在 某 单 元 中 存 储 0 : 晶 体 管 N1 将 试 图 将 Bit 拉 为 0 晶 体 管 P2 将 试 图 将 Bit 为 1 但 是 由 于 这 些 位 线 在 预 充 电 时 都 将 置 为 高 : 那 么 是 否 必 须 需 要 P1 和 P2? bit = 1 bit = 0
SRAM 的 问 题 ( 续 ) Select = 1 N1 的 门 电 容 Vdd P2 当 将 入 0 到 这 个 单 元 时, 置 为 高 在 下 一 次 写 入 之 前, P2 将 一 直 保 持 为 高 On On On N1 On bit = 1 bit = 0 P 型 晶 体 管 (P2) 具 有 三 个 功 能 : 在 读 操 作 期 间, 将 Bit 线 驱 动 为 高 (Select = 1) 在 下 一 次 写 操 作 之 前, 保 持 N1 的 门 一 直 在 高 电 平 在 读 操 作 期 间, 防 止 N1 的 门 电 容 将 它 的 所 有 电 荷 都 泄 漏 给 Bit
4 管 RAM 单 元 Row Select 读 操 作 : 1. 对 b 预 充 电, 使 得 b Vdd 2. 选 择 行 3. 感 应 4. 放 大 数 据 5. 写 刷 新 : 假 读 周 期 写 操 作 : 1. 驱 动 位 线 ( bit lines) 2. 选 择 行 在 读 取 数 据 期 间, 消 耗 掉 的 电 荷, 必 须 被 恢 复 b 优 点 : 较 小 : 取 消 了 2 个 负 载 设 备 和 1 个 供 电 端 缺 点 : 附 加 了 刷 新 周 期 降 低 了 抗 干 扰 能 力 b
单 管 单 元 写 操 作 : 1. 驱 动 位 线 2. 选 择 行 读 操 作 : 1. 预 充 电, 使 得 位 线 Vdd 2. 选 择 行 3. 单 元 和 位 线 共 享 电 荷 位 线 - 在 位 线 上 只 有 非 常 小 的 电 压 变 化 4. 感 应 ( 非 常 奇 妙 的 感 应 放 大 器 ) - 可 以 检 测 到 大 约 一 百 万 电 子 伏 特 的 变 化 5. 写 : 恢 复 电 压 值 刷 新 1. 仅 仅 需 要 对 每 个 单 元 进 行 一 次 假 读 操 作 行 选 择
DRAM 引 论 Dynamic RAM (DRAM): 需 要 刷 新 密 度 非 常 高 耗 电 非 常 低 ( 工 作 时 0.1~0.5 W, 等 待 (standby)0.25 ~10 mw) 每 位 的 成 本 非 常 低 管 脚 敏 感 : - 输 出 使 能 (Output Enable: OE_L) - 写 使 能 (Write Enable:WE_L) addr - 行 地 址 过 滤 (Row address strobe: ras) - 列 地 址 过 滤 (Col address strobe:cas) log N 2 r o w cell array N bits c o l sense 单 感 应 放 大 器 耗 电 较 少, 面 积 小 D
传 统 的 DRAM 组 成 位 线 ( 数 据 ) 行 译 码 器 RAM 单 元 阵 列 RAM Cell Array 每 个 交 叉 点 代 表 一 个 单 管 DRAM 单 元 字 选 择 ( 行 选 择 ) 行 地 址 列 选 择 器 & I/O 电 路 列 地 址 数 据 行 和 列 地 址 在 一 起 : 每 次 选 择 一 位
512 行 典 型 的 DRAM 组 成 典 型 DRAMs: 并 行 访 问 多 位 例 如 : 2 Mb DRAM = 256K x 8 = 512 行 x 512 列 x 8 位 行 和 列 地 址 并 行 作 用 于 所 有 8 个 位 面 (planes) 位 面 7 512 列 位 面 0 256 Kb DRAM 的 一 个 位 面 位 面 1 256 Kb DRAM D<1> 256 Kb DRAM D<7> D<0>
典 型 DRAM 的 逻 辑 框 图 RAS_L CAS_L WE_L OE_L A 256K x 8 DRAM 9 8 D 控 制 信 号 (RAS_L, CAS_L, WE_L, OE_L) 都 是 低 电 平 有 效 Din 和 Dout 合 并 在 一 起 (D): WE_L 有 效 ( 低 ), OE_L 禁 止 ( 高 ) 时, - D 作 为 数 据 输 入 管 脚 WE_L 禁 止 ( 高 ), OE_L 有 效 ( 低 ) - D 作 为 数 据 输 出 管 脚 行 和 列 地 址 共 享 相 同 的 一 组 管 脚 (A) RAS_L 变 成 低 : 管 脚 A 被 锁 定 为 行 地 址 CAS_L 变 成 低 : 管 脚 A 被 锁 定 为 列 地 址
Row Address Decoder DRAM Architecture Col. 1 bit lines Col. word lines 2 M Row 1 N Row 2 N N+M M Column Decoder & Sense Amplifiers Memory cell (one bit) Data D Bits stored in 2-dimensional arrays on chip Modern chips have around 4 logical banks on each chip each logical bank physically implemented as many smaller arrays 北 京 大 4/18/2011 学 计 算 机 科 学 技 术 系 cs252-s11, Lecture 22 北 京 大 学 微 处 理 器 研 究 22开 发 中 心
DRAM Operation: Three Steps Precharge charges bit lines to known value, required before next row access Row access (RAS) decode row address, enable addressed row (often multiple Kb in row) bitlines share charge with storage cell small change in voltage detected by sense amplifiers which latch whole row of bits sense amplifiers drive bitlines full rail to recharge storage cells Column access (CAS) decode column address to select small number of sense amplifier latches (4, 8, 16, or 32 bits depending on DRAM package) on read, send latched bits out to chip pins on write, change sense amplifier latches. which then charge storage cells to required value can perform multiple column accesses on same row without another row access (burst mode) 北 京 大 4/18/2011 学 计 算 机 科 学 技 术 系 cs252-s11, Lecture 22 北 京 大 学 微 处 理 器 研 究 23开 发 中 心
DRAM 写 操 作 时 序 当 RAS_L 有 效 时, 所 有 DRAM 开 始 访 问 A RAS_L CAS_L 256K x 8 DRAM WE_L OE_L 9 8 D RAS_L DRAM 写 时 钟 周 期 CAS_L A Row Address Col Address Junk Row Address Col Address Junk OE_L WE_L D Junk Data In Junk Data In Junk WR Access Time Early Wr Cycle: WE_L asserted before CAS_L WR Access Time Late Wr Cycle: WE_L asserted after CAS_L
DRAM 读 操 作 时 序 当 RAS_L 有 效 时, 所 有 DRAM 开 始 访 问 A RAS_L CAS_L 256K x 8 DRAM WE_L OE_L 9 8 D RAS_L DRAM 读 时 钟 周 期 CAS_L A Row Address Col Address Junk Row Address Col Address Junk WE_L OE_L D High Z Junk Data Out High Z Junk Read Access Time Output Enable Delay Early Read Cycle: OE_L asserted before CAS_L Late Read Cycle: OE_L asserted after CAS_L
DRAM 读 操 作 时 序
主 存 性 能 ( 周 期 时 间 与 访 问 周 期 ) 访 问 时 间 周 期 时 间 时 间 DRAM ( 读 / 写 ) 周 期 时 间 >> DRAM ( 读 / 写 ) 访 问 时 间 DRAM ( 读 / 写 ) 周 期 时 间 : 我 们 可 以 以 多 快 的 频 率 来 开 始 进 行 存 储 访 问? 比 喻 : 我 们 只 能 在 4x 的 年 度 的 夏 天, 才 能 收 看 到 奥 运 会 足 球 赛 DRAM ( 读 / 写 ) 访 问 时 间 : 一 旦 我 们 开 始 进 行 访 问, 那 么 要 过 多 长 时 间 可 以 获 得 数 据? 比 喻 : 在 奥 运 会 期 间, 一 旦 我 们 想 看, 最 多 等 一 天 就 可 以 收 看 到 下 一 场 比 赛 DRAM 的 带 宽 限 制 : 比 喻 : 如 果 我 们 2014 年 还 想 看 新 的 世 界 级 足 球 比 赛?
增 加 带 宽 交 叉 访 问 (Interleaving) 非 交 叉 访 问 的 访 问 模 式 : CPU Memory 得 到 D1 开 始 访 问 D1 四 路 交 叉 访 问 的 访 问 模 式 : 访 问 体 0 访 问 体 1 访 问 体 2 开 始 访 问 D2 访 问 体 3 我 们 可 以 再 次 访 问 体 0 CPU Memory Bank 0 Memory Bank 1 Memory Bank 2 Memory Bank 3
主 存 性 能 简 单 : CPU Cache 总 线 和 主 存 同 宽 (32 或 64 位 ) 宽 度 : CPU/Mux 1 个 存 储 字 ; Mux/Cache 总 线 和 主 存 N 个 存 储 字 (Alpha: 64 位 & 256 位 ; UtraSPARC 512 位 ) 交 叉 (Interleaved): CPU Cache 和 总 线 1 个 存 储 字 : 存 储 器 N 个 存 储 体 (4 模 ); 示 例 为 字 交 叉 (word interleaved) CPU CPU CPU Cache bus M mux cache bus M Cache bus M M M M 第 一 种 解 决 方 案 高 带 宽 DRAM 第 二 种 解 决 方 案 存 储 器 和 Cache 之 间 宽 数 据 通 路 第 三 种 解 决 方 案 存 储 模 块 交 叉 访 问
主 存 性 能 时 序 模 型 ( 字 长 32 位 ) 1 个 周 期 发 送 地 址, 6 个 周 期 访 问 时 间, 1 个 周 期 发 送 数 据 Cache 块 为 4 个 字 Simple M.P. = 4 x (1+6+1) = 32 Wide M.P. = 1 + 6 + 1 = 8 Interleaved M.P. = 1 + 6 + 4x1 = 11
计 算 机 中 的 主 存 系 统
主 存 访 问 过 程
Need for Error Correction! Motivation: Failures/time proportional to number of bits! As DRAM cells shrink, more vulnerable Went through period in which failure rate was low enough without error correction that people didn t do correction DRAM banks too large now Servers always corrected memory systems Basic idea: add redundancy through parity bits Common configuration: Random error correction - SEC-DED (single error correct, double error detect) - One example: 64 data bits + 8 parity bits (11% overhead) Really want to handle failures of physical components as well - Organization is multiple DRAMs/DIMM, multiple DIMMs - Want to recover from failed DRAM and failed DIMM! - Chip kill handle failures width of single DRAM chip
Quest for DRAM Performance 1. Fast Page mode Add timing signals that allow repeated accesses to row buffer without another row access time Such a buffer comes naturally, as each array will buffer 1024 to 2048 bits for each access 2. Synchronous DRAM (SDRAM) Add a clock signal to DRAM interface, so that the repeated transfers would not bear overhead to synchronize with DRAM controller 3. Double Data Rate (DDR SDRAM) Transfer data on both the rising edge and falling edge of the DRAM clock signal doubling the peak data rate DDR2 lowers power by dropping the voltage from 2.5 to 1.8 volts + offers higher clock rates: up to 400 MHz DDR3 drops to 1.5 volts + higher clock rates: up to 800 MHz Improved Bandwidth, not Latency
Fast Memory Systems: DRAM specific Multiple CAS accesses: several names (page mode) Extended Data Out (EDO): 30% faster in page mode Newer DRAMs to address gap; what will they cost, will they survive? RAMBUS: startup company; reinvented DRAM interface - Each Chip a module vs. slice of memory - Short bus between CPU and chips - Does own refresh - Variable amount of data returned - 1 byte / 2 ns (500 MB/s per chip) Synchronous DRAM: 2 banks on chip, a clock signal to DRAM, transfer synchronous to system clock (66-150 MHz) - DDR DRAM: Two transfers per clock (on rising and falling edge) Intel claims FB-DIMM is the next big thing - Stands for Fully-Buffered Dual-Inline RAM - Same basic technology as DDR, but utilizes a serial daisy-chain channel between different memory components. 北 京 大 4/18/2011 学 计 算 机 科 学 技 术 系 cs252-s11, Lecture 22 北 京 大 学 微 处 理 器 研 究 35开 发 中 心
DRAM 技 术 的 发 展 Throughput vs. Latency
N 行 N 行 快 速 页 模 式 (Fast Page Mode, FPM)DRAM 常 规 DRAM 组 成 : N 行 x N 列 x M 位 同 时 读 和 写 M 位 每 M 位 访 问 需 要 一 个 RAS / CAS 周 期 FPM DRAM N x M 锁 存 器 来 保 存 一 行 列 地 址 列 地 址 M 位 输 出 N 列 DRAM N 列 M 位 行 地 址 在 读 取 一 行 到 寄 存 器 后 仅 仅 需 要 CAS 来 访 问 该 行 中 的 其 他 M 位 存 储 块 (bank) 在 RAS_L 保 持 有 效, 同 时 CAS_L 不 断 变 化 DRAM N x M SRAM M 位 输 出 M 位 行 地 址
快 速 页 模 式 操 作 DRAM 性 能 指 标 :(x-y-y-y, 例 如 6-3-3-3) x:first data access time in clock/bus cycles y:successive burst data access time in clock/bus cycles
快 速 页 模 式 操 作
EDO DRAM(Extended Data Out) (20%-40% 性 能 提 升 ) EDO DRAM 性 能 指 标 :5-2-2-2 at 66MHz
Burst EDO DRAM
SDRAM(Synchronous DRAM) 基 于 DRAM 的 技 术 (CAS RAS,etc) 允 许 在 一 个 DIMM 中 包 含 多 个 BANK DIMM SDRAM 168 pin 增 加 了 ba0 ba1 两 个 管 脚 与 CPU 或 芯 片 组 使 用 同 步 时 钟 信 号 五 组 控 制 信 号, 可 组 成 多 种 命 令 CS:chip select RAS:raw address select CAS:col address select WE:write enable DQM:output enable 更 好 的 支 持 Burst 方 式 可 编 程 设 置 模 式 : Bust length,sequence...
SDRAM(Synchronous DRAM) SDRAM Mode Register
SDRAM read
SDRAM performance CAS Latency is important x-y-y( 例 如 :3-2-2) CAS Latency the RAS-to-CAS delay RAS precharge time 时 钟 主 频 PC66:66MHz PC100:100MHz PC133:133MHz
DDR SDRAM DDR:Double data rate 时 钟 上 升 沿 和 下 降 沿 均 可 以 发 送 数 据 ( 带 宽 X2!!) 在 原 有 的 SDRAM 的 架 构 基 础 上 加 以 较 小 的 改 进 ( 可 复 用 原 有 生 产 线 ) SDRAM 和 DDR 均 为 开 放 标 准 (JEDEC)(Important!!) SDRAM DDR
DDR-SDRAM Timing Diagram
图 1: 图 2: SDRAM 的 Bank 和 内 存 规 范 4M X 1bit X 32chip 4bank in a dimm SIMM DIMM single/doul in-line memory module 目 前 使 用 的 都 是 DIMM 时 钟 频 率 PC1600 100MHz - 100 2 8 MB/s PC2100 133MHz PC2400 150MHz 图 1 图 2
DDR3 SDRAM
其 它 DRAM VCDRAM (Virtual Channel DRAM,NEC)
SDRAM timing (Single Data Rate) CAS RAS (New Bank) CAS Latency x Precharge Burst READ Micron 128M-bit dram (using 2Meg 16bit 4bank ver) Row (12 bits), bank (2 bits), column (9 bits) 北 京 大 4/18/2011 学 计 算 机 科 学 技 术 系 cs252-s11, Lecture 22 北 京 大 学 微 处 理 器 研 究 51开 发 中 心
Double-Data Rate (DDR2) DRAM 200MHz Clock Row Column Precharge Row Data [ Micron, 256Mb DDR2 SDRAM datasheet ] 400Mb/s Data Rate 北 京 大 4/18/2011 学 计 算 机 科 学 技 术 系 cs252-s11, Lecture 22 北 京 大 学 微 处 理 器 研 究 52开 发 中 心
DDR vs DDR2 vs DDR3 vs DDR4 All about increasing the rate at the pins Not an improvement in latency In fact, latency can sometimes be worse Internal banks often consumed for increased bandwidth DDR4 (January 2011) Samsung, Currently 2.13Gb/sec Target: 4 Gb/sec 北 京 大 4/18/2011 学 计 算 机 科 学 技 术 系 cs252-s11, Lecture 22 北 京 大 学 微 处 理 器 研 究 53开 发 中 心
DRAM Power: Not always up, but 北 京 大 4/18/2011 学 计 算 机 科 学 技 术 系 cs252-s11, Lecture 22 北 京 大 学 微 处 理 器 研 究 54开 发 中 心
PCB 板 的 Path Length
DRAM Research Areas 提 高 带 宽 是 最 重 要 目 标 降 低 Latency Topology Memory Command Address Mapping
DRAM Packaging Clock and control signals Address lines multiplexed row/column address ~7 ~12 Data bus (4b,8b,16b,32b) DRAM chip DIMM (Dual Inline Memory Module) contains multiple chips arranged in ranks Each rank has clock/control/address signals connected in parallel (sometimes need buffers to drive signals to all chips), and data pins work together to return wide word e.g., a rank could implement a 64-bit data bus using 16x4-bit chips, or a 64-bit data bus using 8x8-bit chips. A modern DIMM usually has one or two ranks (occasionally 4 if high capacity) A rank will contain the same number of banks as each constituent chip (e.g., 4-8)
Main Memory Overview
DRAM: Banks Enable concurrent DRAM accesses (overlapping)
2Gb x8 DDR3 Chip [Micron] Observe: bank organization
Observe: row width, 64 8 bit datapath
DRAM: Timing Constraints Memory controller must respect physical device characteristics trcd= Row to Column command delay - How long it takes row to get to sense amps tcas= Time between column command and data out tccd= Time between column commands - Rate that you can pipeline column commands trp= Time to prechargedram array tras= Time between RAS and data restoration in DRAM array (minimum time a row must be open) trc= tras+ trp= Row cycle time - Minimum time between accesses to different rows
DRAM: Timing Constraints There are dozens of these twtr= Write to read delay twr= Time from end of last write to PRECHARGE tfaw= Four ACTIVATE window (limits current surge) Makes performance analysis, memory controller design difficult Datasheets for DRAM devices freely available http://download.micron.com/pdf/datasheets/dram/ddr3/2gb_ddr3_s DRAM.pdf
DRAM Modules DRAM chips have narrow interface (typically x4, x8, x16) Multiple chips are put together to form a wide interface DIMM: Dual Inline Memory Module To get a 64-bit DIMM, we need to access 8 chips with 8-bit interfaces Share command/address lines, but not data Advantages Acts like a high-capacity DRAM chip with a wide interface 8x capacity, 8x bandwidth, same latency Disadvantages Granularity: Accesses cannot be smaller than the interface width 8x power
A 64-bit Wide DIMM (physical view)
A 64-bit Wide DIMM(logical view)
Multiple DIMMs on a Channel Advantages: Enables even higher capacity Disadvantages: nterconnect latency, complexity, and energy get higher Addr/Cmdsignal integrity is a challenge
DRAM Ranks A DIMM may include multiple Ranks A 64-bit DIMM using 8 chips with x16 interfaces has 2 ranks Each 64-bit group of chips is called a rank All chips in a rank respond to a single command Different ranks share command/address/data lines - Select between ranks with Chip Select signal Ranks provide more banks across multiple chips (but don t confuse rank and bank!)
Multiple Ranks on a DIMM DIMM1 Rank1 Rank2 Rank3 DIMM2 Rank4
DRAM Channels Channel: a set of DIMMsin series All DIMMsget the same command, one of the ranks replies System options Single channel system Multiple dependent (lock-step) channels Single controller with wider interface (faster cache line refill!) Sometimes called Gang Mode Only works if DIMMs are identical (organization, timing) Multiple independent channels Requires multiple controllers Tradeoffs Cost: pins, wires, controller Benefit: higher bandwidth, capacity, flexibility
DRAM Channel Options lock-step Independent
DRAM Controller Functionality Translate memory requests into DRAM command sequences Map Physical Address to DRAM Address Obey timing constraints of DRAM, arbitrate resource conflicts (i.e. bank, channel) Buffer and schedule requests to improve performance Row-buffer management and re-ordering Ensure correct operation of DRAM (refresh) Manage power consumption and thermals in DRAM Turn on/off DRAM chips, manage power modes
A Modern DRAM Controller
FB-DIMM Memories Regular DIMM FB-DIMM Uses Commodity DRAMs with special controller on actual DIMM board Connection is in a serial form: FB-DIMM FB-DIMM FB-DIMM FB-DIMM FB-DIMM Controller
Choices for Future
主 存 系 统 模 型 通 道 (channel): 主 存 控 制 器 与 DRAM 之 间 独 立 的 数 据 总 线 目 前 大 部 分 处 理 器 和 北 桥 芯 片 组 有 2 条 通 道, 允 许 同 时 访 问 2 组 DRAM
主 存 系 统 的 研 究 空 间 并 行 性 每 个 通 道 都 可 以 独 立 并 行 地 处 理 主 存 访 问 时 间 并 行 性 单 个 通 道 内 多 个 主 存 访 问 延 迟 的 重 叠 局 部 性 如 果 连 续 二 个 访 问 指 向 同 一 个 通 道 内 同 一 个 设 备 中 同 一 个 体 同 一 行, 则 第 二 个 主 存 访 问 可 以 仅 需 要 Read 或 Write 一 个 命 令, 能 够 大 大 降 低 第 二 个 主 存 访 问 延 迟
Embedded DRAM CPU 和 DRAM 合 并 在 一 个 芯 片 中 消 除 由 于 Pin 和 PCB 所 带 来 的 带 宽 限 制 巨 大 的 On-chip L3 Cache 的 需 求 IRAM
FLASH Memory Like a normal transistor but: Has a floating gate that can hold charge To write: raise or lower wordline high enough to cause charges to tunnel To read: turn on wordline as if normal transistor - presence of charge changes threshold and thus measured current Two varieties: NAND: denser, must be read and written in blocks NOR: much less dense, fast to read and write Samsung 2007: 16GB, NAND Flash 北 京 大 4/18/2011 学 计 算 机 科 学 技 术 系 cs252-s11, Lecture 22 北 京 大 学 微 处 理 器 研 究 79开 发 中 心
Tunneling Magnetic Junction (MRAM) Tunneling Magnetic Junction RAM (TMJ-RAM) Speed of SRAM, density of DRAM, non-volatile (no refresh) Spintronics : combination quantum spin and electronics Same technology used in high-density disk-drives cs252-s11, Lecture 22 北 京 大 学 微 处 理 器 研 究 80开 发 中 心
Phase Change memory (IBM, Samsung, Intel) Phase Change Memory (called PRAM or PCM) Chalcogenide material can change from amorphous to crystalline state with application of heat Two states have very different resistive properties Similar to material used in CD-RW process Exciting alternative to FLASH Higher speed May be easy to integrate with CMOS processes 4/18/2011 cs252-s11, Lecture 22 81
虚 拟 存 储 系 统 提 供 一 种 理 想 中 的 非 常 非 常 大 的 存 储 器 许 多 工 作 所 需 存 储 器 的 总 和 大 于 实 际 的 物 理 存 储 器 每 个 工 作 的 地 址 空 间 大 于 实 际 的 物 理 存 储 器 使 得 可 利 用 的 ( 快 速 昂 贵 ) 的 物 理 存 储 器 得 以 很 好 地 利 用 简 化 存 储 器 的 管 理 ( 当 今, 使 用 虚 拟 存 储 技 术 的 主 要 原 因 ) 使 用 存 储 层 次, 保 持 平 均 访 问 时 间 很 低 至 少 包 括 两 级 存 储 层 次 : 主 存 和 二 级 存 储 虚 拟 地 址 程 序 员 使 用 的 地 址 虚 拟 地 址 空 间 上 述 地 址 的 集 合 存 储 器 地 址 物 理 存 储 器 中 存 储 字 的 地 址, 也 称 为 物 理 地 址 或 实 地 址 ( Real address)
虚 拟 存 储 系 统 设 计 的 基 本 问 题 如 何 在 分 配 主 存 空 间 以 安 放 代 码 和 数 据? 如 何 为 程 序 分 配 主 存 空 间, 分 配 多 少, 何 时 分 配? 超 过 主 存 容 量 的 一 个 程 序 或 多 个 程 序 的 替 换 策 略? 如 何 软 硬 件 协 同 保 证 运 行 正 常? 如 何 为 用 户 程 序 提 供 独 立 的 地 址 空 间? 如 何 提 供 存 储 保 护?( 病 毒 恶 意 破 坏 错 误 的 编 程 ) reg cache mem disk frame pages
页 式 存 储 管 理 将 主 存 物 理 空 间 按 照 固 定 页 面 大 小 分 割 将 不 连 续 的 主 存 物 理 空 间 映 射 为 连 续 的 程 序 虚 拟 空 间 提 供 页 表 (OS) 和 MMU(CPU) 管 理 机 制 的 支 持 使 用 TLB(Translation lookaside buffer) 提 供 地 址 快 速 变 换 提 供 页 表 基 址 寄 存 器 V = {0, 1,..., n - 1} 虚 拟 地 址 空 间 M = {0, 1,..., m - 1} 物 理 地 址 空 间 映 射 : V M U {0} 地 址 映 射 函 数
0 4096 进 程 页 表 页 帧 0 1 4K 4K 0 4096 页 0 1 2 4K 4K 0 4096 页 帧 0 1 4K 4K 7 4K 31 4K 7 4K 进 程 1 虚 拟 地 址 空 间 33 34 进 程 2 虚 拟 地 址 空 间 索 引 0 1 7 权 限 位 权 限 位 权 限 位 权 限 位 物 理 页 号 31 1 63 物 理 地 址 空 间... 63 4K 索 引 0 1 7 权 限 位 权 限 位 权 限 位 权 限 位 物 理 页 号 2 34 33 进 程 1 页 表 进 程 2 页 表
虚 实 地 址 变 换 机 制 MMU(mem management unit) CPU 发 出 虚 拟 地 址 MMU 通 过 table walk 访 问 主 存 页 表, 获 得 映 射 关 系 MMU 将 虚 页 号 变 换 为 物 理 页 号, 产 生 物 理 地 址, 访 存 缺 页 时, 处 理 器 转 到 页 面 失 效 入 口, 交 给 OS 处 理 VA 虚 页 号 偏 移 量 页 表 基 址 寄 存 器 PA PPN V 页 表 访 问 权 限 偏 移 量 虚 实 地 址 变 换 PPN 处 理 器 VA MMU 地 址 变 换 机 制 PA table walk 地 址 变 换 机 制 页 面 失 效 故 障 入 口 OS 缺 页 处 理 主 存 页 表 DISK OS 完 成
两 级 页 表 变 换 虚 拟 地 址 经 过 两 级 页 表 映 射 页 表 基 址 寄 存 器 存 储 一 级 页 表 首 址 一 级 页 表 中 将 一 个 较 大 虚 拟 地 址 范 围 映 射 到 一 个 二 级 页 表 考 虑 多 页 面 大 小 的 支 持 (4K 64K 4M...) 二 级 页 表 页 表 基 址 寄 存 器 一 级 页 表 代 码 页 数 据 页
快 表 TLB(Translation lookaside buffer) TLB(Translation lookaside buffer, 变 换 旁 路 缓 冲 器 ) TLB 是 页 表 的 Cache 典 型 的 实 现 :64Entry 全 相 联 存 储 器 同 样 要 实 现 替 换 算 法 等 v 虚 页 号 权 限 位 物 理 页 号 相 比 页 表, 要 多 出 虚 页 号 的 域 64 路 全 相 联
主 要 的 虚 拟 存 储 实 现 方 式 段 式 将 程 序 划 分 成 为 若 干 个 地 址 连 续 的 区 域 ( 段 ), 通 过 段 描 述 符 和 段 内 偏 移 来 访 问 代 码 段 数 据 段 堆 栈 段 共 享 段 等 优 点 : 十 分 方 便 的 存 储 共 享 和 存 储 保 护 缺 点 : 段 的 连 续 性 容 易 造 成 存 储 碎 片 问 题? 页 式 将 地 址 空 间 划 分 成 大 小 固 定 的 页 优 点 : 灵 活 性 好 缺 点 : 可 能 造 成 空 间 浪 费, 即 使 只 使 用 一 个 字 节 也 要 分 配 一 个 页 段 页 式 在 段 式 划 分 的 基 础 上, 将 段 再 划 分 成 页 优 点 : 解 决 了 段 的 连 续 存 放 问 题 缺 点 : 开 销 大, 控 制 复 杂, 操 作 系 统 多 不 愿 使 用
虚 拟 存 储 的 主 要 组 成 MMU:Memory Management Unit TLB:Translation lookaside buffer TLB 的 功 能 一 般 包 含 在 MMU 中 Table walking: 页 表 查 找 机 制 页 表 : 主 存 中 的 虚 实 地 址 转 换 信 息 物 理 地 址 Main Memory CPU 虚 拟 地 址 MMU TLB Table walking Page Table
MMU MMU: 存 储 管 理 部 件, Memory Management Unit MMU 是 系 统 中 进 行 虚 实 地 址 转 换 的 核 心 部 件 MMU 的 主 要 工 作 如 下 : 在 TLB 的 协 助 下 完 成 虚 实 地 址 转 换 维 护 TLB 的 控 制 机 制 负 责 存 储 保 护 在 TLB 失 效 或 非 法 访 问 时 向 处 理 器 发 起 中 断 维 护 一 个 TLB 失 效 后 的 再 填 充 机 制 (Table walking) CPU 虚 拟 地 址 MMU TLB TLB 失 效 TLB 命 中 物 理 地 址 Table walking Cache or Main Memory Page Table
TLB TLB: 变 换 旁 视 缓 冲 器,Translation Lookaside Buffer TLB 是 内 存 中 页 表 的 Cache, 用 来 保 存 最 近 用 过 的 页 表 项 信 息 极 大 地 提 高 了 地 址 变 换 的 速 度 相 对 于 Cache, 页 表 项 的 存 储 局 部 性 更 好, 有 更 小 的 失 效 率 典 型 的 TLB 表 项 包 含 符 号 位 VPN PPN 和 权 限 位 符 号 位 : 有 效 位 等 VPN:Virtual Page Number PPN:Physical Page Number,Also as Physical Frame Number 权 限 位 : 对 该 页 面 的 访 问 权 限 控 制, 禁 止 只 读 只 写 读 写 虚 拟 地 址 VPN Offset Flag VPN PPN Perm 物 理 地 址 PPN Offset
TLB( 续 ) VPN TLB 可 以 应 用 Cache 中 的 绝 大 部 分 技 术 直 接 映 射 组 相 联 或 者 全 相 联 组 相 联 -> 全 相 联 -> 组 相 联 多 级 TLB Victim TLB 等 VPN0 VPN1 VPN2 VPN3 PPN0 PPN1 PPN2 =? =? =? =? PPN PPN3 CPU CPU CPU CPU Instr Data Instr Data Instr Data Instr Data TLB Unified TLB ITLB DTLB Split TLB ITLB DTLB Macro TLB ITLB DTLB TLB Level2 TLB
Table walking Table walking 是 当 TLB 失 效 发 生 后, 重 新 填 充 TLB 表 项 的 机 制 硬 件 Table walking 机 制 典 型 代 表 :Intel IA32 系 列 PowerPC 当 TLB 失 效 时, 通 过 硬 件 状 态 机 的 控 制, 搜 索 页 表, 获 得 相 应 的 信 息 并 填 充 到 TLB 中 优 点 : 速 度 快 ( 不 需 中 断 不 需 指 令 执 行 访 问 DCache) 缺 点 : 操 作 系 统 必 须 使 用 规 定 格 式 的 页 表 注 意 :TLB 失 效 后 访 问 DCache 也 可 能 造 成 一 级 二 级 Cache 失 效, 从 而 导 致 较 大 的 失 效 损 失 CPU 虚 拟 地 址 MMU TLB S TLB 命 中 S 物 理 地 址 S Table walking TLB 失 效 Cache or Main Memory Page Table
Table Walking( 续 ) 软 件 Table walking 典 型 代 表 :MIPS Alpha 当 发 生 TLB 失 效 时,MMU 发 出 一 个 失 效 中 断 操 作 系 统 的 失 效 中 断 处 理 函 数 搜 索 页 表, 找 到 相 应 的 表 项, 并 通 过 特 定 的 指 令 填 充 到 TLB 中 去 优 点 : 操 作 系 统 具 有 完 全 的 灵 活 性 可 移 植 性 好 缺 点 : 性 能 较 硬 件 要 差 - 中 断 损 失 - 处 理 函 数 导 致 指 令 Cache 失 效 - 处 理 函 数 访 问 页 表 导 致 数 据 Cache 失 效 - 处 理 函 数 访 问 页 表 导 致 嵌 套 的 TLB 失 效 CPU 虚 拟 地 址 MMU TLB TLB 命 中 TLB 失 效 中 断 物 理 地 址 OS Cache or Main Memory Page Table Table walking
相 关 研 究 TLB 失 效 率 全 相 联, 层 次 式 两 级 TLB 页 表 结 构 MPT LPT HPT GPT CPT Table Walking 机 制 的 开 销 硬 件 软 件, 最 多 访 存 次 数, 与 Cache 的 关 系 大 虚 地 址 空 间 支 持 新 型 页 表, 支 持 多 种 页 大 小 稀 疏 空 间 使 用 的 支 持
请 求 页 式 管 理 与 存 储 保 护 请 求 页 式 管 理 (Demand Paging) 并 不 一 次 将 代 码 和 数 据 全 部 装 如 主 存 通 过 缺 页 中 断 保 证 程 序 可 以 正 常 的 运 行 存 储 保 护 页 表 中 的 权 限 位 使 得 CPU 和 OS 可 以 在 页 面 一 级 管 理 权 限 RWX 访 问 控 制 : 限 制 该 页 面 可 否 做 读 写 执 行 操 作 U(user): 限 制 该 页 面 可 否 由 用 户 态 程 序 访 问 辅 助 位 A(Access): 该 页 是 否 曾 被 访 问 过 M(Modify): 该 页 是 否 曾 被 改 变 过 ( 思 考, 辅 助 位 应 由 谁 设 置,MMU or OS?)
虚 拟 存 储 与 存 储 保 护 进 程 (process) vs. 线 程 (thread) 多 道 程 序 (multiprogramming) 进 程 切 换 (process switch) 操 作 系 统 和 硬 件 结 构 联 合 保 证 多 进 程 共 享 硬 件 资 源 多 进 程 互 不 影 响 对 体 系 结 构 的 要 求 至 少 两 种 运 行 模 式 :User,Kenel/Supervisor 提 供 用 户 进 程 只 读 的 处 理 器 状 态 提 供 模 式 转 换 机 制 提 供 限 制 存 储 访 问 的 机 制 保 护 用 户 进 程 存 储 状 态
Virtual Machine Protection via Virtual machine The increasing importance of isolation and security in modern systems The failures in security and reliability of standard operation systems The sharing of a single computer among many unrelated users The dramatic increases in raw speed of processors, which makes the overhead of VMs more acceptable
Virtual Machine Virtualization of Whole Machine A complete system-level environment at binary ISA level (Operating) System Virtual Machine Run different ISAs in the VM from native hardware
System Virtual Machine
Virtual machine 分 类
System Virtual Machine CPU Virtualization Memory Virtualization I/O virtualization
Virtual Machine ISA support Impact of Virtual machines on Virtual Memory and I/O Virtual memory Physical memory Machine memory Shadow page table/tlb The Xen Virtual machine
Virtual Machine Monitor Virtual machine monitor(vmm) or Hypervisor Managing software Managing hardware Requirements Guest software should behave on a VM exactly as if it were running on the native hardware, except for performance-related behavior or limitations of fixed resources shared by multiple VMs. Guest software should not be able to change allocation of real system At least two processor modes, system and user. A privileged subset of instructions that is available only in system mode, resulting in a trap if executed in user mode. All system resources must be controllable only via these instructions.
Cloud Computing