MEMORY MANAGEMENT

SINGLE CONTIGUOUS ALLOCATION

Single contiguous allocation is a memory management technique where each process is allocated a single continuous block of memory.

Advantages:

Disadvantages:

Overall, while single contiguous allocation is straightforward, it is not suitable for modern computing needs where efficient memory utilization and multitasking are essential.

PARTITONED ALLOCATION

Advantages:

Disadvantages:

AspectInternal FragmentationExternal Fragmentation
DefinitionOccurs when allocated memory is larger than the requested memory, leaving unused space within the block.Happens when free memory is split into small non-contiguous blocks over time.
CauseFixed-size memory allocation leading to partially unused memory blocks.Dynamic memory allocation creating scattered free memory segments.
Impact on MemoryWastes memory within allocated blocks.Difficult to allocate large contiguous memory blocks for new processes.
Fragmentation TypeInternal, within the allocated blocks.External, outside the allocated blocks.
Memory UtilizationLeads to inefficient use of memory within the blocks.Results in fragmented memory, reducing the efficiency of memory utilization.
System PerformanceCan degrade performance due to unused space within blocks.Degrades performance by making it hard to find contiguous blocks for allocation.

AspectFixed PartitioningVariable Partitioning
DefinitionDivides memory into fixed-size partitions. Each partition is a set size that does not change.Divides memory into partitions of varying sizes. The size of partitions can be adjusted dynamically based on the needs of processes.
Memory AllocationEach partition has a fixed size and cannot be changed, meaning that if a process does not use the entire partition, the leftover space is wasted.Partitions can be created and resized dynamically based on process requirements, allowing for more efficient use of memory.
FragmentationProne to internal fragmentation where the fixed-size partitions may not be fully used, leading to wasted space within the partitions.Prone to external fragmentation where free memory becomes scattered into small, non-contiguous blocks, making it difficult to allocate large blocks of memory to new processes.
FlexibilityInflexible, leading to inefficient use of memory since fixed partitions may not match the exact memory needs of processes. This can result in significant waste.More flexible, allowing for better utilization of memory as partitions can be adjusted to fit the size of processes more closely. This adaptability reduces wasted space.
Management ComplexityEasier to manage because partitions are fixed and do not change, simplifying memory allocation and deallocation.More complex to manage due to the dynamic resizing of partitions. The system must track partition sizes and locations, and manage the allocation and deallocation processes.
System UtilizationPotentially lower due to fixed sizes that may not match the memory needs of processes, leading to wasted space and inefficient memory use.Potentially higher due to better fitting of process sizes, which can lead to more efficient use of available memory and higher overall system utilization.
Suitable ForSystems with predictable and uniform process sizes where the memory needs of processes do not vary significantly.Systems with varying and unpredictable process sizes where the memory needs of processes can change frequently. This flexibility allows for more efficient memory use in dynamic environments.
Performance ImpactCan lead to slower performance due to wasted memory space and inefficient use of resources.Can lead to improved performance due to better memory utilization and reduced waste, though the complexity of management can add overhead.
Memory UtilizationOften results in poor memory utilization as fixed partitions may leave small, unused gaps of memory.Generally results in better memory utilization as partitions can be adjusted to fit the exact needs of processes, minimizing wasted space.

NON-CONTIGUOUS MEMORY ALLOCATION

Non-contiguous memory allocation is a memory management technique where a process is divided into several smaller blocks that can be stored in different locations in the main memory. Unlike contiguous memory allocation, where a process must occupy a single contiguous block of memory, non-contiguous allocation allows a process's parts to be scattered throughout the memory.

Advantages:

Disadvantages:

Overall, non-contiguous memory allocation is suited for modern computing environments where efficient memory utilization and multitasking are crucial.

PAGING

Paging is a memory management scheme that eliminates the need for contiguous allocation of physical memory. This method divides the process's virtual memory into fixed-size pages and the physical memory into blocks of the same size called frames. Pages are mapped to frames, allowing the process's pages to be stored non-contiguously in memory.

Ques: What is page?

Answer: A page is a fixed-size block of virtual memory used in paging, a memory management technique that maps these blocks to physical memory frames, allowing processes to be stored non-contiguously.

Ques: What are frames?

Answer: Frames are fixed-size blocks of physical memory that correspond to pages in virtual memory, allowing non-contiguous storage of process data.

Ques: What is a page table?

Answer: A page table is a critical data structure used in virtual memory systems to facilitate efficient memory management and address translation. It serves as a mapping mechanism between the virtual addresses used by programs and the physical addresses in the computer's memory. Each process has its own page table, which contains entries that map virtual pages to physical frames in memory.

The page table entries typically include information such as the frame number, status bits (e.g., valid/invalid, read/write permissions), and other control bits that help manage memory access. When a program accesses a memory location, the operating system uses the page table to determine the corresponding physical address, ensuring the correct data is retrieved or stored.

By using page tables, the operating system can provide the illusion of a large, contiguous block of memory to programs, even if the physical memory is fragmented. This enables more efficient use of memory, better protection and isolation between processes, and support for advanced features like paging, swapping, and memory protection.

Overall, the page table is an essential component of modern operating systems, enabling sophisticated memory management techniques that enhance system performance and stability.

TLB

The Translation Lookaside Buffer (TLB) is a specialized type of cache used in a computer's memory management unit (MMU) to improve the speed of virtual address translation. When a virtual address needs to be translated to a physical address, the TLB is checked first to see if the translation is already cached. If it is, this "TLB hit" allows the address translation to occur quickly without accessing the slower page table in main memory. If the translation is not in the TLB, a "TLB miss" occurs, and the page table must be accessed to retrieve the necessary translation.

Need of TLB

