solution - Operating System : Memory Management (Test 2)

Question : Suppose a 16-bit logical address uses 4 bits for segment number and 12 bits for offset.

Solution :
30820260315010821 Correct Answer : 4096 bytes

Description -

4096 bytes is the maximum size of each segment.

Explanation:

In a segmented memory management system, a logical address is divided into two parts: the Segment Number and the Offset.

  • Segment Number (4 bits): This determines the total number of segments the system can support. With 4 bits, you can have \(2^4 = 16\) unique segments.
  • Offset (12 bits): This determines the maximum size (or the number of addressable locations) within any single segment.

To find the maximum size of a segment, you calculate the total number of bytes that can be addressed by the offset bits:
\(\text{Maximum Segment Size}=2^{\text{offset bits}}\text{ bytes}\)
\(\text{Maximum Segment Size}=2^{12}\text{ bytes}=4096\text{ bytes}\)

(Note: \(2^{10} \text{ bytes} = 1024 \text{ bytes} = 1\text{ KB}\), so \(2^{12} \text{ bytes} = 4 \times 1024 = 4096 \text{ bytes}\) or \(4\text{ KB}\).)

Question : Which of the following is a major disadvantage of segmentation?

Solution :
687920260315010721 Correct Answer : External fragmentation

Description -

External fragmentation is a major disadvantage of segmentation.

Explanation:

Unlike paging, which divides memory into fixed-size blocks, segmentation allocates memory in variable-sized segments based on the actual logical requirements of a program (e.g., code, data, stack).

As programs are loaded and removed from memory, the remaining free memory space gets broken up into small, scattered pieces. Eventually, the total amount of free memory might be large enough to satisfy a program's request, but because the free space is not contiguous (continuous), it cannot be allocated. This phenomenon is called external fragmentation.

Why the other options are incorrect:

  • Internal fragmentation: This occurs when fixed-size blocks are allocated (like in paging) and the program doesn't use the whole block, leaving wasted space inside the allocated block. Segmentation avoids this because segments are exactly the size the program requests.
  • Fixed segment size: This is incorrect because segments are inherently variable in size, not fixed.
  • No logical structure for programs: This is incorrect because providing a logical structure (separating code, data, heap, stack) is the primary advantage of segmentation, as it mirrors how a programmer views a program.

Question : Which information is stored in each entry of the segment table?

Solution :
966220260315010633 Correct Answer : Base address and segment limit

Description -

Each entry in a segment table stores the base address and segment limit.

Explanation:

In a segmented memory management system, the memory is divided into variable-length segments (like code, data, stack, etc.). The CPU generates logical addresses consisting of a segment number and an offset. The segment table uses the segment number as an index to look up two critical pieces of information:

  • Base Address (Base): The starting physical memory address where the segment resides in RAM.
  • Segment Limit (Limit): The physical length or size of the segment. This is used to ensure that the logical address offset does not attempt to access memory outside the legal boundaries of that specific segment.

Question : A logical address in segmentation consists of which two components?

Solution :
142820260315010548 Correct Answer : Segment number and offset

Description -

A logical address in segmentation consists of the segment number and offset.

Explanation:

In a segmented memory management system, the program's virtual address space is broken down into logical, variable-sized units called segments (such as functions, objects, arrays, or stacks). Because of this structure, the hardware requires two parts to locate any specific instruction or data item:

  • Segment Number (\(s\)): Specifies which particular segment is being referenced. It acts as an index into the segment table to find that segment's base address in physical memory.
  • Offset (\(d\)): Specifies the exact displacement or distance from the beginning of that specific segment. The system checks this value against the segment limit to ensure the process does not attempt to access unauthorized memory spaces.

Question : Which of the following best describes segmentation in an operating system?

Solution :
239620260315010501 Correct Answer : Memory is divided into variable-size logical units called segments

Description -

The correct statement is: Memory is divided into variable-size logical units called segments.

Explanation:

