๐ Memory allocation in contiguous memory allocation (14 MCQs)
๐ From Operating System โข 8. Main Memory โข 14 questions available
What is Memory allocation in contiguous memory allocation?
Definition:
Contiguous allocation assigns each process a single continuous segment of memory using strategies like first-fit, best-fit, or worst-fit to manage free holes.
Example:
For a request of size , best-fit selects the smallest free hole minimizing wasted space compared to first-fit.
Reason:
Simple implementation and fast access due to locality but suffers from external fragmentation limiting long-term memory utilization efficiency.
๐ 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.