Q: What is memory management in an operating system?
A:
Memory Management: The process of dynamically dividing up main memory to accommodate multiple processes in a multiprogramming system. It ensures efficient use of memory and supports relocation, protection, sharing, logical organization, and physical organization.
Q: What are the five requirements of memory management?
A:
Relocation: Processes may be moved in memory (e.g., swapped in/out).
Protection: Processes must be protected from interfering with each other.
Sharing: Processes may need to share memory (e.g., shared data structures).
Logical Organization: Programs are organized into modules (e.g., code, data).
Physical Organization: Managing the flow of information between main memory (fast, volatile) and secondary memory (slow, non-volatile).
Q: What is relocation in memory management?
A:
Relocation: The ability to move a process to a different area of memory when it is swapped back in. This requires dynamic address translation to adjust memory references at runtime.
Q: How does memory management ensure protection between processes?
A:
Protection: Each process is isolated from others. The processor hardware checks memory references at runtime to ensure a process only accesses its allocated memory space. This prevents accidental or intentional interference.
Q: How does memory management support sharing between processes?
A:
Sharing: Multiple processes can access the same portion of memory (e.g., shared code or data). The memory management system allows controlled access to shared memory without compromising protection.
Q: What is logical organization in memory management?
A:
Logical Organization: Programs are divided into modules (e.g., code, data). The OS and hardware handle these modules, allowing independent compilation, different protection levels, and sharing among processes.
Q: What is physical organization in memory management?
A:
Physical Organization: Managing the flow of information between main memory (fast, volatile) and secondary memory (slow, non-volatile). The OS handles this to avoid burdening the programmer.
Q: What is fixed partitioning in memory management?
A:
Fixed Partitioning: Main memory is divided into fixed-size partitions. Processes are loaded into partitions that are large enough to hold them.
Disadvantages:
Internal Fragmentation: Wasted space within a partition if the process is smaller than the partition.
Limited Processes: The number of partitions limits the number of active processes.
Q: What is dynamic partitioning in memory management?
A:
Dynamic Partitioning: Memory is divided into variable-size partitions based on process size. Processes are allocated exactly as much memory as they need.
Disadvantages:
External Fragmentation: Free memory becomes fragmented over time, leading to wasted space.
Compaction: Time-consuming process of shifting processes to consolidate free memory.
Q: What are the three placement algorithms used in dynamic partitioning?
A:
First-Fit: Allocate the first available block that is large enough.
Best-Fit: Allocate the smallest block that is large enough.
Next-Fit: Allocate the next available block after the last allocation.
Q: What is the buddy system in memory management?
A:
Buddy System: A compromise between fixed and dynamic partitioning. Memory is divided into blocks of size 2^k. When a process requests memory, the system splits blocks into smaller "buddies" until a suitable size is found.
Advantages: Reduces fragmentation and simplifies allocation/deallocation.
Disadvantages: Can still lead to internal fragmentation.
Q: What is paging in memory management?
A:
Paging: Memory is divided into fixed-size frames, and processes are divided into fixed-size pages. Pages are loaded into available frames, which need not be contiguous.
Advantages: Eliminates external fragmentation and simplifies memory allocation.
Disadvantages: Internal fragmentation can occur if the last page is not fully used.
Q: What is a page table, and how does it work?
A:
Page Table: A data structure maintained by the OS for each process. It maps logical page numbers to physical frame numbers.
Usage: When a process accesses memory, the processor uses the page table to translate logical addresses (page number + offset) into physical addresses (frame number + offset).
Q: What is segmentation in memory management?
A:
Segmentation: Memory is divided into variable-size segments based on logical divisions of a program (e.g., code, data, stack). Each segment has a segment table that maps logical addresses to physical addresses.
Advantages: Eliminates internal fragmentation and aligns with the logical structure of programs.
Disadvantages: Can lead to external fragmentation.
Q: What is the difference between logical and physical addresses?
A:
Logical Address: A reference to a memory location independent of the current assignment of data to memory (e.g., page number + offset).
Physical Address: The actual location in main memory (e.g., frame number + offset).
Translation: The processor translates logical addresses to physical addresses using page tables or segment tables.
Q: How does address translation work in paging?
A:
Steps:
Extract the page number from the logical address.
Use the page number to index the page table and find the frame number.
Combine the frame number with the offset to form the physical address.
Q: How does address translation work in segmentation?
A:
Steps:
Extract the segment number from the logical address.
Use the segment number to index the segment table and find the base address of the segment.
Add the offset to the base address to form the physical address.
Q: What is internal fragmentation?
A:
Internal Fragmentation: Wasted space within a partition or page because the allocated block is larger than the data it holds.
Example: A process uses only part of a fixed-size partition or page, leaving the rest unused.
Q: What is external fragmentation?
A:
External Fragmentation: Wasted space between partitions or segments due to the allocation and deallocation of variable-size blocks.
Solution: Compaction (shifting processes to consolidate free memory).
Q: What is compaction in memory management?
A:
Compaction: The process of shifting processes in memory to consolidate free memory into a single block.
Purpose: Reduces external fragmentation and allows larger processes to be loaded.
Disadvantage: Time-consuming and requires dynamic relocation.
Q: What is virtual memory?
A:
Virtual Memory: A memory management technique that allows processes to use more memory than physically available by swapping data between main memory and secondary memory.
Techniques: Based on paging and segmentation.
Q: What are overlays in memory management?
A:
Overlays: A technique where parts of a program are loaded into memory only when needed, allowing large programs to run in limited memory.
Disadvantage: Requires manual management by the programmer.
Q: What are base and bounds registers used for?
A:
Base Register: Holds the starting address of a process in memory.
Bounds Register: Holds the ending address of a process.
Purpose: Used for relocation and protection by ensuring memory references stay within the process’s allocated space.
Q: Why is page size typically a power of 2 in paging systems?
A:
Reason: Simplifies address translation. The offset is the lower bits of the logical address, and the page number is the upper bits. This makes it easy to calculate the physical address by combining the frame number and offset.
Q: What are the key takeaways from Chapter 7?
A:
Memory Management: Ensures efficient use of memory by allocating and managing memory for multiple processes.
Techniques: Fixed Partitioning, Dynamic Partitioning, Paging, Segmentation, and Virtual Memory.
Goals: Relocation, Protection, Sharing, Logical Organization, and Physical Organization.
Fragmentation: Internal (wasted space within a block) and External (wasted space between blocks).