Memory Hierarchy: Types, Design, and Characteristics

Memory-Hierarchy-Feature-Image.jpg

The memory hierarchy of modern computing affects system performance by bridging the speed gap between the CPU and all storage devices via organized memory levels. Memory levels also range from fast registers to magnetic tape. Every level has its own design and structure, and better performance from both hardware and software will come from understanding the memory hierarchy of your system. In this article, we will discuss the memory hierarchy, the importance of memory hierarchy, types of memory hierarchy, memory hierarchy design, characteristics of memory hierarchy, advantages and disadvantages of memory hierarchy, and system-supported standards for memory hierarchy.

Table of Contents: 

What is Memory Hierarchy?

Memory hierarchy is the structured arrangement of different types of storage in a computer system based on speed, cost, and capacity. It is designed to balance performance and cost by organizing memory from the fastest and most expensive but smallest to the slowest and cheapest but largest. The main goal of the memory hierarchy is to provide the illusion of a very large, fast, and affordable memory system.

Why is a Memory Hierarchy Required in the System?

The role of the memory hierarchy will help to bridge the gap between the faster CPU and the slower memory elements. Since high efficiency memory (faster memory) is more costly and has limited size, and low efficiency memory (slower memory) is less expensive but has high capacity, memory hierarchy makes it possible for systems to work effectively with high efficiency memory for those data elements that are accessed easily and utilize low efficiency memory to store data elements that are less frequently used.

The reasons for the memory hierarchy are:

  • Improved system performance
  • Cost efficiency 
  • Better resource management
  • Reduced CPU idle time

Types of Memory Hierarchy

There are two memory hierarchies, internal memory and external memory, which are typically divided based on speed, cost, and performance of the CPU. Let’s discuss both of them briefly.

1. Internal Memory

The internal memory is simply referred to as the memory units that can be accessed directly by the CPU. These are fast, volatile, and used in immediate data processing and execution. Internal memory typically consists of registers, cache, and RAM. The operating system maintains and uses the internal memory for the immediate execution of programs and the immediate switching of tasks.

2. External Memory

The external memory is also known as the secondary memory and is not directly accessible by the CPU. It provides non-volatile, long-term storage for programs and files. Flash memory, hard drives, and magnetic tapes come under the external memory. It is used to store the files, backups, and system images.

Memory Hierarchy Design

Memory hierarchy is typically divided into several levels, each having different roles, speed, cost, and capacity.

Memory Hierarchy Design

1. Registers

Registers are the smallest and fastest type of memory, which are located within the CPU. They are used to store data, instructions, and addresses temporarily during the execution. Registers are used to hold the operands for processing and the results from the calculations. Due to the speed of the registers, the CPU can access them instantly and easily. However, registers have limited capacity, typically only a few bytes. Examples are the accumulator, the program counter, and the instruction register.

The key features of the registers are:

Feature Description
Location Within the CPU
Speed Fastest memory available
Access Time 1 CPU clock cycle (typically nanoseconds or less)
Capacity Very limited (typically 32 to 256 registers per CPU core)
Volatility Volatile means the data in the registers is lost when power is off
Cost Highest cost per bit

2. Cache Memory

Cache memory is a small and high-speed memory located close to or inside the CPU. It acts as a buffer between the CPU and the main memory (RAM) for storing the frequently accessed data and the instructions to speed up the processing. Caches are typically organized in levels (L1, L2, L3), with L1 being the fastest and closest to the CPU. A cache significantly improves the overall system performance by minimizing the memory access delays.

The key features of the cache memory are:

Feature Description
Location On or near the CPU chip (L1-L3)
Speed Faster than RAM, slower than registers
Access Time 1 to 10 nanoseconds
Capacity Small
Volatility Volatile
Cost High cost per bit. But it is less than the cost of registers
Choose Your Path: Backend, Full Stack, DevOps & More.
Enroll in the Software Development Course!
quiz-icon

3. Main Memory (RAM)

Main Memory (RAM) is the primary storage that stores the data and programs currently in use by the CPU. It is volatile memory, which is why all the data is lost when the system is powered off. RAM offers fast access compared to secondary storage, enabling smooth execution of tasks. It works as a bridge between the CPU and slower storage devices like hard drives. Also, there are two types of main memory, Static RAM and Dynamic RAM.

The key features of the main memory are:

Feature Description
Type Volatile memory
Location Directly connected to the CPU via the memory bus
Speed Slower than cache, faster than secondary storage
Access Time Typically, in the range of tens to hundreds of nanoseconds
Capacity Moderate to large (commonly 4 GB to 64+ GB in modern systems)
Cost per Bit Moderate, cheaper than cache, more expensive than disk storage
Function Stores data and programs currently being executed

4. Flash Memory

Flash memory is a type of non-volatile storage that retains data even when the power is turned off. It is commonly used in Solid-State Drives (SSDs), USB drives, memory cards, and embedded systems.

The key features of the flash memory are:

Feature Description
Location External or internal storage (e.g., SSDs, USB drives)
Speed Faster than hard disks, slower than RAM
Access Time Microseconds
Capacity Moderate to large (GBs to TBs)
Volatility Non-volatile means it can retain data without power
Cost Moderate, but cheaper than RAM, costlier than hard disks

5. Magnetic Disks

Magnetic disks, such as hard disk drives (HDDs), are non-volatile storage devices used for long-term data storage. They store data magnetically on spinning platters and are widely used due to their large capacity and low cost. However, they are slower than flash memory due to mechanical movement during data access.

