II’nd PART OPERATING SISTEMS
description
Transcript of II’nd PART OPERATING SISTEMS
II’nd PART OPERATING SISTEMS
LECTURE 10
MEMORY MANAGEMENT
Ştefan Stăncescu
1
MEMORY MANEGEMENT
2
Main Memory – cf. von Neumann arh. (nonremanent – fast ) :
• Cell row where info are deposed, modified, kept
• Code & data space where programs act as processes
Memory management :• Free/allocated memory space management
• Allocate/free memory spaces to processes in run
• Swap => MP – disk transfer
• Transfers between hierarchical levels of memories
• Virtual memory management – page fault mechanisms
MEMORY MANEGEMENT
3
No MM
MSDOS – Only one user program in memory – cooperativ SO – one program after each, in batch processing
Al resources available – no security
Multiprocessing only with collaborative threads in time sharing UC -
- embedded systems
User programs
OS
OS
User programs
DD(I/O)User
programs
OS
MEMORY MANEGEMENT
4
Fixed memory partitions managementTime shared UC for separate processes –allocation at boot
• Each process runs only in previously fixed space
• In each memory fixed partition
• Batch processing management in each partition
• Process queue management at each fixed partition
• Process memory space allocation at fixed partition accordingly with partition resources (space)
Empty partitions with satisfied queues and a lot of partitions with processes in wait for memory space
=> only one queue for all
but inappropriate space allocation
Partitia 1
Partitia 2
Partitia 3
Partitia 4
Partitia 5
MEMORY MANEGEMENT
5
Swap memory – variable “partitions”Disk (external memory) resident programs
• when a process run is needed by process scheduler
program is loaded and run from disc in MM
with instant space required by process
• when a process run is ended,
all data needed are saved on disk and
memory space in MM is released
• Disc main memory = swapSpace allocation/released accountedFree space compaction and management
Partitia 1
Partitia 2
Partitia 3
Partitia 4
Partitia n
MEMORY MANEGEMENT
Variable memory partitions – swap
=> Free space management
Process memory space allocation optimized
PROCES B
PROCES A
PROCES C
PROCES B
PROCES A
PROCES D
3
PROCES B
PROCES A
PROCES D
Prtitia 3PROCES E
PROCES A
PROCES F
PROCES D
PROCES E
PROCES A
MEMORY MANEGEMENT
7
Rule 50%
N processes N/2 holes1 process => up 50% probability hole/process
down 50% probability hole/process Total 2 processes for 1 hole
MEMORY MANEGEMENT
8
Unused memory rule(N/2) * kS = M-NS
M=NS(1+k/2)
f=% unused space in memory
f=(N/2) * (kS /M) // no. holes * hole dim/ all memory dim.
f=NkS/2M=NkS/2(NS*(1+k/2)) // with M calculated before f=k/(2+k) // f is dependent only of k
Ex: k=1/2 => f=(1/2)/(2+1/2)=1/5=20%
k=1/4 => f=11%
S = medium process dimkS = medium hole dimM = all memory dimN = no. processesn/2= no. holes (50% rule)
MEMORY MANEGEMENT
9
Process allocation in holes with holes list1. First fit => first hole in list sufficient for process => fast
2. Next fit => first fit in rest list => little worse as first fit
3. Best fit => most near dim in list => worsest
4. Worst fit => anti best fit, small process in greater hole
All alg are slow, by hole list analysis time improvements => sorting, separate lists, etc.
5. Quick fit => separate hole lists of fixed dims
=> Problem=> merging little holes – working with big holes
MEMORY MANEGEMENT
10
Modele in gestiunea de spatii de memorie
Harta de biti -Bitmap1 1 1 1 1 0 0 0
0 1 1 1 1 1 1 1
1 1 0 0 1 1 1 1
1 1 1 1 1 0 0 0
1 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0
5 4 9 2 9 3 3
MEMORY MANEGEMENT
11
Modele in gestiunea de spatii de memorie
Liste inlantuite:
5 4 9 2 9 3 3
1 5 0 4 1 9
0 2
0 1001 3
0 31 9
MEMORY MANEGEMENT
12
Modele in gestiunea de spatii de memorie
Modificari la liste inlantuite
A X B A B
X B
A
B
A X
X
MEMORY MANEGEMENT
13
Modele in gestiunea de spatii de memorie Buddy sistem32k 64k 128 256 512
A A 128 256 512
A A B 128 256 512
A A B C C 256 512
B C C 256 512
B D C C 256 512
D C C 256 512
C C 256 512
256 512
MEMORY MANEGEMENT
14
Page Replacement Algorithms at Page FaultsOptimal Page Replacement Algorithm
Not Recently Used – NRU
First In First Out – FIFOSecond chance
ClockLeast Recently Used - LRUNot Frequently Used - NFU
Not Frequently Used – NFU w/AgingWorking set - WS
WS w/Clock
MEMORY MANEGEMENT
15
Page Replacement Algorithms at Page FaultsOptimal Page Replacement Algorithm
Ideal one, not realizable
Optimality:
First the program runs with fixed data
Note the page demanding list
Decide best replacements by keeping minimum PF
(the most delayed use page will be replaced)
At each PF => calculate the most delayed use page
replace that one with the demanded page
MEMORY MANEGEMENT
16
Some HW adjacent each physical page
w info needs in decision about page replacement.
Reference-Modify HW cell memories:
R M
0 0 No referred page, w/o read/write - modify
1 0 Recent read page, w/o write-modify
0 1 Old read page, w/old write-modify
1 1 Recent read page, w/old or recent write-modify
R erased at clock IT (“forget” old unnecessary reads)
MEMORY MANEGEMENT
17
NRU (not recently used)
w/RM help in page ranking
R M
0 0 Class 3 Max priority
1 0 Class 2
0 1 Class 1
1 1 Class 0 min priority
NRU => At PF eject at random any page
from the less priority nonempty class
Simple, no optimal, reasonably efficient, no big mistakes
MEMORY MANEGEMENT
18
FIFO (First In First Out)
FIFO queue w/ index requested pagesAlg:Fill the queue and reuse any pages in queue is requestedAfter queue full – PF
eject page in front (earliest in)
Simple, efficient, butmay eject page in current use,
should be kept for next intensive work,although the page has spent much time in
memory
MEMORY MANEGEMENT
19
FIFO Second Chance
FIFO queue w/ index requested pages and RMAlg.: AT PF
if (R=0) then
replace //old page, unreffered
else
R=0 //pretend to not be read, although R=1
move from front to end of FIFO queue
//consider as a new loaded page
go to next position
(if same page found, replace, without remorse)
MEMORY MANEGEMENT
20
FIFO Clock
Hand points to the oldest page
On a page fault, follow the hand to inspect pages
Apply clock second chance:
if (R=1),
R=0 and advance the hand
if (R=0)
replace page
(only if all pages are R=1, second chance get first page)
Long round
MEMORY MANEGEMENT
21
Least Recently Used LRU
NR couter/register attached to each page to count accesses
Alg:
at each clock IT
all NR are increments with R (0/1)
//each NR keeps reference page rank
at PF, page with smallest rank is ejected
=> old heavy runs are kept also! – wrong!
Idea: aging = replace bold text w/
shift all NR 1 bit right
add R(0/1) at left (msb position bit in NR)
GESTIUNE DE MEMORIE
22
Least Recently Used LRU
0 1 2 3 2
1 0 3 23
0 1 1 1
0 0 0 0
0 0 0 0
0 0 0 0
0 0 1 1
1 0 1 1
0 0 0 0
0 0 0 0
0 0 0 1
1 0 0 1
1 1 0 1
0 0 0 0
0 0 0 0
1 0 0 0
1 1 0 0
1 1 1 0
0 0 0 0
1 0 0 0
1 1 0 1
1 1 0 0
0 0 0 0
1 0 1 1
1 0 0 1
1 0 0 0
0 1 1 1
0 0 1 1
0 0 0 1
0 0 0 0
0 1 1 0
0 0 1 0
0 0 0 0
1 1 1 0
0 1 0 0
0 0 0 0
1 1 0 1
1 1 0 0
0 1 0 0
0 0 0 0
1 1 0 0
1 1 1 0
MEMORY MANEGEMENT
23
Not Frequently Used - NFU
NR couter/register attached to each page
And a overall process time counter
Alg:
At each reference overall increment time counter
and transfer content to referred page NR
// NR keeps page data access time stamp
at PF
eject the page with oldest data stamp (lowest content)
GESTIUNE DE MEMORIE
24
Not Frequently Used - NFU
0 1 2
3 4 5
Pagina
CK
0 1 2 3 4 5
0 1 0 1 0 1 1
1 1 1 0 0 1 0
2 1 1 0 1 0 1
3 1 0 0 0 1 0
4 0 1 1 0 0 0
1 0 0 0 0 0 0
1 1 0 0 0 0 0
1 1 1 0 0 0 0
1 1 1 1 0 0 0
0 1 1 1 1 0 0
0 0 0 0 0 0 0
1 0 0 0 0 0 0
1 1 0 0 0 0 0
0 1 1 0 0 0 0
1 0 1 1 0 0 0
1 0 0 0 0 0 0
0 1 0 0 0 0 0
0 0 1 0 0 0 0
0 0 0 1 0 0 0
1 0 0 0 1 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
1 0 0 0 0 0 0
0 1 0 0 0 0 0
0 0 1 0 0 0 0
1 0 0 0 0 0 0
1 1 0 0 0 0 0
0 1 1 0 0 0 0
1 0 1 1 0 0 0
0 1 0 1 1 0 0
1 0 0 0 0 0 0
0 1 0 0 0 0 0
1 0 1 0 0 0 0
0 1 0 1 0 0 0
0 0 1 0 1 0 0
GESTIUNE DE MEMORIE
25
Least Recently Used - LRU /Not Frequently Used – NFU
LRU update at each access (instruction)
NFU update at each IT (many instructions)
a page may count a lot of references between IT’s
same rank for a few or a lot of references
pages w/first references between IT are at
same rank as pages w/last references in interval