Segmentation is a memory management technique that satisfies the programmer's view of memory. Instead of looking at memory as a linear array of bytes or fixed blocks, it views it as a collection of variable-length modules or units (segments) that reflect the logical components of a program.

  • Variable-Size: Unlike paging, where memory is chopped into equal, arbitrary chunks, segments match the natural sizes of a program's pieces (such as the main function, individual objects, global data arrays, or the execution stack).
  • Logical Units: Each segment represents a distinct logical division of the program, making it easier to assign specific access permissions (like read-only for code segments, or read-write for data segments).

Why the other options are incorrect:

  • Memory is divided into equal fixed-size blocks: This describes fixed partitioning or paging, not segmentation.
  • Memory is divided into frames and pages of equal size: This is the exact definition of paging.
  • Memory is divided only for secondary storage: Memory management techniques like segmentation handle primary storage (RAM) allocation.

Question : Consider a demand paging system with:
Page fault rate = 0.02
Memory access time = 100 ns
Page fault service time = 8 ms
What is the Effective Access Time (EAT)?

Solution :
826020260315010309 Correct Answer : 160,098 ns

Description -

The correct answer is 160,098 ns.

Explanation:

The Effective Access Time (EAT) in a demand paging system accounts for both normal memory accesses and the overhead introduced when a page fault occurs. It is calculated using the following formula:

\(\text{EAT}=(1-p)\times \text{Memory Access Time}+p\times \text{Page Fault Service Time}\)

Where:

  • \(p = \text{Page fault rate} = 0.02\)
  • \(1 - p = \text{Probability of a page hit} = 1 - 0.02 = 0.98\)
  • \(\text{Memory Access Time} = 100\text{ ns}\)
  • \(\text{Page Fault Service Time} = 8\text{ ms} = 8,000,000\text{ ns}\) (Note: Units must be uniform, so milliseconds are converted to nanoseconds).

Substituting the values into the formula:
\(\text{EAT}=(0.98\times 100\text{ ns})+(0.02\times 8,000,000\text{ ns})\)
\(\text{EAT}=98\text{ ns}+160,000\text{ ns}\)
\(\text{EAT}=160,098\text{ ns}\)

Question : Which of the following best explains why demand paging improves memory utilization?

Solution :
498720260315010038 Correct Answer : Only required pages are loaded into main memory

Description -

The correct statement is: Only required pages are loaded into main memory.

Explanation:

Demand paging operates on a lazy evaluation philosophy, often summarized as "don't load a page into physical memory until it is explicitly requested by the executing process."

  • Lazy Loading: When a process initiates, only its initial executing instructions are loaded into RAM. The remaining portions of the program reside on secondary storage (like an SSD or HDD) until a page fault triggers their transfer into a physical frame.
  • Optimised Memory Allocation: Programs frequently contain massive blocks of code that are rarely or never executed during a typical run—such as error-handling routines, obscure features, or initialization functions. By completely avoiding loading these unneeded pages, physical RAM usage is minimized.
  • Increased Multiprogramming: Because each active process consumes a smaller physical footprint in RAM, the operating system can accommodate a higher count of concurrent processes in main memory simultaneously, vastly improving overall system throughput.

Why the other options are incorrect:

  • All process pages are loaded at once: This describes pure swapping or strict prepaging, which demands immense amounts of RAM upfront.
  • Pages are stored permanently in RAM: Pages are highly dynamic and actively swapped out to disk via page replacement policies (like LRU) when RAM becomes full.
  • Secondary memory is not used: Secondary memory is a core requirement of demand paging, acting as the backing store where unallocated pages wait until they are needed.

Question : Which condition best describes thrashing in a demand paging system?

Solution :
392020260315125956 Correct Answer : When page fault rate becomes extremely high and CPU spends most time swapping pages

Description -

The correct statement is: When page fault rate becomes extremely high and CPU spends most time swapping pages.

Explanation:

