Core Concepts of Virtual Memory Management and Allocation Strategies
Classified in Computers
Written on in
English with a size of 3.47 KB
Virtual Memory Management Fundamentals
What is Memory Management?
Memory Management is responsible for the efficient use of main memory in a multiprogramming environment where processes compete for memory resources.
Types of Address Space
- Actual Addresses: Refer to the physical main memory (RAM) of the machine.
- Logical or Virtual Addresses: The memory space perceived or known by the process. Each process maintains its own independent logical or virtual address space.
The central idea of virtual memory is to utilize the memory hierarchy: storing the most frequently accessed data in faster, lower-capacity storage tiers (RAM) and less frequently accessed data on less expensive, higher-capacity devices (disk).
Evolution of Memory Management Systems
- Fixed partitions
- Variable partitioning
- Segmentation
- Pagination
- Demand paging
Memory Allocation Strategies
These strategies are used to allocate memory segments or partitions to processes:
- First-Fit: The list of available memory segments or partitions is traversed sequentially to find the first segment that is larger than or equal to the requested size.
- Best-Fit: The list is traversed to find the segment or partition that is the closest match (smallest size greater than or equal to) to what was requested.
- Worst-Fit: The list is traversed until the largest available segment or partition is found.
Swapping Mechanism
The swap space is a portion of the disk which is reserved for use by the virtual memory manager of the kernel.
Swapping means moving the entire process image from main memory to the swap space and vice versa.
Segmentation: Implementing Virtual Address Spaces
Segmentation is a scheme used to implement virtual address spaces. Each process has its own virtual address space, independent of other processes.
Segments Defined
Segments: Each segment is a contiguous region within the real memory of the computer, defined by its length, segment number, and protection attributes.
The Operating System (OS) maintains a segment table unique to each program. This table stores the segment base address, limit (size), and access type.
From the user's standpoint and that of compilers, a process is naturally divided into sections: text, data, stack, and heap. Assigning different address spaces to each of these sections simplifies the compiler's task and maintains this natural division.
Advantages of Segmentation
- Automatic extension of the stack in case of overflow.
- Explicit extension of the data, such as using
sbrk(int)for the primitive process data segment. - Efficient implementation of
fork(). - Swapping of processes.
- Implementation of semi-lightweight processes.
Disadvantages of Segmentation
- The implementation of
fork()can be inefficient because it requires copying segments immediately and completely. - Compaction introduces a general pause which is difficult to distinguish from a system crash.
- The size of the process should not exceed the actual memory size, since a process must be fully resident in memory.