Chapter 7 Memory Organization
Chapter 7 Memory Organization
Sequential: Tape units have sequential access. Data are generally stored in units called
“records”. Data is accessed sequentially; the records may be passed (or rejected) until the record
that is searched is found.
Random: Each addressable location in memory has a unique addressing mechanism. The time to
access a given location is independent of the sequence of prior accesses and constant. Any
location can be selected at random and directly addressed and accessed. Main memory and cache
systems are random access.
Performance
Access time: For random-access memory, this is the time it takes to perform a read or write
operation: that is, the time from the instant that an address is presented to the memory to the
instant that data have been stored or made available for use. For nonrandom-access memory,
access time is the time it takes to position the read-write mechanism at the desired location.
Transfer rate: This is the rate at which data can be transferred into or out of a memory unit.
Physical Type
Physical Characteristics
Hit Ratio
The ratio of the total number of hits divided by the total CPU accesses to memory (i.e. hits plus
misses) is called Hit Ratio.
Hit Ratio = Total Number of Hits / (Total Number of Hits + Total Number of Miss)
Example
A system with 512 x 12 cache and 32 K x 12 of main memory.
P R E P A R E D H A F T O M P a g e 3 | 10
Figure 4.3: Hit Ratio
Types of Cache Mapping
Direct Mapping
Associative Mapping
Set Associative Mapping
Direct Mapping
The direct mapping technique is simple and inexpensive to implement.
When the CPU wants to access data from memory, it places an address. The index field of CPU
address is used to access address.
The tag field of CPU address is compared with the associated tag in the word read from the
cache.
If the tag-bits of CPU address is matched with the tag-bits of cache, then there is a hit and the
required data word is read from cache.
If there is no match, then there is a miss and the required data word is stored in main memory. It
is then transferred from main memory to cache memory with the new tag.
P R E P A R E D H A F T O M P a g e 4 | 10
Figure 7.4: Direct Mapping
Associative Mapping
An associative mapping uses an associative memory.
This memory is being accessed using its contents.
Each line of cache memory will accommodate the address (main memory) and the contents of
that address from the main memory.
That is why this memory is also called Content Addressable Memory (CAM). It allows each
block of main memory to be stored in the cache.
P R E P A R E D H A F T O M P a g e 5 | 10
Set Associative Mapping
That is the easy control of the direct mapping cache and the more flexible mapping of the fully
associative cache.
In set associative mapping, each cache location can have more than one pair of tag + data items.
That is more than one pair of tag and data are residing at the same location of cache memory. If
one cache location is holding two pair of tag + data items, that is called 2-way set associative
mapping.
First-In-First-Out (FIFO):
The FIFO algorithm selects for replacement the item that has been in the cache from the longest
time.
Least Frequently Used (LFU):
The LRU algorithm selects for replacement the item that has been least frequently used by the
CPU.
Random:
The random algorithm selects for replacement the item randomly.
Writing into Cache
P R E P A R E D H A F T O M P a g e 6 | 10
When memory write operations are performed, CPU first writes into the cache memory. These
modifications made by CPU during a write operation, on the data saved in cache, need to be
written back to main memory or to auxiliary memory.
These two popular cache write policies (schemes) are:
o Write-Through
o Write-Back
Write-Through
In a write through cache, the main memory is updated each time the CPU writes into cache.
The advantage of the write-through cache is that the main memory always contains the same data
as the cache contains.
This characteristic is desirable in a system which uses direct memory access scheme of data
transfer. The I/O devices communicating through DMA receive the most recent data.
Write-Back
In a write back scheme, only the cache memory is updated during a write operation.
The updated locations in the cache memory are marked by a flag so that later on, when the word
is removed from the cache, it is copied into the main memory.
The words are removed from the cache time to time to make room for a new block of words.
Virtual Memory
The term virtual memory refers to something which appears to be present but actually it is not.
The virtual memory technique allows users to use more memory for a program than the real
memory of a computer.
So, virtual memory is the concept that gives the illusion to the user that they will have main
memory equal to the capacity of secondary storage media.
Concept of Virtual Memory
A programmer can write a program which requires more memory space than the capacity of the
main memory. Such a program is executed by virtual memory technique.
The program is stored in the secondary memory. The memory management unit (MMU)
transfers the currently needed part of the program from the secondary memory to the main
memory for execution.
This to and from movement of instructions and data (parts of a program) between the main
memory and the secondary memory is called Swapping.
Address Space and Memory Space
Virtual address is the address used by the programmer and the set of such addresses is called the
address space or virtual memory.
An address in main memory is called a location or physical address. The set of such locations
in main memory is called the memory space or physical memory.
CPU generated logical address consisting of a logical page number plus the location within that
page (x).
It must be mapped onto an actual (physical) main memory address by the operating system using
mapper.
If the page is present in the main memory, CPU gets the required data from the main memory.
P R E P A R E D H A F T O M P a g e 7 | 10
If the mapper detects that the requested page is not present in main memory, a page fault occurs
and the page must be read from secondary storage (4, 5) into a page frame in main memory.
P R E P A R E D H A F T O M P a g e 8 | 10
Consider a paging system having capacity of 3 pages. The execution of a program requires
references to five distinct pages P1, P2, P3, P4 and P5. The pages are executed in the following
sequence:
P2 P3 P2 P1 P5 P2 P4 P5 P3 P2 P5 P2
P R E P A R E D H A F T O M P a g e 10 | 10