Operating Systems: Memory Management Assoc. Prof. Dr. Latifah Munirah Kamarudin SEM 2 2017/2018
Operating Systems: Memory Management Assoc. Prof. Dr. Latifah Munirah Kamarudin SEM 2 2017/2018
MEMORY MANAGEMENT
ASSOC. PROF. DR. LATIFAH MUNIRAH
KAMARUDIN
SEM 2 2017/2018
MEMORY MANAGEMENT
Fixed Dynamic
Partitioning Partitioning
Simple Simple
Paging Segmentation
FIXED PARTITIONING
Allocation algorithm
Best-fit
algorithm: Allocate the smallest hole that fits
Worst-fit
algorithm: Allocate the largest hole
First-fit Allocate the first hole that fits from the
algorithm: beginning
Next-fit: Allocate the first hole that fits from the last
placement
DYNAMIC PARTITIONING
DYNAMIC PARTITIONING
• Eventually main memory holes too small to hold any process - external
fragmentation.
• Total memory space exist but not continuous
• Compaction reduce external fragmentation by shuffling memory contents to place
all free memory together in one large block
COMPACTION
EXERCISES
The shaded areas are allocated blocks; the white areas are free blocks. Using the
following placement algorithms, show the partition allocated for the processes of size
110K, 150K, 300K and 200K (loaded in that order):
• First-fit
• Best-fit
• Next-fit
EXERCISES
EXERCISES
A dynamic partitioning scheme is being used, and the following is the memory
configuration at a given point in time:
The shaded areas are allocated blocks. The next three memory request are for:
40M, 20M and 10M. Indicate the starting address of each of the three blocks using
the indicated place algorithm
1. First Fit
2. Best Fit
3. Next Fit
4. Worst Fit
EXERCISES
A dynamic partitioning scheme is being used, and the following is the memory
configuration at a given point in time:
BUDDY SYSTEM
• A reasonable compromise between fixed and dynamic partitioning
schemes.
• Entire space available is treated as a single block of 2U
• If a request of size s where 2U-1 < s <= 2U
• 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
EXAMPLE OF BUDDY SYSTEM
TREE REPRESENTATION OF BUDDY SYSTEM
BUDDY SYSTEM
• No External Fragmentation
• No need for compaction
• On average, internal fragmentation is 25%
• Each block is at least 50% occupied
SWAPPING
C C C C C
B B B B
A
A A A
D D D
OS OS OS OS OS OS OS
24
MEMORY MANAGEMENT
PAGING
PAGING
Paging is a memory management technique that:
• does not let the amount of physical memory limit the size of process.
• allows memory allocation to be non-contiguous and has no external
fragmentation problems, simplifying memory management and obviating
any need for compaction.
• lets us keep more processes in memory than the sum of their memory needs
so that we can keep the CPU utilization as high as possible.
• lets us us keep just the parts of a process that we're using in memory and
the rest on the disk. 26
MEMORY
PAGING 0x00 0x10
PROGRAM 0x01 0x11
PAGE
0:a 0x02 0x12
1:b 0x03 0x13
2:c 0x04 0x14
3:d 0x15
0x05
4:e FRAME 0x06 0x16
5:f 0x07 0x17
6:g 0x08 0x18
7:h 0x19
0x09
8:I 0x0a 0x1a
9:j 0x0b 0x1b
10 : k 0x0c 0x1c
11 : l 0x1d
0x0d
12 : m 0x0e 0x1e
13 : n 0x0f 0x1f
14 : o
15 : p Memory is divided into small equal
Program/Process is divided into small fixed-size chunks called frames
equal fixed-size chunks called pages * Blocks in physical address spaces
* Blocks in logical address spaces
MEMORY
PAGING PAGE TABLE 0x00 F0 0x10 F4
0x01 0x11
PAGE FRAME
0x02 0x12
PROGRAM 0 1 0x03 0x13
0:a P0 1 4 0x04 F1 0x14 F5
1:b 0x05 0x15
2:c 2 3 0x16
0x06
3:d 3 5 0x07 0x17
4:e P1 0x08 F2 0x18 F6
5:f 0x09 0x19
6:g 0x0a 0x1a
7:h 0x0b 0x1b
8:I P2 0x0c F3 0x1c F7
9:j 0x0d 0x1d
10 : k 0x0e 0x1e
11 : l 0x0f 0x1f
12 : m P3
13 : n
14 : o
15 : p
PAGING
PROGRAM
00 00 0:a P0
00 01 1:b How to calculate Logical address?
00 10 2:c
00 11 3:d Size of Page = 4 bytes
01 00 4:e P1 How many bits can represent 4 bytes? à
01 01 5:f
0110 6:g
Need 2 bits (22 = 4)
01 11 7:h
10 00 8:I P2 Number of Page = 4
10 01 9:j
10 10 10 : k How many bits can represent 4 page?
10 11 11 : l à Need 2 bits (22 = 4)
11 00 12 : m P3
11 01 13 : n
11 10 14 : o Total bits needed for logical address = 4 bits
11 11 15 : p
Page size = 256 bytes = 28 . Hence, 8 bits are required for the page offset. So 11-‐8 = 3 bits are
for the page number in the logical address =>number of pages=23 = 8
What are the physical addresses for the following logical addresses or indicate if a
segment fault occurs
What are the physical addresses for the following logical addresses or indicate if a
segment fault occurs