Memory Management Interview Questions with Numericals
Last updated 2026-11-19
Memory management questions test whether you understand how the operating system shares limited RAM between processes safely. Interviews start with logical versus physical addresses and fragmentation, then move to numericals: placing processes into partitions with first fit, best fit and worst fit, translating a segmented address, or sizing a buddy allocation. This page covers contiguous allocation, segmentation, swapping and the allocators the kernel uses.
Paging and virtual memory, including page tables, TLBs and page replacement, have their own page: paging and virtual memory interview questions. For the whole subject outline see operating systems interview questions, and for exam strategy how to crack an OS interview.
| Numericals | First/best/worst fit, segment translation, buddy allocation, fragmentation |
|---|---|
| Related depth page | Paging and virtual memory |
| Questions | 15 |
Terms to keep straight
- Logical (virtual) address: generated by the CPU. Physical address: seen by the memory unit. The MMU maps one to the other at run time.
- Internal fragmentation: unused space inside an allocated block. External fragmentation: free space split into pieces too small to use.
- Base and limit registers: the base is added to every logical address, the limit rejects addresses beyond the process size.
Memory Management Interview Questions with Numericals: questions with worked answers
1 Differentiate between logical and physical addresses.
easyA logical address is generated by the CPU while a program runs and is what the program sees, starting from zero. A physical address is the actual location in main memory. The memory-management unit translates between them at run time, using a relocation (base) register in simple schemes or page tables in paged systems. This lets the OS move a process in memory and keeps processes from touching each other's data.
2 How do base and limit registers provide protection?
easyEvery address a process generates is compared with the limit register; if it is greater than or equal to the limit the hardware traps to the OS. Otherwise the base register is added to give the physical address. Example: base = 30000, limit = 12000 means the process may use physical addresses 30000 to 41999. Logical address 500 maps to 30500, while 13000 causes a trap.
3 What is the difference between internal and external fragmentation?
easyInternal fragmentation is wasted space inside a block given to a process, such as a 4 KB page allocated to a 1 KB request (3 KB wasted), and it occurs with fixed partitions and paging. External fragmentation is free memory scattered in holes that are individually too small, even though the total would suffice; it occurs with dynamic partitioning and segmentation. Compaction or paging can remove external fragmentation.
4 Numerical: Partitions of 100, 500, 200, 300 and 600 KB (in this order). Place processes of 212, 417, 112 and 426 KB, in this order, using first fit, best fit and worst fit.
mediumFirst fit takes the first hole that is large enough: 212 goes to 500 (leaving 288), 417 goes to 600 (leaving 183), 112 goes to the 288 hole (leaving 176), and 426 finds no hole of 426 or more (holes are 100, 176, 200, 300, 183), so it waits. Best fit takes the smallest sufficient hole: 212 to 300 (88 left), 417 to 500 (83 left), 112 to 200 (88 left), 426 to 600 (174 left), so all four are placed. Worst fit takes the largest: 212 to 600 (388), 417 to 500 (83), 112 to 388 (276), and 426 has no hole (100, 83, 200, 300, 276), so it waits. Best fit made the best use here.
5 Compare first fit, best fit and worst fit.
mediumFirst fit scans from the start and stops at the first adequate hole, so it is fast. Best fit searches the whole list for the smallest adequate hole, leaving tiny unusable remainders and costing more time unless the list is sorted by size. Worst fit picks the largest hole hoping the remainder is useful, but simulations show it performs poorly. Both first fit and best fit are generally better than worst fit in utilisation, and first fit is usually faster.
6 What is compaction? When is it possible?
mediumCompaction shuffles allocated blocks together to make all free memory one large hole, eliminating external fragmentation. It is possible only if relocation is dynamic, that is, if addresses are bound at execution time through a base register, because the process addresses must change after it is moved. It is costly because it copies a lot of memory, so systems use paging instead.
7 Numerical: A segment table has entries (base, limit): seg 0 (1400, 1000), seg 1 (6300, 400), seg 2 (4300, 400), seg 3 (3200, 1100), seg 4 (4700, 1000). Translate (2, 53), (3, 852) and (0, 1222).
mediumFor each pair (s, d) check d < limit(s), then physical address = base(s) + d. For (2, 53): 53 < 400, so address = 4300 + 53 = 4353. For (3, 852): 852 < 1100, so address = 3200 + 852 = 4052. For (0, 1222): 1222 is not less than the limit 1000, so the hardware raises an addressing-error trap.
8 What are the advantages and disadvantages of segmentation?
mediumSegmentation matches the programmer's view (code, data, stack, each a segment), allows sharing and protection per segment (a code segment can be read-only and shared), and the segment table is small. The disadvantages are external fragmentation because segments vary in length, and the need to find a hole large enough for each segment. Segmentation with paging, as in older x86 designs, divides each segment into pages to remove external fragmentation.
9 What is swapping?
mediumSwapping temporarily moves a whole process from main memory to a backing store (disk or SSD) and brings it back later, so the total memory demand of all processes can exceed RAM. A process swapped out while waiting for I/O needs care: either do I/O into kernel buffers or never swap a process with pending I/O. Modern systems swap or page out individual pages instead of entire processes, and Linux uses a swap partition or file for this.
10 Numerical: Describe the buddy system by allocating 70 KB from a 256 KB block, then 35 KB, then 80 KB.
mediumThe buddy system rounds each request up to a power of two. 70 KB needs 128 KB: split 256 into 128 + 128 and allocate one 128 block (internal waste 58 KB). 35 KB needs 64 KB: split the free 128 into 64 + 64 and allocate one (waste 29 KB). 80 KB needs 128 KB, but the only 128 block is used; the remaining 64 KB is too small, so the request fails until memory is freed. On free, a block merges with its buddy (found by flipping one address bit) if the buddy is also free. The scheme gives fast merging but wastes space on rounding.
11 What is the difference between static and dynamic loading and linking?
mediumStatic linking copies library code into the executable at build time, so the file is large but self-contained. Dynamic linking (shared libraries such as .so or .dll) defers resolution to load or run time, so many programs share one copy in memory and libraries can be updated separately. Dynamic loading loads a routine only when it is first called, saving memory for rarely used code.
12 Describe the layout of a process in memory.
mediumFrom low to high addresses a typical layout has the text segment (machine code, read-only), initialised data, uninitialised data (BSS), the heap that grows upward through malloc or new, and the stack that grows downward holding call frames and local variables. Shared libraries and memory-mapped files sit between heap and stack. Stack overflow occurs when the stack grows into other regions or hits its limit; heap leaks occur when allocated memory is never freed.
13 Numerical: In a variable-partition system, holes of 10, 4, 20, 18, 7, 9, 12 and 15 KB exist in memory order. Requests of 12, 10 and 9 KB arrive. Which holes does next fit use?
hardNext fit resumes searching from where the last search stopped. Start at the beginning: 12 KB takes the 20 KB hole (the 10 and 4 are too small; the 20 is the first that fits), leaving 8. Next fit continues after the 20 hole for the 10 KB request: 18 fits, leaving 8. For 9 KB it continues after 18: 7 is too small, 9 fits exactly. So the allocations are 20, 18 and 9. First fit would have used 12 -> 20, 10 -> 10, 9 -> 18, showing how the algorithms diverge.
14 How does the kernel allocate small objects efficiently, and what problem does it solve?
hardGeneral-purpose page allocation is too coarse and wasteful for small kernel objects such as process descriptors or inodes. The slab allocator keeps caches of pre-initialised objects of one type. Each cache has slabs (one or more contiguous pages) split into object-sized slots, tracked as full, partial or empty. Allocation takes a slot from a partial slab, and freeing returns it, reusing the already constructed object. This removes internal fragmentation for those sizes and speeds up allocation. Linux uses slab, slub or slob variants.
15 Why does external fragmentation not occur in paging, and what replaces it?
hardPhysical memory is divided into frames of equal size, and any free frame can hold any page, so a process needs only enough free frames, not contiguous ones. The waste moves to internal fragmentation: on average half a page per process is unused in the last page. Choosing page size is a trade-off between that waste, page-table size and disk transfer efficiency. See paging and virtual memory.
Frequently asked questions
Which is better, first fit or best fit?
Neither always wins. First fit is quicker because it stops at the first adequate hole. Best fit leaves the smallest remainder per allocation but creates many tiny holes and costs more time. Exam questions like the one above are designed so that one of them succeeds where another fails.
What is the difference between memory management and virtual memory?
Memory management is the whole subject of allocating and protecting RAM. Virtual memory is one technique within it that lets a process use more address space than physical RAM by keeping part of it on disk.
What is thrashing?
Thrashing occurs when a system spends more time paging than executing because processes do not have enough frames for their working sets. It is covered on the paging and virtual memory page.
How is memory protected between processes?
Through the MMU: base and limit registers in simple schemes, or per-process page tables with valid and permission bits in paged systems. Any access outside the allowed range triggers a trap into the kernel.
Related guides
- Operating Systems Interview Questions with Worked Answers
- Paging and Virtual Memory Interview Questions with Numericals
- Process and Thread Interview Questions with fork() Output Problems
- Cache Memory and Computer Organization Interview Questions with Numericals
- File System Interview Questions: Inodes, Allocation and Disk Scheduling
- Linux Interview Questions and Answers: Concepts, Permissions and Processes
More in CS Fundamentals Interview Questions
- Message Queue and Kafka Interview Questions
- Microservices Interview Questions and Answers
- MongoDB Interview Questions and Answers
- Network Security Interview Questions: Cryptography, Firewalls and Attacks
- Normalization Interview Questions with Worked Examples
- NoSQL Interview Questions and Answers
- OOPs Interview Questions and Answers
- Operating Systems Interview Questions with Worked Answers
- OSI Model Interview Questions: Layers, PDUs, Devices and Encapsulation
- Paging and Virtual Memory Interview Questions with Numericals
- Process and Thread Interview Questions with fork() Output Problems
- Process Synchronization Interview Questions: Semaphores, Mutex and Classic Problems