Memory Management: Virtual Memory Flashcards
What is the programmer’s ideal memory model?
he ideal memory for programmers would have these characteristics:
○Private
○Infinitely large
○Infinitely fast
○Nonvolatile
○Cheap
What are the primary goals of an Operating System’s (OS) memory management?
OS memory management aims to achieve the following:
○ Main Memory Allocation: Determine the allocation of main memory, addressing:
■Where to locate the kernel in memory
■How many processes to allow concurrently
■How to allocate memory effectively to each process
○Protection: Ensure robust memory access control to prevent:
■Processes from corrupting the OS or other processes
■Processes from reading data belonging to other processes (privacy)
○Transparency: Create an abstraction of memory that hides the complexities of shared memory from processes, ensuring that:
■Processes remain unaware that they are sharing memory with others
■Memory management functions correctly irrespective of the number or location of running processes
How is memory protected to prevent one process from accessing the memory of another process or the kernel?
Memory protection is achieved by adding a check mechanism between the CPU and memory. This check ensures that every memory access request from the CPU is validated against the process’s allocated memory space. If a process attempts to access memory outside its designated region, an error is triggered, preventing unauthorized access
What is memory transparency in the context of operating systems?
Memory transparency means that programmers do not need to be concerned about:
○ The physical location of their program in memory.
○ The location or existence of other programs in memory
●The OS handles the mapping between virtual and physical addresses, allowing programs to run as if they have their own isolated memory space.
What is the typical memory location for the OS kernel and why?
The kernel is almost always located in low memory. On x86 architectures, this placement is primarily due to the location of interrupt vectors in low memory.
Explain the concept of virtual memory and its significance.
Virtual memory separates the memory addresses used by a program (virtual addresses) from the actual physical addresses in RAM. This separation is crucial because:
○ It allows processes to run even if they are only partially loaded in main memory.
○ It enables the OS to provide each process with the illusion of a large, private address space, even if the physical memory is shared.
Distinguish between virtual and physical address spaces.
○ Virtual Address Space: This is the address space that a program or programmer perceives. It represents the program’s view of memory.
○ Physical Address Space: This is the actual memory space available on the physical RAM chips. It represents the hardware’s view of memory
Explain how the Memory Management Unit (MMU) facilitates virtual to physical address translation and protection.
The MMU is a hardware component that translates virtual addresses to physical addresses. It acts as a bridge between the CPU and memory, intercepting every memory access request from the CPU. Key functions include:
○ Address Translation: The MMU uses a mapping mechanism (typically a page table) to translate the virtual address generated by the CPU into the corresponding physical address.
○ Protection: It enforces protection rules by verifying if the process is allowed to access the requested memory location based on the process’s permissions. This prevents unauthorized memory access and ensures process isolation
Describe the base and bounds memory mapping scheme.
The base and bounds scheme uses a base register and a bounds register to define a process’s address space:
○ Base Register: Stores the starting address (base address) of the process’s allocated memory in physical memory.
○ Bounds Register: Holds the size of the allocated memory space, defining the upper limit (bound).
● The MMU adds the virtual address to the base address to get the physical address, ensuring it falls within the bounds
Explain the problem of external fragmentation in memory management, particularly in the context of the base and bounds scheme.
External fragmentation occurs when enough free memory is available to satisfy a request, but it is scattered throughout physical memory in non-contiguous blocks, making it unusable for allocating to processes. This happens in base and bounds because as processes are loaded and removed, gaps (holes) are created in memory. Over time, these holes become too small to accommodate new processes, leading to wasted space and inefficient memory utilization
Describe the process of a context switch in the base and bounds memory management scheme.
A context switch involves switching the CPU from executing one process to another. Key steps include:
1.Saving the Current Process State: The OS saves the current process’s registers (including the base and bounds registers) to its Process Control Block (PCB).
- Loading the New Process State: The OS loads the new process’s registers from its PCB into the CPU, effectively switching the base and bounds to point to the new process’s allocated memory area.
- Resuming Execution: The CPU continues execution from the instruction where the new process left off
What is internal fragmentation in the context of memory management?
Internal fragmentation occurs when a process is allocated more memory than it actually needs, leading to wasted space within the allocated memory block. Unlike external fragmentation, this wasted space is internal to the allocated block and cannot be easily reclaimed
Describe the concept of segmentation in memory management.
Segmentation divides a program’s address space into logical units called segments. These segments can represent different components of a program, such as:
○Code: Instructions of the program
○Heap: Dynamically allocated memory
○Stack: Function call stack and local variables
●Segments are stored separately in physical memory, and their location and size are tracked in a segment table
Explain how a virtual address is structured in a segmentation-based memory management scheme.
A virtual address in segmentation has two parts:
1.Segment Number (s): This part identifies the segment to which the address belongs.
2.Offset (d): This part specifies the location (offset) within the identified segment
How does the MMU translate virtual addresses to physical addresses in a segmentation-based system?
The MMU uses a segment table for address translation:
1. Index the Table: It uses the segment number (s) from the virtual address to index into the segment table.
2. Retrieve Base and Limit: It retrieves the base address and limit (size) of the segment from the corresponding segment table entry.
3. Check Bounds and Calculate: The MMU checks if the offset (d) is within the segment’s limit. If valid, it adds the offset to the base address to calculate the physical address