9 Memory Organization

Computer Architecture · Unit 9 · 4 hrs

Memory Organization

Exam-focused notes for Memory Organization (Computer Architecture, CSC213): what the TU syllabus asks and how it has actually been tested, with 8 solved past questions from this unit.

Memory Organization in short

No single memory technology is simultaneously fast, large and cheap, so a computer instead organizes several kinds of memory into a hierarchy and lets a mix of hardware and software keep the most-needed data in the fastest layer. This chapter covers that hierarchy, an older but instructive fully-parallel design (associative memory), and the workhorse of the hierarchy today, cache memory.

Memory Organization: notes

Memory Hierarchy, Main Memory, RAM and ROM Chips, Memory Address Map, Memory Connection to CPU, Auxiliary Memory

The memory hierarchy arranges storage technologies by a trade-off: registers are fastest and smallest, then cache, then main memory, then auxiliary (secondary) memory such as disk, each successive level larger and cheaper per bit but slower to access, so the goal is the highest access speed at the lowest overall cost. Main memory is the memory directly connected to the CPU and used during program execution to hold running programs and data; Random Access Memory (RAM) comes in two forms, static RAM (SRAM), built from internal flip-flops with short read/write cycles, and dynamic RAM (DRAM), which stores each bit as charge on a capacitor and must be refreshed every few milliseconds as that charge leaks away. Read-Only Memory (ROM) holds programs and constants that must survive a power cycle unchanged; the bootstrap loader, the initial program that starts the operating system when the computer is switched on, is stored in ROM, so that at power-on the hardware sets the program counter to the bootstrap loader's address, which then loads the rest of the operating system from disk into main memory.

A RAM or ROM chip is enabled by one or more chip-select lines (commonly two, one asserted high and one asserted low, so the chip responds only to its own address range) together with read (RD) and write (WR) control lines for RAM (ROM omits these, since it cannot be written). Building a memory address map assigns each chip its own block of the address space; for example, four 128-word RAM chips and one 512-word ROM chip need 7 address lines to select a word within a RAM chip and 9 address lines within the ROM chip, with the remaining high-order address lines, decoded externally, selecting which chip is enabled for a given address. The CPU connects to this collection of chips through shared address and data buses: the low-order address lines select the byte within whichever chip is enabled, and the higher-order lines feed a decoder whose outputs drive each chip's select inputs.

What this unit covers

  • Memory Hierarchy, Main Memory, RAM and ROM Chips, Memory address Map, Memory Connection to CPU, Auxiliary Memory (magnetic Disk, Magnetic Tape)
  • Associative Memory: Hardware Organization, Match Logic, Read Operation, Write Operation
  • Cache Memory: Locality of Reference, Hit & Miss Ratio, Mapping, Write Policies

Cache Memory

2081 · 5 marks

What is meant by cache mapping? Explain working of direct mapping with suitable block diagram. [5]

Show solved answer

Cache Mapping

Definition

Cache mapping refers to the technique or procedure by which the contents of main memory blocks are mapped (assigned) to cache memory locations. Since cache memory is much smaller than main memory, a mapping function is needed to determine which cache location a particular main memory block will occupy when it is brought into cache.


Direct Mapping

Concept

In direct mapping, each block of main memory can be placed in one and only one specific location in the cache. Main memory is divided into pages that correspond in size with the cache. Each memory address is divided into three fields:

FieldPurpose
TagIdentifies which page/block of main memory is currently in cache
Index (Line/Block number)Specifies which cache line the block maps to
Word (Block offset)Identifies the specific word within the block

Address Division

For a memory address of k bits:

| TAG  |  INDEX (Cache Line)  |  WORD (Offset)  |
|  t   |         d            |       w         |
  • Number of cache lines = 2^d
  • Number of words per block = 2^w
  • Tag bits = k - d - w

The cache line number is determined by:

Cache Line = (Main Memory Block Number) mod (Number of Cache Lines)


Block Diagram of Direct Mapping

