session: "5102-foundations-of-comp-sys/2026-11-22 0000 FCS 22 Nov"
title: "FCS 22 Nov"
date: "2026-11-22 00:00"
duration: "--"
language: "en"
model: "deepseek-ai/DeepSeek-V3.2"
parts: 3
transcript_chars: 71459
generated: "2026-11-23T01:41:31+05:30"
FCS 22 Nov
Overview
This class covered the memory hierarchy and its management, focusing on the hardware/software contract for caches and virtual memory. It began with the motivation for studying memory hierarchy due to the disparity between processor speed and data access latency. The lecture detailed cache organization, policies (write-through/write-back, replacement), and miss classification. It then transitioned to virtual memory concepts, including address translation via page tables and the TLB, page faults, and the distinction between virtual memory and virtual machines. The session concluded with a demonstration of cache and virtual memory simulation and logistics for the upcoming quiz and final exam.
Learning outcomes
- Explain the trade-offs in the memory hierarchy (speed, capacity, cost, persistence).
- Define temporal and spatial locality and identify them in code examples.
- Describe cache organization (line, set, tag/index/offset) and policies (placement, replacement, write).
- Classify cache misses as compulsory, capacity, or conflict.
- Perform virtual-to-physical address translation given a page table mapping.
- Distinguish between a TLB miss, a page fault, and a protection fault.
- Differentiate between virtual memory (an OS memory management technique) and a virtual machine (a software-simulated computer).
Core concepts
Memory Hierarchy
A layered structure of memory storage (registers, caches, RAM, storage) that trades off access speed, capacity, cost per bit, and persistence. Higher levels (e.g., L1 cache) are faster, smaller, and more expensive per bit. Lower levels (e.g., HDD) are slower, larger, cheaper, and often persistent. This is a practical implementation strategy to approximate fast, large, cheap memory.
Locality
A statistical tendency in program behavior, not an architectural promise. Temporal Locality: The likelihood of reusing the same memory location soon. Spatial Locality: The likelihood of accessing nearby memory locations soon. Caches are designed to exploit these properties.
Cache Organization and Operation
A cache is a small, fast memory that holds copies of data from a larger, slower memory. The cache line is the unit of transfer and allocation. An address is split into tag (identifies the block), index (selects the set), and byte offset (selects the byte within the line). A cache hit means the data is present at that level; a cache miss requires fetching from a lower level.
Cache Write Policies
Define how writes are handled. Write-through: Data is written to both the cache and the lower-level memory immediately. Write-back: Data is written only to the cache; the line is marked dirty and written back to memory only upon eviction. Write allocate is commonly used, fetching a line into the cache on a write miss.
Cache Miss Classification
Categorizes the cause of a miss. Compulsory miss: First access to a block. Capacity miss: Working set exceeds cache size. Conflict miss: Blocks compete for the same set in a set-associative or direct-mapped cache, despite cache capacity not being full.
Virtual Memory
A memory management technique that provides each process with a private virtual address space, separate from physical RAM. It uses address translation to map Virtual Page Numbers (VPN) to physical frame numbers via a page table. The offset within a page remains unchanged.
TLB (Translation Lookaside Buffer)
A special cache inside the CPU for recent page table entries. A TLB hit provides a fast translation. A TLB miss requires a slower page table walk in memory but is not a page fault.
Page Fault
An exception (trap) raised by the hardware when a process accesses a valid virtual page that is not resident in physical memory. The operating system handles it, potentially loading the page from disk (demand paging), zero-filling it, or performing copy-on-write.
Formulas and maths
- Number of sets in a cache:
Total Cache Size / (Line Size Associativity). Example: 64 / (16 2) = 2 sets. - Virtual to Physical Address Translation:
Physical Address = (Frame Number * Page Size) + Offset. - Hit Rate Calculation:
Hit Rate = (Number of Hits) / (Total Accesses).
Worked examples
- Hierarchy Example: A laptop with 32 GB RAM (fast, volatile) and a 1 TB hard disk (slower, persistent).
- Locality Example: Loop
for i in range(n): total += values[i]. Variable total exhibits temporal locality. Consecutive array accesses values[0], values[1], values[2] exhibit spatial locality. - Cache Line Example: For an array of 30 elements, if a cache line holds 10 elements, accessing element 0 loads elements 0-9. Accessing element 11 triggers a load of the next cache line (elements 10-19).
- Address Anatomy Example: With a 16-byte line size, addresses 0-15 belong to block 0, 16-31 to block 1. With a 2-way cache, addresses 0 and 32 might map to the same set.
- Address Translation Example: Page size = 256. Virtual address = 270.
- VPN = 270 / 256 = 1.
- Offset = 270 - 256 = 14.
- If VPN 1 maps to frame 2: Physical Address = (2 * 256) + 14 = 526.
- Cache Simulation: Parameters: 64-byte capacity, 16-byte line, 2-way set-associative. Access sequence: Reads/writes to addresses 0, 4, 32, 0, 4, 64, 32, 32. Result: 3 hits, 5 misses. Hit rate = 3/8 = 37.5%.
- Virtualization Example: A physical server with 64 GB RAM hosts VMs with 8 GB RAM each. Kubernetes pods within those VMs might be allocated 2 GB each.
Questions asked in class
- Q: If spatial locality improves cache performance, what happens with random memory accesses?
- A: The CPU still loads the entire cache line on a miss. Random accesses with no reuse lead to poor locality and more misses, but data is still fetched from lower memory levels.
- Q: Why is a memory address divided into tag, index, and offset?
- A: Not answered in this session.
- Q: Where are replacement policies used?
- A: In the cache, to decide which line to evict when a new line needs to be brought into a full set. Write-back policy retains modified data in the cache until eviction.
- Q: Clarification on virtual memory vs. virtual machine.
- A: Virtual memory is a memory management technique for processes. A virtual machine is a software-simulated computer that virtualizes physical resources (CPU, memory). A VM uses virtual memory for its own processes.
- Q (Satya): If RAM is crowded, OS moves data to swap. That swap space is virtual memory.
- A: Correct. The process is called paging. Swap memory is the disk space used for this.
- Q: Is swap accepted in applications like Kubernetes?
- A: Generally, no. Kubernetes expects clear resource identities. Using disk as swap can cause confusion, leading to application hangs or termination. However, paging can be used on a standalone VM.
- Q: What is the main role of Kubernetes?
- A: It is a container orchestration tool that manages and runs containers across a cluster of machines, pooling their resources.
- Q: If you run an AWS/Azure VM, why use Putty on our machine?
- A: Putty is an SSH client for remote access. It provides an interface to interact with the remote VM; it does not create or run the VM, which uses cloud resources.
- Q: If using Putty on a laptop to access a VM running on the same laptop, does it use the laptop's resources?
- A: Yes, 100%. Putty is just an interface; the VM itself consumes the host laptop's CPU and memory.
- Q: Clarification on the final exam format.
- A: Expected 25-30 questions covering all topics. Types: multiple choice, true/false, multiple right answers, potentially short descriptive answers with word limits. No programming questions.
Key takeaways
- The memory hierarchy exists to bridge the speed gap between the CPU and main memory/storage.
- Locality (temporal and spatial) is a workload property that caches exploit for efficiency.
- A cache line is the unit of transfer; accessing one byte can load 64 adjacent bytes (for example).
- Address bits are partitioned into tag, index, and offset based on cache geometry.
- Write-back cache policy reduces traffic to lower memory by deferring writes until eviction.
- A conflict miss occurs in set-associative caches when blocks map to the same set, even if the cache isn't full.
- Virtual memory provides each process with an isolated, contiguous address space larger than physical RAM.
- Address translation converts a Virtual Page Number (VPN) to a Physical Frame Number using a page table.
- The TLB caches page table entries to accelerate address translation; a TLB miss triggers a page table walk.
- A page fault occurs when a page is not in RAM; a protection fault occurs on a permission violation (e.g., writing to a read-only page).
- A virtual machine (e.g., VMware) virtualizes hardware, while virtual memory virtualizes the address space.
- Kubernetes orchestrates containers and generally requires swap to be disabled on cluster nodes.
Exam-style questions
1. Question: A 2-way set-associative cache has a total size of 64 bytes and a line size of 16 bytes. For a memory address 0x2C (44 in decimal), calculate the tag, index, and offset. Assume byte-addressable memory.
- Answer Outline: First, determine number of sets: 64/(16*2)=2 sets. Index needs 1 bit (log2(2)). Offset needs 4 bits (log2(16)). Remaining bits are tag. Convert 44 to binary, partition from LSB: offset (4 bits), index (1 bit), tag (remaining bits).
2. Question: Classify the following cache miss scenarios: (a) The first access to an array element. (b) Repeatedly accessing a dataset larger than the cache. (c) Two different memory blocks mapping to the same cache set in a direct-mapped cache.
- Answer Outline: (a) Compulsory miss (first access). (b) Capacity miss (working set > cache size). (c) Conflict miss (blocks compete for the same set).
3. Question: Given a system with a page size of 4 KB, a virtual address 0x8014, and a page table entry indicating VPN 8 maps to frame 12, calculate the physical address.
- Answer Outline: Page size 4 KB = 4096 = 0x1000. VPN = 0x8014 / 0x1000 = 8. Offset = 0x8014 % 0x1000 = 0x14. Physical Address = (12 * 4096) + 20 = 49152 + 20 = 49172 (0xC014).
4. Question: Explain the difference between a TLB miss and a page fault. Can one occur without the other?
- Answer Outline: A TLB miss means the translation is not in the TLB cache, requiring a page table walk. A page fault means the page is not in physical RAM, requiring OS intervention. Yes, one can occur without the other: a TLB miss can happen for a page that is resident in RAM (page table walk succeeds). A page fault can occur even on a TLB hit if the PTE indicates the page is not present.
Glossary
- Cache Line - The fixed-size, aligned block of memory transferred between cache and main memory.
- Locality - The tendency of programs to access the same or nearby memory locations repeatedly.
- Write-back - A cache write policy where updates are written to memory only when the dirty line is evicted.
- Conflict Miss - A cache miss caused by multiple memory blocks mapping to the same cache set.
- Virtual Memory - A technique that gives each process the illusion of a large, private address space.
- Page Table - A data structure used by the OS to map virtual page numbers to physical frame numbers.
- TLB - Translation Lookaside Buffer; a hardware cache for recent virtual-to-physical address translations.
- Page Fault - An exception triggered when a process accesses a non-resident page in its address space.
- Virtual Machine - A software simulation of a physical computer system.
- Kubernetes - An open-source system for automating deployment and management of containerized applications.
Follow-ups
- The lecturer will start with "write-around" cache policy after the break (not covered in this session).
- A Python demonstration simulating cache behavior (write-through/write-back, LRU) and virtual memory translation will be shown; the code will be uploaded.
- The lecturer will confirm with the course coordinator if descriptive questions will be part of the final exam format.
- Slides and programs from recent and upcoming lab sessions will be uploaded.
- The unit for the example page size "256" was not clarified (likely bytes or KB).
- The distinction between architectural promises and CPU implementation was not explicitly covered in this session but is a core course rule.