Memory Organization
Explore computer memory organization, including memory hierarchy, SRAM and DRAM, ROM, auxiliary storage, associative memory, cache mapping and write policies, virtual memory, paging, segmentation, TLB address translation, and MMU-based memory protection.
Introduction
How can a computer execute billions of instructions per second, maintain terabytes of data, and switch seamlessly between dozens of applications—all without costing a fortune or running out of storage space? The secret lies in memory organization, an architectural masterpiece that blends high-speed physical components with ingenious software abstractions.
In this lesson, we will explore the complete landscape of computer memory systems as outlined in classic computer architecture:
- Analyze the structural and economic trade-offs across the memory hierarchy.
- Differentiate between SRAM, DRAM, ROM, and auxiliary storage devices like disks and tapes.
- Evaluate fast-access searching techniques using Associative Memory (CAM).
- Compare cache mapping procedures, write policies, and virtual memory address translations.
- Examine Memory Management Hardware (MMU), segmented-page mapping, and memory protection mechanism.
Memory Hierarchy
The memory unit is an essential component in any digital computer, serving as the central storage hub for programs and data. While a tiny single-purpose microcontroller might survive on a modest block of onboard memory, general-purpose computers demand vastly more capacity than a single memory device can supply. Most computer users accumulate massive software applications and large datasets—far more than can fit inside a computer's high-speed primary memory at one time.
Fortunately, a processor doesn't need access to all stored information simultaneously. It is far more economical to construct a memory hierarchy using devices of varying speeds, capacities, and costs:
- Cache Memory: A small, extremely fast memory built right near the CPU logic to store instructions and temporary data currently being executed. Its access time closely matches the processor's clock cycle.
- Main Memory: The central memory unit that communicates directly with the CPU and through an Input/Output (I/O) processor. It contains only the active programs and data needed right now.
- Auxiliary Memory: High-capacity, low-cost backup storage devices—primarily magnetic disks and magnetic tapes—used for storing long-term files, system software, and inactive programs.
Economic and Performance Dynamics
Why not build the entire computer out of super-fast cache memory? The answer boils down to economics and physics. As storage capacity increases, the cost per bit decreases, but access time becomes longer. Cache memory is very fast but small and expensive per bit; auxiliary memory is vast and inexpensive per bit but remarkably slow.
| Level | Relative Cost per Bit | Relative Access Speed | Typical Access Time | Block Transfer Size |
|---|---|---|---|---|
| Cache Memory | Highest | Highest | ~100 ns | 1 to 16 words |
| Main Memory | Moderate | Moderate | ~700 ns | 1 word |
| Auxiliary Memory | Lowest | Lowest | ~1,000x Main Memory | 256 to 2048 words |
Multiprogramming and Memory Management
In modern operating systems, multiprogramming enables the CPU to execute multiple independent programs concurrently. When one running program requests an I/O transfer from auxiliary memory, the CPU delegates that transfer to an I/O processor and immediately switches execution to another program sitting ready in main memory. The subsystem that supervises this seamless flow of active and inactive information between auxiliary memory and main memory is called the memory management system.
Main Memory
Main memory acts as the primary workbench for the CPU during active operation. It is predominantly constructed from semiconductor integrated circuit chips, divided into two key functional families: RAM (Random-Access Memory) and ROM (Read-Only Memory).
RAM Technologies: Static vs. Dynamic
In modern terminology, RAM refers specifically to read/write memory. It comes in two primary internal operating modes:
- Static RAM (SRAM): Consists internally of logic flip-flops that store binary state. Information remains valid as long as electrical power is applied. SRAM features shorter read/write cycles and easier interfacing, making it the premier choice for implementing cache memory.
- Dynamic RAM (DRAM): Stores binary information as electric charges on micro-capacitors inside MOS transistors. Because capacitors naturally discharge over time, DRAM requires periodic refreshing (cycling through memory words every few milliseconds). Despite this complexity, DRAM offers significantly reduced power consumption and vastly higher storage density per chip, making it ideal for main memory (e.g., SDRAM, multibank DRAM).
ROM and the Computer Startup Sequence
While RAM holds volatile user programs that disappear when power is cut, ROM stores permanent system routines. Crucially, ROM holds the bootstrap loader—the initial startup program executed when the computer is powered on.
When power is applied, hardware automatically initializes the Program Counter (PC) to the first address of the bootstrap loader in ROM. This routine reads a portion of the operating system from disk into RAM and transfers execution control to it.
Chip Structure and Control Signals
To allow multiple chips to share common system address and data buses, RAM and ROM chips utilize three-state buffers. Outputs can exist in logic 1, logic 0, or a high-impedance state (which behaves like an open circuit, disconnecting the output from the bus).
A typical RAM chip requires:
- 7 address lines ( bytes).
- 8-bit bidirectional data bus.
- Read () and Write () control inputs.
- Chip Select inputs ( and ): The chip is active only when and . Otherwise, the data bus is placed in high-impedance mode.
In contrast, a same-sized physical footprint for a ROM chip provides four times the capacity because internal ROM cells take less physical space than RAM flip-flops or charge circuits. ROM requires 9 address lines and operates in output-only mode during reads.
Memory Address Map Example
To assign memory addresses across multiple chips, engineers create a memory address map. Suppose a system requires 512 bytes of RAM (built with four chips) and 512 bytes of ROM (built with one chip):
- Address lines 1 to 7 select specific bytes inside the RAM chips.
- Address lines 1 to 9 select specific bytes inside the ROM chip.
- Address lines 8 and 9 connect to a decoder to select among the four RAM chips.
- Address line 10 selects between RAM () and ROM ().
Hexadecimal Range | Line 10 | Lines 9-8 | Lines 7-1 | Component
-------------------|---------|-----------|-----------|-----------
0000 - 007F | 0 | 0 0 | xxxxxxx | RAM 1
0080 - 00FF | 0 | 0 1 | xxxxxxx | RAM 2
0100 - 017F | 0 | 1 0 | xxxxxxx | RAM 3
0180 - 01FF | 0 | 1 1 | xxxxxxx | RAM 4
0200 - 03FF | 1 | x x | xxxxxxxxx | ROM
Auxiliary Memory
Auxiliary storage provides long-term, non-volatile memory capable of holding large program files and bulk datasets. The two dominant electromechanical auxiliary storage media are magnetic disks and magnetic tapes.
Key Performance Parameters
Regardless of physical design, auxiliary devices are evaluated using key logical characteristics:
- Access Time: The average time needed to reach a memory location and retrieve its content. For moving mechanical parts, access time consists of seek time (positioning the head over the desired track) plus transfer time (time taken to read data).
- Transfer Rate: The speed at which characters or words are transmitted per second after positioning is complete.
Magnetic Disks
A magnetic disk is a circular metal or plastic plate coated with magnetic material. Both sides of the disk are frequently coated, and multiple disks can be stacked on a single rotating spindle. Bits are recorded as microscopic magnetized spots along concentric circular tracks, which are subdivided into sectors.
- Hard Disks: Permanently mounted assemblies providing high density, fast rotation speeds, and massive storage capacity.
- Floppy Disks: Removable, flexible plastic disks enclosed in protective jackets (e.g., 3.5-inch formats historically used for software distribution).
- Constant Recording Density: Because outer tracks near the circumference are longer than inner tracks near the center, some systems equalize sector capacity by utilizing higher recording density on inner tracks.
Magnetic Tape
A magnetic tape system moves a plastic ribbon coated with magnetic material past stationary read/write heads. Typically, 7 or 9 bits (including a parity bit) are recorded simultaneously across the width of the tape to represent a character.
Because tape cannot stop or start instantaneously between individual characters, data is organized into blocks or records. Unrecorded areas called inter-record gaps are placed between records to allow the tape to accelerate to full constant speed before reaching data.
Associative Memory
In traditional RAM, finding a specific item requires searching sequentially or using complex search software algorithms. Associative Memory, also known as Content Addressable Memory (CAM), dramatically reduces search times by accessing stored items directly by their data content rather than by physical address.
Hardware Architecture
An associative memory consists of a memory array of words ( bits per word) paired with three specialized hardware registers:
- Argument Register (): Holds the bit pattern being searched for.
- Key Register (): Serves as a bitmask to specify which fields in the argument register should be compared (, ).
- Match Register (): Contains individual match bits (one per word in memory). A word that matches all unmasked bits sets its corresponding bit to
1.
Argument (A): 1 0 1 1 1 1 1 0 0
Key (K): 1 1 1 0 0 0 0 0 0 (Mask: compare only 3 leftmost bits)
--------------------------------------------------------------------
Word 1: 1 0 0 1 1 1 1 0 0 --> No Match (M1 = 0)
Word 2: 1 0 1 0 0 0 0 0 1 --> MATCH! (M2 = 1)
Cell Logic and Boolean Equations
Each internal cell contains a storage flip-flop and comparison logic. First, two bits and are equal if both are 1 or both are 0:
To account for the mask bit , we OR the expression with so that when , the term forces a logic 1 (no match penalty):
For a full word to match, all bits must produce a logic 1 through an -input AND gate:
Reading and Writing in CAM
To write data, CAM searches a tag register (which tracks active vs. inactive locations) to locate the first empty slot. During read operations, if multiple words match simultaneously, the system scans through the match register bits sequentially to read matched items one by one.
Cache Memory
Analysis of computer program execution reveals a fundamental property known as locality of reference: over short time intervals, memory references tend to be confined to localized address regions (e.g., program loops, subroutine calls, iterative counters, and array processing).
By placing a small, high-speed cache memory between the CPU and main memory, frequently accessed instructions and data can be delivered at near-processor speeds. Cache performance is measured by the hit ratio:
Real-world hit ratios frequently exceed , dropping average memory access time dramatically (e.g., reducing access time from down to when cache access is ).
Mapping Procedures
When the CPU requests a word, the virtual or physical address must be translated to check if the word is currently in cache. Three mapping techniques are widely used:
- Associative Mapping: Stores both the full memory address and data together inside associative cache memory. Any word from main memory can reside in any cache location. It is extremely flexible but requires expensive hardware registers.
- Direct Mapping: Divides a memory address into a Tag field and an Index field. The length of the Index field equals the address length of the cache memory ( words in cache index bits). When accessing memory, the index bits pick the cache line, and the stored tag is compared against the CPU address tag.
- Block Size > 1 Word: The index field is further divided into a Block field and a Word field so multi-word blocks transfer from main memory on a miss.
- Set-Associative Mapping: Combines direct and associative mapping. Each cache index points to a set containing tag-data pairs (e.g., a 2-way set associative cache stores two data words per index). This eliminates collision misses when two active memory locations share the same index address.
Replacement Algorithms
When a cache set is full and a miss occurs, a block must be evicted. Common replacement policies include:
- First-In, First-Out (FIFO): Replaces the item that has resided in the set the longest.
- Least Recently Used (LRU): Replaces the item that has gone unreferenced for the longest time.
- Random: Selects a target item randomly.
Cache Write Strategies & Initialization
- Write-Through: Updates main memory simultaneously with every cache write. Guarantees main memory always contains valid data, which is critical for DMA I/O operations.
- Write-Back: Updates only the cache entry during a write and sets a dirty flag. Main memory is updated only when the block is evicted from cache.
- Cache Initialization: At boot, all lines are cleared by setting a Valid Bit to
0. The valid bit transitions to1only when valid blocks are fetched from main memory.
Virtual Memory
Virtual Memory gives programmers the illusion that the system possesses a vast main memory space equal to the full capacity of auxiliary memory. Hardware and software dynamically translate program-generated addresses into actual physical main memory locations while programs run.
Address Space vs. Memory Space
- Virtual Address (Address Space ): An address generated by software programs.
- Physical Address (Memory Space ): An actual location inside main memory.
For example, if auxiliary storage holds words and main memory holds words, the virtual address requires 20 bits while the physical memory address requires only 15 bits.
Address Mapping using Pages and Blocks
To simplify mapping, address space is divided into equal fixed-sized chunks called pages, and physical memory space is divided into equal chunks called blocks (or page frames):
Because page size equals block size, the lower-order line bits pass directly through unchanged. Only the page number must be translated into a block number.
Page Tables & Associative Page Translation
In a standard Memory Page Table, the page number serves as an index address into a RAM table. The table entry yields the assigned block number along with a Presence Bit (1 = in RAM, 0 = on disk).
However, a RAM page table for pages where main memory holds only blocks wastes unused entries! To eliminate this inefficiency, systems use an Associative Memory Page Table, which stores only active mappings (page number paired with block number).
Page Faults and Replacement
If the CPU references a virtual address whose presence bit is 0, a page fault occurs:
- Execution of the current program is suspended.
- An interrupt alerts the operating system to initiate an I/O fetch from auxiliary disk storage.
- The CPU switches to execute another task while the I/O processor transfers the page into RAM.
- If main memory is full, the operating system uses FIFO or LRU (tracked via aging registers) to select a resident page for eviction.
Memory Management Hardware
In multiprogramming environments, a dedicated Memory Management Unit (MMU) provides three essential services:
- Dynamic storage relocation mapping logical memory references to physical memory addresses.
- Sharing common programs (e.g., shared library compilers) across multiple users.
- Protecting system programs and user data from unauthorized access or corruption.
Segmented-Page Mapping
Fixed page sizes don't always match software structures. Modern systems divide programs into variable-length logical units called segments (e.g., subroutines, symbol tables, arrays).
To combine the flexibility of segmentation with the ease of fixed page management, systems partition logical addresses into three distinct fields:
Address translation follows a two-tier lookup process:
- The Segment Number indexes into a Segment Table to retrieve a pointer address for the corresponding Page Table base.
- The Page Table Base is added to the Page Number to index into the Page Table, yielding the physical Block Number.
- Concatenating the Block Number with the Word Offset produces the final physical memory address.
Accelerating Translation with the TLB
Performing two sequential table lookups for every memory reference would slow the system to one-third speed. To solve this, MMUs incorporate a fast associative cache called a Translation Lookaside Buffer (TLB).
The TLB keeps the most recently used mapping entries (Segment + Page Block). If an associative search matches the TLB, the physical address is formed instantly, bypassing the two-level lookup process.
[Logical Address: Segment | Page | Word]
|
+---> [ Search TLB Associative Cache ]
| |
(TLB Hit) (TLB Miss)
| |
v v
[Extract Block No.] [Segment Table -> Page Table]
| |
+-----------+-----------+
|
v
[Physical Address: Block | Word]
Memory Protection and Descriptors
Protection parameters are integrated into segment entries called Descriptors. A segment descriptor contains:
- Base Address: Pointer to the page table or memory block.
- Length Field: The maximum number of pages assigned to the segment. If a program attempts an offset exceeding this boundary, a size violation error occurs.
- Protection Field: Defines access rights for the segment:
- Full Read and Write: Standard user workspace.
- Read Only (Write Protection): Shared utility functions and routines.
- Execute Only (Program Protection): Prevents copying executable source code.
- System Only (OS Protection): Restricts critical kernel code to operating system mode.
Summary
Computer memory systems bridge the divide between high-speed CPU execution logic and vast, low-cost long-term storage. By structuring memory into a dynamic hierarchy—utilizing cache memory, main memory (RAM/ROM), content-addressable memory (CAM), virtual memory paging, and hardware MMU protection—modern computer architectures achieve high average processing speeds while maximizing capacity and ensuring multi-user security.
Key Takeaways
- Memory Hierarchy Trade-offs: Strives for the highest average access speed at the lowest overall cost by layering cache (SRAM), main memory (DRAM), and auxiliary storage (disks/tapes).
- RAM vs ROM: SRAM uses flip-flops for fast cache; DRAM uses capacitors needing refresh for dense main memory; ROM holds permanent bootstrap startup code.
- Associative Memory (CAM): Matches stored data by content rather than physical address using mask registers and parallel match logic.
- Cache Mapping Strategies: Employs Associative, Direct, or Set-Associative mapping alongside Write-Through or Write-Back policies to capitalize on locality of reference.
- Virtual Memory & MMU: Translates logical/virtual addresses to physical memory using pages, blocks, page tables, TLB acceleration, and descriptor-based access protection.