Course: Operating Systems Instructor: M Umair
Memory Management
Introduction { Ref: Operating System Concepts 8th Edition Abraham Silberschatz, Greg Gagne, Peter B. Galvin }
Address Binding Addresses in the source program are generally symbolic (such as count). A compiler will typically bind these symbolic addresses to relocatable addresses. 14 bytes from the beginning of this module. The linkage editor or loader will in turn bind the re-locatable addresses to absolute addresses. For example 74014. { Ref: Operating System Concepts 8th Edition Abraham Silberschatz, Greg Gagne, Peter B. Galvin }
Address Binding Compile time If you know at compile time where the process will reside in memory, then absolute code can be generated. Load time If it is not known at compile time where the process will reside in memory, then the compiler must generate relocatable code. Final binding is delayed until load time. { Ref: Operating System Concepts 8th Edition Abraham Silberschatz, Greg Gagne, Peter B. Galvin }
Address Binding Execution time If the process can be moved during its execution from one memory segment to another, then binding must be delayed until run time. Special hardware must be available for this scheme to work. { Ref: Operating System Concepts 8th Edition Abraham Silberschatz, Greg Gagne, Peter B. Galvin }
Multiprogramming with Fixed Partitions Divide memory up into n (possibly unequal) partitions. This partitioning can be done manually when the system has started up.
Multiprogramming with Fixed Partitions
CPU Utilization
Swapping Sometimes there is not enough main memory to hold all the currently active processes. Excess processes must be kept on disk and brought in to run dynamically. Swapping, consists of bringing in each process, running it for a while, then putting it back on the disk. Virtual memory, allows programs to run even when they are only partially in main memory.
Swapping
Swapping Swapping creates multiple holes in memory It is possible to combine them all into one big one by moving all the processes downward as far as possible. This technique is known as memory compaction. Example On a 256-MB machine that can copy 4 bytes in 40 nsec, it takes about 2.7 sec to compact all of memory.
Swapping Growing Segments Dynamically Allocation of Memory! 1. Grow into hole OR 2. Move process to a hole in memory large enough to hold it OR 3. Wait / Kill
Memory Management with Bitmaps
Virtual Memory Combined size of the program, data, and stack may exceed the amount of physical memory available for it. The operating system keeps those parts of the program currently in use in main memory, and the rest on the disk. Example A 16-MB program can run on a 4-MB machine by carefully choosing which 4 MB to keep in memory at each instant, with pieces of the program being swapped between disk and memory as needed.
Virtual Memory - Paging MMU maps the virtual address onto the physical address. MMU is not required if there is no virtual memory
Virtual Memory - Paging virtual address space is divided up into units called pages corresponding units in the physical memory are called page frames
Virtual Memory - Paging Address Translation Example 00000 8192 8192 24576 20500 12308
Virtual Memory Page Fault Page Fault Example MOV REG, 32768????? CPU generates trap for OS Page Fault OS picks/removes little used page Brings in requested page Change the map Restart trap instruction
Virtual Memory Page Fault Handling
Virtual Memory Page Table { Ref: Operating System Concepts 8th Edition Abraham Silberschatz, Greg Gagne, Peter B. Galvin }
Virtual Memory Page Table Translation Example 0 0000 0000 0000 0000 At 0000 the information is 2 i.e 0010 0010 0000 0000 0000 -> 8192
Virtual Memory Page Replacement Algorithms Optimal Page Replacement Algorithm If one page will not be used for 8 million instructions and another page will not be used for 6 million instructions, removing the former pushes the page fault. Problem with this algorithm is that it is unrealizable. The operating system has no way of knowing when each of the pages will be referenced next.
Virtual Memory Page Replacement Algorithms Not Recently Used Page Replacement Algorithm Removes a page at random from the lowest numbered nonempty class. Use of R/M bit and clock interrupt. Remove a modified page that has not been referenced in at least one dock tick (typically 20 msec). Classification 3. referenced, modified 2. referenced, not modified 1. not referenced, modified 0. not referenced, not modified
Virtual Memory Page Replacement Algorithms First-In, First-Out (FIFO) Page Replacement Algorithm The operating system maintains a list of all pages currently in memory. The page at the head of the list is the oldest one and the page at the tail is the most recent arrival. On a page fault, the page at the head is removed and the new page added to the tail of the list.
Virtual Memory Page Replacement Algorithms Second Chance Page Replacement Algorithm Replace only if page is old and unused otherwise put on to the end of list.