The key features of the magnetic disks are:

Feature Description
Location External or internal secondary storage
Speed Slower than flash memory and RAM
Access Time Milliseconds (due to mechanical movement)
Capacity Large (typically from hundreds of GBs to multiple TBs)
Volatility Non-volatile (retains data when power is off)
Cost Low (cheapest per bit among commonly used storage types)

6. Magnetic Tapes

Magnetic tapes are non-volatile memory that have sequential access storage devices primarily used for data backup and archival. They offer very high storage capacity at a low cost per bit. However, they are extremely slow compared to other storage types due to their linear read/write nature. Tapes are ideal for storing large volumes of data that are rarely accessed.

The key features of the magnetic tapes are:

Feature Description
Location External storage, typically used in data centers and archives
Speed Very slow (due to sequential access)
Access Time Several seconds (must wind to the correct position)
Capacity Very large (up to multiple terabytes per tape)
Volatility Non-volatile (data is retained without power)
Cost Very low (the cheapest cost per bit for large data storage)

Characteristics of Memory Hierarchy Design

1. Performance: The higher levels of memory hierarchy (registers, cache) offer better performance with lower latency. As data travels down the hierarchy, the access time of the data increases, but the cost per bit decreases.

2. Access Time: Access time is the time that is required to read from or write to a memory location. In the memory hierarchy, access time increases as we move from the top (fastest, smallest memory) to the bottom (slowest, largest memory).

  • Registers: Few nanoseconds
  • Cache: Tens of nanoseconds
  • RAM: Hundreds of nanoseconds
  • Disks: Milliseconds (HDDs), microseconds (SSDs)
  • Tapes: Seconds (due to accessing in sequence)

3. Capacity

Capacity increases as we move from registers to tapes. Lower levels offer much more space, but at the cost of slower access.

4. Cost Per Bit

Cost per bit decreases as we move from high-speed memory (registers, cache) to mass storage (disks, tapes). This gradient occurs so that we can achieve an efficient balance when we want to consider performance relative to the affordability of the technology. 

Get 100% Hike!

Master Most in Demand Skills Now!

System-Supported Memory Standards

Hierarchy Level Memory Type Standard/Protocol Description
Level 0 (L0) Registers CPU Architecture (e.g., x86, ARM ISA) Fastest, internal to CPU, no external standard
Level 1 (L1) Cache Memory CPU-defined (L1/L2/L3 Cache) On-chip SRAM speed varies by CPU design
Level 2 (L2) Main Memory (RAM) DDR3, DDR4, DDR5 Volatile DRAM, system main memory
Level 3 (L3) Flash Memory (SSD) NVMe (PCIe), SATA Non-volatile, faster with NVMe; slower with SATA
Level 4 (L4) Magnetic Disks (HDD) SATA, IDE (legacy) Slower mechanical storage, large capacity
Level 5 (L5) Magnetic Tapes LTO, SCSI Tape Very slow, sequential access, used for backup/archive
Auxiliary ROM / Firmware EEPROM, NOR Flash Non-volatile storage for BIOS/UEFI
Peripheral External Flash Storage USB 2.0/3.0/3.1, SD, CF Portable/removable non-volatile storage

Advantages of Memory Hierarchy

  • Memory hierarchy speeds up and makes the system more responsive.
  • It reduces the average memory access time.
  • Memory hierarchy optimizes the use of fast memory for the active processes.
  • It minimizes the cost through the selective use of expensive memory.
  • It supports multitasking and efficient CPU utilization.

Disadvantages of Memory Hierarchy

  • The design and management of the memory hierarchy in computer systems is too complex.
  • Due to different types of memory storage overhead in data transfer between levels occurs.
  • Cache misses in the memory processes can impact performance.
  • Due to the complex design, synchronization issues occur in multi-core systems.
  • It increases the hardware cost for a multi-tier architecture because it is difficult to maintain.

Conclusion

The importance of memory hierarchy in computational systems cannot be ignored for performance, capacity, and cost. With the help of a memory hierarchy, systems can arrange memory from ultra-fast registers to high-capacity magnetic tapes, allowing them the ability to store large quantities of data while providing quick access to the most frequently used data. Memory hierarchy, if used correctly, can create high-performance computing solutions. Thus, understanding it helps you know how it helps in increasing performance and making the system more responsive in this modern computing environment.

Memory Hierarchy Design and Characteristics – FAQs

Q1. What is memory hierarchy?

Memory hierarchy is a layered structure consisting of different memory types ordered in speed, cost, and size, in such a way as to achieve the best performance in a system.

Q2. Why is memory hierarchy important?

Memory hierarchy provides better performance for the system, and achieves a balance between speed and cost by using faster memory for already available information.

Q3. What are the levels of memory hierarchy?

The main levels of the hierarchy are: Registers, Cache, Main Memory (RAM), Flash Memory(SSD), Magnetic Disks (HDD), and Magnetic Tapes.

Q4. What is the fastest memory?

Registers are the fastest type of memory and are located inside the CPU with a nanosecond access time.

Q5. What is the difference between RAM and cache memory?

RAM is the main memory of the system(compared to cache memory), while cache memory is smaller and used to store frequently used data closer to the CPU with faster memory.

About the Author

Senior Consultant Analytics & Data Science, Eli Lilly and Company

Sahil Mattoo, a Senior Software Engineer at Eli Lilly and Company, is an accomplished professional with 14 years of experience in languages such as Java, Python, and JavaScript. Sahil has a strong foundation in system architecture, database management, and API integration. 

fullstack