Presentation is loading. Please wait.

Presentation is loading. Please wait.

OS/SSS S:1 Memory Management. OS/SSS S:2 Background A compiler creates an executable code An executable code must be brought into main memory to run Operating.

Similar presentations


Presentation on theme: "OS/SSS S:1 Memory Management. OS/SSS S:2 Background A compiler creates an executable code An executable code must be brought into main memory to run Operating."— Presentation transcript:

1 OS/SSS S:1 Memory Management

2 OS/SSS S:2 Background A compiler creates an executable code An executable code must be brought into main memory to run Operating system maps the executable code onto the main memory Hardware accesses the memory locations in the course of the execution

3 OS/SSS S:3 Background Applications must request memory through OS calls (or user libs calling certain SVC like page(x)) p=malloc(x) then releases them :free(p)

4 OS/SSS S:4 Memory management Fetching: When ? –On Demand –Anticipatory Pre-Allocation: Before request Post-Allocation: Just When reading/writing Placement: From where? How?

5 OS/SSS S:5 0000: 0010: 01 77 77 00 10 … ; PCB 0 0020: 01 88 88 00 20 … ; PCB 1 Processes in RAM Fixed Partition Multiprogramming ;x=[1040] 1000:a1 40 10;mov AX, x 1003:40;inc AX 1004:a3 40 10;mov x, AX 1040: 00 00;add [BX+SI],AL? ;y=[2040] 2000:b8 0800;mov AX, 8 2003:a3 40 02;mov y,AX 2040: 00 00;add [BX+SI],AL? PCB 0 St: 1 ;ready AX: 7777 PC: 1000 PCB 1 St: 1 ;ready AX: 8888 PC: 2000

6 OS/SSS S:6 0000: 0010: 01 77 77 00 10 … ; PCB 0 0020: 01 88 88 00 20 … ; PCB 1 Processes in RAM Fixed Partition Multiprogramming ;x=[1040] 1000:a1 40 10;mov AX, x 1003:40;inc AX 1004:a3 40 10;mov x, AX 1040: 00 00;add [BX+SI],AL? ;y=[2040] 2000:b8 0800;mov AX, 8 2003:a3 40 02;mov y,AX 2040: 00 00;add [BX+SI],AL? PCB 0 St: 1 ;ready AX: 7777 PC: 1000 PCB 1 St: 1 ;ready AX: 8888 PC: 2000 Fixed Partitions AND Absolute translation and loading Bad – what a waste Fixed Partitions AND Absolute translation and loading Bad – what a waste

7 OS/SSS S:7 Fixed Partitions Absolute translation and loading Limits # processes Memory Misuse Internal/External Fragments Site Dependent Compilation/Linking Limited possibility of run time dynamic allocation Partition 0 Proc 7 Partition0 Proc 7 Partition 1 Free

8 OS/SSS S:8 Memory Management Requirements Protection: Processes and OS from malicious references –Processes must be unable to reference addresses of other processes or those of the operating system –Each memory access must be checked for validity/Enforced by hardware

9 OS/SSS S:9 0000: 0010: 01 77 77 00 10 … ; PCB 0 0020: 01 88 88 00 20 … ; PCB 1 Processes in RAM Fixed Partition Multiprogramming ;x=[1040] 1000:a1 40 10;mov AX, x 1003:40;inc AX 1004:a3 40 10;mov x, AX 1040: 00 00;add [BX+SI],AL? ;y=[2040] 2000:b8 0800;mov AX, 8 2003:a3 40 02;mov y,AX 2040: 00 00;add [BX+SI],AL? PCB 0 St: 1 ;ready AX: 7777 PC: 1000 LB: 0990 UP: 1100 PCB 1 St: 1 ;ready AX: 8888 PC: 2000 LB: 2000 UP: 3000 An Exception will be triggered if any address outside [990- 1100] is referenced for read or write

