You are on page 1of 19

Memory Management

Background Logical Versus Physical Address Space Swapping Paging Virtual Memory Demand Paging Thrashing

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.

Address Binding
Address binding of instructions and data to memory addresses can happen at three different stages. -Compile Time -Load Time -Execution Time

Dynamic Loading
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

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.

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.

Logical Vs Physical address space


Relocation register
1400 Logical address 346 Physical address 14346

CPU

Memory

MMU

Dynamic relocation using a relocation register

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

Schematic View of Swapping

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

Paging
Logical address CPU P d F d Physical Page table Memory

Paging hardware

Paging
E.g u 1 2 3 4 5 6 7 8 9 10 11 a b c d e f g h i j k l 0 0 1 2 3 3 4 4 1 2 Page table 16 8 I j k l m n o p a b c d e f g h Physical memory

12

Logical Memory

page Example for 32-byte memory with 4byte pages

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

DemandDemand-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.

Valid-Invalid Bit Valid With each page table entry a valid-invalid bit is associated. Example of a page table snapshot
Frame # valid-invalid bit

1 1 1 1 0 M

DemandDemand-paging
3 OS 2 1 Load M i 6

Free frame 4

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.

Thrashing
If process doesnt 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

Thrashing
Causes Of Thrashing:
C P U U t I l I z a t I o n Degree of multiprocessing Thrashing

You might also like