Download presentation
Presentation is loading. Please wait.
1
Day 19 Memory Management
2
Assumptions A process need not be stored as one contiguous block.
The entire process must reside in main memory.
3
Paging Split the process into small fixed size pages.
Split main memory into fixed size frames. Frame size = page size Now, if a process is 4 pages long, find 4 free frames to hold the 4 pages. If 4 contiguous blocks are not found, that’s okay. Simply find 4 available blocks. No external fragmentation. No internal fragmentation (only last block) Use a page table to keep track of the frames that are allocated to the process.
5
Page table Every process in memory has a page table.
A page table has as many entries as the process has pages. Indexed by the page number. Page table entry at a minimum holds the frame number.
6
Page number Frame number
7
Address translation in paging
Logical address Address specified in the program (starting at 0) Physical address Actual address in main memory
8
Example If an instruction has a logical address of 20 and if the program is placed in a page in memory which starts at address 1024, then the physical address of the instruction will be 1044. If page size = frame size = 256 bytes Instruction is in page 0 which is placed in frame 4 Physical address = 4 x = 1044.
9
Address translation in paging
To make it convenient, the size of a page is the power of 2. Given a (page #, offset), find (frame #, offset) 2k > number of frames => k bits to hold the frame number 2n > number of pages => n bits to hold the page number 2m = number of bytes in a page => m bits to determine the offset within a page A logical address is n||m A physical address is simply k||m where k is the frame corresponding to page “n” (obtained from the page table).
10
Address calculation using a page table
11
Main memory Process Page table Page # Logical Address Value A 1 B 2 C
Frame # Physical address Value E 1 F 2 G 3 H 4 7 8 A 9 B 10 C 11 D 12 15 16 M 17 N 18 O 19 P 5 20 I 21 J 22 K 23 L Page # Logical Address Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P Page # Frame # 2 1 5 3 4 Page table Logical address 6 = 0110 Page size = 4 => 2 bits for offset (i.e. 4 addresses per page) Number of pages = 4 => 2 bits for page number Frame size = page size = 4 => 2 bits ofr offset # of frames = 6 => 3 bits for frame number 01 10 a. Replace 01 i.e. page number by frame number i.e. 000 b is the address => 2
12
Example Translate logical address 6 = 0110
Page size (i.e. # of addresses per page) = 4 => 2 bits for offset # of pages = 4 => 2 bits for page number Frame size = page size = 4 => 2 bits for offset # of frames = 6 => 3 bits for frame number Logical address = a. Replace 01 i.e. page number by frame number i.e. 000 b is the physical address => 2 Page number Offset
13
Segmentation Divide a process into unequal blocks called segments.
Reflects the logical organization of the program. Makes sharing simpler. A physical address consists of a segment address and an offset. Similar to dynamic partitioning, except the process need not be in a contiguous block. No internal fragmentation as the block can be just as large as needed. There can be external fragmentation. Use a segment table. An entry must hold the start address in main memory and a bounds address or an end address.
14
Address translation in segmentation
Consider an n+m bit address. “n” is the segment number and the rightmost “m” bits are the offset. Given a logical address, Extract the “n” leftmost bits. You must know what “n” is or know how many segments there are. (x segments => log2x bits = n) Use the process segment table to determine what the starting address of the segment is. Use the remaining bits (offset) and compare with the length of the segment. If greater than the length of the segment, an interrupt has occurred. If not, base address + offset will give the physical address.
15
Address Translation using a segment table
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.