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:
- Simple to implement and manage. The simplicity of this method makes it easy for developers and system administrators to set up and maintain, reducing the likelihood of errors and minimizing the need for extensive training.
- Low overhead since memory is allocated in a single block. By allocating memory in a single block, the system reduces the complexity and time required to manage memory, leading to faster execution times and more efficient use of computational resources.
Disadvantages:
- Inefficient use of memory due to fragmentation (Internal/externa). Memory fragmentation can result in wasted space, as small gaps between allocated memory blocks cannot be utilized effectively, leading to a decrease in overall system performance and efficiency over time.
- Limits the ability to run multiple processes simultaneously as each process requires a large continuous block of memory. This constraint can significantly impact the system’s multitasking capabilities, preventing it from handling multiple applications or processes concurrently, which can be particularly detrimental in environments that demand high levels of parallel processing and multitasking.
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:
- Increased System Utilization: Partitioned allocation allows multiple processes to be loaded into memory simultaneously, thereby increasing overall system utilization and efficiency.
- Reduced External Fragmentation: By dividing memory into fixed-size or variable-size partitions, this method reduces external fragmentation, which occurs when free memory is split into small non-contiguous blocks over time.
- Compaction and Coalescing: Compaction and coalescing techniques can be used to manage fragmentation by rearranging memory contents to place all free memory together in one large block. This helps in better utilizing memory and making larger contiguous memory blocks available for allocation.
Disadvantages:
- Internal Fragmentation: Fixed-sizat eliminates the need for contiguous allocatioe partitions can lead to internal fragmentation, where allocated memory blocks are larger than the requested memory, leaving unused space within the blocks.
- Management Complexity: Managing and allocating partitions, especially with variable-size partitions, can be complex. The system needs to keep track of all partitions and ensure efficient allocation and deallocation, which can add overhead and complexity.
| Aspect | Internal Fragmentation | External Fragmentation |
| Definition | Occurs 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. |
| Cause | Fixed-size memory allocation leading to partially unused memory blocks. | Dynamic memory allocation creating scattered free memory segments. |
| Impact on Memory | Wastes memory within allocated blocks. | Difficult to allocate large contiguous memory blocks for new processes. |
| Fragmentation Type | Internal, within the allocated blocks. | External, outside the allocated blocks. |
| Memory Utilization | Leads to inefficient use of memory within the blocks. | Results in fragmented memory, reducing the efficiency of memory utilization. |
| System Performance | Can degrade performance due to unused space within blocks. | Degrades performance by making it hard to find contiguous blocks for allocation. |
| Aspect | Fixed Partitioning | Variable Partitioning |
| Definition | Divides 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 Allocation | Each 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. |
| Fragmentation | Prone 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. |
| Flexibility | Inflexible, 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 Complexity | Easier 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 Utilization | Potentially 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 For | Systems 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 Impact | Can 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 Utilization | Often 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:
- Better memory utilization: By allowing processes to occupy non-adjacent memory blocks, non-contiguous allocation reduces fragmentation and makes better use of available memory.
- Flexibility: Processes can be easily resized by allocating or deallocating memory blocks without needing to find a large contiguous space.
- Improved multitasking: Multiple processes can coexist in memory more efficiently, enhancing the system's ability to handle multiple tasks simultaneously.
- Internal and External fragmentation problem is tried to be resolved in this non contiguous memory allocation
Disadvantages:
- Increased complexity: Managing non-contiguous memory allocation requires more complex bookkeeping to keep track of all the memory blocks assigned to a process.
- Overhead: The system needs additional mechanisms to map logical addresses to physical addresses, potentially introducing overhead and reducing performance.
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
- The Translation Lookaside Buffer (TLB) speeds up virtual address translation in a computer's memory management unit (MMU).
- Without a TLB, every memory access would need a lookup in the relatively slow page table in main memory.
- The TLB caches recent address translations.
- When there is a "TLB hit," physical addresses are retrieved faster.
- This reduces latency associated with memory accesses.
- Enhances overall system performance.
- Minimizes the overhead of frequent page table lookups.
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:
- 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.
- 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.
- 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:
Where:
- TLB hit rate: The probability that the desired address translation is found in the TLB.
- TLB miss rate: The probability that the desired address translation is not found in the TLB (1 - TLB hit rate).
- TLB access time: The time it takes to access the TLB and retrieve an address translation.
- Page table access time: The time it takes to access the page table in main memory if there is a TLB miss.
- Memory access time: The time it takes to access the actual data in main memory.

