Computer Architecture Chapter 5: Memory Hierarchy Dr. Phạm Quốc Cường Adapted from Computer Organization the Hardware/Software Interface – 5th Computer Engineering – CSE – HCMUT 1 Principle of Locality • Programs access a small proportion of their address space at any time • Temporal locality – Items accessed recently are likely to be accessed again soon – e., instructions in a loop, induction variables • Spatial locality – Items near those accessed recently are likely to be accessed soon – E., sequential instruction access, array data Chapter 5 — Memory Hierarchy 2 Taking Advantage of Locality • Memory hierarchy • Store everything on disk • Copy recently accessed (and nearby) items from disk to smaller DRAM memory – Main memory • Copy more recently accessed (and nearby) items from DRAM to smaller SRAM memory – Cache memory attached to CPU Chapter 5 — Memory Hierarchy 3 Memory Hierarchy Levels • Block (aka line): unit of copying – May be multiple words • If accessed data is present in upper level – Hit: access satisfied by upper level • Hit ratio: hits/accesses • If accessed data is absent – Miss: block copied from lower level • Time taken: miss penalty • Miss ratio: misses/accesses = 1 – hit ratio – Then accessed data supplied from upper level Chapter 5 — Memory Hierarchy 4 Memory Technology • Static RAM (SRAM) – 0.5ns, $2000 – $5000 per GB • Dynamic RAM (DRAM) – 50ns – 70ns, $20 – $75 per GB • Flash Memory – 5s – 50s, $0.75 - $1 per GB • Magnetic disk – 5ms – 20ms, $0.20 – $2 per GB • Ideal memory – Access time of SRAM – Capacity and cost/GB of disk Chapter 5 — Memory Hierarchy 5 Cache Memory • Cache memory – The level of the Mem. hierarchy closest to the CPU • Given accesses X1, …, Xn–1, Xn • How do we know if the data is present? • Where do we look? Chapter 5 — Memory Hierarchy 6 Direct Mapped Cache • Location determined by address • Direct mapped: only one choice – (Block address) modulo (#Blocks in cache) • #Blocks is a power of 2 • Use low-order address bits Chapter 5 — Memory Hierarchy 7 Tags and Valid Bits • How do we know which particular block is stored in a cache location? – Store block address as well as the data – Actually, only need the high-order bits – Called the tag • What if there is no data in a location? – Valid bit: 1 = present, 0 = not present – Initially 0 Chapter 5 — Memory Hierarchy 8 Cache Example • 8-blocks, 1 word/block, direct mapped • Initial state Index V Tag Data 000 N 001 N 010 N 011 N 100 N 101 N 110 N 111 N Chapter 5 — Memory Hierarchy 9 Cache Example Word addr Binary addr Hit/miss Cache block 22 10 110 Miss 110 Index V Tag Data 000 N 001 N 010 N 011 N 100 N 101 N 110 Y 10 Mem[10110] 111 N Chapter 5 — Memory Hierarchy 10 Cache Example Word addr Binary addr Hit/miss Cache block 26 11 010 Miss 010 Index V Tag Data 000 N 001 N 010 Y 11 Mem[11010] 011 N 100 N 101 N 110 Y 10 Mem[10110] 111 N Chapter 5 — Memory Hierarchy 11 Cache Example Word addr Binary addr Hit/miss Cache block 22 10 110 Hit 110 26 11 010 Hit 010 Index V Tag Data 000 N 001 N 010 Y 11 Mem[11010] 011 N 100 N 101 N 110 Y 10 Mem[10110] 111 N Chapter 5 — Memory Hierarchy 12 Cache Example Word addr Binary addr Hit/miss Cache block 16 10 000 Miss 000 3 00 011 Miss 011 16 10 000 Hit 000 Index V Tag Data 000 Y 10 Mem[10000] 001 N 010 Y 11 Mem[11010] 011 Y 00 Mem[00011] 100 N 101 N 110 Y 10 Mem[10110] 111 N Chapter 5 — Memory Hierarchy 13 Cache Example Word addr Binary addr Hit/miss Cache block 18 10 010 Miss 010 Index V Tag Data 000 Y 10 Mem[10000] 001 N 010 Y 10 Mem[10010] 011 Y 00 Mem[00011] 100 N 101 N 110 Y 10 Mem[10110] 111 N Chapter 5 — Memory Hierarchy 14 Address Subdivision Chapter 5 — Memory Hierarchy 15 Example: Larger Block Size • 64 blocks, 16 bytes/block – To what block number does address 1200 map? • Block address = 1200/16 = 75 • Block number = 75 modulo 64 = 11 31 10 9 4 3 0 Tag Index Offset 22 bits 6 bits 4 bits Chapter 5 — Memory Hierarchy 16 Block Size Considerations • Larger blocks should reduce miss rate – Due to spatial locality • But in a fixed-sized cache – Larger blocks fewer of them • More competition increased miss rate – Larger blocks pollution • Larger miss penalty – Can override benefit of reduced miss rate – Early restart and critical-word-first can help Chapter 5 — Memory Hierarchy 17 Cache Misses • On cache hit, CPU proceeds normally • On cache miss – Stall the CPU pipeline – Fetch block from next level of hierarchy – Instruction cache miss • Restart instruction fetch – Data cache miss • Complete data access Chapter 5 — Memory Hierarchy 18 Write-Through • On data-write hit, could just update the block in cache – But then cache and memory would be inconsistent • Write through: also update memory • But makes writes take longer – e., if base CPI = 1, 10% of instructions are stores, write to memory takes 100 cycles • Effective CPI = 1 + 0.1×100 = 11 • Solution: write buffer – Holds data waiting to be written to memory – CPU continues immediately • Only stalls on write if write buffer is already full Chapter 5 — Memory Hierarchy 19 Write-Back • Alternative: On data-write hit, just update the block in cache – Keep track of whether each block is dirty • When a dirty block is replaced – Write it back to memory – Can use a write buffer to allow replacing block to be read first Chapter 5 — Memory Hierarchy 20 Write Allocation • What should happen on a write miss? • Alternatives for write-through – Allocate on miss: fetch the block – Write around: don’t fetch the block • Since programs often write a whole block before reading it (e., initialization) • For write-back – Usually fetch the block Chapter 5 — Memory Hierarchy 21 Example: Intrinsity FastMATH • Embedded MIPS processor – 12-stage pipeline – Instruction and data access on each cycle • Split cache: separate I-cache and D-cache – Each 16KB: 256 blocks × 16 words/block – D-cache: write-through or write-back • SPEC2000 miss rates – I-cache: 0.2% Chapter 5 — Memory Hierarchy 22 Example: Intrinsity FastMATH Chapter 5 — Memory Hierarchy 23 Main Memory Supporting Caches • Use DRAMs for main memory – Fixed width (e., 1 word) – Connected by fixed-width clocked bus • Bus clock is typically slower than CPU clock • Example cache block read – 1 bus cycle for address transfer – 15 bus cycles per DRAM access – 1 bus cycle per data transfer • For 4-word block, 1-word-wide DRAM – Miss penalty = 1 + 4×15 + 4×1 = 65 bus cycles – Bandwidth = 16 bytes / 65 cycles = 0.25 B/cycle Chapter 5 — Memory Hierarchy 24 Increasing Memory Bandwidth • 4-word wide memory - Miss penalty = 1 + 15 + 1 = 17 bus cycles - Bandwidth = 16 bytes / 17 cycles = 0.94 B/cycle • 4-bank interleaved memory - Miss penalty = 1 + 15 + 4×1 = 20 bus cycles - Bandwidth = 16 bytes / 20 cycles = 0.8 B/cycle Chapter 5 — Memory Hierarchy 25 Measuring Cache Performance • Components of CPU time – Program execution cycles • Includes cache hit time – Memory stall cycles • Mainly from cache misses • With simplifying assumptions: Memory accesses Memory stall cycles Miss rate Miss penalty Program Instructions Misses Miss penalty Program Instruction Chapter 5 — Memory Hierarchy 26 Cache Performance Example • Given – I-cache miss rate = 2% – D-cache miss rate = 4% – Miss penalty = 100 cycles – Base CPI (ideal cache) = 2 – Load & stores are 36% of instructions • Miss cycles per instruction – I-cache: 0.44 – Ideal CPU is 5.72 times faster Chapter 5 — Memory Hierarchy 27 Average Access Time • Hit time is also important for performance • Average memory access time (AMAT) – AMAT = Hit time + Miss rate × Miss penalty • Example – CPU with 1ns clock, hit time = 1 cycle, miss penalty = 20 cycles, I-cache miss rate = 5% – AMAT = 1 + 0.05 × 20 = 2ns • 2 cycles per instruction Chapter 5 — Memory Hierarchy 28 Performance Summary • When CPU performance increased – Miss penalty becomes more significant • Decreasing base CPI – Greater proportion of time spent on memory stalls • Increasing clock rate – Memory stalls account for more CPU cycles • Can’t neglect cache behavior when evaluating system performance Chapter 5 — Memory Hierarchy 29 Associative Caches • Fully associative – Allow a given block to go in any cache entry – Requires all entries to be searched at once – Comparator per entry (expensive) • n-way set associative – Each set contains n entries – Block number determines which set • (Block number) modulo (#Sets in cache) – Search all entries in a given set at once – n comparators (less expensive) Chapter 5 — Memory Hierarchy 30 Associative Cache Example Chapter 5 — Memory Hierarchy 31 Spectrum of Associativity • For a cache with 8 entries Chapter 5 — Memory Hierarchy 32 Associativity Example • Compare 4-block caches – Direct mapped, 2-way set associative, fully associative – Block access sequence: 0, 8, 0, 6, 8 • Direct mapped Block Cache Hit/miss Cache content after access address index 0 1 2 3 0 0 miss Mem[0] 8 0 miss Mem[8] 0 0 miss Mem[0] 6 2 miss Mem[0] Mem[6] 8 0 miss Mem[8] Mem[6] Chapter 5 — Memory Hierarchy 33 Associativity Example • 2-way set associative Block Cache Hit/miss Cache content after access address index Set 0 Set 1 0 0 miss Mem[0] 8 0 miss Mem[0] Mem[8] 0 0 hit Mem[0] Mem[8] 6 0 miss Mem[0] Mem[6] 8 0 miss Mem[8] Mem[6] • Fully associative Block Hit/miss Cache content after access address 0 miss Mem[0] 8 miss Mem[0] Mem[8] 0 hit Mem[0] Mem[8] 6 miss Mem[0] Mem[8] Mem[6] 8 hit Mem[0] Mem[8] Mem[6] Chapter 5 — Memory Hierarchy 34 How Much Associativity • Increased associativity decreases miss rate – But with diminishing returns • Simulation of a system with 64KB D-cache, 16-word blocks, SPEC2000 – 1-way: 10.
Chương 5: Cấu Trúc Bộ Nhớ Trong Kiến Trúc Máy Tính
Chuyên khảo phân tích Chapter 5 memory hierarchy, đánh giá các khía cạnh quan trọng, đề xuất hướng nghiên cứu tiếp theo., phục vụ nghiên cứu và ứng dụng thực tiễn
Trường đại học
Hồ Chí Minh University of TechnologyChuyên ngành
Computer EngineeringNgười đăng
Ẩn danhThể loại
EssayPhí lưu trữ
35 PointMục lục chi tiết
Tóm tắt
I. Tìm Hiểu Về Cấu Trúc Bộ Nhớ Trong Kiến Trúc Máy Tính
Cấu trúc bộ nhớ là một phần quan trọng trong kiến trúc máy tính. Nó ảnh hưởng đến hiệu suất và khả năng xử lý của hệ thống. Bộ nhớ được chia thành nhiều cấp độ khác nhau, mỗi cấp độ có tốc độ và dung lượng khác nhau. Việc hiểu rõ về cấu trúc này giúp tối ưu hóa hiệu suất máy tính.
1.1. Tổng Quan Về Cấu Trúc Bộ Nhớ
Cấu trúc bộ nhớ bao gồm nhiều loại bộ nhớ như RAM, ROM, và bộ nhớ cache. Mỗi loại có vai trò và chức năng riêng trong việc lưu trữ và truy xuất dữ liệu.
1.2. Các Loại Bộ Nhớ Trong Máy Tính
Các loại bộ nhớ chính bao gồm bộ nhớ tĩnh (SRAM), bộ nhớ động (DRAM), và bộ nhớ flash. Mỗi loại có ưu điểm và nhược điểm riêng, ảnh hưởng đến hiệu suất tổng thể của hệ thống.
II. Vấn Đề Và Thách Thức Trong Quản Lý Bộ Nhớ
Quản lý bộ nhớ là một thách thức lớn trong kiến trúc máy tính. Các vấn đề như độ trễ truy xuất, tỉ lệ lỗi và hiệu suất bộ nhớ cần được giải quyết để tối ưu hóa hoạt động của hệ thống.
2.1. Độ Trễ Truy Xuất Bộ Nhớ
Độ trễ truy xuất bộ nhớ ảnh hưởng trực tiếp đến hiệu suất của CPU. Việc tối ưu hóa độ trễ này là rất quan trọng để cải thiện tốc độ xử lý.
2.2. Tỉ Lệ Lỗi Trong Bộ Nhớ
Tỉ lệ lỗi trong bộ nhớ có thể dẫn đến mất dữ liệu và giảm hiệu suất. Các phương pháp như mã sửa lỗi (ECC) được sử dụng để giảm thiểu vấn đề này.
III. Phương Pháp Tối Ưu Hóa Cấu Trúc Bộ Nhớ
Có nhiều phương pháp để tối ưu hóa cấu trúc bộ nhớ trong máy tính. Việc áp dụng các kỹ thuật này có thể cải thiện hiệu suất và giảm thiểu độ trễ.
3.1. Sử Dụng Bộ Nhớ Cache Hiệu Quả
Bộ nhớ cache giúp tăng tốc độ truy xuất dữ liệu bằng cách lưu trữ các dữ liệu thường xuyên được sử dụng. Việc tối ưu hóa kích thước và chiến lược truy xuất cache là rất quan trọng.
3.2. Tối Ưu Hóa Quản Lý Bộ Nhớ
Quản lý bộ nhớ hiệu quả giúp giảm thiểu độ trễ và tăng cường hiệu suất. Các thuật toán quản lý bộ nhớ như LRU và FIFO được áp dụng để tối ưu hóa việc sử dụng bộ nhớ.
IV. Ứng Dụng Thực Tiễn Của Cấu Trúc Bộ Nhớ
Cấu trúc bộ nhớ có nhiều ứng dụng trong thực tiễn, từ máy tính cá nhân đến các hệ thống máy chủ lớn. Việc hiểu rõ về cấu trúc này giúp cải thiện hiệu suất và khả năng xử lý của các ứng dụng.
4.1. Ứng Dụng Trong Máy Tính Cá Nhân
Trong máy tính cá nhân, cấu trúc bộ nhớ ảnh hưởng đến tốc độ xử lý và khả năng đa nhiệm. Việc tối ưu hóa bộ nhớ giúp cải thiện trải nghiệm người dùng.
4.2. Ứng Dụng Trong Hệ Thống Máy Chủ
Trong các hệ thống máy chủ, cấu trúc bộ nhớ cần được tối ưu hóa để xử lý khối lượng công việc lớn. Việc sử dụng bộ nhớ cache và DRAM hiệu quả là rất quan trọng.
V. Kết Luận Về Cấu Trúc Bộ Nhớ Trong Kiến Trúc Máy Tính
Cấu trúc bộ nhớ là một yếu tố quan trọng trong kiến trúc máy tính. Việc hiểu rõ về các loại bộ nhớ và cách tối ưu hóa chúng sẽ giúp cải thiện hiệu suất hệ thống. Tương lai của công nghệ bộ nhớ hứa hẹn sẽ mang lại nhiều cải tiến đáng kể.
5.1. Tương Lai Của Công Nghệ Bộ Nhớ
Công nghệ bộ nhớ đang phát triển nhanh chóng với nhiều cải tiến về tốc độ và dung lượng. Các công nghệ mới như bộ nhớ 3D và bộ nhớ phi tập trung đang được nghiên cứu.
5.2. Tầm Quan Trọng Của Nghiên Cứu Về Bộ Nhớ
Nghiên cứu về cấu trúc bộ nhớ giúp phát triển các giải pháp mới cho các vấn đề hiện tại. Điều này sẽ đóng góp vào sự phát triển của công nghệ máy tính trong tương lai.
THÔNG TIN CHI TIẾT
Người hướng dẫn: Dr. Phạm Quốc Cường
Trường học: Hồ Chí Minh University of Technology
Chuyên ngành: Computer Engineering
Đề tài: Tìm Hiểu Về Cấu Trúc Bộ Nhớ Trong Kiến Trúc Máy Tính
Loại tài liệu: Essay
Năm xuất bản: 2023
Địa điểm: Hồ Chí Minh
Trích đoạn nội dung tài liệu
Nội dung được bảo vệ bản quyền — Tải xuống đầy đủ
Tài liệu Tìm Hiểu Về Cấu Trúc Bộ Nhớ Trong Kiến Trúc Máy Tính cung cấp cái nhìn sâu sắc về các thành phần và chức năng của bộ nhớ trong hệ thống máy tính. Nó giải thích cách mà bộ nhớ được tổ chức, từ bộ nhớ tạm thời (RAM) đến bộ nhớ vĩnh viễn (ROM), và vai trò của chúng trong việc xử lý dữ liệu. Độc giả sẽ hiểu rõ hơn về cách thức hoạt động của bộ nhớ, cũng như tầm quan trọng của nó trong hiệu suất của máy tính.
Bên cạnh đó, tài liệu này còn giúp người đọc nhận thức được các yếu tố ảnh hưởng đến tốc độ và hiệu quả của bộ nhớ, từ đó có thể áp dụng kiến thức này vào việc tối ưu hóa hệ thống máy tính của mình. Để mở rộng thêm kiến thức, bạn có thể tham khảo tài liệu 10 bộ nhớ máy tính giáo trình khtn, nơi cung cấp cái nhìn tổng quan về các loại bộ nhớ khác nhau và ứng dụng của chúng trong thực tế. Những thông tin này sẽ giúp bạn có cái nhìn toàn diện hơn về cấu trúc và chức năng của bộ nhớ trong kiến trúc máy tính.