Download - Chapter 7 Physical Memory
![Page 1: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/1.jpg)
Chapter 7 Physical Memory
• Preparing a program for execution
• Memory partitioning schemes
• Allocation strategies for variable partitions
• Managing insufficient memory
![Page 2: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/2.jpg)
7.1 preparing a program for execution
• Program transformations compilation/assembly linking loading
Source module1
Object module1
Source module2
Object module2
Source module3
Object module3
. . .
Load module (in secondary
memory)
Load module (in main memory)
translation linking loading execution
![Page 3: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/3.jpg)
• Logical-to-physical address binding
notations: binding( relocation) static binding dynamic binding (dynamically) relocatable
Fun1(){ … fun2(); …}
Fun2(){ …}
… call m2,fun2 …
//fun2 …
… Call Ladd1 …Ladd1: //fun2 …
… Call Fadd1 …Fadd1: //fun2 …
![Page 4: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/4.jpg)
• Static binding programming-time binding compile-time binding link-time binding load-time binding
int i;
……
i= …;
……
f();
……
……
Store 20
……
Branch f
i20
0Function f
……
……
Store 120
……
Branch 0
i
100
0
120
Function f
……
……
Store 1120
……
Branch 1000
i
1100
1000
1120
![Page 5: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/5.jpg)
• Dynamic binding
the binding occurs at runtime, i.e., immediately preceding each memory reference. This delays the binding of the program to the machine until the latest possible moment.
Physical_address=address_map(logical_address)
Processor Main memory
Address_map
Logical
address
Physicaladdress
Data transfers(R/W)
![Page 6: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/6.jpg)
Processor Main memory
Relocation register
Logical
addressPhysicaladdress
Data transfers(R/W)
+
Physical_address=logical_address+ RR
int i;
……
i= …;
……
f();
……
……
Store 20
……
Branch f
i20
0Function f
……
……
Store 120
……
Branch 0
i
100
0
120
Function f
……
……
Store 120
……
Branch 0
i
1100
1000
1120
Address map
![Page 7: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/7.jpg)
7.2 Memory partitioning schemes
• Fixed partitions
properties: the sizes of partitions are determined statically the sizes of partitions cannot be changed at runtime partitions have different sizes to accommodate
the different programs
Schemes to schedule for the partitions: using a separate queue for each partition using a common queue
![Page 8: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/8.jpg)
processes
OS
queues
processes
OS
queues
![Page 9: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/9.jpg)
• Variable partitions
properties: the sizes of partitions are determined at
runtime the sizes of partitions equal the exact amount of
space requested memory consist of variable size blocks,
alternating between occupied blocks and free blocks
A B C D E
![Page 10: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/10.jpg)
memory management: requests to allocate free memory areas
AB C
A’B C
AB
B C’
AB C
C
AB C
C
B’ B’
![Page 11: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/11.jpg)
• Linked list implementation
freesize A
occupied
size B
occupied
size Cfreesize E
occupied
size D
![Page 12: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/12.jpg)
• Bitmap implementation
00011111 11100000 …
1-KB block is represented by one bit( A, B, C, D, E: 3KB, 2KB, 5KB, 1KB, 5KB)
Releasing block:
Allocating block:
Searching block:
B [i]=b [i] & ‘11011111’
B [i]=b [i] | ‘11000000’
B [0]=b [0] & ‘10000000’
B [0]=b [0] & ‘01000000’
……
![Page 13: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/13.jpg)
• The buddy system assumption:
fixed number of possible hole sizes, and each of which is a power of 2 buddies:
any hole of size 2i can be divided into two holes of size 2i-1, these two holes are called buddies implementation:
0 4 6 8 12 14
H
01234 .....
![Page 14: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/14.jpg)
allocation( a request for n unit)find the smallest hole size such that n <=2i;
if list I is not empty
remove a hole form the list&allocate;
else
find a larger hole list( not empty) than list I;
remove and divide into two holes(l&r) of half of size;
place r on the next-lower list;
if hole l is the smallest one for the request
allocate;
else
divide repeatedly;
![Page 15: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/15.jpg)
release( for the block of size 2i)If the buddy of the block is occupied
the new hole is added to the list i;
Else
remove the buddy from the list I;
coalesce the two holes into a hole of size 2i+1;
repeat until the largest possible hole is created;
![Page 16: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/16.jpg)
7.3 Allocation strategies for variable partitions
• First-Fit:finding the first hole large enough to accommodate the given request.
• Next_Fit( rotating-first-fit)starting each search at the point where the previous search stopped.
• Best_Fitselecting the hole with the closest fit.
• Worst_fitusing the largest currently available hole for any given request.
![Page 17: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/17.jpg)
• Measures of memory utilization
Equilibrium state:
Prob(release)==Prob(request)
Prob(n++)==Prob(n--)
AB C AB
AB C AB C
C
a b
c d
![Page 18: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/18.jpg)
m=a+b+c+d (7.1)
n= (7.2)
N=d+b (7.3)
Prob(n++)=Prob(release)*a/m (7.4)
Prob(n--)=Prob(release)*d/m+Prob(request)*(1-p) (7.5)
A=d+(1-p)m (7.6)
22 cbd
)1( pmd
ma
![Page 19: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/19.jpg)
m=d+(1-p)m+b+c+d
=(1-p)m+2b+2d
=(1-p)m+2n
Conclusion1:n=0.5pm
The fraction of memory occupied by holes:
f =?
![Page 20: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/20.jpg)
Assumption:
average hole size: h
average occupied block size: b
k=
M=nh+mb
=0.5kmb+mb
=mb(0.5k+1)
Conclusion2:
bh
2)15.0(5.0
kk
kmbkmh
Mnh
f
![Page 21: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/21.jpg)
7.4 Managing insufficient memory
• Memory compaction
~~ ~~
2
3
4
2
5
5
9 ~~ ~~
3
2
5
20
~~ ~~
3
2
11
5
9 ~~ ~~
3
2
11
5
9
p1
p2
p3
p1
p2
p3
p3
p1
p2
p2
p1
p3
![Page 22: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/22.jpg)
• Swapping
creating new space by selecting one of the resident processes and temporarily evicting it to secondary storage.
properties: can always evict as many resident
processes as is necessary; affects only one or a small number of
processes; requires accesses to secondary
memory.
![Page 23: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/23.jpg)
• Overlays
different portions of the program replace( overlay) each other in memory as execution proceeds.
A
B C
D E
0A
B C
A
D
A
C
E
![Page 24: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/24.jpg)
FAQs
• 3.1 m.A() x=11,y=9;m.A() x=12,y=10;m.B() x=11,y=10;m.B() x=10,y=10;m.B() x=10,y=10;m.B() x=10,y=10;m.A() x=10,y=8;m.A() x=10,y=8;
![Page 25: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/25.jpg)
• 3.3monitor stack{
char array[MAX];
UINT bottom=MAX-1,top=MAX-1;
condition c;
void push(char x){
if(bottom-top<MAX)
array[top--]=x;
if(bottom-top==1)
c.signal;
}
void pop(char &x){
if(bottom==top)
c.wait;
x=array[++top];
}
}
![Page 26: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/26.jpg)
• 4.8Pb(s){
do{
R=0;
SWAP(R,S);
while(!R);
}
Vb(s){
s=1;
}
![Page 27: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/27.jpg)
• 4.13f(x){
P(mutex);if(x){
condcnt_c1++;if(urgentcnt)
V(urgent);else
V(mutex);P(condsem_c1);condcnt_c1--;
}x++;////////////////if(condcnt_c2){
urgentcnt++;V(condsem_c2);P(urgent);urgentcnt--;
}////////////////x=0;if(urgentcnt)
V(urgent);else
V(mutex);
![Page 28: Chapter 7 Physical Memory](https://reader035.vdocuments.mx/reader035/viewer/2022062321/56813f4a550346895daa038e/html5/thumbnails/28.jpg)
• 4.19
500 20Hardware timers
Wall-clock countdown
Timer queue TQ p1 20 p2 125 p3 50 p4 15
520 70Hardware timers
Timer queue TQ p1 70 p2 55 p3 50 p4 15
590 55Hardware timers
Timer queue TQ p1 55 p2 15 p3 35 p4 15