Advantages of Using Hardware TLB
- Speed: The primary advantage of using a hardware TLB is the significant speed improvement in address translation. TLB hits allow for rapid address translation, reducing the time required for memory accesses.
- Efficiency: By caching recent translations, the TLB reduces the number of times the page table needs to be accessed, decreasing the overall memory access latency and improving system performance.
- Reduced Overhead: The use of a TLB minimizes the overhead associated with frequent page table lookups, freeing up system resources for other tasks and enhancing the efficiency of the memory management system.
Disadvantages
- Complexity: Implementing and managing a hardware TLB adds complexity to the memory management unit. The system must handle TLB misses and ensure that the TLB remains coherent with the page table.
- Limited Size: The TLB is typically small in size due to its high-speed nature. This limitation means that not all address translations can be cached, leading to potential TLB misses and the need for page table accesses.
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:
- Segment Number Lookup: The segment number from the logical address is used to index into the segment table.
- Base Address Retrieval: The segment table provides the base address of the segment in physical memory.
- 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:
- Logical Organization: Segmentation aligns with the logical structure of programs, dividing memory into meaningful sections like code, data, and stack. This organization makes it easier to manage and protect memory.
- Efficient Memory Utilization: Since segments can vary in size, memory can be allocated more precisely to fit the needs of different program components, reducing waste.
- Protection and Isolation: Segmentation provides a mechanism for protecting different parts of a program from each other. For example, a code segment can be marked as read-only to prevent accidental modification, enhancing overall system stability and security.
- Support for Dynamic Loading: Segments can be loaded and unloaded independently, allowing for dynamic loading of program modules, which is useful for large applications with many components.
Disadvantages of Segmentation:
- Complexity: Managing variable-sized segments and maintaining the segment table adds complexity to the memory management system. The operating system must handle segment allocation, deallocation, and protection, which can be resource-intensive.
- Fragmentation: While segmentation helps with internal fragmentation, it can lead to external fragmentation as free memory is scattered into small, non-contiguous blocks. This fragmentation can make it difficult to find contiguous memory for new segments.
- Overhead: The need to maintain and manage the segment table introduces overhead. Every memory access requires a lookup in the segment table, which can slow down the system if not efficiently managed.
Segmentation vs. Paging:
Segmentation and paging are both techniques used to manage memory, but they have distinct differences:
| Aspect | Segmentation | Paging |
| Memory Division | Divides memory into variable-sized segments based on logical units. | Divides memory into fixed-size pages for uniformity. |
| Address Structure | Logical addresses consist of a segment number and an offset. | Logical addresses consist of a page number and an offset. |
| Fragmentation | Prone to external fragmentation. | Prone to internal fragmentation but eliminates external fragmentation. |
| Protection and Sharing | Provides better protection and sharing as segments represent logical units. | Provides uniformity but less natural support for logical protection and sharing. |
| Overhead | Higher 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:
- 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.
- 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.
- 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.
- 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:
- Increased Memory Space: Virtual memory allows programs to use more memory than is physically available, enabling the execution of larger applications and multitasking.
- Isolation and Protection: Each process has its own virtual address space, which isolates it from other processes. This enhances security and stability by preventing processes from interfering with each other.
- Efficient Memory Utilization: By using techniques like demand paging and swapping, virtual memory optimizes the use of physical memory, reducing waste and improving performance.
- Simplified Programming: Programmers can write applications without worrying about the limitations of physical memory, as the operating system handles memory management transparently.
Disadvantages of Virtual Memory:
- Performance Overhead: Virtual memory introduces overhead due to the need for address translation and page table management. Swapping can also slow down the system if it occurs frequently.
- Complexity: Implementing and managing virtual memory requires sophisticated algorithms and data structures, adding complexity to the operating system.
- Storage Requirements: Swapping requires additional storage space on disk, which can be a limitation if disk space is scarce.
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:
- FIFO (First-In, First-Out): The oldest page in memory is swapped out first.
- LRU (Least Recently Used): The page that has not been used for the longest time is swapped out.
- Optimal Page Replacement: The page that will not be used for the longest time in the future is swapped out. This algorithm is theoretical and used for comparison purposes.
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:
- Working Set Model: The operating system keeps track of the working set of each process and ensures that it fits into physical memory.
- Load Control: The operating system limits the number of processes in memory to prevent overloading and thrashing.