Main Memory Address
+--------+----------+--------+
|  TAG   |  INDEX   |  WORD  |
+--------+----------+--------+
     |         |         |
     |         |         |
     |    +----v----+    |
     |    |  Cache  |    |
     |    |  Index  |    |
     |    | (Select |    |
     |    |  Line)  |    |
     |    +----+----+    |
     |         |         |
     |    +----v-----------------------+
     |    | Cache Line                 |
     |    |  +-------++--------------+ |
     |    |  | Valid ||  TAG | DATA  | |
     |    |  +-------++--------------+ |
     |    +----+-----------+----------+
     |         |           |
  +--v--+   Compare      Block
  | TAG |----+           Data
  +-----+    |              |
             v              |
          +------+          |
          | Hit? |          |
          +--+---+          |
             |              |
         YES | NO           |
             |   (Fetch     |
             |    from      v
             |    Main   +------+
             |    Memory)|      |
             v           | WORD |
          +------+       | MUX  |
          | Data |<------+------+
          | Out  |
          +------+

Working Steps

  1. The CPU generates a memory address which is split into Tag, Index, and Word fields.
  2. The Index field is used to directly select a specific cache line.
  3. The Tag stored in that cache line is compared with the Tag from the CPU address.
  4. If the Valid bit = 1 and Tags match → Cache HIT: the required word is read from the cache using the Word field.
  5. If the Tags do not match or Valid bit = 0 → Cache MISS: the block is fetched from main memory, loaded into the indicated cache line, and the tag is updated.

Example

Suppose main memory has 32 blocks and cache has 8 lines:

  • Block 0 maps to Cache Line 0 (0 mod 8 = 0)
  • Block 1 maps to Cache Line 1 (1 mod 8 = 1)
  • Block 9 maps to Cache Line 1 (9 mod 8 = 1)
  • Block 17 maps to Cache Line 1 (17 mod 8 = 1)

Note: Blocks 1, 9, and 17 all compete for the same cache line, which is the main disadvantage of direct mapping.


Advantages and Disadvantages

AdvantagesDisadvantages
Simple and fast to implementTwo blocks with the same index cannot reside in cache simultaneously
Low hardware costHigh miss rate if frequently used blocks share the same cache line
Straightforward tag comparisonInflexible placement of blocks
Open this answer on its own page →

2080 · 5 marks

What is cache memory? Explain the elements of cache design. [5]

Cache memory is a fast, small-capacity memory that holds the information most likely to be accessed by the CPU. Its access time is less than the access time of main memory by a factor of 5 to 10. Cache is the fastest component in the memory hierarchy and is placed between the CPU and main memory....

Open this answer on its own page →

2079 · 10 marks

What is cache memory? Explain the mapping process. Differentiate between direct mapping and associate mapping.[10]

Show solved answer

Cache Memory and Mapping Process

1. What is Cache Memory? (2 marks)

Cache memory is a small, high-speed memory placed between the CPU and main memory (RAM). Its purpose is to store frequently used instructions and data so that the CPU can access them faster, reducing the average time needed to access data from main memory.

Key characteristics:

  • Faster than main memory but smaller in size
  • Sits closest to the CPU in the memory hierarchy
  • Transparent to the programmer (managed by hardware)
  • Reduces the speed mismatch between CPU and main memory

2. The Mapping Process (3 marks)

: "The transformation of data from main memory to cache memory is referred to as a mapping process."

When the CPU needs data, it first checks the cache:

  • Cache Hit: Data found in cache -- CPU reads directly (fast)
  • Cache Miss: Data not in cache -- fetched from main memory and a copy is placed in cache

Since cache is much smaller than main memory, a mapping function is needed to determine where a block of main memory will be placed in cache.

The three practical mapping procedures are:

  1. Direct Mapping
  2. Associative Mapping
  3. Set-Associative Mapping

3. Direct Mapping (2 marks)

: "Main memory locations can only be copied into one location in the cache. This is accomplished by dividing main memory into pages that correspond in size with the cache."

How it works:

  • Main memory is divided into pages of the same size as the cache.
  • Each block of main memory maps to exactly one fixed location in the cache.
  • The memory address is divided into three fields:
| TAG | INDEX (Cache Line) | BLOCK OFFSET |
  • Tag: Identifies which page of main memory the block came from
  • Index: Specifies the cache line where the block must be stored
  • Offset: Identifies the specific word within the block

Example:

If cache has 128 lines and main memory has 4096 blocks:

  • Block 0, 128, 256, ... all map to cache line 0
  • Block 1, 129, 257, ... all map to cache line 1

Advantage:

  • Simple and inexpensive to implement