10 OS/SSS S:10 Memory Management Requirements Protection Relocation: To relax that unacceptable absolute binding ! –Compiler generated addresses are relative –A process can be loaded at different memory location, swapped in/out, Actual physical mapping is not known at compile time

11 OS/SSS S:11 0000: 0010: 01 77 77 00 10 … ; PCB 0 0020: 01 88 88 00 20 … ; PCB 1 Processes in RAM Dynamic Partition Multiprogramming ;x=[1040] 1000:a1 40 10;mov AX, x 1003:40;inc AX 1004:a3 40 10;mov x, AX 1040: 00 00;add [BX+SI],AL? ;y=[2040] 2000:b8 0800;mov AX, 8 2003:a3 40 02;mov y,AX 2040: 00 00;add [BX+SI],AL? PCB 0 St: 1 ;ready AX: 7777 PC: 1000 LB: 0990 UP: 1100 PCB 1 St: 1 ;ready AX: 8888 PC: 2000 LB: 2000 UP: 3000 How Hiding from Proc 0 the later fact that it will load at 990 And P1 at 2000 How Hiding from Proc 0 the later fact that it will load at 990 And P1 at 2000

12 OS/SSS S:12 0000: 0010: 01 77 77 00 10 … ; PCB 0 0020: 01 88 88 00 20 … ; PCB 1 Processes in RAM Dynamic Partition Multiprogramming ;x=[0040] 1000:a1 40 00;mov AX, x 1003:40;inc AX 1004:a3 40 00;mov x, AX 1040: 00 00;add [BX+SI],AL? ;y=[0040] 2000:b8 0800;mov AX, 8 2003:a3 40 00;mov y,AX 2040: 00 00;add [BX+SI],AL? PCB 0 St: 1 ;ready AX: 7777 PC: 1000 LB: 0990 UP: 1100 RR: 1000 PCB 1 St: 1 ;ready AX: 8888 PC: 2000 LB: 2000 UP: 3000 RR: 2000

13 OS/SSS S:13 0000: 0010: 01 77 77 00 10 … ; PCB 0 0020: 01 88 88 00 20 … ; PCB 1 Processes in RAM Dynamic Partition Multiprogramming ;x=[0040] 1000:a1 40 00;mov AX, x 1003:40;inc AX 1004:a3 40 00;mov x, AX 1040: 00 00;add [BX+SI],AL? ;y=[0040] 2000:b8 0800;mov AX, 8 2003:a3 40 00;mov y,AX 2040: 00 00;add [BX+SI],AL? PCB 0 St: 1 ;ready AX: 7777 PC: 1000 LB: 0990 UP: 1100 RR: 1000 PCB 1 St: 1 ;ready AX: 8888 PC: 2000 LB: 2000 UP: 3000 RR: 2000 40 +

14 OS/SSS S:14 0000: 0010: 01 77 77 00 10 … ; PCB 0 0020: 01 88 88 00 20 … ; PCB 1 Processes in RAM Dynamic Partition Multiprogramming ;x=[0040] 1000:a1 40 00;mov AX, x 1003:40;inc AX 1004:a3 40 00;mov x, AX 1040: 00 00;add [BX+SI],AL? ;y=[0040] 2000:b8 0800;mov AX, 8 2003:a3 40 00;mov y,AX 2040: 00 00;add [BX+SI],AL? PCB 0 St: 1 ;ready AX: 7777 PC: 1000 LB: 0990 UP: 1100 RR: 1000 PCB 1 St: 1 ;ready AX: 8888 PC: 2000 LB: 2000 UP: 3000 RR: 2000 40 + User (Process) address space is disassociated from physical space But contiguity is still preserved User (Process) address space is disassociated from physical space But contiguity is still preserved