Thrashing is a critical performance state that occurs when the system spends significantly more time handling page faults and swapping pages in and out of secondary storage than it does executing actual instructions.

  • The Spiral of Thrashing: It typically triggers when a process does not have enough physical memory frames allocated to hold its active working set (the collection of pages it needs to access frequently).
  • High Fault Rate: Because the required pages are missing from RAM, every few instructions cause a page fault. The operating system must suspend the process, write a page to disk, and read a new page in.
  • Drop in CPU Utilization: As processes get blocked waiting for disk I/O, CPU utilization drops sharply. The operating system mistakenly thinks it needs to introduce more processes to increase CPU utilization, which worsens the memory shortage and drives the system into absolute stagnation.

Why the other options are incorrect:

  • When page replacement algorithms fail to execute: Algorithms do not fail to execute during thrashing; rather, they run continuously because pages are constantly being swapped out.
  • When CPU utilization is very high: During thrashing, CPU utilization drops close to zero because the CPU spends almost all its time waiting for slow disk I/O operations to complete.
  • When the page table becomes full: The page table maps the virtual address space of a process. Thrashing is driven by a lack of physical frames in RAM, not the capacity of the tracking table itself.

Question : Which formula correctly represents the Effective Access Time (EAT) in a demand paging system?
p = page fault rate, s = page fault service time, m = memory access time

Solution :
116620260315125850 Correct Answer : EAT = p × s + (1 − p) × m

Description -

The correct formula is EAT = p × s + (1 − p) × m.

Explanation:

The Effective Access Time (EAT) is a weighted average that measures the average time it takes for a computer to access memory in a demand paging environment. It divides system performance into two operational outcomes based on probability:

  1. Page Fault Occurrence (\(p\)): The probability that a page is not in main memory is represented by \(p\) (the page fault rate). When this happens, the system must endure the lengthy page fault service time (\(s\)) to bring the page from disk into RAM. This contribution to the total average time is expressed as:
    \(p\times s\)
  2. Page Hit Occurrence (\(1 - p\)): The probability that a page is already present in main memory is represented by \((1 - p)\). In this ideal case, the system only incurs the quick memory access time (\(m\)). This contribution to the total average time is expressed as:
    \((1-p)\times m\)

Adding these two weighted components together yields the complete equation for calculating EAT.

Question : In a demand paging system, what happens when a process references a page that is not currently in main memory?

Solution :
462720260315125642 Correct Answer : The OS generates a page fault and loads the page from secondary memory

Description -

The correct statement is: The OS generates a page fault and loads the page from secondary memory.

Explanation:

When a process attempts to access a virtual memory page that is not currently mapped to a physical frame in RAM, it triggers a hardware interrupt known as a page fault. The system handles this event through a specific sequence of steps:

  1. Trap to the OS: The CPU detects that the valid-invalid bit in the page table entry for that page is set to "invalid" (meaning it is not in main memory), causing a trap (interrupt) to the operating system.
  2. Backing Store Lookup: The OS pauses the running process and looks at an internal table to verify whether the memory reference was valid and where the requested page resides on secondary memory (such as an SSD or hard drive).
  3. Allocation & Fetching: The OS finds a free physical frame in RAM. It then schedules a disk I/O operation to read the desired page from the backing store into that newly allocated frame.
  4. Table Update: Once the I/O operation completes, the OS updates the process's page table by entering the physical frame number and changing the status bit from "invalid" to "valid".
  5. Restart Instruction: The OS restores the state of the interrupted process and restarts the exact instruction that originally caused the page fault, allowing execution to continue smoothly.

Why the other options are incorrect:

  • The process is immediately terminated: A process is only terminated if it attempts an illegal memory access (which results in a segmentation fault), not a routine page fault.
  • The CPU ignores the instruction: The CPU cannot skip instructions; doing so would corrupt the program's intended logic and execution state.
  • The page is permanently removed from the page table: The page remains mapped in the page table; its state is simply updated to reflect its new physical location in RAM.

Question : If the physical address space = 64 KB and word size = 8 bytes, what is the number of bits required for the physical address?

Solution :
517920260315125400 Correct Answer : 13 bits

Description -

The correct answer is 13 bits.

Explanation and Calculation:

