Memory L
Memory L
Memory L
Main Memory
Memory Hierarchy
DRAM vs. SRAM
•DRAM is short for Dynamic Random Access Memory
(M1) Cache
(M2)Main Memory
register file
ALU
I/O main
bus interface
bridge memory
Read Operation
•On a read the CPU will first try to find the data in the cache, if it is not there
the cache will get updated from the main memory and then return the data to
the CPU.
Write Operation
Network
There are two types of main memory, Random Access Memory (RAM) and Read
Only Memory (ROM)
5. Cache memory
• Small amount of memory typically 256 or 512 kilobytes
• Temporary store for often used instructions
• Level 1 cache is built within the CPU (internal)
• Level 2 cache may be on chip or nearby (external)
• Faster for CPU to access than main memory
Types of RAM
6. Video Random Access memory
• Holds data to be displayed on computer screen
• Has two data paths allowing READ and WRITE to occur at the same time
• A system’s amount of VRAM relates to the number of colours and resolution
• A graphics card may have its own VRAM chip on board
7. Virtual memory
• Uses backing storage e.g. hard disk as a temporary location for programs
and data where insufficient RAM available
• Swaps programs and data between the hard-disk and RAM as the CPU
requires them for processing
• A cheap method of running large or many programs on a computer system
• Cost is speed: the CPU can access RAM in nanoseconds but hard-disk in
milliseconds (Note: a millisecond is a thousandth of a second)
• Virtual memory is much slower than RAM
Locality Of reference
• 90-10 rule: A typical Programe may spend 90%
of its execution time on only 10% on code.
• Temporal
• Spatial
• sequential
• Principle of Locality:
Locality
– Programs tend to reuse data and instructions near those they
have used recently, or that were recently referenced
themselves.
– Temporal locality: Recently referenced items are likely to be
referenced in the near future.
– Spatial locality: Items with nearby addresses tend to be
referenced close together in time.
Memory Capacity Planning
• Hit Ratio
• Effective access time
• Cost of memory hierarchy
Page replacement algorithm
• FIFO
• Optimal PR
• LRU
• LFU
• MFU
Page Replacement Algorithms
• So, when we have a page fault we have to find
an eviction candidate.
• Optimally, we would like to evict the page that
will not be referenced again for the longest
amount of time.
– In reality the OS has no way of knowing when
each of the pages will be referenced next.
Not Recently Used
• Examine M and R bits associated with each page.
• Page fault occurs, OS places all pages in 1 or 4
classifications
– Class 0: R=0, M=0
– Class 1: R=0, M=1
– Class 2: R=1, M=0
– Class 3: R=1, M=1
• NRU Algorithm says to remove a page at random
from the lowest nonempty class.
FIFO
• Simple design of having a queue maintained for
pages in memory.
• The head of the queue contains oldest page in
memory.
• The tail of the queue contains the newest page in
memory.
• Is there a potential problem with evicting the head of
the queue each time?
Optimal Page-Replacement Algorithm
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
37
Optimal algorithm
• Belady's anomaly led to the search for an optimal page replacement algorithm
– optimal algorithm will have the lowest page fault rate
– optimal algorithm will never suffer from Belady's anomaly
OPT: select as victim the page that will not be used for the longest time
same reference string requires only 9 page faults (compared with 15 for FIFO)
38
Virtual Memory
Virtual memory
• memory management allows us a logical view of memory that is
consistent with the program creation process
40
Virtual space > physical space
• logical address space can be much larger than physical address space
– an application is allocated a large virtual address space
– multiple jobs can share the same physical space, each with its own larger
virtual space
– requires (hardware) translation of virtual address to physical address
– the virtual address space can be continuous or segmented
41
Caches
• Cache: A smaller, faster storage device that acts as a staging
area for a subset of the data in a larger, slower device.
• Fundamental idea of a memory hierarchy:
– For each k, the faster, smaller device at level k serves as a cache
for the larger, slower device at level k+1.
• Why do memory hierarchies work?
– Programs tend to access the data at level k more often than they
access the data at level k+1.
– Thus, the storage at level k+1 can be slower, and thus larger and
cheaper per bit.
– Net effect: A large pool of memory that costs as much as the
cheap storage near the bottom, but that serves data to programs
at the rate of the fast storage near the top.
Write Policy:
Write-Through vs Write-Back
• Write-through: all writes update cache and underlying
memory/cache
– Can always discard cached data - most up-to-date data is in memory
– Cache control bit: only a valid bit
• Write-back: all writes simply update cache
– Can’t just discard cached data - may have to write it back to memory
– Cache control bits: both valid and dirty bits
• Other Advantages:
– Write-through:
• memory (or other processors) always have latest data
• Simpler management of cache
– Write-back:
• much lower bandwidth, since data often overwritten multiple times
• Better tolerance to long-latency memory?
Read only memory (ROM)
ROM holds programs and data permanently even when computer is switched off
Data can be read by the CPU in any order so ROM is also direct access
Stores a program called the bootstrap loader that helps start up the computer