15 OS/SSS S:15 0000: 0010: 01 77 77 00 10 … ; PCB 0 0020: 01 88 88 00 20 … ; PCB 1 Processes in RAM Dynamic Partition Multiprogramming ;x=[0040] 1000:a1 40 00;mov AX, x 1003:40;inc AX 1004:a3 40 00;mov x, AX 1040: 00 00;add [BX+SI],AL? ;y=[0040] 2000:b8 0800;mov AX, 8 2003:a3 40 00;mov y,AX 2040: 00 00;add [BX+SI],AL? PCB 0 St: 1 ;ready AX: 7777 PC: 1000 LB: 0990 UP: 1100 RR: 1000 PCB 1 St: 1 ;ready AX: 8888 PC: 2000 LB: 2000 UP: 3000 RR: 2000 40 + User (Process) address space is disassociated from physical space But contiguity is still preserved Each process has its own address space [0…something] However Separate Ranges {[m..n],[k..l] needs complex management ! User (Process) address space is disassociated from physical space But contiguity is still preserved Each process has its own address space [0…something] However Separate Ranges {[m..n],[k..l] needs complex management !

16 OS/SSS S:16 The Placement problem Where to allocate: –Fixed Partitions –Dynamic placement algorithms First Fit Best Fit Worst Fit –Buddy Systems

17 OS/SSS S:17 Dynamic partitioning example 224null672 320….128 PCB0 224null448 PCB1 128null896 Free P0 Requests 320 units [h0] P1 Requests 224 units [h1] P0 Requests 224 units [h2] OS 128 P 0 320 128 P 1 224 P 0 224 0 128 448 672 896 1 K

18 OS/SSS S:18 Dynamic partitioning example 224null672 320….128 PCB0224null448 128...896 Free P0 Requests 320 units [h0] P1 Requests 224 units [h1] P0 Requests 224 units [h2] P1 exits [releases h1] OS 128 P 0 320 128 224 P 0 224 0 128 448 672 896 1 K

19 OS/SSS S:19 Dynamic partitioning example 224null672 320….128 PCB0224null448 128...896 Free P0 Requests 320 units [h0] P1 Requests 224 units [h1] P0 Requests 224 units [h2] P1 exits [releases h1] Now P2 Requests 120 ? WF ! OS 128 P 0 320 128 224 P 0 224 0 128 448 672 896 1 K From Here? First Fit Best Fit Or Worst fit

20 OS/SSS S:20 Dynamic partitioning example 224null672 320….128 PCB0104null568 128...896 Free P0 Requests 320 units [h0] P1 Requests 224 units [h1] P0 Requests 288 units [h2] P1 exits [releases h1] P2 request 120 [h3] WF 120null448 PCB2 OS 128 P 0 320 128 104 P 0 224 0 128 448 672 896 1 K P 2 120 568

21 OS/SSS S:21 Dynamic partitioning example 224null672PCB0 P0 Requests 320 units [h0] P1 Requests 224 units [h1] P0 Requests 288 units [h2] P1 exits [releases h1] P2 request 128 [h3] WF P0 releases h0 104…568 128...896 Free 120null448 PCB2320null128 OS 128 320 128 104 P 0 224 0 128 448 672 896 1 K P 2 120 568

22 OS/SSS S:22 Dynamic partitioning example 224null672PCB0 P0 Requests 320 units [h0] P1 Requests 224 units [h1] P0 Requests 288 units [h2] P1 exits [releases h1] P2 request 128 [h3] WF P0 releases h0 P2 Requests 100 ! 104…568 128...896 Free 120null448 PCB2320null128 OS 128 320 128 104 P 0 224 0 128 448 672 896 1 K P 2 120 568 First Fit Best Fit Worst Fit

23 OS/SSS S:23 Dynamic partitioning example 224null672PCB0 P0 Requests 320 units [h0] P1 Requests 224 units [h1] P0 Requests 288 units [h2] P1 exits [releases h1] P2 request 128 [h3] WF P0 releases h0 P2 Requests 100 ! 104…568 128...896 Free 120null448 PCB2320null128 OS 128 320 128 104 P 0 224 0 128 448 672 896 1 K P 2 120 568 First Fit Best Fit Worst Fit

24 OS/SSS S:24 Dynamic partitioning example 224null672PCB0 P0 Requests 320 units [h0] P1 Requests 224 units [h1] P0 Requests 288 units [h2] P1 exits [releases h1] P2 request 128 [h3] WF P0 releases h0 P2 Requests 100 ! FF 4…668 128...896 Free 120…448 PCB2320null128 OS 128 320 128 P 2 100 P 0 224 0 128 448 672 896 1 K P 2 120 568 Who wants that 100null568

25 OS/SSS S:25 Dynamic partitioning example 224null672PCB0 P0 Requests 320 units [h0] P1 Requests 224 units [h1] P0 Requests 288 units [h2] P1 exits [releases h1] P2 request 128 [h3] WF P0 releases h0 P2 Requests 100 ! FF 320null128...896 Free 120…448 PCB2 OS 128 320 128 P 2 104 P 0 224 0 128 448 672 896 1 K P 2 120 568 104null568 Internal Fragment Why ?

26 OS/SSS S:26 104 Dynamic partitioning example 224null672 PCB0 OS 128 320 128 P 0 224 0 128 448 672 896 1 K 120 568 320…128...896 Free104null568120…448 4…668 128...896 Free 120…448 320…128 100null568 Needs Coalescing Case of internal fragments Case of exact placement P2 exits Someone wants 541 unit

27 OS/SSS S:27 Dynamic partitioning example 224null672 PCB0 OS 128 554 128 P 0 224 0 128 672 896 1 K 128...896 Free554null128 Someone wants 541 unit – ok But Someone Requests 600 ! External Fragments and Garbage collection Needs Garbage Collection External Fragments

28 OS/SSS S:28 Dynamic partitioning example OS 128 0 128 512 1 K OS 128 0 128 512 1 K Going BF Going WF Worst- Fit Best- Fit 1011 2012 4033 6063 8082 10041 12022 14012 16016 Free2090

29 OS/SSS S:29 Dynamic partitioning example OS 128 0 128 512 1 K OS 128 0 128 512 1 K Going BF Going WF

30 OS/SSS S:30 Dynamic partitioning example OS 128 0 128 512 1 K OS 128 0 128 512 1 K Going BF Going WF Random FF Preserves large blocks for futurePreserves large blocks for future External fragmentsExternal fragments More Normally distributedMore Normally distributed More predictableMore predictable

31 OS/SSS S:31 Buddy System Entire space available is treated as a single block of 2 UEntire space available is treated as a single block of 2 U If a request of size s such that 2 U-1 < s <= 2 U, entire block is allocatedIf a request of size s such that 2 U-1 < s <= 2 U, entire block is allocated  Otherwise block is split into two equal buddies  Process continues until smallest block greater than or equal to s is generated

32 OS/SSS S:32 Buddy System

33 OS/SSS S:33 Buddy System 100/12860/6464256 256/256 256

34 OS/SSS S:34 Buddy System Internal Fragments !Internal Fragments ! Overcomes limited processes [Fixed partitioning] and overhead imposed by Dynamic allocation.Overcomes limited processes [Fixed partitioning] and overhead imposed by Dynamic allocation. Useful in special memory managers such as kernel memory allocation, parallel systems, …etc.Useful in special memory managers such as kernel memory allocation, parallel systems, …etc.

35 OS/SSS S:35 Memory Management Requirements Protection Relocation External Fragments management Sharing Post Allocation ? Why? Managing Requests greater then physically available

36 OS/SSS S:36 Memory Management Requirements Protection Relocation External Fragments management Sharing Post Allocation ? Why? Managing Requests greater then physically available

37 OS/SSS S:37 Thanks && comments


Download ppt "OS/SSS S:1 Memory Management. OS/SSS S:2 Background A compiler creates an executable code An executable code must be brought into main memory to run Operating."

Similar presentations


Ads by Google