The number of bits required for a physical address depends on the total number of unique, addressable memory locations (words) available in the system.

  1. Convert the total memory size into bytes:
    \(\text{Physical Address Space}=64\text{ KB}=64\times 1024\text{ Bytes}=65,536\text{ Bytes}=2^{16}\text{ Bytes}\)
  2. Express the word size in bytes:
    \(\text{Word\ Size}=8\text{ Bytes}=2^{3}\text{ Bytes}\)
  3. Calculate the total number of addressable words:
    Since memory is addressed by words, divide the total byte capacity by the size of a single word:
    \(\text{Total Words}=\frac{\text{Physical Address Space (in bytes)}}{\text{Word Size (in bytes)}}=\frac{2^{16}}{2^{3}}=2^{13}\text{ Words}\)
  4. Determine the number of bits:
    To unique address \(2^{13}\) distinct word locations, the Memory Address Register (MAR) needs exactly 13 bits (\(\log_2(2^{13}) = 13\)).

Question : In modern operating systems, which statement about user access to physical addresses is correct?

Solution :
902520260315125317 Correct Answer : Users access physical memory indirectly through logical addresses.

Description -

The correct statement is: Users access physical memory indirectly through logical addresses.

Explanation:

In modern operating systems, hardware and software work together to isolate user programs from actual physical RAM for safety, convenience, and efficiency.

  • Abstraction via Virtual Memory: Programs execute inside a simulated environment called a logical (or virtual) address space. A user application handles pointers and variables based entirely on these logical addresses.
  • Role of the MMU: When a program tries to read or write to memory, a specialized hardware component called the Memory Management Unit (MMU) intercepts the request. The MMU looks up tables maintained by the operating system to map that logical address onto a completely different, secure physical address in the RAM chips.
  • Security & Isolation: By preventing users from directly interacting with physical locations, the operating system ensures that one buggy or malicious application cannot accidentally overwrite or spy on the memory space of another process or the OS kernel itself.

Why the other options are incorrect:

  • Users can directly access physical addresses: Allowing direct access would defeat all modern OS security, exposing the entire computer to frequent crashes and system-wide vulnerabilities.
  • Physical addresses are visible only during compilation: The compiler has no idea where a program will eventually land in physical RAM when executed. It compiles instructions using relative logical addresses; physical mapping happens dynamically at runtime.
  • Logical and physical addresses are always identical: They are only identical in primitive, non-virtualized systems (like raw MS-DOS or basic microcontrollers). In modern operating systems, they are almost never the same.

Question : If the physical address space = N words, the number of bits required to represent a physical address is:

Solution :
711120260315125126 Correct Answer : Log2 N

Description -

The correct option is \(\log _{2}N\) (Log2 N).

Explanation:

A physical memory address space consists of \(N\) distinct addressable units (words). In digital computers, memory locations are indexed using binary numbers (base 2).

To find the minimum number of binary bits (\(x\)) required to uniquely identify and assign a distinct address label to every single one of these \(N\) items, we use the following relationship:
\(2^{x}\ge N\)

Taking the base-2 logarithm (\(\log _{2}\)) of both sides gives:
\(x=\lceil \log _{2}N\rceil \)

For an exact power of 2, the number of bits is exactly \(\log _{2}N\).

Analytical Example:

  • Suppose a memory system contains \(N = 8\) words.
  • Using the formula: \(\log_2(8) = \log_2(2^3) = 3\) bits.
  • With 3 binary bits, you can construct exactly 8 unique address combinations (000, 001, 010, 011, 100, 101, 110, 111), which is precisely what is needed to address all 8 locations.

Question : Which statement correctly describes the logical address space?

Solution :
82220260315124209 Correct Answer : It is the set of addresses generated by the CPU for a process.

Description -

The correct statement is: It is the set of addresses generated by the CPU for a process.

Explanation:

