Chapter 3 - Memory Managment
Chapter 3 - Memory Managment
CHAPTER 3
Memory management
Introduction
• Memory is an important resource that needs to be
managed properly.
• Why?-
• they are limited in nature!
• What is programmers/expert users need?
• Private, infinitely large and fast memory that is also nonvolatile.
• Can the technology provide that?
• NO but, may be in the future.
• Hence the operating system owes to manage the
memory.
• How?
4
Introduction…
The OS has a part called Memory manager that manipulates
and perform an operation on memory hierarchy.
<1
Registers
nsec
2 nsec
Cache Memory
10 nsec
Main Memory
10 msec
Magnetic Disk
100 sec
Magnetic Tape
Memory Management
Memory management systems are divided in to
two classes.
◦ Those that move processes back and forth b/n main
memory and disk (paging and swapping) b/c of
memory insufficiency
◦ Those that do not (simpler)
User Program
User Program
User program
OS in RAM OS in RAM
0
Swapping
Swapping…
Allocating space
for a growing data
segment.
10
Swapping…
• Allocating space for a
growing stack and a
growing data segment.
11
MM using Bitmaps
The Size of
the bitmap
depends on
the size of
memory and
size of the
allocation unit.
a) A part of memory with five processes and three holes. The tick marks
show the memory allocation units. The shaded regions (0 in the bitmap) are
free.
(b) The corresponding bitmap.
(c) The same information as a list.
13
Activity
0 8 16 24 32
14
Virtual Memory
Formerly Overlays were used as a virtual memory.
◦ Splitting done manually by the programmer
◦ Swapping done by the system
But some overlay systems were so complex and expensive to
work with. And the first task, by nature, is time consuming and
boring.
Hence in 1961 a method of doing every thing using system
is advised.
◦ i.e. Virtual Memory.
The main idea is to put currently used data, program and
stack in the main memory and the rest in the disk.
◦ i.e. X MB Program can run on YMB machine where X>>Y and X and
Y are size of power of 2
16
Paging
• VM uses a technique called paging.
• For instance- the instruction MOV REG,1000 –copy the content of
memory address 1000 in to REG
17
Paging…
Pages and page frames are
always equal. Here 4KB
◦ How much pages and page
frames can we get from 64 KB
of Virtual address space and
32 KB of physical memory?
Lets do the following
instruction.
MOV REG 0
MOV REG 8192
will be transformed in to
___, and ____, output will
be moved to bus
What happens if the
program tries to use MOV
REG, 32780
See answer next slide:
18
The exact layout of an entry in the page table is highly machine dependent, but
the kind of information present is roughly the same from machine to machine.
The size varies from computer to computer, but 32 bits is a common size The
most important field is the Pa g e frame number.
After all, the goal of the page mapping is to output this value.
Next to it we have the Present/absent bit. If this bit is 1, the entry is valid and can
be used, else the virtual page to which the entry belongs is not currently in
memory.
24
Page Replacement
• Prevent over-allocation of memory by modifying page-fault service routine to include
page replacement.
• A process may have 10 pages but only 5 are in use.
• This allows us to bring more programs into memory – increase degree of multiprogramming
or over-allocating memory.
• If have 40 frames, run 8 processes using 5 pages each instead of 4 processes using 10
pages.
• What happens when a process suddenly needs all 10 pages? All memory is in use.
• Page replacement
27