Memory Managment Os

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 27

Memory Management

Basics of Memory Management


• Size
• Access
Memory
• Per unit Cost
VARIOUS MEMORY LEVELS HARD DISK
RAM
CPU 1 WORD
1 WORD

MEMORY
1 WORD 1 WORD

CPU REGISTERS DISK


Basics of Memory Management
Q: How it works
Ans: With help of Locality of Reference

CPU Cache Main Memory Secondary

I1 . . . I200 . . . I1000
E.g: Shop and Godown
Memory Management
It is method of managing “Primary memory”.

CPU Main Memory Secondary

I1 . . . I200 . . . I1000
Secondary
CPU Main Memory
Hit % =90 10 ms 100 ms

Avg = Hit % (M memory acess time )+ Remaining % (M memory access time


+ Sec Memory access time
= .9 (10)+.1(10+100)
= 9 + 11
= 20 ms
VARIOUS STORAGE DEVICE HARD DISK
RAM
CPU 1 WORD
1 WORD

CPU FETCHING WORD


FROM RAM

MEMORY
1 WORD 1 WORD

CPU REGISTERS DISK


• CPU copy words from Memory and put in Register for execution.
• Register are fast memory in computer.
• Any operation perform by PC with help of Registers for execution.
• Size of register is 1 word.
• Entire memory is divided in to words.
• Inside word we can place instruction or data.
• In Computers memory only two things are stored Instruction and Data.
• Instruction is a part of program.
• Data can be number , letter, word, sentence, image, audio or video.
• All things in Computers placed in 1 or 0.
• Data can be any storage device of computer in form of machine language.
• Every word of RAM consist instruction or data.
• All pc implements in different ways.
• Some pc use two word or three represent 1 instruction.
• Conventionally text book assumed that 1 word contain one instruction.
• Every word of RAM is addressed or indexed.
• Size of word is not fixed its depends of PC architecture.
• Some PC 4 Bytes or 8 Bytes but it is always size of word calculated by
2^n,similarly Size of RAM is also 2^n, Size of Hard Disk 2^n and Size of
Register is also 2^n like 4 bytes,8bytes,16 bytes, 32 bytes.
RAM • Word always addressed in form of binary digits
0 like 4 can be represented in 100,0100,00100
1 • Size of ram is calculated by formula 2 ^ n for no of bits addressed of a word.
2 n bits = 2 ^ n numbers.
3 2 ^ m words= m bits. 0
. • if m = 32 bits then addressing starts from
1
. 0= 0000………0000,
2
.
1 = 0000………0001,
3
n
2 = 0000……0002..
4 word
• CPU always ask for only single word.
• In case cpu ask for word 4 then it will give address of word 4 to ram .
.
Then Ram send copy of word to register for Execution by CPU.
HOW cpu request for word? n
Buses.
ADDRESS SPACE
• It means collection of address or set of address e.g Address 1,Address 2,
• RAM is collection of words
• Every word has address so RAM is collection of Address.
• These Address are Physical Address so RAM is also known as Physical Address
Space
Physical Address Space

ADDRESS SPACE

Address 1
Address 2
Address 3
• Process are placed inside RAM .
RAM
PROCESS 1 Process 1

Physical Address Space


Process 2
Process 3
.
.
PROCESS 2 .
Logical Address Space

.
Process n

PROCESS n
Logical Physical
Address Translate Address

Secondary
CPU Main Memory

Regarding Architecture OS has two responsibilities


1.Memory Allocation
Among all processes which process will get which space area inside main memory.
2.Address Translation
Logical address translated to physical address.
Memory
Allocation

Non-
Contiguous
Contiguous
Memory Allocation
S.M
• Two Policies for M.M

memory
Contiguous
allocation and P1 P1

their names are P2 P2


written as
under: P1
P1
• Contiguous Non Contiguous
P2
P1 P2
P2
• Non Contiguous
Contiguous allocation

10 KB

Advantages: Array
4 KB 2 KB 4 KB
Address Translation
Access very fast and easy P1= 5 KB
Disadvantage:
External fragmentation
First Non Contiguous allocation n

10 KB

4 KB 2 KB 4 KB
Link List
Advantages: P1= 5 KB pointer
No External fragmentation

Disadvantage:
Access time is very slow
Contiguous

Fixed Size / Static Variable Size /


Partitioning Dynamic Partitioning
P1 P1

CPU M.M S.M

P1
Contiguous Allocation
Internal Fragmentation

10 kb

P1
5 Kb 2 Kb 2 Kb 1Kb

P1= 4 Kb
Fixed Partition
No Internal Fragmentation

10 kb

P1 P2
4 Kb 3 Kb 3 Kb

P1= 4 Kb, P2=3 Kb


Variable Partition
P1=300
50 150 300 350 600 P2=25
P3=125
P4=50
First
50 150 300 350 600

Best
50 150 300 350 600

Worst
50 150 300 350 600
Variable Size Partition
First fit policy
25 125 50
300
P1=300
P2=25 P P P P After
P3=125 2 3 1 4
P4=50 50 150 300 350 600

Before
50 150 300 350 600

This scenario in middle state not from initial state


Always start allocation from 1st.
Best fit policy
25 125 300 25 25
P1=300
P2=25 P P P After
P3=125 3 1 2
P4=50 50 150 300 350 600

Before
50 150 300 350 600

First search all free space from memory than select


Smallest space
Worst fit policy
25 125 50
300
P1=300
P2=25 P P P P After
P3=125 2 3 1 4
P4=50 50 150 300 350 600

Before
50 150 300 350 600

First search all free space from memory than select


Largest space
P1=357
P2=210
P3=468
P4=491
200 400 600 500 300 250
P1 P2 P3
P1=357
First P2=210
200 400 600 500 300 250 P3=468
P4=491
P1 P4 P3 P2
Best
200 400 600 500 300 250
P1 P2
Worst
200 400 600 500 300 250

Fixed Size Partition

You might also like