Download presentation
1
Memory Management Techniques
Single Contiguous Overlays Fixed (static) partitions Relocation (Dynamic) Partitions Paging Demand Paging Segmented Segmented/ Demand Paging For each technique, observe: Algorithms, Advantages, Disadvantages and Special Requirements
2
1. Single Contiguous While (job is ready) Do
If (JobSize <= MemorySize) Then Begin Allocate Memory Load and Execute Job Deallocate Memory End Else Error Advantages: Simplicity Disadvantages CPU wasted, Main memory not fully used, Limited job size
3
II Overlays Programs can be sectioned into modules
Not all modules need to be in main memory at the same time A B E C D Programmer specifies which modules can overlay each other Linker inserts commands to invoke the loader when the modules are referenced The “parent” must stay in memory
4
Overlays(Cont) Advantages: Reduced memory usage Disadvantages:
Overlap map must be specified by programmer Programmer must know memory requirements Overlapped modules must be completely disjoint
5
Fixed Partition(1) Must ensure that a process does not access memory space dedicated to another process Base Register – Holds the address of the beginning of the partition Bounds Register – Hold the size of the job Each relative address is compared to the bounds register and if in range it is added to the base register to produce a physical address
6
Fixed Partition(2) Partition A A + Virtual Address A + L Bounds Reg L
7
Dynamic Partitions(1) Consider the following scenario (100K memory):
Job 1 arrives; size = 22 K Job 2 arrives; size = 24 K Job 3 arrives; size = 30 K Job 4 arrives; size = 10 K Job 1 terminates Job 3 terminates Job 5 terminates
8
Dynamic Partitions(2) Lets trace our what happens: 100
100 Where should job 5 be put? What are pros/cons of each placement?
9
Table Sort Illustration(1)
FREE – 22K a IN USE – 24K b FREE - 30K c IN USE – 10K d FREE 14K e
10
Table Sort Illustration(2)
First fit Start addr Length A C E Best fit Start addr Length E A C Worst fit Start addr Length C A E
11
Partition Selection Algorithm
Implementation requires a free block table Sorting table in a particular manner results in a specific selection algorithm First Fit Sort by location Best Fit Sort by size (ascending) [don’t break up big blocks) Worst Fit Sort by size (descending) [break up big blocks]
12
What if we cannot find a big enough hole for an arriving job?
Suppose a 35K job arrives? Suppose a 90K job arrives? 22K Free 24K 2 30K Free 4 10K 14K Free
13
Compaction Shuffle jobs to create larger contiguous free memory
Do the values of pointers need changing? Consider the arrival of a 40K job: Job A 15K Job A 15K Job B 20K Job B 20K Job C 7K Job C 7K
14
Dynamic Partitions Requires two OS operations: Allocation:
Form a partition from a free partition of ample size Deallocation: Return partition to free table and merge where possible
15
Pros/Cons of Dynamic Partitions
Advantages: Efficient memory usage Disadvantages: Partition Management Compaction or external fragmentation
16
Demand Page Management
Page Map Table (PMT) Maps page to block Status: Main Memory Secondary Memory In Transit 2) Memory Block Table (MBT) Maps block to page Reference Bit Change Bit 3) File Map Table (FMT) Maps a job’s pages to secondary memory PMT for the disk 1 FMT/ job 1 entry / page
17
Demand Paging Schematic(1)
What does 3 mean? PMTAR OS 3 1 PMT 2 M M 3 1 2 S 4 5 M = In Memory S = On secondary storage I = In transit 6 7
18
Demand Paging Schematic(2)
FMT Disk 1 2
19
Demand Paging Schematic(3)
OS Referenced 1 2 J1 P0 R C 3 4 J1 P1 R C 5 6 7 Changed
20
Sharing Pages of Reentrant Code or Data Between Processes
Q. What problem is caused if a shared page frame corresponds to two different page #s? (Hint: consider page replacement) A. Alias or synonym problem
21
Address Translation Steps: Look up p in TLB
if not found look up p in PMT (must be found) Replace p by p’ to form PA
22
Page Replacement Local VS Global Page Replacement
Local Requires that each process removes a page from its own set of allocated blocks Global A replacement page may be selected from the set of all blocks
23
Locality At any given time, the locality of a process is the set of pages that are actively being used together Spacial There is a high probability that once a location is referenced, the one after it will be accessed in the near future EX: Sequential code, array processing Temporal A referenced location is likely to be accessed again in the near future EX: Loops. Single data elements
24
Working Set Theory W (t,) = The set of pages referenced between times t and t+ The number of elements in W is called the working Set Size Working set size is an estimation of locality size A job should not be scheduled unless there is room for its entire working set
25
Page Replacement Algorithms
Optimal Replacement Replace the page which will not be used for the longest period of time Lowest page fault rate of all algorithms Requires future knowledge 2) FIFO Replace the “oldest” page A frequently used page may be swapped out Belady’s Anomaly: For some page replacement algorithms, the page fault rate may increase as the number of blocks increase
26
Page Trace: 1 2 1 2 3
27
Replacement Algorithms Continued
3) Least Recently Used (LRU) Uses the recent past as an approximation of the near future Statck algorithm Does NOT suffer from Belady’s Anomaly Hardware/ Overhead intensive 4) LRU Approximation Uses reference bits in the MBT and a static reference pointer(RP) The reference pointer is not reinitialized between calls to LRU Approximation
28
LRU Approximation Algorithm
Initially: RP 0; Begin Done := FALSE; While (NOT Done) Do If (MBT[RP].ref = 1) Then MBT [RP].ref := 0 Else Begin Return(RP); Done :== TRUE; End; RP:=RP+1;
29
LRU Approximation Example
Page Trace: NOTE: Slightly different from previous example Page Reference Bit 1 2 RP = 0 Page Fault Rate =
30
Page Replacement Local VS Global page replacement Local
Requires that each process remove a page from its own set of allocated blocks Global A replacement page may be selected from the set of all blocks
31
VIII Segmentation An alternative to paging
Recall variable Size partitioning: Program allocation contiguous Use first fit, etc Segmentation: Put subroutines, arrays, etc. into separate segments Each segment must occupy contiguous locations, but segments may be scattered throughout memory Segmentation = Paging with variable size pages Why do this? What problems arise?
32
VIII Segmentation Divide each process into logical segments (procedures, arrays, etc) Logical breakdown gives an intuitive structure to main memory Managing segments: Segment Map Table ( SMT ) Length Address 1 SMT/job 1 entry/segment
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.