Paging, and segmentationMemory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated efficiently to pack as many processes into memory as possible2Big Picture3DataStackText (shared)kernel stack/u areaDataStackText (shared)kernel stack/u areaDataStackText (shared)kernel stack/u areaproc structkernel memoryMemory mgnt requirements Relocation Protection Sharing Logical organization Physical organization4Relocation When program loaded in memory, absolute memory locations assigned A process may occupy different partitions thus different absolute memory locations during execution (from swapping) Compaction will also cause a program to occupy a different partition which means different absolute memory locations5Addresses Logical Reference to a memory location independent of the current assignment of data or program to memory Translation must be made to the physical address Relative Address expressed as a location relative to some known point A relative address is an example of a logical address Physical The absolute address or actual location in memory6Hardware Support for Relocation7Interrupt tooperating systemProcess image inmain memoryRelative addressAbsoluteaddressProcess ControlBlockProgramDataStackAdderComparatorBase RegisterBounds RegisterRegisters Used during Execution Base register Starting address for the process Bounds register Ending location of the process These values are set when the process is loaded and when the process is swapped in8Registers Used during Execution The value of the base register is added to a relative address to produce an absolute address The resulting address is compared with the value in the bounds register If the address is not within bounds, an interrupt is generated to the operating system9Simple paging Partition memory into small equal-size pieces Pieces of memory are called frames Divide each process into the same size pieces Pieces of a process are called pages All process pages are loaded in memory frames when process is loaded Operating system maintains a page table for each process Contains the frame number for each process page memory address = frame number + offset10Simple paging Like fixed partitioning, but: Partitions are small A process can occupy more than 1 partition Partitions need not be contiguous Some internal fragmentation (last page), but no external fragmentation111201234567A.0A.1B.0B.1A.0A.1C.0B.0B.1A.0A.1C.0A.0A.1C.0A.0A.1D.0D.1D.2D.301232356Process DPage Table7Free FrameList01234567Memory framesAddress translation in paging To make it convenient, the size of a page is a power of 2 Given a (page #, offset), find (frame #, offset) 2n> number of pages => n bits to hold the page number 2k> number of frames => k bits to hold the frame number 2m= number of bytes in a page => m bits to determine the offset within a page Logical address is nm Physical address is simply km where k is the frame that stores page “n” (obtained from the page table)13Address translation in paging140 0 0 0 0 1 0 1 1 1 0 1 1 1 1 0Page # (n bits)0 0 0 0 1 00 0 0 0 1 10 0 0 0 1 1 0 1 1 1 0 1 1 1 1 0012Physical AddressOffset (m bit)Process Page Table:0 0 0 1 0 1. . .Frame # (k bits)Address translation e.g.Page #Logical AddressValue0 0 A0 1 B0 2 C0 3 D1 4 E1 5 F1 6 G1 7 H2 8 I2 9 J2 10 K2 11 L3 12 M3 13 N3 14 O3 15 PPage #Frame #0 21 02 53 4Frame # Physical address Value0 0 E0 1 F0 2 G0 3 H1 41 72 8 A2 9 B2 10 C2 11 D3 123 154 16 M4 17 N4 18 O4 19 P5 20 I5 21 J5 22 K5 23 LPage tableProcessMain memory15Segmentation Divide a process into unequal size blocks called segments There is a maximum segment length Addressing consist of two parts A segment number and an offset Since segments are not equal Segmentation is similar to dynamic partitioning16Address translation in segmentation17Segment #0 0 0 1 0 0 1 0 1 1 1 1 0 0 0 0001011101110011110011110000001000000000000100000001000000 0 1 0 0 0 1 1 0 0 0 1 0 0 0 001+Physical AddressOffsetProcess Segment Table:Length Base
View Full Document