Disadvantage:

  • Two blocks with the same index but different tags cannot reside in cache simultaneously, causing frequent replacements (cache thrashing)

4. Associative Mapping (2 marks)

In associative (fully associative) mapping, any block of main memory can be placed in any line of the cache. There is no fixed mapping.

How it works:

  • The memory address is divided into only two fields:
| TAG | BLOCK OFFSET |
  • The entire tag is stored with each cache entry.
  • When the CPU requests data, all cache tags are searched simultaneously (using associative/content-addressable memory) to find a match.

Advantage:

  • Flexible: Any memory block can go into any cache line
  • Eliminates the thrashing problem of direct mapping
  • Higher hit rate

Disadvantage:

  • Expensive and complex hardware required for simultaneous tag comparison
  • Replacement policy (LRU, FIFO) must be implemented

5. Set-Associative Mapping (1 mark)

: "Set-Associative mapping is an improvement over direct mapping organization. Each word of cache can store two or more words of memory under the same index address."

  • It is a compromise between direct and associative mapping.
  • Cache is divided into sets, each set containing a fixed number of lines (called the set size or k-way).
  • A memory block maps to a specific set (like direct mapping) but can go into any line within that set (like associative mapping).

6. Differentiation: Direct Mapping vs. Associative Mapping (Table) (marks covered above)

FeatureDirect MappingAssociative Mapping
PlacementEach memory block maps to exactly one fixed cache lineA memory block can be placed in any cache line
Address FieldsTag + Index + OffsetTag + Offset (no index)
Search MethodUses index to locate line, then checks tagSearches all tags simultaneously
Hardware CostSimple and inexpensiveComplex and expensive (needs CAM)
FlexibilityLow -- fixed mappingHigh -- fully flexible
Conflict/ThrashingHigh -- same index blocks conflictNone -- no fixed slot restriction
Hit RateLower (due to conflicts)Higher
SpeedFast lookup via indexSlightly slower due to parallel search overhead
Replacement PolicyNot needed (only one possible location)Required (LRU, FIFO, etc.)

Summary

Cache memory bridges the speed gap between the CPU and main memory. The mapping process determines how main memory blocks are placed into cache. Direct mapping is simple but suffers from conflicts since each block has only one possible cache location. Associative mapping is flexible and conflict-free but requires costly hardware. Set-associative mapping is the practical middle ground used in modern processors.

Open this answer on its own page →

2078 · 5 marks

What are the advantage and disadvantage of direct mapping and associative mapping between cache and main memory? [5]

In direct mapping, each main memory location can only be copied into one specific location in the cache. Main memory is divided into pages that correspond in size with the cache, and each memory block maps to exactly one cache line determined by its address. Advantage -------------- 1 Simple impl...

Open this answer on its own page →

2077 · 5 marks

Give the appropriate reasons why replacement algorithm is required in associative mapping? [5]

In associative mapping, any block from main memory can be loaded into any line (slot) of the cache. This is the most flexible cache organization because there is no restriction on placement. However, this very flexibility creates a critical problem that makes a replacement algorithm necessary. --...

Open this answer on its own page →

2075.1 · 10 marks

Explain the mapping process. Differentiate between direct mapping and associate mapping.[10]

A mapping process is one of the key sequencing techniques used in a microprogrammed control unit. It provides: "A mapping process from the bits of the instruction to an address for control memory." In this context, the mapping process converts the operation code (opcode) bits of a machine instruc...

Open this answer on its own page →

Associative Memory

2075 · 5 marks

Define associative memory. Explain with block diagram how it can be implemented. [5]

Associative memory (also called Content Addressable Memory or CAM) is a type of memory in which the stored data is accessed based on its content rather than by a specific address. Instead of supplying an address to retrieve data, the user supplies a portion of the data (a key or argument), and th...

Open this answer on its own page →

Memory Hierarchy, Main Memory, RAM and ROM Chips, Memory address Map, Memory Connection to CPU, Auxiliary Memory

2075.1 · 6 marks

What are the main characteristics of memory system? Explain [6]

A memory system in a computer is characterized by several key properties that determine its performance, capacity, and suitability for different purposes. These characteristics help in understanding the trade-offs between speed, cost, and capacity in a memory hierarchy. --- Memory can be located ...

Open this answer on its own page →