๐ Memory allocation in contiguous memory allocation (14 MCQs)
Assigning Continuous Physical Regions to Processes
Contiguous memory allocation is a memory-management approach in which each process receives one continuous region of physical main memory. The operating system maintains information about occupied regions and available holes, selecting a suitable free region whenever a process enters memory. Depending on the allocation strategy, partitions may have fixed or variable sizes. The method provides straightforward placement but requires careful management of available memory regions.
Choosing Between Fixed and Variable Partitioning
Fixed partitioning divides memory into predetermined regions before processes are allocated, whereas variable partitioning creates regions according to individual process requirements. Fixed partitions simplify bookkeeping but can waste unused space inside allocated regions. Variable partitions improve flexibility but leave separated free holes as processes enter and leave memory. The allocation policy determines which available hole receives each incoming process.
First-Fit, Best-Fit and Worst-Fit Selection
First-fit scans available holes from the beginning and selects the first sufficiently large region. Best-fit chooses the smallest hole that accommodates the request, often requiring examination of the available list. Worst-fit selects the largest available hole. After selection, variable partitioning divides the chosen hole, assigning the required portion to the process and retaining any usable remainder.
Allocating a Process from Three Available Holes
Suppose available holes have sizes of 100 KB, 500 KB, and 200 KB, in that order. A process requiring 180 KB is allocated the 500 KB hole by first-fit, while best-fit selects the 200 KB hole. Worst-fit also selects the 500 KB hole. The remaining free regions differ, affecting the sizes of holes available for subsequent process requests.
Allocation Efficiency and Process Placement
Allocation policies influence memory utilisation, allocation speed, and future fragmentation. First-fit is usually simple and relatively quick, while best-fit may produce small unusable remainders. Worst-fit attempts to preserve larger remaining holes but does not guarantee better utilisation. Variable partitioning accommodates different process sizes, but repeated allocation and deallocation reduce the availability of suitably sized contiguous regions.
Frequent Confusions About Partition Selection
'First-fit always chooses the smallest suitable hole' is incorrect because that is the selection principle of best-fit. 'Worst-fit selects the smallest available partition' is incorrect because it chooses the largest available hole. 'Fixed partitions eliminate memory waste' is incorrect because an allocated partition can exceed its process requirements, leaving unused internal space.
Exam Focus: Tracing Allocation Policies
Apply first-fit, best-fit, and worst-fit to the same ordered list of memory holes. Track the remaining space after every allocation and note how earlier decisions affect later requests. Distinguish fixed partitioning from variable partitioning, and identify whether unused space lies inside an allocated partition or between separate allocations.
Key Terms of Contiguous Allocation
- Partition - Allocated memory region.
- Hole - Available contiguous memory region.
- First-fit - Selects first suitable hole.
- Best-fit - Selects smallest suitable hole.
- Worst-fit - Selects largest available hole.
- Variable partition - Region sized for a process.
๐ All Memory allocation in contiguous memory allocation MCQs
Q1. What does the base register store in a protected memory system?
๐ Explanation: The base register holds the lowest physical address a process may reference, establishing the start of its allowed region. This ensures the CPU cannot address memory below that point. Options B, C, and D describe unrelated concepts: the largest address is defined by the limit, the segment size is the limit value, and privilege flags are stored elsewhere. By keeping the base correct, the system enforces isolation and prevents accidental or malicious access to other memory areas.
Q2. Why is a limit register needed alongside a base register?
๐ Explanation: The limit register specifies how far beyond the base address a process may go, effectively setting the maximum legal address. Without it, the CPU would have no way to know where the process's memory region ends, risking overlap with other processes. Options A, C, and D describe unrelated functions: priorities are managed by the scheduler, flags are part of status registers, and mode indication is handled by separate control bits.
Q3. If a process has a base register value of 300040 and a limit register value of 120900, what is the highest physical address the process may legally access?
๐ Explanation: The highest address equals base plus limit minus one: . This calculation defines the inclusive upper bound of the process's address space. Option A is off by one low, Option B exceeds the limit by one, and Option D is far beyond the allowed range. Understanding this arithmetic is crucial for ensuring a process cannot read or write outside its allocated region, which could corrupt other processes or the operating system.
Q4. A user program attempts to read address 421000 with base 300040 and limit 120900. What hardware response is most likely?
๐ Explanation: The CPU compares the requested address with the base and limit; because 421000 exceeds , the check fails and the hardware raises a protection fault, terminating or trapping the process. Options A and C describe behaviors that would break isolation, while Option B would mask the error and lead to unpredictable results. The fault mechanism preserves system stability by preventing illegal memory accesses.
Q5. How do base and limit registers relate to the concept of virtual memory?
๐ Explanation: Base and limit registers implement a basic form of address translation by mapping a contiguous virtual region to a physical region, much like a single segment in segmented memory. This is a precursor to full virtual memory systems, which use more complex structures such as page tables. Options B and D incorrectly claim they remove translation mechanisms, and Option C misstates their scope to kernel memory only.
Q6. Why is memory protection typically enforced by hardware rather than by the operating system?
๐ Explanation: Hardware can perform address checks on every memory reference with minimal latency, avoiding the performance penalty of a software trap for each access. An OSโlevel check would require context switches and additional instructions, dramatically slowing execution. Options A and D misrepresent OS capabilities, and Option C describes a function not related to protection. Fast hardware enforcement thus keeps programs running efficiently while still maintaining strict isolation.
Q7. Given a base register of 200000 and a limit register of 50000, what physical address corresponds to logical address 12345?
๐ Explanation: Physical addresses are calculated by adding the logical offset to the base: . This simple addition respects the limit because 12345 is less than 50000, so the address is valid. Options A, B, and D are close but incorrect arithmetic results, illustrating common offโbyโfew errors. Correct translation is essential for a process to locate its data correctly within the allocated physical memory region.
Q8. Process X has base 100000 and limit 40000. Process Y has base 130000 and limit 30000. Which statement is true?
๐ Explanation: Process X occupies 100000โ139999, while Process Y occupies 130000โ159999, creating an overlapping region from 130000โ139999. Therefore their spaces are not disjoint, and neither process fully contains the other. Options A, B, and C each mischaracterize the relationship, ignoring the shared interval. Overlap would allow one process to read or modify the other's data, violating protection guarantees.
Q9. If a processโs limit register is set to a value smaller than the actual size of its code segment, what is the most likely outcome?
๐ Explanation: When the process tries to execute instructions located beyond the defined limit, the hardware detects the violation and raises a protection fault, typically terminating the program. The OS does not silently adjust limits (Option B), and the CPU does not disregard the limit (Option C). Option D is unrealistic because memory allocation is not dynamic based on faults. This scenario highlights the importance of correctly configuring limit values during loading.
Q10. Which statement best compares base/limit protection with paging?
๐ Explanation: The accurate comparison is that base/limit protection offers a simple contiguous segment, whereas paging breaks memory into fixedโsize pages and uses page tables for translation. Option A reverses the correct description, Option C incorrectly claims paging removes limits, and Option D misstates the capability of a single register set to handle many processes. Recognizing these differences clarifies why modern systems favor paging for flexibility despite added complexity.
Q11. A system mistakenly loads a limit register with value 0xFFFFFFFF for a user process. Which mitigation technique would prevent the process from corrupting the kernel?
๐ Explanation: Validating limit values before they are programmed into the hardware ensures that absurdly large limits, like 0xFFFFFFFF, are rejected, preserving kernel integrity. A privilege check (Option A) controls access but does not catch malformed limits, ASLR (Option B) randomizes addresses but does not enforce size constraints, and guard pages (Option D) protect against overrun but assume the limit is already reasonable. Proper validation is the primary defense against such configuration errors.
Q12. What is the primary performance penalty associated with hardware address checks using base and limit registers on every memory reference?
๐ Explanation: Each memory reference triggers a comparison of the generated address against the base and limit registers, adding a small but measurable delay to every load or store operation. Options A and B describe unrelated hardware characteristics, while Option C pertains to multitasking overhead, not perโaccess checks. Understanding this cost helps architects balance security with speed, especially in highโthroughput systems where many memory accesses occur.
Q13. Three processes have the following base and limit values: P1 (base 0, limit 50000), P2 (base 45000, limit 30000), P3 (base 80000, limit 20000). What is the total amount of physical memory occupied and does any overlap occur?
๐ Explanation: P1 occupies 0โ49999, P2 occupies 45000โ74999, and P3 occupies 80000โ99999. The overlap between P1 and P2 (45000โ49999) is 5000 bytes. Unique memory used = 50000 (P1) + 30000 (P2) โ 5000 (overlap) + 20000 (P3) = 95000 bytes, and overlap is present. Options B and D give incorrect totals, and Option C incorrectly states there is no overlap. This calculation demonstrates how overlapping segments waste memory and violate protection rules.
Q14. Which tradeโoff best describes the use of base/limit registers versus more complex segmentation schemes in modern operating systems?
๐ Explanation: Base and limit registers give a straightforward, lowโoverhead way to delineate a processโs address space, making address checks fast but limiting the ability to create multiple, variableโsize segments. Segmentation offers greater flexibility by allowing several segments with different attributes, but it introduces extra hardware and software complexity. Options A and D misrepresent the hardware requirements, and Option C reverses the typical securityโperformance relationship. Recognizing this tradeโoff helps designers choose the appropriate protection mechanism for their system goals.