Top 30 OS Memory Management Interview Questions & Answers (2026)

What changed in 2026 drives
Mass-recruiter offer letters are flatter for 2026 batch - the 4-5 LPA ASE band has barely budged in three years while inflation eats real wages. Premium tracks (Digital, Pro, Elite, Specialist) are still where the differential lives, and they are entirely test-driven. If you are aiming higher than the default offer, the coding round is not optional pageantry - it is the entire interview.
What I'd actually study for this
- 01Two solid coding-round answers (1 medium-hard DSA each, with edge-case discussion) > five half-baked ones
- 02One real project you can defend end-to-end - file paths, design decisions, and what you would change
- 03One DBMS schema you actually built (not a textbook ER diagram), with at least 3 join-heavy queries written from memory
- 04Three behavioural STAR stories: failure recovered, conflict handled, ownership taken
Where most candidates trip up
The single biggest mistake is treating company-specific guides as primary prep and DSA as secondary. It is the opposite. Mass recruiters use the test as a filter, but premium tracks at every IT services company use coding to allocate offer band. Spend 70% of prep time on DSA + system fundamentals, 20% on company-specific patterns, 10% on HR rehearsal. Reverse that ratio and you collect the default offer.
Editorial commentary by Aditya Sharma · written for PapersAdda · not generated, not aggregated.
Last Updated: June 2026 | Level: Beginner to Advanced | Format: Q&A with Diagrams and Algorithm Traces
Memory management is tested extensively in OS interviews at product companies and service companies alike. Candidates report questions ranging from "what is virtual memory?" to page replacement algorithm calculations and TLB design appearing in written rounds. According to candidate accounts and public preparation resources, FIFO and LRU page replacement with miss rate calculations are among the most common numerical problems. This guide covers 30 memory management questions with diagrams described in text, tables, and step-by-step calculations.
Table of Contents
- Memory Basics (Q1-Q8)
- Virtual Memory and Paging (Q9-Q17)
- Page Replacement (Q18-Q24)
- Advanced Topics (Q25-Q30)
Memory Basics
Q1. What is memory management in an OS? What are its goals? Easy
Memory management is the OS function that controls and coordinates the use of RAM.
Goals:
- Relocation: Programs can run at any memory address (not hardcoded to a specific location).
- Protection: Processes cannot access each other's memory (isolation).
- Sharing: Multiple processes can share specific memory regions (shared libraries, IPC).
- Logical organization: Support logical structure of programs (code, data, stack as separate regions).
- Physical organization: Handle the memory hierarchy (registers, cache, RAM, disk) transparently.
Memory management techniques (evolution):
Single contiguous allocation
-> Fixed partitioning
-> Dynamic partitioning
-> Paging
-> Segmentation
-> Segmented paging (modern systems)
Q2. What is the difference between logical address and physical address? Easy
| Aspect | Logical Address (Virtual Address) | Physical Address |
|---|---|---|
| Generated by | CPU during instruction execution | Memory Management Unit (MMU) hardware |
| Visible to | User programs | Only OS and hardware |
| Range | 0 to max virtual space (e.g., 0 to 2^64-1) | 0 to size of installed RAM |
| Role | Process thinks it owns all virtual address space | The real location in physical RAM |
Address translation:
CPU generates logical address
--> MMU translates using page table
--> Physical address sent to RAM
Why separate? Logical addressing provides each process the illusion of having its own memory space starting at address 0. This enables relocation and protection without processes needing to know about each other.
Q3. What is base and limit register approach? Easy
The simplest hardware support for memory protection:
- Base register: Holds the starting physical address of the process.
- Limit register: Holds the size of the process's allowed memory region.
Address validation:
On every memory access:
if (logical address < 0 OR logical address >= limit):
raise protection fault (segmentation violation)
physical address = base + logical address
Diagram:
Process A: base=300K, limit=120K
Valid addresses: 300K to 420K
Logical address 50K -> physical 350K (OK)
Logical address 130K -> FAULT (>limit)
Limitation: Entire process must fit in one contiguous physical region. If a 200MB process needs RAM and there are two 150MB gaps, it cannot run even though 300MB is available total. This is external fragmentation.
Q4. What is fragmentation? Explain internal and external fragmentation. Easy
Internal Fragmentation: Wasted space INSIDE an allocated memory block.
OS allocates blocks of 64 bytes.
Process needs 50 bytes.
Allocated: 64 bytes.
Internal fragmentation = 14 bytes (unused but allocated).
Caused by fixed-size allocation units (pages, blocks). Paging causes internal fragmentation (average half a page wasted per process).
External Fragmentation: Free memory exists but is in small non-contiguous pieces too small to satisfy a large request.
Total free memory: 100KB
Hole 1: 30KB
Hole 2: 40KB
Hole 3: 30KB
Process needs: 75KB contiguous
Result: cannot satisfy even though 100KB is free.
Caused by variable-size allocation (dynamic partitioning, segmentation).
Solution to external fragmentation:
- Compaction: Move allocated blocks together, merge free space. Expensive (requires stopping processes and copying memory).
- Paging/Segmentation: Allow non-contiguous physical allocation.
Q5. What are the memory allocation strategies for free holes? Easy
When a process needs memory and there are multiple free holes:
| Strategy | Rule | Advantage | Disadvantage |
|---|---|---|---|
| First Fit | Allocate from the first hole that is big enough | Fast | May leave large holes fragmented at start |
| Best Fit | Allocate from the smallest hole that is big enough | Minimizes wasted space per allocation | Slow (scan all holes); leaves many tiny unusable holes |
| Worst Fit | Allocate from the largest hole | Remaining hole is largest (may be reusable) | Destroys large holes quickly |
| Next Fit | Like First Fit but starts scanning from last allocation point | Spreads allocation more evenly | Similar fragmentation to First Fit |
Simulation result: First Fit and Best Fit are better than Worst Fit. First Fit is generally faster and performs similarly to Best Fit in practice.
Q6. What is swapping? How does it differ from paging? Medium
| Aspect | Swapping | Paging |
|---|---|---|
| Unit of transfer | Entire process | Individual pages (4KB typically) |
| Granularity | Coarse | Fine |
| When triggered | Memory pressure; entire process moved to disk | Page fault; only missing pages loaded |
| Context | Older systems, swap partitions | Modern virtual memory |
| Overhead | Very high (entire process I/O) | Lower per operation |
Swapping: When physical RAM is full and a new process needs to run, the OS swaps out an entire sleeping process to disk (swap space). When that process is scheduled again, it is swapped back in.
Modern systems (paging-based): The page-out/page-in mechanism replaces whole-process swapping. Only the pages that are actively referenced stay in RAM (working set principle).
Q7. What is the working set model? Hard
The working set of a process at time t with window size delta is the set of pages referenced in the interval (t-delta, t). It approximates the process's active pages.
Working Set W(t, delta) = {pages accessed in last delta time units}
Working Set Model usage:
- Each process is allocated enough frames to hold its current working set.
- If sum of working sets across all processes > total frames: suspend a process (swap it out) to reduce memory pressure.
- When a process's working set fits in memory, it runs without page faults.
Why it matters:
- Prevents thrashing: if too many processes compete for memory, each continually page-faults. The working set model ensures each process has enough frames to run smoothly before being admitted.
Approximation in practice: True working set requires tracking every access. OSes approximate it using the reference bit and periodic sampling (clearing reference bits, checking which pages were re-set before next clearing).
Q8. What is compaction? What is its cost? Easy
Compaction is the process of shuffling memory contents to consolidate all free holes into one large contiguous block.
Before compaction:
[P1:50KB][FREE:30KB][P2:80KB][FREE:20KB][P3:40KB][FREE:50KB]
After compaction:
[P1:50KB][P2:80KB][P3:40KB][FREE:100KB]
Cost:
- Must stop and relocate processes (requires hardware support: base/limit registers updated after move).
- I/O equivalent: if processes total 1GB, compaction copies 1GB of data.
- Time: proportional to the amount of memory being moved. On modern systems, this is very expensive and rarely done.
Alternative: Use paging or segmentation to eliminate the need for contiguity. Modern systems avoid compaction entirely through non-contiguous allocation.
Virtual Memory and Paging
Q9. What is virtual memory? What are its benefits? Easy
Virtual memory is a memory management technique where each process believes it has a large contiguous address space, even if physical RAM is smaller or fragmented.
Benefits:
| Benefit | Explanation |
|---|---|
| Programs larger than RAM | OS pages in only needed portions; rest stays on disk |
| Memory isolation | Each process has its own virtual address space |
| Efficient sharing | Multiple processes can map the same physical pages (shared libraries) |
| Simplified memory allocation | Programs use virtual addresses; OS handles physical placement |
| Copy-on-Write (COW) | fork() copies page table entries pointing to same physical pages; physical copy made only when a page is written |
Virtual memory is implemented through paging (modern systems) or segmentation, or both.
Q10. Explain paging. How does address translation work? Medium
Paging divides both logical address space and physical memory into fixed-size blocks:
- Logical blocks: pages
- Physical blocks: frames
- Page size = frame size (typically 4KB)
Address structure:
Logical address:
┌─────────────────┬──────────────┐
│ Page Number │ Page Offset │
│ (upper bits) │ (lower bits)│
└─────────────────┴──────────────┘
For 32-bit address, 4KB pages (12 offset bits):
Page number = bits 31-12 (20 bits -> 2^20 = 1M page entries)
Offset = bits 11-0 (12 bits -> 4KB)
Address translation:
1. CPU generates logical address (page_num, offset)
2. MMU looks up page_num in Process Page Table
3. Page table gives frame_num
4. Physical address = frame_num * page_size + offset
Example:
Logical: page=3, offset=100, page_size=1024
Page table: page 3 -> frame 7
Physical address: 7*1024 + 100 = 7268
No external fragmentation (any frame can hold any page). Internal fragmentation exists (last page may be partially filled, avg half page per process).
Q11. What is a page table? What are its types? Medium
A page table is a data structure maintained by the OS (per process) that maps logical page numbers to physical frame numbers.
Problem with simple page table: For a 32-bit address space with 4KB pages:
- 2^20 = 1M entries * 4 bytes/entry = 4MB per process page table
- 100 processes = 400MB just for page tables. Unacceptable.
Page table structures:
| Type | Mechanism | Memory use |
|---|---|---|
| Flat/Single-level | Direct array indexed by page number | 4MB per process (impractical) |
| Two-level / Hierarchical | Page directory -> page table -> frame | Only allocate page table pages that are used |
| Inverted | One entry per physical frame; indexed by (pid, page) | O(physical frames) total, not per process; slow lookup |
| Hashed | Hash (pid, page) -> chain of entries | O(1) average lookup with good hash |
Two-level paging (common in 32-bit systems):
Logical address: [10 bits outer | 10 bits inner | 12 bits offset]
Outer page table: 2^10 = 1024 entries (always present, 4KB)
Inner page tables: allocated only for used regions (each 4KB)
Q12. What is a TLB (Translation Lookaside Buffer)? Medium
A TLB is a hardware cache inside the MMU that stores recently used page-to-frame translations. It eliminates the need to access the page table in RAM for every memory reference.
Memory access without TLB:
1. Access page table (RAM) -> get frame number (1 memory access)
2. Access actual data (RAM) (1 memory access)
Total: 2 memory accesses
Memory access with TLB:
TLB hit:
1. TLB lookup (cache, nanoseconds) -> get frame (hardware)
2. Access actual data (RAM) (1 memory access)
Total: 1 memory access + tiny TLB lookup time
TLB miss:
1. TLB lookup (miss)
2. Access page table (RAM) -> get frame (1 memory access)
3. Update TLB with new entry
4. Access actual data (RAM) (1 memory access)
Total: 2 memory accesses + TLB miss penalty
Effective Access Time (EAT):
EAT = hit_ratio * (TLB_time + mem_time) + (1 - hit_ratio) * (TLB_time + 2 * mem_time)
Example: TLB_time=10ns, mem_time=100ns, hit_ratio=0.90
EAT = 0.90*(10+100) + 0.10*(10+200) = 99 + 21 = 120ns
Without TLB: 2*100 = 200ns -> TLB gives 40% speedup
TLB on context switch: Entire TLB must be flushed OR each entry tagged with an ASID (Address Space Identifier) so entries from multiple processes coexist. Modern x86 and ARM use ASID-tagged TLBs.
Q13. What is a page fault? What happens when one occurs? Medium
A page fault occurs when a process accesses a virtual page that is not currently mapped to a physical frame (the valid bit in the page table entry is 0).
Page fault handling sequence:
1. CPU accesses logical address -> MMU checks page table
2. Page table entry valid bit = 0 -> hardware raises page fault interrupt
3. OS page fault handler invoked:
a. Check if reference is valid (legal address in process's virtual space)
If invalid -> segmentation fault, terminate process
b. Find a free frame in physical memory
If no free frame -> run page replacement algorithm to evict a victim page
c. Read the required page from disk (swap space or file)
d. Update page table entry: valid=1, frame=new_frame
e. Restart the faulting instruction
4. Process resumes as if no fault occurred
Performance impact:
EAT = (1 - p) * mem_time + p * page_fault_time
where p = page fault rate
page_fault_time ≈ disk access time ≈ 8ms (HDD), 0.1ms (SSD)
mem_time ≈ 100ns
For 10% slowdown: p <= 0.0000025 (less than 1 fault per 400,000 accesses)
Q14. Explain demand paging. What is its advantage over loading entire process? Easy
Demand paging: Pages are loaded into memory only when accessed (on-demand), not all at once when the process starts.
Advantages:
| Benefit | Detail |
|---|---|
| Less I/O at startup | Only needed pages loaded; process starts faster |
| Less memory needed | Many pages of a process may never be accessed |
| More processes can run | OS fits more processes in RAM |
| Supports programs larger than RAM | Only active portions need to be in RAM |
Program locality: Programs tend to access a small fraction of their pages most of the time (80/20 rule). Only a small working set is frequently accessed. Demand paging exploits this.
Pure demand paging: Start with zero pages in memory. Service every access as a page fault until the working set is loaded. After initial loading phase, faults become rare.
Q15. What are page table entries (PTEs) made of? Medium
A typical 32-bit PTE contains:
PTE bit structure (x86 example):
Bit 31-12: Frame number (physical frame address >> 12)
Bit 11-9: OS-available bits (can be used by OS for any purpose)
Bit 8: Global flag (don't flush from TLB on context switch)
Bit 7: Page size flag (for large/huge pages)
Bit 6: Dirty bit (page has been written since last cleared)
Bit 5: Accessed bit (page has been accessed since last cleared)
Bit 4: Cache disable
Bit 3: Write-through caching
Bit 2: User/Supervisor (user-mode accessible?)
Bit 1: Read/Write (writable?)
Bit 0: Present/Valid (page is in physical memory?)
Key bits for OS operation:
- Valid/Present bit (0): Page fault if 0 and page accessed.
- Dirty bit (6): If dirty when evicted, must write to disk. If clean, can discard (reload from disk).
- Accessed/Reference bit (5): Used by page replacement algorithms (LRU approximation, clock algorithm).
- Protection bits (1,2): Implement read/write/execute protection per page.
Q16. What is Copy-on-Write (CoW)? How does it optimize fork()? Medium
Copy-on-Write: When a process forks, instead of immediately copying all parent pages to the child, both parent and child share the same physical pages (marked read-only). A physical copy is made only when either process writes to a shared page.
Without CoW:
Parent process: 100MB of memory
fork() -> immediately copy 100MB for child
Time: proportional to 100MB copy
With CoW:
fork() -> copy page table entries only (point child to same frames)
Time: microseconds (just page table copy)
When child writes to page X:
-> write protection fault triggered
-> OS allocates new frame, copies page X content
-> updates child's page table to new frame
-> write proceeds
Result: For programs that fork() then exec() immediately (like shell spawning a process), the 100MB physical copy is never made. exec() replaces the address space entirely. Huge performance gain.
Used in: Linux fork(), macOS fork(), vfork() (even more aggressive: child shares parent's address space until exec(), no copy at all).
Q17. What is a huge page / large page? Why is it used? Hard
Standard page size: 4KB. Huge pages are larger pages: 2MB or 1GB on x86.
Advantage:
- For a 2MB huge page: TLB has 1 entry covering 2MB (vs. 512 entries for 512 * 4KB pages).
- Reduces TLB misses for large memory applications.
- Fewer page table levels needed.
When to use:
- Database buffer pools (MySQL innodb_buffer_pool, PostgreSQL shared_buffers).
- Java JVM heap (large heaps with standard pages = millions of TLB entries).
- HPC (High-Performance Computing) workloads with large working sets.
Linux huge pages:
- Explicit huge pages:
mmap()withMAP_HUGETLBflag; must pre-allocate from/proc/sys/vm/nr_hugepages. - Transparent Huge Pages (THP): Kernel automatically uses huge pages for large allocations. No application change needed, but can cause latency spikes (page compaction to create huge pages).
Trade-off: Internal fragmentation increases (a 2MB page used for a 5KB object wastes 2MB - 5KB). Only beneficial for large, long-lived allocations.
Page Replacement
Q18. What is page replacement? When is it needed? Easy
Page replacement is the OS operation of selecting a physical frame to evict when a page fault occurs and no free frames are available.
Decision: Which page to evict (write to disk if dirty, discard if clean)?
Good replacement policy: Minimize future page faults (i.e., evict pages least likely to be used soon).
The problem: The OS cannot see the future. Different approximation algorithms use past access patterns to predict future use.
Q19. Explain FIFO page replacement algorithm. What is Belady's anomaly? Easy
FIFO: Evict the page that has been in memory the longest.
Example (3 frames, reference string: 7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1):
Simulating first 8 references with 3 frames:
7: [7,-,-] FAULT
0: [7,0,-] FAULT
1: [7,0,1] FAULT
2: [2,0,1] FAULT (evict 7, oldest)
0: [2,0,1] HIT
3: [2,3,1] FAULT (evict 0)
0: [2,3,0] FAULT (evict 1)
4: [4,3,0] FAULT (evict 2)
So far: 7 faults in 8 references.
Belady's Anomaly: Increasing the number of frames can INCREASE page faults with FIFO.
Classic example: Reference string 1 2 3 4 1 2 5 1 2 3 4 5
- 3 frames: 9 page faults
- 4 frames: 10 page faults (more frames, MORE faults -- anomaly!)
FIFO is the only commonly taught algorithm that exhibits Belady's anomaly. LRU, OPT, and clock algorithm do not.
Q20. Explain OPT (Optimal) page replacement. Why is it not practical? Medium
OPT (Belady's Optimal Algorithm): Replace the page that will not be used for the longest time in the future.
Example (3 frames, string: 7 0 1 2 0 3 0 4 2 3 0 3):
7: [7,-,-] FAULT
0: [7,0,-] FAULT
1: [7,0,1] FAULT
2: [2,0,1] FAULT (evict 7: next use of 7 is never in remaining string; next use of 0 is position 4, 1 is far, 7 is farthest)
0: [2,0,1] HIT
3: [2,0,3] FAULT (evict 1: next use of 1 is never; 2 is used at pos 8, 0 is used at pos 6)
0: [2,0,3] HIT
4: [4,0,3] FAULT (evict 2: next use of 2 is pos 8; next use of 3 is pos 9; next use of 0 is pos 10; 2 is farthest? Actually 0 next at pos 10 is farthest. Evict 0? Let's just note OPT evicts the farthest.)
OPT produces the minimum possible page faults for any algorithm. It is used as a benchmark to evaluate other algorithms.
Why impractical: Requires knowing the future reference string in advance. No OS can know what pages will be accessed next by a running program. OPT is a theoretical lower bound.
Q21. Explain LRU page replacement. How is it implemented? Medium
LRU (Least Recently Used): Evict the page that was accessed least recently. The intuition: recently-used pages are likely to be used again (temporal locality).
LRU does NOT exhibit Belady's anomaly.
Example (3 frames, string: 7 0 1 2 0 3 0 4):
7: [7,-,-] FAULT
0: [7,0,-] FAULT
1: [7,0,1] FAULT
2: [2,0,1] FAULT (evict 7: LRU order is 7,0,1; 7 least recent)
0: [2,0,1] HIT (0 was just used)
3: [2,0,3] FAULT (evict 1: LRU order is 1,2,0; 1 least recent)
0: [2,0,3] HIT
4: [4,0,3] FAULT (evict 2: LRU order is 2,3,0; 2 least recent)
LRU implementations:
| Implementation | Mechanism | Cost |
|---|---|---|
| Counter-based | Each page has a counter = CPU clock value on last access. On replacement, find min counter. | O(n) search on every fault |
| Stack-based | Maintain a stack of page numbers; on access, move page to top. LRU page is always at bottom. | O(1) access with doubly-linked list + hash map |
| Hardware timestamps | Special hardware timestamps every memory access. | Expensive hardware |
Most practical: Stack-based LRU (doubly-linked list + hash map) gives O(1) access and update. Used in OS and cache designs.
Q22. Explain the Clock (Second Chance) page replacement algorithm. Medium
Clock Algorithm: A practical LRU approximation that avoids full LRU tracking overhead.
Mechanism:
- Pages arranged in a circular queue with a clock hand pointer.
- Each page has a reference bit (set by hardware on access, cleared by OS).
- On page fault (need a frame):
- Check page at clock hand.
- If reference bit = 1: clear it (second chance), advance hand, go to step 1.
- If reference bit = 0: evict this page, place new page here, advance hand.
Example:
Frames (circular): [A(ref=1)] -> [B(ref=0)] -> [C(ref=1)] -> [D(ref=1)] -> (back to A)
Clock hand at A.
Fault (need frame):
A: ref=1, clear to 0, advance to B
B: ref=0, EVICT B. Load new page E here. Advance to C.
Result: [A(ref=0)] -> [E(ref=1)] -> [C(ref=1)] -> [D(ref=1)]
Why it works: A page that was recently accessed gets one extra chance (its reference bit is cleared rather than evicted). If it is accessed again before the clock returns, it survives. If not, it is evicted next round.
Linux page replacement: Linux uses a two-list LRU approximation (active/inactive lists) rather than a pure clock, but the reference bit mechanism is the same.
Q23. What is the difference between global and local page replacement? Medium
| Aspect | Local Replacement | Global Replacement |
|---|---|---|
| Scope | Replace only within process's own allocated frames | Replace from ALL frames in the system |
| Frame count | Fixed per process | Can grow/shrink dynamically |
| Isolation | One process's page fault does not affect others | An aggressive process can steal frames from others |
| Efficiency | May underutilize (process may hold frames it rarely uses) | Better overall utilization |
| Fairness | Guaranteed minimum frames per process | No guarantee |
Global replacement is generally more efficient and is used by Linux (with proportional frame allocation that adapts over time). Local replacement provides stronger isolation guarantees needed in multi-tenant environments.
Q24. What is thrashing? How is it detected and fixed? Hard
Thrashing occurs when a process spends more time handling page faults than doing useful work. The CPU utilization drops as processes wait for pages to be loaded from disk.
Cause: Too many processes competing for too little memory. Each process has fewer frames than its working set needs.
CPU utilization vs. degree of multiprogramming:
Utilization
100% | *
| * *
| * *
50%| * *
| * *
0% |___________________*__
Low High <-- Degree of multiprogramming
thrashing starts here
Detection signals:
- CPU utilization drops while disk I/O spikes.
- System feels sluggish despite low CPU %.
- Page fault rate very high (thousands per second vs. normal dozens).
Fix:
| Solution | Mechanism |
|---|---|
| Reduce degree of multiprogramming | Suspend (swap out) some processes to give remaining processes enough frames |
| Working set model | Allocate each process enough frames to hold its working set before admitting it |
| Page fault frequency (PFF) control | If a process's page fault rate > upper threshold, give it more frames. If < lower threshold, take frames away |
| Locality-aware scheduling | Group processes by memory locality (e.g., database vs. video encoder have different working sets) |
Advanced Topics
Q25. What is a segmented-paging system? Hard
Segmented Paging combines segmentation and paging:
- Logical address space is divided into segments (matching logical units: code, data, stack).
- Each segment is further divided into pages.
- Physical memory is managed in fixed-size frames (paging layer handles allocation).
Address translation:
Logical address: [segment_number | page_number | offset]
1. Segment table entry gives base of that segment's page table + protection info.
2. Page table entry gives physical frame number.
3. Physical address = frame_number * page_size + offset
Benefits:
- Logical structure of segments (shared code segments, different permissions per segment).
- Physical memory allocation is paging-based (no external fragmentation).
Used in: Intel x86 (IA-32 hardware has full segment + page translation, though modern OSes mostly use flat segments to simplify to pure paging). Linux sets segment bases to 0 and uses paging only.
Q26. What is memory-mapped I/O (MMIO) and memory-mapped files? Hard
Memory-Mapped I/O (MMIO): Device registers are mapped into the physical address space. CPU reads/writes to those addresses communicate directly with the device instead of going to RAM.
Physical address space layout (x86):
0x00000000 - 0x9FFFFFFF: RAM
0xA0000000 - 0xBFFFFFFF: Video memory (mapped)
0xC0000000 - 0xCFFFFFFF: ROM BIOS
0xD0000000 - 0xFFFFFFFF: Device registers (NIC, GPU, etc.)
Writing to a device register address = sending a command to the device (no IN/OUT instructions needed for many modern devices).
Memory-Mapped Files (mmap): A file is mapped into the virtual address space. Reading/writing the memory region reads/writes the file directly.
// Map a file into memory
int fd = open("data.bin", O_RDWR);
char *ptr = mmap(NULL, file_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
ptr[100] = 'X'; // Writes directly to file at offset 100
munmap(ptr, file_size);
Advantages: No explicit read()/write() calls. OS manages page-in/page-out of file data. Multiple processes can mmap the same file and share data (IPC). Used by databases (SQLite, RocksDB) and shared libraries.
Q27. What is NUMA (Non-Uniform Memory Access)? Hard
NUMA is a memory architecture used in multi-processor systems where different processors have different access latencies to different memory regions.
NUMA topology (2-node system):
Node 0: CPU0, CPU1 | Local RAM: 32GB
Node 1: CPU2, CPU3 | Local RAM: 32GB
Access times:
CPU0 to Node 0 RAM: 40ns (local)
CPU0 to Node 1 RAM: 80ns (remote, via QPI/HyperTransport interconnect)
OS implications:
- NUMA-aware allocator tries to allocate memory on the same node as the thread that will use it.
- Linux uses the
numactltool and NUMA-aware page allocation policies. - Process migration between nodes incurs cache invalidation and potentially re-allocating pages on new node.
In production: Database servers (MySQL, PostgreSQL, Redis) are NUMA-aware. Binding a process to a NUMA node and its local memory reduces latency by 50-100ns per access. This matters significantly for high-throughput workloads.
Q28. What is the buddy system allocator? Hard
The buddy system is a memory allocation scheme that keeps free blocks in powers-of-2 sizes.
Mechanism:
To allocate K bytes:
1. Round K up to nearest power of 2, call it 2^n.
2. Find smallest free block of size 2^m >= 2^n.
3. If 2^m > 2^n: split 2^m into two buddies of size 2^(m-1).
4. Repeat until a block of exactly 2^n is found. Allocate it.
To free a block of size 2^n:
1. Check if its buddy is also free.
2. If yes: merge them into a single block of size 2^(n+1).
3. Repeat until buddy is not free or max size reached.
Example:
Available: [256KB free]
Allocate 32KB:
256 -> split -> [128, 128]
128 -> split -> [64, 64, 128]
64 -> split -> [32, 32, 64, 128]
Give first 32 to process A.
Allocate 64KB:
Take the 64KB block. Give to process B.
Free process A (32KB):
Buddy of first 32 is second 32 (free) -> merge to [64, 64, 128]
Buddy of merged 64 is the 64 used by B (not free) -> stop.
Used in: Linux kernel (__alloc_pages() buddy allocator for physical pages). Slab allocator built on top for sub-page allocations.
Q29. What is the slab allocator? Hard
The slab allocator is a memory management mechanism for allocating small kernel objects (inodes, dentry, task_struct, etc.) efficiently.
Problem it solves: The buddy allocator works with full pages (4KB+). Kernel objects are typically 64-512 bytes. Allocating a full page for each object wastes memory and causes fragmentation.
Slab concept:
Cache "task_struct_cache":
Slab 1 (1 page = 4KB, holds ~8 task_structs):
[task 1][task 2][task 3][FREE][FREE][FREE][task 4][task 5]
Slab 2 (full):
[task 6][task 7][task 8][task 9][task 10][task 11][task 12][task 13]
Slab 3 (empty - ready for new allocations)
Allocation: Take from a partially-full slab. If none, carve from an empty slab. If none, allocate new slab from buddy allocator.
Advantages:
- No fragmentation within slabs (objects are all same size).
- Fast: returning an object puts it back in the slab cache (not zeroed, constructor already run).
- Reuses objects: if a task_struct is freed and immediately needed, the same physical memory is reused.
Linux implementation: kmalloc() uses the SLUB allocator (an improved slab variant). The slab API: kmem_cache_create(), kmem_cache_alloc(), kmem_cache_free().
Q30. How would you answer "explain virtual memory" in a 3-minute interview? Easy
A structured answer:
1. Definition (30 sec): "Virtual memory is a layer of abstraction that gives each process the illusion of having a large, private address space, even if physical RAM is limited or fragmented. The OS manages the mapping between virtual addresses used by the program and physical RAM locations."
2. Mechanism (60 sec): "It is implemented through paging. Both logical address space and physical memory are divided into fixed-size blocks called pages and frames. When a process accesses a virtual page that is not in RAM, the OS handles a page fault: it loads the required page from disk into a free physical frame, updates the page table, and resumes the process."
3. Benefits (30 sec): "Virtual memory lets programs larger than RAM run, enforces memory isolation between processes, enables shared libraries, and enables Copy-on-Write optimization for fork()."
4. Trade-off (30 sec): "The cost is page fault overhead. If a process's working set does not fit in RAM, it thrashes: spending more time on I/O than actual work. Tuning involves giving processes enough frames to hold their working set."
5. Production example (30 sec): "On a JVM with a 32GB heap on a 16GB RAM machine, the OS pages out rarely-used JVM objects to disk. The JVM sees a 32GB heap but only 16GB is actually in RAM at any time. This is virtual memory in production."
FAQ
Q: What is the difference between paging and swapping? Swapping moves entire processes to disk. Paging moves individual pages. Modern systems use paging; swapping is mostly a legacy concept or refers loosely to paging.
Q: How much internal fragmentation does paging cause? On average, half a page per process. With 4KB pages and 1000 processes, about 2MB of internal fragmentation. Acceptable.
Q: Why are page sizes always powers of 2? Because the offset within a page corresponds to the lower bits of the address. Power-of-2 sizes make bit masking and shifting simple and fast in hardware.
Related PapersAdda guides:
Methodology applied to this articlelast verified 8 Jun 2026
- No fabricated salary numbers or success rates. If we quote a range, it's sourced.
- No noun-substituted templates. This article was not generated by swapping company names in a stock prompt.
- No paid placements, sponsored coaching links, or affiliate-shilled course pushes.
Explore this topic cluster
More resources in Interview Questions
Use the category hub to browse similar questions, exam patterns, salary guides, and preparation resources related to this topic.
Paid contributor programme
Sat this this year? Share your story, earn ₹500.
First-person experience reports help future candidates prep smarter. We pay verified contributors ₹500 via UPI per accepted story - with byline.
Submit your story →Ready to practice?
Take a free timed mock test
Put what you learned into practice. Our mock tests match the 2026 pattern with timer, navigator, reveal, and score breakdown. No signup.
Start Free Mock Test →More from PapersAdda
Accenture Interview Questions 2026 (with Answers for Freshers)
Capgemini Interview Questions 2026 (with Answers for Freshers)
HCLTech Interview Questions 2026 (TechBee + TGT, with Answers)
IBM Interview Questions 2026 (with Answers for Freshers)