II PART OPERATING SISTEMS
LECTURE 10MEMORY 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 securityMultiprocessing 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 allbut 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 schedulerprogram is loaded and run from disc in MMwith instant space required by process
• when a process run is ended, all data needed are saved on disk andmemory 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 managementProcess 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-NSM=NS(1+k/2)f=% unused space in memoryf=(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 kEx: 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 => fast2. Next fit => first fit in rest list => little worse as first fit3. Best fit => most near dim in list => worsest4. 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 00 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 memorieModificari 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