Memory Management 1 Background Logical Versus Physical Address

Memory Management • • 1 Background Logical Versus Physical Address Space Swapping Paging Virtual Memory Demand Paging’ Thrashing SLC/VER 1. 0/OS CONCEPTS/OCT'99

Background • Program must be brought into memory and placed within a process for it to be executed • Input queue – collection of processes on the disk that are waiting to be brought into memory for execution. • User programs go through several steps before being executed. 2 SLC/VER 1. 0/OS CONCEPTS/OCT'99

Address Binding • Address binding of instructions and data to memory addresses can happen at three different stages. -Compile Time -Load Time -Execution Time 3 SLC/VER 1. 0/OS CONCEPTS/OCT'99

Dynamic Loading • • 4 Routine is not loaded until it is called Better memory-space utilization Useful for large amount of code are needed No special support from the OS is required SLC/VER 1. 0/OS CONCEPTS/OCT'99

Dynamic Linking • Linking postponed until execution time. • Stub used to locate the appropriate memoryresident library routine. • OS needed to check if routine is in processes memory address. 5 SLC/VER 1. 0/OS CONCEPTS/OCT'99

Logical Vs Physical address space • Logical address are generated by CPU • Unit of memory is commonly referred as a physical addresses • logical and physical address differ at the execution time • The run time mapping from virtual to physical address is done by the MMU, which is a hardware device. 6 SLC/VER 1. 0/OS CONCEPTS/OCT'99

Logical Vs Physical address space Relocation register 1400 CPU Logical address 346 + Physical address Memory 14346 MMU Dynamic relocation using a relocation register 7 SLC/VER 1. 0/OS CONCEPTS/OCT'99

SWAPING • A process can be swapped temporarily out of memory to a backing store, and then brought back into memory for continued execution • swapping can be done on priority bases • A process that is swapped out will be swapped back into the same memory space that is occupied previously 8 SLC/VER 1. 0/OS CONCEPTS/OCT'99

Schematic View of Swapping 9 SLC/VER 1. 0/OS CONCEPTS/OCT'99

Paging • Physical memory is broken into fixed size blocks called frames • logical memory is broken into blocks of same size called pages • paging is done with the hardware support 10 SLC/VER 1. 0/OS CONCEPTS/OCT'99

Paging Logical address CPU P d F d Physical Page table p f Paging hardware 11 SLC/VER 1. 0/OS CONCEPTS/OCT'99 Memory

Paging E. g u 1 2 3 4 a b c d 0 1 3 4 4 5 6 e f g 2 1 7 h 3 2 8 9 10 11 i j k l Logical Memory 12 0 8 12 Page table 16 page Example for 32 -byte memory with 4 byte pages SLC/VER 1. 0/OS CONCEPTS/OCT'99 I j k l m n o p a b c d e f g h Physical memory

Virtual Memory • Virtual memory – separation of user logical memory from physical memory. – Only part of the program needs to be in memory for execution. – Logical address space can therefore be much larger than physical address space. – Need to allow pages to be swapped in and out. • Virtual memory can be implemented via: – Demand paging 13 SLC/VER 1. 0/OS CONCEPTS/OCT'99

Demand-paging • Bring a page into memory only when it is needed -Less I/O needed -Less memory needed -Faster response -more users • Page in, Page out and Page fault. 14 SLC/VER 1. 0/OS CONCEPTS/OCT'99

Valid-Invalid Bit • With each page table entry a valid-invalid bit is associated. • Example of a page table snapshot Frame # valid-invalid bit 1 1 0 M 15 SLC/VER 1. 0/OS CONCEPTS/OCT'99

Demand-paging 3 OS 2 1 Load M i 6 5 16 Free frame 4 SLC/VER 1. 0/OS CONCEPTS/OCT'99

What happens if there is no free frame? • Page replacement - find some page in memory, but not really in use, swap it out -algorithms -performance-want an algorithm which will result in minimum number of page faults. • Same page may be brought into memory several times. 17 SLC/VER 1. 0/OS CONCEPTS/OCT'99

Thrashing • If process doesn’t have “enough” pages, the page-fault rate is very high. This leads to: -low CPU utilization -OS thinks that it needs to increase the degree of multiprogramming -another process added to the system • Thrashing= a process is busy swapping pages in and out 18 SLC/VER 1. 0/OS CONCEPTS/OCT'99

Thrashing Causes Of Thrashing: C P U Thrashing U t I l I z a t I o n Degree of multiprocessing 19 SLC/VER 1. 0/OS CONCEPTS/OCT'99
- Slides: 19