Paging with Hardware TLB

Paging with hardware TLB involves using this specialized cache to speed up the process of mapping virtual pages to physical frames. Here’s how it works:

  1. TLB Check: When a process accesses a memory location, the MMU first checks the TLB to see if the virtual address to physical address mapping is already present. If the mapping is found in the TLB (a TLB hit), the physical address is quickly retrieved, and the memory access proceeds.
  1. TLB Miss: If the mapping is not found in the TLB (a TLB miss), the MMU must access the page table in main memory to find the corresponding physical address. This process is slower because accessing main memory is more time-consuming than accessing the TLB.
  1. Update TLB: After retrieving the mapping from the page table, the TLB is updated with the new translation. This way, subsequent accesses to the same virtual address can benefit from the faster TLB lookup.

Effective Memory Access Time (EMAT) in TLB Search

The formula for Effective Memory Access Time (EMAT) when using a TLB can be expressed as:

EMAT=H(Ttlb+Tmm)+(1H)(Ttlb+2Tmm)EMAT = H * (Ttlb + Tmm) + (1 - H) * (Ttlb + 2Tmm)

Where:

Advantages of Using Hardware TLB

Disadvantages

Overall, paging with hardware TLB is a powerful technique that enhances the efficiency of virtual memory systems by speeding up address translation and reducing memory access latency. It is a critical component in modern computer architectures, contributing to improved system performance and responsiveness.

Belady’s Anomaly

Belady's Anomaly is a phenomenon in which increasing the number of page frames in a paging system unexpectedly increases the number of page faults. This counterintuitive behavior occurs in certain page replacement algorithms like FIFO (First-In, First-Out) and highlights the complexity of memory management in operating systems.

SEGMENTATION

Segmentation is a memory management technique that divides a process's memory into variable-sized segments, each representing a logical unit of the process, such as code, data, or stack. Unlike paging, which divides memory into fixed-size blocks, segmentation reflects the logical structure of the program, allowing for more efficient memory utilization and protection.

HOW SEGMENTATION WORKS?

Each segment has a unique segment number and a defined length, and the operating system maintains a segment table that maps these segment numbers to physical addresses. This segment table is crucial for translating logical addresses (composed of a segment number and an offset within that segment) into physical addresses in the computer's memory.

When a program attempts to access a memory location, the operating system performs the following steps:

  1. Segment Number Lookup: The segment number from the logical address is used to index into the segment table.
  1. Base Address Retrieval: The segment table provides the base address of the segment in physical memory.
  1. Offset Calculation: The offset within the segment, also part of the logical address, is added to the base address to compute the final physical address.

This process allows the operating system to efficiently locate and access the required memory locations for each segment. Segmentation offers several advantages, including:

Advantages of Segmentation:

Disadvantages of Segmentation:

Segmentation vs. Paging:

Segmentation and paging are both techniques used to manage memory, but they have distinct differences:

AspectSegmentationPaging
Memory DivisionDivides memory into variable-sized segments based on logical units.Divides memory into fixed-size pages for uniformity.
Address StructureLogical addresses consist of a segment number and an offset.Logical addresses consist of a page number and an offset.
FragmentationProne to external fragmentation.Prone to internal fragmentation but eliminates external fragmentation.
Protection and SharingProvides better protection and sharing as segments represent logical units.Provides uniformity but less natural support for logical protection and sharing.
OverheadHigher due to complex segment management.Lower due to simpler page management but introduces page table overhead.

Combining Segmentation and Paging:

Many modern operating systems combine segmentation and paging to leverage the strengths of both techniques. This approach, known as "segmented paging" or "paged segmentation," involves dividing the logical address space into segments, which are further divided into fixed-size pages. The operating system maintains both a segment table and a page table, using the segment table to find the base address of a segment and the page table to translate page numbers within that segment to physical addresses.

In summary, segmentation is a powerful memory management technique that offers logical organization, efficient utilization, and robust protection. However, it also introduces complexity and potential fragmentation challenges. Combining segmentation with paging can mitigate some of these issues, providing a balanced approach to memory management in modern computing environments.

VIRTUAL MEMORY

Virtual memory is a memory management technique that provides an "illusion" of a large, contiguous block of memory to programs, even if the physical memory is fragmented or limited. This allows for more efficient use of physical memory and enables larger applications to run on systems with limited RAM.

Virtual memory is a memory management technique that provides an "illusion" of a large, contiguous block of memory to programs, even if the physical memory is fragmented or limited. This allows for more efficient use of physical memory and enables larger applications to run on systems with limited RAM.

How Virtual Memory Works:

  1. Paging and Segmentation: Virtual memory systems often use a combination of paging and segmentation to manage memory. This means that the operating system divides the virtual memory into pages or segments, which are then mapped to physical memory.
  1. Page Tables: The operating system maintains page tables that map virtual addresses to physical addresses. When a program accesses memory, the virtual address is translated to a physical address using the page table.
  1. Swapping: When the physical memory is full, the operating system can move inactive pages from RAM to a storage device, such as a hard disk or SSD. This process is called swapping, and it frees up RAM for active pages.
  1. Demand Paging: Virtual memory systems use demand paging, where pages are loaded into memory only when they are needed. This reduces the amount of physical memory required and improves system performance.

Advantages of Virtual Memory:

Disadvantages of Virtual Memory:

Page Replacement Algorithms:

When the physical memory is full, the operating system must decide which pages to swap out to make room for new pages. This decision is made using page replacement algorithms, such as:

Thrashing:

Thrashing occurs when a system spends more time swapping pages in and out of memory than executing actual processes. This can happen if the working set of a process (the set of pages actively used) exceeds the available physical memory. Thrashing severely degrades system performance and can be mitigated by: