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.
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 answerHide 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:
| Field | Purpose |
|---|---|
| Tag | Identifies 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
- The CPU generates a memory address which is split into Tag, Index, and Word fields.
- The Index field is used to directly select a specific cache line.
- The Tag stored in that cache line is compared with the Tag from the CPU address.
- If the Valid bit = 1 and Tags match → Cache HIT: the required word is read from the cache using the Word field.
- 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
| Advantages | Disadvantages |
|---|---|
| Simple and fast to implement | Two blocks with the same index cannot reside in cache simultaneously |
| Low hardware cost | High miss rate if frequently used blocks share the same cache line |
| Straightforward tag comparison | Inflexible placement of blocks |
2080 · 5 marks
What is cache memory? Explain the elements of cache design. [5]
2079 · 10 marks
What is cache memory? Explain the mapping process. Differentiate between direct mapping and associate mapping.[10]
Show solved answerHide 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:
- Direct Mapping
- Associative Mapping
- 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)
| Feature | Direct Mapping | Associative Mapping |
|---|---|---|
| Placement | Each memory block maps to exactly one fixed cache line | A memory block can be placed in any cache line |
| Address Fields | Tag + Index + Offset | Tag + Offset (no index) |
| Search Method | Uses index to locate line, then checks tag | Searches all tags simultaneously |
| Hardware Cost | Simple and inexpensive | Complex and expensive (needs CAM) |
| Flexibility | Low -- fixed mapping | High -- fully flexible |
| Conflict/Thrashing | High -- same index blocks conflict | None -- no fixed slot restriction |
| Hit Rate | Lower (due to conflicts) | Higher |
| Speed | Fast lookup via index | Slightly slower due to parallel search overhead |
| Replacement Policy | Not 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.
2078 · 5 marks
What are the advantage and disadvantage of direct mapping and associative mapping between cache and main memory? [5]
2077 · 5 marks
Give the appropriate reasons why replacement algorithm is required in associative mapping? [5]
2075.1 · 10 marks
Explain the mapping process. Differentiate between direct mapping and associate mapping.[10]
Associative Memory
2075 · 5 marks
Define associative memory. Explain with block diagram how it can be implemented. [5]
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]
Make Unit 9 stick
Practice CSC213 with flashcards & quizzes