Memory hierarchy describes how the computer organizes the memory devices based on their speed, size and cost per bit. The various memory devices we use to design a system are registers, cache memory, main memory, and magnetic disks. All these memories operate at different speeds and have different costs per bit.
Why Memory Hierarchy?
How much memory (size) of each kind will be enough to design a system is an open-ended question. Because as much memory will be available, the applications will develop to utilize the available memory space. So, memory size alone is not the constraint on which we can decide the memory hierarchy.
Our next constraint is speed. The performance of any system depends on how fast the processor can access any particular memory in the system. The faster the processor is able to access the memory, the faster it will execute the required instructions of the program or application. So speed is an important constraint that plays a vital role in deciding the memory hierarchy.
Now the last constraint is cost per bit. Although the system’s performance matters a lot, but if we think practically, the memory units must be cost-effective in relation to the other components of the computing devices, such as processors, motherboards, etc.
So, these three constraints, speed, cost, and size, go hand in hand while deciding the memory hierarchy.
The relationship between these three constraints is:
- Memory with the fastest access time has the greatest cost per bit.
- The memory with greater capacity has a slower access time.
- Memory with greater capacity has a smaller cost per bit.
Observing the above relationship between the constraints of memory devices, the designer can choose memory with greater capacity to satisfy the large memory requirement. The greater capacity memories are also cost-effective as their cost per bit is low.
However, to enhance the system’s performance, the designer has to choose faster memory in lower capacity to maintain the balance between the access time and the cost per bit of the memory.
Thus, a system designer must employ memory hierarchy instead of relying on a single component. We usually use the memory hierarchy to design a computer system with smaller, expensive, faster memories supplemented by larger, cheaper, and slower ones.
Memory devices in Memory Hierarchy
Registers are internal to the CPU. The system uses high-speed storage elements to store operands when they are brought into the processor. Registers are the smallest memory unit capable of storing one word of data.
Registers have the shortest access time compared to other memory units in the memory hierarchy. A processor can have several registers for different purposes; some common registers are:
- Instruction Registers – Holds the instruction currently in execution.
- Program Counter – Holds the memory address of the next instruction that the system has to fetch and execute.
- Accumulator – Holds temporary operands and the result of an ALU operation.
Although registers are at the top of the memory hierarchy, they only provide a small portion of the required memory.
Cache memory is next in the memory hierarchy after registers in terms of speed of access. It’sIt’s a small memory unit implemented directly on the processor chip. The system employs cache memory to hold copies of instructions and data recently being processed.
However, the system permanently stores the instructions and data in a much larger memory external to the processor. Now, when the processor requires the same set of recently used instructions, it can access the copy stored in cache memory instead of returning to the main memory.
Cache memory has an even shorter access time if compared to the main memory. Now even cache memory has two or more levels. The primary cache, or the Level 1 (L1) cache, is internal to the processor chip. However, the access time to the primary cache memory is comparable to the access time of registers.
The system designer places the secondary cache, i.e. Level 2 (L2) cache, between the L1 cache and main memory. Its access time is comparatively larger than the L1 cache. Even an L2 cache is implemented on the processor chip.
The tertiary cache or Level 3 L3 cache is somewhat larger than L1 and L2, and its access time is even larger than L1 and L2. The system places L3 between L2 and L3 cache. L3 cache may or may not be implemented on the processor chip.
Main memory, or primary memory, or RAM, is next in the memory hierarchy after cache memory. The main memory is a large dynamic memory implemented externally to the processor chip. The access time to the main memory can be 100 times longer as compared to the primary cache.
The magnetic disk is the secondary storage, and the designer employs disks in large amounts in a computer system. The magnetic disk has a longer access time as compared to other memory units in the memory hierarchy. Thus, the magnetic disk is present at the bottom of the memory hierarchy.
The magnetic tape has an even longer access time as compared to the magnetic disks. Thus, we place it at the bottom of the memory hierarchy. Magnetic tapes are portable, non-volatile secondary memory. It stores the programs and data files as files and records instead of bytes and words.
So far, we have discussed the concepts of the memory hierarchy and the motive behind organizing the memory devices in a hierarchy. Finally, we have discussed each of the memory devices with their features and characteristics. The hierarchical memory operates to bring the instructions and data closer to the processor that the processor will require shortly.