Memory management is an integral part of an operating system. Systems that are capable of supporting multiprogramming must manage available resources effectively so that processes will have the least amount of idle time. Many operating systems use virtual memory, a form of memory management, by storing additional memory to disk. This memory is actually an extension of main memory used by processes that require larger amounts of memory space. Virtual memory improved simple paging and segmentation that used fixed and dynamic partitions by using logical addresses that translate into physical addresses at runtime (Stallings, 2009, p. 346). Paging concepts used in virtual memory is discussed as it correlates in an exercise simulating virtual memory and random replacement policy.
Virtual memory is a modern form of memory management that enables the operating system to support multiprogramming more efficiently. This type of memory management allows execution of programs requiring more memory than the capacity that main memory can hold. The two memory components used in computers are primary memory contained in RAM, and secondary memory stored on disk called a page file.
The memory manager determines the amount of memory space required by a process and divides the process into smaller fixed-size units in a page table stored in virtual memory. A portion of the page table is loaded in main memory for the page currently running (Stallings, 2009, p. 352). Each page table uses a unique frame number and two indicator bits that indicate when a page is present in main memory and a modify bit indicating a modified page should be written to disk. Modified pages are written to a page file through a process known as paging (Stallings, 2009, p. 350).
The hardware issues a page fault when a process requires a page not loaded in primary memory. After a page fault, a "page in" (Ixora, 2007) operation retrieves the next corresponding page into main memory from the page file on disk (Stallings, 2009, p. 356). A page fault triggers the operating system to modify the page table with new data about the process state and continues executing the next set of instructions. This memory management technique rotates all active processes in the same manner between main and secondary memory.
Virtual memory also uses segmentation where each process has its own segment table containing program data logically divided into segments (Stallings, 2009, p. 361). Segmentation uses logical addresses consisting of a segment number and an offset for referencing an address space in memory stored in a segment table. Each segment size can be established dynamically to accommodate a program needing an unknown data structure size during execution. Since segmentation can change dynamically, programmers use this advantage writing programs without the need to know the exact size of the data structure (Stallings, 2009, p. 361). With segmentation, programmers can also share data among multiple segments as well as protect segments from unauthorized access.
The first simulation demonstrates how virtual memory performs paging. There are eight processes, eight page tables, and 16 pages representing secondary memory stored on disk. A dark blue process indicates it is running, light blue indicates the process is waiting to run (Virginia Tech, n.d.). Whenever a process is running, it examines the page table for the next desired page, and if present, a TBL-hit occurs and retrieves that page in main memory, and continues execution. When a table page changes to yellow, a "page out" operation occurs by writing the changed content out to disk and a "page in" operation retrieves the next page. When a page fault occurs, the process turns red and a "page in" operation reads another page from virtual memory. Page faults cause the memory manager to decide which page should be loaded next by using a replacement policy.
Memory management uses several different policies to determine which page in main memory to replace with another page from secondary memory. This decision is performed by a random replacement policy triggered by a page fault. Replacement policies are a variety of algorithms used to determine the best page in main memory to replace (Stallings, 2009, p. 367). The goal for each policy is to remove the page which is least likely to be used again in the near future. Policies having greater complexity require that hardware and software support computer performance needed to implement them (Stallings, 2009, p. 367). First-In-First-Out (FIFO) and Least Recently Used (LRU) are two policies discussed and observed in a simulator to understand the concept of replacement policies.
FIFO is a policy that maintains a list of all pages in memory and replaces the oldest page first. The page frames for each process are treated as a circular buffer by using a pointer that circles through each frame in a round-robin technique (Stallings, 2009, p. 369). This policy can result in more page faults due to a program requiring a particular page frequently even though the policy determined it is no longer needed.
LRU uses an algorithm that determines a page in memory that has not been used the longest as a replacement candidate. According the Stallings (2009), LRU policy performs nearly as well as optimal policy, however, it is difficult to implement and requires sufficient hardware to support it.
The second simulator demonstrates the behavior of page replacement. Clicking the Start button begins the simulation as it cycles through the page faults and calculates page reference totals. The occurrence of a page fault signifies main memory requires a new page reference from the page file on disk. The Fast button increased the cycle speed of the policies and the Slow button decreased the cycle speed (Virginia Tech, n.d.). Both buttons resulted with the same outcome. After pressing the Stop button, the results show the comparisons between each policy. The number of page faults for FIFO was 18 and LRU was 17. Both policies had 25 for the total number of page references. FIFO had a Page Fault Rate of 72% and LRU had 68%. The percentage values proved that FIFO is slower since it had more I/O operations due to the number of page faults. Using the sample string, each number represents a requested page for totaling eight pages (Virginia Tech, n.d.). The results for both FIFO and LRU were the same: 8 page faults, total number of page references were 58, and the percentage were 38%. Restarting the simulator several times and clicking both Fast and Slow returned the same results. I would have assumed that FIFO should have more page faults than LRU, however, it did not.
Virtual memory is a complex method for memory management. This is an important component for both hardware and operating systems to perform efficiently. Paging allows processes to use pages with fixed length whereas segmentation is scalable and provide programmers the ability to specify exact memory size and location. The operation of virtual memory is seamless and transparent to the user allowing several programs to appear as if they are running concurrently. Virtual memory concepts prove beneficial due to an increasing demand for more memory that today's applications require.