๐ŸŽ“ BookMCQ
โ† Back to 8. Main Memory

๐Ÿ“ 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.
3
Easy
6
Medium
5
Hard

๐Ÿ“ All Memory allocation in contiguous memory allocation MCQs

Q1. What does the base register store in a protected memory system?

A.The smallest legal physical address โœ…
B.The largest legal physical address
C.The size of the memory segment
D.A flag indicating user mode
๐Ÿ’ก Difficulty: easy | โœ… Correct: A

๐Ÿ“– 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?

A.To store the process priority
B.To define the upper bound of the process's address space โœ…
C.To hold CPU flags
D.To indicate user mode
๐Ÿ’ก Difficulty: easy | โœ… Correct: B

๐Ÿ“– 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?

A.420938 โœ…
B.420940
C.420939
D.421000
๐Ÿ’ก Difficulty: easy | โœ… Correct: A

๐Ÿ“– Explanation: The highest address equals base plus limit minus one: 300040+120900โˆ’1=420939300040 + 120900 - 1 = 420939. 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?

A.Translate to a kernel address
B.Silently wrap around to the start of the segment โœ…
C.Ignore the limit and allow the access
D.Raise a protection fault
๐Ÿ’ก Difficulty: medium | โœ… Correct: B

๐Ÿ“– Explanation: The CPU compares the requested address with the base and limit; because 421000 exceeds 300040+120900โˆ’1=420939300040 + 120900 - 1 = 420939, 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?

A.They provide a simple contiguous mapping similar to a segment
B.They eliminate the need for page tables
C.They are used only for kernel memory โœ…
D.They replace the need for address translation hardware
๐Ÿ’ก Difficulty: medium | โœ… Correct: C

๐Ÿ“– 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?

A.Because the OS cannot access memory at all
B.Because hardware checks are faster than OS checks
C.Because hardware can modify program code โœ…
D.Because the OS lacks necessary privileges
๐Ÿ’ก Difficulty: medium | โœ… Correct: C

๐Ÿ“– 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?

A.212300
B.212340
C.212345 โœ…
D.212350
๐Ÿ’ก Difficulty: medium | โœ… Correct: C

๐Ÿ“– Explanation: Physical addresses are calculated by adding the logical offset to the base: 200000+12345=212345200000 + 12345 = 212345. 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?

A.Their address spaces are disjoint
B.Y is fully contained within X's space
C.X is fully contained within Y's space
D.Their address spaces overlap โœ…
๐Ÿ’ก Difficulty: medium | โœ… Correct: D

๐Ÿ“– 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?

A.The program crashes when accessing code beyond the limit
B.The operating system automatically expands the limit โœ…
C.The CPU ignores the limit and continues execution
D.The process receives extra memory from the system
๐Ÿ’ก Difficulty: medium | โœ… Correct: B

๐Ÿ“– 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?

A.Base/limit provides variableโ€‘sized segments while paging uses fixedโ€‘size pages โœ…
B.Base/limit and paging are functionally identical
C.Paging eliminates the need for limit registers
D.Base/limit can protect multiple processes with a single register set
๐Ÿ’ก Difficulty: hard | โœ… Correct: A

๐Ÿ“– 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?

A.Use a separate privilege level check โœ…
B.Enable address space layout randomization
C.Require the OS to validate limit values before loading
D.Implement a guard page beyond the limit
๐Ÿ’ก Difficulty: hard | โœ… Correct: A

๐Ÿ“– 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?

A.Increased cache size
B.Longer instruction decode time
C.Need for context switches โœ…
D.Additional comparison per access
๐Ÿ’ก Difficulty: hard | โœ… Correct: C

๐Ÿ“– 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?

A.95000 bytes with overlap
B.100000 bytes without overlap
C.95000 bytes without overlap โœ…
D.100000 bytes with overlap
๐Ÿ’ก Difficulty: hard | โœ… Correct: C

๐Ÿ“– 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?

A.Base/limit requires more hardware support than segmentation
B.Base/limit is simpler and faster but less flexible
C.Segmentation provides better security at the cost of speed โœ…
D.Segmentation eliminates the need for paging
๐Ÿ’ก Difficulty: hard | โœ… Correct: C

๐Ÿ“– 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.

๐Ÿ”— Related Topics (MCQs)