Beruflich Dokumente
Kultur Dokumente
CS2600 (3003)
By
Dr. Sk Subidh Ali
Memory Hierarchy
Memory Hierarchy
0011010100
a.out 0001101001
Cache 0011010100
ALU
0101010000
0001101001
0011010100
0001101001
0101010000
1010010100
1100101010
CPU
0011101010
RAM Registers
a.out
gcc
$gcc a.c TextEd Reg.
a.c FF
Costlier
Faster
Cache
Void main() SRAM
{
int a ,b=9,c=8;
a=b+c Primary Memory
print(a) a.out a.c DRAM
}
Hard Disk
note.doc DAC.php Secondary Storage
Readme.txt Hard disk
$TexEdit a.c
Primary Memory
Organization
Primary Organization
RAM
RAM
0x0000
Resident monitor Monitor
0x00ff
Designer doesnt know executables (OS)
Fence Address 0x00ff
OS must be protected from users
0x0ffff
a.out
Physical Address
How does it protect OS? Logical Address
Multiprogramming
Multiprogramming Environment
Executes multiple programs together
hello
Running
0001101001
0011010100
New Ready Halted/
0101010000 ./hello exited
1010010100
1100101010
0011101010
Wait
0011010100
Need:
Void main()
{ Ready
ALU
int a ,b=9,c=8; queue
a=b+c
print(a) Waiting
0001101001
} queue a.out
gcc
TextEd
RAM
Registers CPU
unning program is called a process
Multiprogramming Environment
Executes multiple programs together
Running
Wait
./hello
Process hello created
HDD OS
ALU
hello
edit
encrypt
RAM
Registers CPU
DD : hard disc
Multiprogramming Environment
Executes multiple programs together
Running
hello Wait
./encrypt
HDD OS
ALU
hello
edit
encrypt hello
RAM
Registers CPU
Multiprogramming Environment
Executes multiple programs together
Running
encrypt Wait
./edit
0011010100
HDD OS
ALU
hello
0001101001
edit
encrypt
encrypt hello
RAM
Registers CPU
Multiprogramming Environment
Executes multiple programs together
Running
encrypt Wait
edit
Instructions of hello is
getting executed in CPU
Void main()
0011010100
{ OS
int a= ,b=6,
I/O operations
ALU
c=8;
scan(a) executes in I/O
c=a+b+c
devices (slow)
0001101001
print(a)
print(c) take more time edit
} encrypt
hello
RAM
Registers CPU
Multiprogramming Environment
Executes multiple programs together
Running
encrypt Halted/
New Ready
exited
edit Wait encrypt start running in CPU
hello
hello is waiting for I/O
(scan(a) to complete)
Void main()
0011010100
{ OS
int a= ,b=6,
I/O operations
ALU
c=8;
scan(a) executes in I/O
c=a+b+c
devices (slow)
0001101001
print(a)
print(c) take more time edit
} encrypt
hello
RAM
Registers CPU
Multiprogramming Environment
Executes multiple programs together
Running
encrypt Halted/
New Ready
exited
edit Wait
hello encrypt start running in CPU
0011010100
HDD OS
ALU
Slow processing
hello
0001101001
edit edit
encrypt
encrypt hello
RAM
Swap out
ProcessRegisters CPU
Multiprogramming Environment
Executes multiple programs together
Running
encrypt Halted/
New Ready
exited
edit Wait encrypt start running in CPU
hello
hello is waiting for I/O
(scan(a) to complete)
0011010100
OS
ALU
Memory should be partitioned
for different processes
0001101001
edit
encrypt
hello
RAM
Registers CPU
Fixed Memory Partitioning
Memory Partitioning
OS
OS MFT can handle up to n number of processes
OS
OS MFT can handle up to n number of processes
Process P1 size is 4K
Fixed Memory Partitioning
Utilized Memory Partitioning
Wasted
Process P1 size is 4K
Fixed Memory Partitioning
Utilized Memory Partitioning
Wasted
OS
OS MFT can handle up to n number of processes
Process P1 size is 4K
Process P2 size is 1k
Fixed Memory Partitioning
Utilized Memory Partitioning
Wasted/fragmentation
OS
OS MFT can handle up to n number of processes
OS
OS MFT can handle up to n number of processes
1K
Process P1 size is 4K
Fixed Memory Partitioning
Memory Partitioning
OS
OS MFT can handle up to n number of processes
1K
Process P5 size is 5K
Fixed Memory Partitioning
Memory Partitioning
OS
OS MFT can handle up to n number of processes
Process P5 size is 5K
Fixed Memory Partitioning
Memory Partitioning
OS
OS MFT can handle up to n number of processes
External fragmentation
Fixed Memory Partitioning
Memory Partitioning
50K
P3(20K)
Fixed Memory Partitioning
Memory Partitioning
Compaction
Shift existing processes byte-by-byte up or down to make
a big partition
10K OS
OS
P1(10K) Compaction can overcome
external fragmentation up to
P3(20K) certain extent
50K
How to keep track of partitions
10K OS
OS
Up Link Tag
50K
Up Link Tag
P3(30K)
LL Size Tag RL There will be two link
lists: empty and allocated
Up Link Tag
Size: Size of the partition
Tag=0/1 (partition is empty/allocated) List should have option to
merge to empty partition
Left Link (LL): points to previous empty partition
Null
Right Link (RL): points to next empty partition
Up Link : points to its own LL
Fixed Memory Partitioning
Memory Partitioning
Head: Points the first partition
LL Size Tag
FHead
RL
10K OS
OS
Up Link Tag
AHead
LL Size Tag RL
P
if (P+size)->Tag=0
50K {
Up Link Tag
P=(P+size +(P+size)->size +
LL Size Tag RL P->Tag=0
P->UpLink=P->Uplink->LL
}
Up Link Tag
Size: Size of the partition
Tag=0/1 (partition is empty/allocated)
Left Link (LL): points to previous empty partition
Null
Right Link (RL): points to next empty partition
Up Link : points to its own LL
Fixed Memory Partitioning
Memory Partitioning
Head: Points the first partition
LL Size Tag
FHead
RL
10K OS
OS
Up Link Tag
AHead
LL Size Tag RL
P
if (P+size)->Tag=0
50K {
Up Link Tag
P=(P+size +(P+size+1)->siz
LL Size Tag RL P->Tag=0
P->UpLink=P->Uplink->LL
}
Up Link Tag
Size: Size of the partition
Tag=0/1 (partition is empty/allocated)
Left Link (LL): points to previous empty partition
Null
Right Link (RL): points to next empty partition
Up Link : points to its own LL
Fixed Memory Partitioning
Memory Partitioning
Head: Points the first partition
LL Size Tag
FHead
RL
10K OS
OS
Up Link Tag
AHead
LL Size Tag RL
P
if (P+size)->Tag=0
50K {
Up Link Tag
P=(P+size +(P+size+1)->siz
LL Size Tag RL P->Tag=0
P->UpLink=P->Uplink->LL
}
Up Link Tag
Size: Size of the partition
Tag=0/1 (partition is empty/allocated)
Left Link (LL): points to previous empty partition
Null
Right Link (RL): points to next empty partition
Up Link : points to its own LL
Fixed Memory Partitioning
Memory Partitioning
Head: Points the first partition
LL Size Tag
FHead
RL
10K OS
OS
Up Link Tag
AHead
LL Size Tag RL
P
if (P+size)->Tag=0
50K {
Up Link Tag
P=(P+size +(P+size+1)->siz
LL Size Tag RL P->Tag=0
P->UpLink=P->Uplink->LL
}
Up Link Tag
Size: Size of the partition
Tag=0/1 (partition is empty/allocated)
Left Link (LL): points to previous empty partition
Null
Right Link (RL): points to next empty partition
Up Link : points to its own LL
Fixed Memory Partitioning
Memory Partitioning
Head: Points the first partition
LL Size Tag
FHead
RL
10K OS
OS
Up Link Tag
AHead
LL Size Tag RL
P
if (P+size)->Tag=0
50K {
Up Link Tag
P=(P+size +(P+size+1)->siz
LL Size Tag RL P->Tag=0
P->UpLink=P->Uplink->LL
P->uplink->RL=
P->uplink->RL->
Up Link Tag
Size: Size of the partition
}
Tag=0/1 (partition is empty/allocated)
Left Link (LL): points to previous empty partition
Null
Right Link (RL): points to next empty partition
Up Link : points to its own LL
Fixed Memory Partitioning
Memory Partitioning
Head: Points the first partition
LL Size Tag
FHead
RL
10K OS
OS
if (P+size)->Tag=0
50K {
P=(P+size +(P+size+1)->siz
P->Tag=0
P->UpLink=P->Uplink->LL
P->uplink->RL=
P->uplink->RL->
Up Link Tag Ahead=NULL
Size: Size of the partition
}
Tag=0/1 (partition is empty/allocated)
Left Link (LL): points to previous empty partition AHead
Null
Right Link (RL): points to next empty partition
Up Link : points to its own LL
Fixed Memory Partitioning
Memory Partitioning
LL Size Tag RL
10K OS
OS
Up Link Tag
LL Size Tag RL
50K
Up Link Tag
P3(30K)
LL Size Tag RL There will be two link
lists: empty and allocated
Up Link Tag
Size: Size of the partition
Tag=0/1 (partition is empty/allocated) List should have option to
merge to empty partition
Left Link (LL): points to previous empty partition
Right Link (RL): points to next empty partition
Up Link : points to its own LL
Fixed Memory Partitioning
Memory Partitioning
LL Size Tag RL
10K OS
OS
Up Link Tag
LL Size Tag RL
50K
Up Link Tag
P3(30K)
LL Size Tag RL There will be two link
lists: empty and allocated
Up Link Tag
Size: Size of the partition
Tag=0/1 (partition is empty/allocated) List should have option to
merge to empty partition
Left Link (LL): points to previous empty partition
Right Link (RL): points to next empty partition
Up Link : points to its own LL
Paged Memory
Organization
Paging
Physical
Process Memory
4K
12K
Paging
Memory partitions are of equal size Physical
Process Memory
0 1K Block Page 0
1
1
2 1K Block Frame
2
3
3
4K Logical 4
5
6
7
8
9
10
11
12K Physical
OS is omitted in Fig.
Paging
Memory partitions are of equal size Physical
Process Memory
0
0 2 0
1
1 7 1
2
2 8 2
3
3 10 3
4K Logical 4
Page Mapping Table(PMT)
5
6
7
8
9
10
11
12K Physical
Paging
Memory partitions are of equal size Physical
Process Memory
0
0 2 0
1
1 7 1
2
2 8 2
3
3 10 3
4K Logical 4
5
6
CPU PNo Offset FNo Offset
7
Logical Addr Physical Addr
8
9
Your memory management
10
allows
at max 64 pages to a 11
process. The page size is 12K Physical
512Byte and Physical
memory is 2MB. What is the
size of physical and logical
address?
Multiple Process in Paging
Memory partitions are of equal size Physical
P0 Memory
0 0 2
0
1 1 7
1
2 2 8
2
3 3 10
3
4K Logical PMT1 4
P1
0 0 5
0
1 1 6
1
2 3 7
2
3 4 8
3
4 11 9
4
PMT2 10
5K Logical
11
No need for contagious allocation
12K Physical
Pros: No external fragmentation
Cons: Complex Mapping and internal
fragmentation
Code Sharing in Paging
Memory partitions are of equal size Physical
P0 Memory
0 0 5
0
1 1 6
1
2 2 9
2
3 3 10
3
4K Logical PMT1 4
P1
0 5 5
0
1 6 6
1
2 9 7
2
3 4 8
3
4 11 9
4
PMT2 10
5K Logical
11
P0 and P1 share Firefox i.e., open
two instances of Firefox
12K Physical
P0 Data
P1 Data
Firefox code should not be modified by P0 and P1
Code of Reentrant code
Segment Memory
Organization
Segmentation
Memory partitions are of equal size Physical
P0 Memory
0
Each module get a 0
Main
new memory 1
segment 2
Squire 1
Segment Table (ST) 3
printf 2
3 0 4
scanf
1 5
Structure programming
2 BA Lmt 6
3 7 Squire
Can we share code?
8 printf
9
CPU SNo Offset BA 10 scanf
Logical Addr 11
12K Physical
Y
SNo: Segment no
BA: Base address
< +
N Physical Addr
Lmt: Limit of the address Trap
Paged Segment Memory
Organization
Paged Segmentation
P0
Physical
Memory
0
0
Main
How offset and offset1 related? 1 Main
1 2
Squire
ST 3
printf 2
scanf 3 4
PT 5
Structure programming
BA Lmt 6
7 Squire
Lmt 8 printf
Y BA
< 9
N 10 scanf
Trap
+ 11
12K Physical
CPU SNo Offset PNo Offset1 FNo Offset1
70120304
7 7 7 2 2 2 2 4
0 0 0 0 3 3 3
1 1 1 1 0 0
Belady Anomally
Page Replacement Algo.
ocal vs. Global: In local same process's page is replaced where as in global other
rocesss page is replace
70120304
7 7 7 2 2 2 2 4
0 0 0 0 3 3 3
1 1 1 1 0 0
Belady Anomally
123412512345
1 1 1 4 4 4 5 3 3 3
2 2 2 1 1 1 1 4 5
3 3 3 2 2 2 2 5
1234567778910
Page Replacement Algo.
ocal vs. Global: In local same process's page is replaced where as in global other
rocesss page is replace