Memory Organization
Memory Organization
The primary technology used for the main memory is based on semiconductor
integrated circuits. The integrated circuits for the main memory are classified into
two major units.
The dynamic RAM exhibits the binary information in the form of electric charges that
are applied to capacitors. The capacitors are integrated inside the chip by MOS
transistors. The dynamic RAM consumes less power and provides large storage
capacity in a single memory chip.
RAM chips are available in a variety of sizes and are used as per the system requirement.
The following block diagram demonstrates the chip interconnection in a 128 * 8 RAM
chip.
o A 128 * 8 RAM chip has a memory capacity of 128 words of eight bits (one byte)
per word. This requires a 7-bit address and an 8-bit bidirectional data bus.
o The 8-bit bidirectional data bus allows the transfer of data either from memory
to CPU during a read operation or from CPU to memory during
a write operation.
o The read and write inputs specify the memory operation, and the two chip
select (CS) control inputs are for enabling the chip only when the
microprocessor selects it.
o The bidirectional data bus is constructed using three-state buffers.
o The output generated by three-state buffers can be placed in one of the three
possible states which include a signal equivalent to logic 1, a signal equal to
logic 0, or a high-impedance state.
ROM integrated circuit
The primary component of the main memory is RAM integrated circuit chips, but a
portion of memory may be constructed with ROM chips.
A ROM memory is used for keeping programs and data that are permanently resident
in the computer.
Apart from the permanent storage of data, the ROM portion of main memory is needed for
storing an initial program called a bootstrap loader. The primary function of the bootstrap
loader program is to start the computer software operating when power is turned on.
ROM chips are also available in a variety of sizes and are also used as per the system
requirement. The following block diagram demonstrates the chip interconnection in a
512 * 8 ROM chip.
o A ROM chip has a similar organization as a RAM chip. However, a ROM can only
perform read operation; the data bus can only operate in an output mode.
o The 9-bit address lines in the ROM chip specify any one of the 512 bytes stored
in it.
o The value for chip select 1 and chip select 2 must be 1 and 0 for the unit to
operate. Otherwise, the data bus is said to be in a high-impedance state
Types of DRAM :
There are mainly 5 types of DRAM:
1. Asynchronous DRAM (ADRAM) –
The DRAM described above is the asynchronous type DRAM. The timing of the
memory device is controlled asynchronously. A specialized memory controller
circuit generates the necessary control signals to control the timing. The CPU
must take into account the delay in the response of the memory.
CACHE MEMORY
Cache Memory is a special very high-speed memory. It is used to speed up and
synchronize with high-speed CPU. Cache memory is costlier than main memory or disk
memory but more economical than CPU registers. Cache memory is an extremely fast
memory type that acts as a buffer between RAM and the CPU. It holds frequently requested
data and instructions so that they are immediately available to the CPU when needed. Cache
memory is used to reduce the average time to access data from the Main memory. The
cache is a smaller and faster memory that stores copies of the data from frequently used
main memory locations. There are various different independent caches in a CPU, which
store instructions and
data.
Cache Performance: When the processor needs to read or write a location in main
memory, it first checks for a corresponding entry in the cache.
• If the processor finds that the memory location is in the cache, a cache hit has
occurred and data is read from the cache.
• If the processor does not find the memory location in the cache, a cache
miss has occurred. For a cache miss, the cache allocates a new entry and copies
in data from main memory, then the request is fulfilled from the contents of the
cache.
The performance of cache memory is frequently measured in terms of a quantity called Hit
ratio.
Hit ratio(H) = hit / (hit + miss) = no. of hits/total accesses
Miss ratio = miss / (hit + miss) = no. of miss/total accesses = 1 - hit ratio(H)
We can improve Cache performance using higher cache block size, and higher
associativity, reduce miss rate, reduce miss penalty, and reduce the time to hit in the
cache.
Cache Mapping: There are three different types of mapping used for the purpose of cache
memory which is as follows: Direct mapping, Associative mapping, and Set-Associative
mapping. These are explained below.
A. Direct Mapping
The simplest technique, known as direct mapping, maps each block of main memory into
only one possible cache line. or In Direct mapping, assign each memory block to a specific
line in the cache. If a line is previously taken up by a memory block when a new block
needs to be loaded, the old block is trashed. An address space is split into two parts index
field and a tag field. The cache is used to store the tag field whereas the rest is stored in
the main memory. Direct mapping`s performance is directly proportional to the Hit ratio.
1. For purposes of cache access, each main memory address can be viewed as
consisting of three fields. The least significant w bits identify a unique word or
byte within a block of main memory. In most contemporary machines, the
address is at the byte level. The remaining s bits specify one of the 2 s blocks of
main memory. The cache logic interprets these s bits as a tag of s-r bits (most
significant portion) and a line field of r bits. This latter field identifies one of the
m=2r lines of the cache. Line offset is index bits in the direct mapping.
B. Associative Mapping
In this type of mapping, the associative memory is used to store content and addresses of
the memory word. Any block can go into any line of the cache. This means that the word id
bits are used to identify which word in the block is needed, but the tag becomes all of the
remaining bits. This enables the placement of any word at any place in the cache memory.
It is considered to be the fastest and the most flexible mapping form. In associative
mapping the index bits are zero.
C. Set-associative Mapping
This form of mapping is an enhanced form of direct mapping where the drawbacks of
direct mapping are removed. Set associative addresses the problem of possible thrashing
in the direct mapping method. It does this by saying that instead of having exactly one line
that a block can map to in the cache, we will group a few lines together creating a set.
Then a block in memory can map to any one of the lines of a specific set. Set-associative
mapping allows that each word that is present in the cache can have two or more words in
the main memory for the same index address. Set associative cache mapping combines
the best of direct and associative cache mapping techniques. In set associative mapping
the index bits are given by the set offset bits. In this case, the cache consists of a number
of sets, each of which consists of a number of lines. The relationships are
A few instructions in the localized areas in memory are executed repeatedly for some time duration and
other instructions are accessed infrequently. This phenomenon is known as the property of locality of
reference.
There are two dimensions of the locality of reference property: temporal and spatial.
1. Spatial Locality of reference This says that there is a chance that the element
will be present in close proximity to the reference point and next time if again
searched then more close proximity to the point of reference.
2. Temporal Locality of reference In this Least recently used algorithm will be
used. Whenever there is page fault occurs within a word will not only load word
in main memory but complete page fault will be loaded because the spatial
locality of reference rule says that if you are referring to any word next word will
be referred to in its register that’s why we load complete page table so the
complete block will be loaded.
Parts of programs and data are brought into main memory from secondary memory, as the CPU needs
them. Virtual memory is a technique used in some large computer systems, which gives the programmer
an illusion of having a large main memory, although which may not be the case. The size of
virtual memory is equivalent to the size of secondary memory. Each address referenced by the CPU
called the virtual (logical) address is mapped to a physical address in main memory. This mapping is
done during run-time and is performed by a hardware device called memory-management unit (MMU)
with the help of a memory map table, which is maintained by the operating system.
The virtual memory makes the task of programming much easier, because the programmer no
longer needs to bother about the amount of physical memory available. For example, a program size
is 18 MB and the available user part of the main memory is 15 MB (Other part of the main memory is
occupied by the operating system). First, 15 MB of the program is loaded into main memory and then
remaining 3 MB is still in the secondary memory. When the remaining 3 MB code is needed for
execution, swap out the 3 MB code from main memory to secondary memory and swap in new 3 MB
code from secondary memory to main memory.
The advantage of virtual memory is efficient utilization of main memory, because the larger size
program is divided into blocks and partially each block is loaded in the main memory whenever it is
required. Thus, multiple programs can be executed simultaneously. The technique of virtual memory
has other advantages of efficient CPU utilization and improved throughput.
Logical (Virtual) Address Space and Physical Address Space When a program needs to be
executed, the CPU would generate addresses called logical addresses. The corresponding addresses in
the physical memory, as occupied by the executing program, are called physical addresses. The set of
all logical addresses generated by the CPU or program is called logical-address space and the set of
all physical addresses corresponding to these logical addresses is called physical-address space. The
memory-management unit (MMU) maps each logical address to a physical address during program
execution. The Fig. 4.30 illustrates this mapping method, which uses a special register called base
register or relocation register. The content of the relocation register is added to every logical address
generated by the user program at the beginning of execution. For example, if the relocation register
holds an address value 2000, then a reference to the location 0 by the user is dynamically relocated to
2000 address. A reference to the address 150 is mapped to the address 2150.
Paging
Paging is a memory management scheme that eliminates the need for contiguous
allocation of physical memory. The process of retrieving processes in the form of pages
from the secondary storage into the main memory is known as paging. The basic purpose
of paging is to separate each procedure into pages. Additionally, frames will be used to
split the main memory. This scheme permits the physical address space of a process to be
non – contiguous.
Features of paging:
1. Mapping logical address to physical address.
2. Page size is equal to frame size.
3. Number of entries in a page table is equal to number of pages in logical
address space.
4. The page table entry contains the frame number.
5. All the page table of the processes are placed in main memory.
Example:
• If Logical Address = 31 bit, then Logical Address Space = 231 words = 2 G
words (1 G = 230)
• If Logical Address Space = 128 M words = 27 * 220 words, then Logical Address
= log2 227 = 27 bits
• If Physical Address = 22 bit, then Physical Address Space = 222 words = 4 M
words (1 M = 220)
• If Physical Address Space = 16 M words = 24 * 220 words, then Physical
Address = log2 224 = 24 bits
The mapping from virtual to physical address is done by the memory management unit
(MMU) which is a hardware device and this mapping is known as paging technique.
• The Physical Address Space is conceptually divided into a number of fixed-size
blocks, called frames.
• The Logical address Space is also splitted into fixed-size blocks, called pages.
• Page Size = Frame Size
Let us consider an example:
• Physical Address = 12 bits, then Physical Address Space = 4 K words
• Logical Address = 13 bits, then Logical Address Space = 8 K words
• Page size = frame size = 1 K words (assumption)
Address generated by CPU is divided into
• Page number(p): Number of bits required to represent the pages in Logical
Address Space or Page number
• Page offset(d): Number of bits required to represent particular word in a page
or page size of Logical Address Space or word number of a page or page
offset.
Physical Address is divided into
• Frame number(f): Number of bits required to represent the frame of Physical
Address Space or Frame number.
• Frame offset(d): Number of bits required to represent particular word in a
frame or frame size of Physical Address Space or word number of a frame or
frame offset.
The hardware implementation of page table can be done by using dedicated registers.
But the usage of register for the page table is satisfactory only if page table is small. If
page table contain large number of entries then we can use TLB(translation Look-aside
buffer), a special, small, fast look up hardware cache.
• The TLB is associative, high speed memory.
• Each entry in TLB consists of two parts: a tag and a value.
• When this memory is used, then an item is compared with all tags
simultaneously. If the item is found, then corresponding value is returned.
Paging is a memory management technique used in operating systems to manage
memory and allocate memory to processes. In paging, memory is divided into fixed-size
blocks called pages, and processes are allocated memory in terms of these pages. Each
page is of the same size, and the size is typically a power of 2, such as 4KB or 8KB.
In paging, the physical memory is divided into fixed-size blocks called page frames, which
are the same size as the pages used by the process. The process’s logical address space
is also divided into fixed-size blocks called pages, which are the same size as the page
frames. When a process requests memory, the operating system allocates one or more
page frames to the process and maps the process’s logical pages to the physical page
frames.
The mapping between logical pages and physical page frames is maintained by the page
table, which is used by the memory management unit to translate logical addresses into
physical addresses. The page table maps each logical page number to a physical page
frame number.
1. First In First Out (FIFO): This is the simplest page replacement algorithm. In this
algorithm, the operating system keeps track of all pages in the memory in a queue, the
oldest page is in the front of the queue. When a page needs to be replaced page in the
front of the queue is selected for removal.
Example 1: Consider page reference string 1, 3, 0, 3, 5, 6, 3 with 3 page [Link] the
number of page faults.
Initially, all slots are empty, so when 1, 3, 0 came they are allocated to the empty slots —
> 3 Page Faults.
when 3 comes, it is already in memory so —> 0 Page Faults. Then 5 comes, it is not
available in memory so it replaces the oldest page slot i.e 1. —>1 Page Fault. 6 comes, it
is also not available in memory so it replaces the oldest page slot i.e 3 —>1 Page
Fault. Finally, when 3 come it is not available so it replaces 0 1 page fault.
Belady’s anomaly proves that it is possible to have more page faults when increasing the
number of page frames while using the First in First Out (FIFO) page replacement
algorithm. For example, if we consider reference strings 3, 2, 1, 0, 3, 2, 4, 3, 2, 1, 0, 4,
and 3 slots, we get 9 total page faults, but if we increase slots to 4, we get 10-page faults.
2. Optimal Page replacement: In this algorithm, pages are replaced which would not be
used for the longest duration of time in the future.
Example-2: Consider the page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4 page
frame. Find number of page fault.
Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page
faults
0 is already there so —> 0 Page fault. when 3 came it will take the place of 7 because it is
not used for the longest duration of time in the future.—>1 Page fault. 0 is already there
so —> 0 Page fault. 4 will takes place of 1 —> 1 Page Fault.
Now for the further page reference string —> 0 Page fault because they are already
available in the memory.
Optimal page replacement is perfect, but not possible in practice as the operating system
cannot know future requests. The use of Optimal Page replacement is to set up a
benchmark so that other replacement algorithms can be analyzed against it.
3. Least Recently Used: In this algorithm, page will be replaced which is least recently
used.
Example-3: Consider the page reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4
page frames. Find number of page faults.
Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4 Page
faults
0 is already their so —> 0 Page fault. when 3 came it will take the place of 7 because it is
least recently used —>1 Page fault
0 is already in memory so —> 0 Page fault.
4 will takes place of 1 —> 1 Page Fault
Now for the further page reference string —> 0 Page fault because they are already
available in the memory.