Preuzmite Computer Memory Lecture notes i više Skripte u PDF od Informatika samo na Docsity!
Chapter 6
Memory
6.1 Introduction
(^) Memory lies at the heart of the stored-program
computer.
(^) In previous chapters, we studied the
components from which memory is built and the
ways in which memory is accessed by various
ISAs.
(^) In this chapter, we focus on memory
organization. A clear understanding of these
ideas is essential for the analysis of system
performance.
6.2 Types of Memory
(^) SRAM consists of circuits similar to the D flip-flop that we studied in Chapter 3.
(^) SRAM is very fast memory and it doesn’t need to be refreshed like DRAM does. It is used to build cache memory, which we will discuss in detail later.
(^) ROM also does not need to be refreshed, either. In fact, it needs very little charge to retain its memory.
(^) ROM is used to store permanent, or semi- permanent data that persists even while the system is turned off.
6.3 The Memory Hierarchy
(^) Generally speaking, faster memory is more expensive than slower memory.
(^) To provide the best performance at the lowest cost, memory is organized in a hierarchical fashion.
(^) Small, fast storage elements are kept in the CPU, larger, slower main memory is accessed through the data bus.
(^) Larger, (almost) permanent storage in the form of disk and tape drives is still further from the CPU.
6.3 The Memory Hierarchy
(^) To access a particular piece of data, the CPU first sends a request to its nearest memory, usually cache.
(^) If the data is not in cache, then main memory is queried. If the data is not in main memory, then the request goes to disk.
(^) Once the data is located, then the data, and a number of its nearby data elements are fetched into cache memory.
6.3 The Memory Hierarchy
(^) This leads us to some definitions.
(^) A hit is when data is found at a given memory level.
(^) A miss is when it is not found.
(^) The hit rate is the percentage of time data is found at a given memory level.
(^) The miss rate is the percentage of time it is not.
(^) Miss rate = 1 - hit rate.
(^) The hit time is the time required to access data at a given memory level.
(^) The miss penalty is the time required to process a miss, including the time that it takes to replace a block of memory plus the time it takes to deliver the data to the processor.
6.4 Cache Memory
(^) The purpose of cache memory is to speed up accesses by storing recently used data closer to the CPU, instead of storing it in main memory.
(^) Although cache is much smaller than main memory, its access time is a fraction of that of main memory.
(^) Unlike main memory, which is accessed by address, cache is typically accessed by content; hence, it is often called content addressable memory.
(^) Because of this, a single large cache memory isn’t always desirable-- it takes longer to search.
6.4 Cache Memory
(^) The “content” that is addressed in content addressable cache memory is a subset of the bits of a main memory address called a field.
(^) The fields into which a memory address is divided provide a many-to-one mapping between larger main memory and the smaller cache memory.
(^) Many blocks of main memory map to a single block of cache. A tag field in the cache block distinguishes one cached memory block from another.
6.4 Cache Memory
(^) The diagram below is a schematic of what cache looks like.
(^) Block 0 contains multiple words from main memory, identified with the tag 00000000. Block 1 contains words identified with the tag 11110101.
(^) The other two blocks are not valid.
6.4 Cache Memory
(^) The size of each field into which a memory address is divided depends on the size of the cache.
(^) Suppose our memory consists of 2^14 words, cache has 16 = 2^4 blocks, and each block holds 8 words. - (^) Thus memory is divided into 214 / 2 8 = 2^11 blocks.
(^) For our field sizes, we know we need 4 bits for the block, 3 bits for the word, and the tag is what’s left over:
6.4 Cache Memory
(^) If subsequently the program generates the address 1AB , it will find the data it is looking for in block 0101 , word 011.
(^) However, if the program generates the address, 3AB , instead, the block loaded for address 1AA would be evicted from the cache, and replaced by the blocks associated with the 3AB reference.
6.4 Cache Memory
(^) Suppose a program generates a series of memory references such as: 1AB, 3AB, 1AB, 3AB ,... The cache will continually evict and replace blocks.
(^) The theoretical advantage offered by the cache is lost in this extreme case.
(^) This is the main disadvantage of direct mapped cache.
(^) Other cache mapping schemes are designed to prevent this kind of thrashing.
6.4 Cache Memory
(^) Suppose, as before, we have 14-bit memory addresses and a cache with 16 blocks, each block of size 8. The field format of a memory reference is:
(^) When the cache is searched, all tags are searched in parallel to retrieve the data quickly.
(^) This requires special, costly hardware.
6.4 Cache Memory
(^) You will recall that direct mapped cache evicts a block whenever another memory reference needs that block.
(^) With fully associative cache, we have no such mapping, thus we must devise an algorithm to determine which block to evict from the cache.
(^) The block that is evicted is the victim block.
(^) There are a number of ways to pick a victim, we will discuss them shortly.