Section 6: Memory Management - bmitch26/Operating-Systems GitHub Wiki
Memory management is the process of efficiently allocating, tracking, and optimizing the use of a computer's memory resources. It ensures that each program gets the memory it needs, resolves memory allocation conflicts, and manages swapping between physical and virtual memory.
"Memory Management in Operating System." GeeksforGeeks, n.d., https://www.geeksforgeeks.org/ memory-management-in-operating-system/. Accessed 22 Nov. 2024.
Logical Address vs. Physical Address
• Logical Address: The address generated by the CPU during program execution, also known as a virtual address. • Physical Address: The actual address in the memory hardware where data or instructions are stored. The memory management unit (MMU) translates logical addresses to physical addresses.
"What Is the Difference Between Logical and Physical Address w.r.t. Operating System." AfterAcademy, n.d., https://afteracademy.com/blog/what-is-the-difference-between-logical-and-physical-address-wrt-operating-system/. Accessed 22 Nov. 2024.
Memory Allocation Techniques
• Contiguous Allocation: Memory is allocated in a single continuous block. Each process occupies a contiguous section of memory, simplifying address translation but potentially causing fragmentation.
"Memory Management in Operating System." GeeksforGeeks, n.d., https://www.geeksforgeeks.org/ memory-management-in-operating-system/. Accessed 22 Nov. 2024.
• Non-Contiguous Allocation: Memory is allocated in multiple, separate blocks. This allows better utilization of available memory and reduces fragmentation. Techniques like paging and segmentation fall under this category.
"Non-Contiguous Allocation in Operating System." GeeksforGeeks, n.d., https://www.geeksforgeeks.org/non-contiguous-allocation-in-operating-system/. Accessed 22 Nov. 2024.
Paging
A memory management technique that divides the process's memory into fixed-sized blocks called pages and the physical memory into blocks of the same size called frames. Pages are mapped to frames using page tables.
"Memory Management in Operating System." GeeksforGeeks, n.d., https://www.geeksforgeeks.org/ memory-management-in-operating-system/. Accessed 22 Nov. 2024.
Segmentation
A memory management technique where memory is divided into variable-sized segments based on logical divisions in a program, such as code, data, and stack segments. Each segment has a base and limit value.
"Segmentation in Operating System." GeeksforGeeks, n.d., https://www.geeksforgeeks.org/segmentation-in-operating-system/. Accessed 22 Nov. 2024.
Page Tables
A data structure used in paging to map logical page numbers to physical frame numbers in memory. • Multi-Level Page Tables: A hierarchical structure of page tables used to manage large virtual address spaces by breaking the page table into multiple levels.
"Multilevel Paging in Operating System." GeeksforGeeks, n.d., https://www.geeksforgeeks.org/multilevel-paging-in-operating-system/. Accessed 23 Nov. 2024.
• Inverted Page Tables: A page table structure where there is one entry per frame in physical memory, mapping physical frames back to the virtual pages that occupy them. This reduces the size of the page table.
"Inverted Page Table in Operating System." GeeksforGeeks, n.d., https://www.geeksforgeeks.org/inverted-page-table-in-operating-system/. Accessed 23 Nov. 2024.
Virtual Memory
A memory management technique that provides the illusion of a large, continuous memory space by using both physical memory (RAM) and secondary storage (e.g., disk). It allows programs to exceed the size of physical memory.
Page Fault
A page fault occurs when a program attempts to access a page that is not currently in physical memory. The operating system must load the required page from secondary storage into memory, potentially replacing an existing page.
"Page Fault Handling in Operating System." GeeksforGeeks, n.d., https://www.geeksforgeeks.org/page-fault-handling-in-operating-system/. Accessed 23 Nov. 2024.
Demand Paging
A technique where pages are loaded into memory only when they are needed, rather than pre-loading all pages at program startup. This reduces memory usage but can increase page fault frequency.
"What is Demand Paging in Operating System." GeeksforGeeks, n.d., https://www.geeksforgeeks.org/ what-is-demand-paging-in-operating-system/. Accessed 23 Nov. 2024.
Page Replacement Algorithms • First-In-First-Out (FIFO): Replaces the oldest page in memory (the one loaded the earliest) when a new page needs to be loaded.
• Least Recently Used (LRU): Replaces the page that has not been used for the longest period of time.
• Optimal Page Replacement: Replaces the page that will not be used for the longest time in the future. This algorithm is theoretical and not typically implementable in real systems.
• Clock (Second-Chance) Algorithm: A variation of FIFO that gives pages a "second chance" to stay in memory by using a circular queue and checking reference bits to determine replacement.
"Second Chance or Clock Page Replacement Policy." GeeksforGeeks, n.d., https://www.geeksforgeeks.org/second-chance-or-clock-page-replacement-policy/. Accessed 23 Nov. 2024. "Page Replacement Algorithms in Operating Systems." GeeksforGeeks, n.d., https://www.geeksforgeeks.org/page-replacement-algorithms-in-operating-systems/. Accessed 23 Nov. 2024. "Second Chance or Clock Page Replacement Policy." GeeksforGeeks, n.d., https://www.geeksforgeeks.org/second-chance-or-clock-page-replacement-policy/. Accessed 23 Nov. 2024.
Thrashing
Thrashing occurs when a system spends more time handling page faults and swapping pages in and out of memory than executing actual processes. This leads to a significant decline in performance.
"Thrashing in Operating System." Studytonight, n.d., https://www.studytonight.com/operating-system/thrashing-in-operating-system. Accessed 23 Nov. 2024.
Fragmentation
• Internal Fragmentation: Occurs when allocated memory blocks have unused space due to allocation being larger than what is actually needed.
"Internal Fragmentation." PrepInsta, n.d., https://prepinsta.com/operating-systems/internal-fragmentation/. Accessed 23 Nov. 2024.
• External Fragmentation: Occurs when free memory is scattered in small, non-contiguous blocks, making it difficult to allocate large contiguous blocks even though enough total memory is available.
"External Fragmentation." PrepInsta, n.d., https://prepinsta.com/operating-systems/external-fragmentation/. Accessed 23 Nov. 2024.