Download presentation
Presentation is loading. Please wait.
Published byHubert Conley Modified over 8 years ago
1
Chapter 7 Physical Memory Preparing a program for execution Memory partitioning schemes Allocation strategies for variable partitions Managing insufficient memory
2
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) translationlinkingloadingexecution
3
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 …
4
Static binding programming-time binding compile-time binding link-time binding load-time binding int i; …… i= …; …… f(); …… Store 20 …… Branch f i 20 0 Function f …… Store 120 …… Branch 0 i 100 0 120 Function f …… Store 1120 …… Branch 1000 i 1100 1000 1120
5
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 Physical address Data transfers(R/W)
6
Processor Main memory Relocation register Logical address Physical address Data transfers(R/W) + Physical_address=logical_address+ RR int i; …… i= …; …… f(); …… Store 20 …… Branch f i 20 0 Function f …… Store 120 …… Branch 0 i 100 0 120 Function f …… Store 120 …… Branch 0 i 1100 1000 1120 Address map
7
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
8
processes OS queues processes OS queues
9
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 BCD E
10
memory management: requests to allocate free memory areas A BC A’ BC A B BC’ A BC C A BC C B’
11
Linked list implementation free size A occupied size B occupied size C free size E occupied size D
12
Bitmap implementation 0001111111100000 … 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’ ……
13
The buddy system assumption: fixed number of possible hole sizes, and each of which is a power of 2 buddies: any hole of size 2 i can be divided into two holes of size 2 i-1, these two holes are called buddies implementation: 04681214 H 0 1 2 3 4.....
14
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;
15
release( for the block of size 2 i ) 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 2 i+1 ; repeat until the largest possible hole is created;
16
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_Fit selecting the hole with the closest fit. Worst_fit using the largest currently available hole for any given request.
17
Measures of memory utilization Equilibrium state: Prob(release)==Prob(request) Prob(n++)==Prob(n--) A BC A B A BC A BC C ab c d
18
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)
19
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 =?
20
Assumption: average hole size: h average occupied block size: b k= M=nh+mb =0.5kmb+mb =mb(0.5k+1) Conclusion2:
21
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 5 9 p1p1 p2p2 p3p3 p1p1 p2p2 p3p3 p3p3 p1p1 p2p2 p2p2 p1p1 p3p3
22
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.
23
Overlays different portions of the program replace( overlay) each other in memory as execution proceeds. A BC DE 0 A B C A D A C E
24
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.A()x=10,y=8;
25
3.3 monitor 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]; }
26
4.8 Pb(s){ do{ R=0; SWAP(R,S); while(!R); } Vb(s){ s=1; }
27
4.13 f(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);
28
4.19 50020 Hardwar e timers Wall-clockcountdown Timer queue TQ p1p1 20p2p2 125p3p3 50p4p4 15 52070 Hardwar e timers Timer queue TQ p1p1 70p2p2 55p3p3 50p4p4 15 59055 Hardwar e timers Timer queue TQ p1p1 55p2p2 15p3p3 35p4p4 15
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.