The logical address space (often called virtual address space) is the abstract view of memory that a program has while it is running.

  • CPU Generation: When a program executes instructions (like loading a variable or jumping to a function), the CPU generates an address. This address is completely virtual and exists within the bounds assigned to that specific program.
  • Process Isolation: Every process is given its own independent logical address space, typically starting at address 0. This keeps the program from having to worry about where other programs are located in physical RAM.
  • Translation: Before any data can actually be read or written, this logical address must be passed to the hardware Memory Management Unit (MMU) to be converted into a real physical address inside the RAM chips.

Why the other options are incorrect:

  • It represents the size of the main memory / It is the set of all physical addresses mapped to RAM: Both of these describe the physical address space, which is limited by the actual hardware RAM installed in the computer.
  • It is directly accessed by hardware memory modules: Hardware memory modules (RAM chips) can only understand and process physical addresses routed through the system bus.

Question : Which component is primarily responsible for translating logical addresses into physical addresses in an operating system?

Solution :
223020260315124113 Correct Answer : Memory Management Unit (MMU)

Description -

The correct component is the Memory Management Unit (MMU).

Explanation:

The Memory Management Unit (MMU) is a specialized hardware component located inside or very close to the CPU. Its primary job is to perform real-time address translation.

  • Dynamic Translation: When a program executes, the CPU generates a logical address. Before this request is sent over the system bus to fetch data from the actual RAM chips, the MMU intercepts it and translates it into a corresponding physical address.
  • Hardware Efficiency: Because memory accesses happen billions of times per second, this translation cannot be done efficiently via software. The MMU uses high-speed hardware tables (like the Page Table) and internal caches (like the TLB - Translation Lookaside Buffer) to complete this mapping instantly.
  • Protection: The MMU also checks every memory access against permission bits to ensure a process doesn't illegally modify data belonging to another program or the operating system.

Why the other options are incorrect:

  • CPU Scheduler: This is a software component of the OS kernel responsible for deciding which ready process gets to run on the CPU next; it has nothing to do with memory address mapping.
  • Compiler: The compiler converts source code into machine code using symbolic or relative logical addresses. It operates before the program ever runs and has no visibility into physical RAM.
  • Disk Controller: This hardware component manages the communication between the computer system and secondary storage devices (like HDDs or SSDs).

Question : When a process tries to access a page that is not currently present in main memory, the event is called:

Solution :
185620260315123541 Correct Answer : Page fault

Description -

The correct answer is Page fault.

Explanation:

A page fault is a specific type of hardware interrupt raised by the Memory Management Unit (MMU) when a program tries to access a page of virtual memory that is valid but not currently mapped into the physical frames of the main memory (RAM).

When this happens:

  1. The CPU detects that the page's status bit in the page table is set to "invalid" or "not present".
  2. The execution of the program is temporarily suspended, and control is handed over to the operating system kernel via a trap.
  3. The operating system locates the missing page in secondary storage (like an SSD or hard disk), reads it into an empty slot in the physical RAM, updates the page table to "valid", and safely restarts the interrupted instruction.

Why the other options are incorrect:

  • Page hit: This is the exact opposite of a page fault; it happens when the requested page is already sitting in RAM, allowing for a fast access cycle.
  • Page interrupt: While a page fault is an interrupt, "page interrupt" is not standard operating system terminology for this event.
  • Page overflow: This is an invalid term in this context. It shouldn't be confused with a buffer overflow (writing past memory boundaries) or a stack overflow (using too much stack space).

Question : Which hardware component is primarily responsible for translating logical addresses into physical addresses in a paging system?

Solution :
807720260315123448 Correct Answer : Memory Management Unit (MMU)

Description -

The correct hardware component is the Memory Management Unit (MMU).

Explanation:

Regardless of whether a system uses paging or segmentation, the Memory Management Unit (MMU) is the dedicated hardware component responsible for translating logical (virtual) addresses generated by the CPU into physical addresses in the main memory (RAM).

In a paging system, the MMU carries out this task using a specialized workflow:

  • Splitting the Address: It splits the CPU's logical address into two parts: a page number (\(p\)) and a page offset (\(d\)).
  • Page Table Lookup: It uses the page number as an index to look up the corresponding frame number (\(f\)) inside the page table (which is kept in RAM or cached inside the MMU).
  • Final Address Assembly: It combines the frame number (\(f\)) with the original page offset (\(d\)) to pinpoint the exact physical location in the RAM chips.

Why the other options are incorrect:

  • Arithmetic Logic Unit (ALU): This part of the CPU handles arithmetic operations (like addition and subtraction) and logical evaluations (like AND/OR checks). It does not manage memory translations.
  • Control Unit: This component directs the operational flow of the CPU by fetching, decoding, and managing the execution of machine instructions.
  • Cache Controller: This hardware manages high-speed cache memories (L1, L2, L3) and handles data transfers between the CPU registers and the cache blocks, but it does not perform the primary virtual-to-physical address mapping.

Question : Which problem of memory management is significantly reduced by using paging?

Solution :
452720260315123400 Correct Answer : External fragmentation

Description -

The correct answer is External fragmentation.

Explanation:

External fragmentation occurs when there is enough total free memory space to satisfy a allocation request, but the space is split into small, scattered blocks across the system, making it non-contiguous. As a result, a process cannot be loaded because no single continuous block is large enough to hold it.

Paging eliminates external fragmentation through its structural design:

  • Fixed-Size Chunks: Physical memory is broken down into fixed-sized blocks called frames, and logical memory is broken into blocks of the exact same size called pages.
  • Non-Contiguous Allocation: Because any logical page can be mapped to any available physical frame anywhere in RAM, the operating system does not need to look for a single, unbroken block of physical memory to fit a process. As long as there are enough total free frames scattered throughout the system, the process can run successfully.

Why the other options are incorrect:

  • Internal fragmentation: Paging actually introduces or suffers from internal fragmentation. If a process requires memory that doesn't perfectly match a multiple of the page size, the last frame allocated to it will have unused leftover space at the end.
  • Deadlock / Starvation: These are process synchronization and CPU scheduling issues (where processes wait forever for resources or execution time), not problems related to physical memory fragmentation.

Question : In paging, logical memory is divided into pages, while physical memory is divided into:

Solution :
575520260315123315 Correct Answer : Frames

Description -

The correct answer is Frames.

Paging relies on a strict structural alignment between virtual (logical) memory and real physical RAM to eliminate external fragmentation. To make this work:

  • Logical Memory (the program's view) is divided into equal, fixed-size blocks called pages.
  • Physical Memory (the actual RAM hardware) is divided into blocks of the exact same size called frames.

Question : Which of the following is the main reason paging is required in an operating system?

Solution :
487420260315123231 Correct Answer : To allow non-contiguous allocation of physical memory to processes

Description -

The correct statement is: To allow non-contiguous allocation of physical memory to processes.

Explanation:

The primary reason modern operating systems use paging is to solve the massive problem of external fragmentation that occurs with contiguous memory allocation.

  • Breaking the Requirement for Contiguity: Without paging, an entire program must be loaded into one single, unbroken block of physical RAM. If memory becomes fragmented into tiny, scattered free spaces over time, a new program cannot start—even if the total amount of free memory is more than enough to fit it.
  • Flexible Mapping: Paging solves this by dividing a process's logical memory into fixed-size pages and physical RAM into matching fixed-size frames. Because any page can be mapped to any available frame anywhere in RAM, the operating system can scatter a program's pieces across non-contiguous physical locations while keeping it appearing perfectly continuous to the CPU.

Why the other options are incorrect:

  • To increase CPU clock speed: Clock speed is entirely a hardware property of the CPU crystal oscillator; software memory management schemes have no impact on it.
  • To eliminate the need for secondary storage: Paging actually relies heavily on secondary storage (like SSDs/HDDs) to act as a backing store for swapping and virtual memory.
  • To reduce the number of processes in the system: Paging does the exact opposite. By utilizing memory efficiently and keeping physical footprints minimal, it allows a higher number of concurrent processes to run at once (increasing the degree of multiprogramming).