Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
CPU
Memory
14346
MMU
Fixed partition
Variable partition
CONTIGUOUS ALLOCATION
Fixed partition Memory is divided into a no. of fixed sized partitions. Each partition may contain exactly one process. When a partition is free, a process is selected from the input Queue and is loaded into a free partition. Variable partition Initially all memory is available for user processes, and is considered as large block of available memory. When a process arrives and needs memory, we search for a hole large enough for this process and allocate only as much. External and Internal Fragmentation Multiple partition allocation schemes suffer from external fragmentation. As processes are loaded and removed from the memory, the free memory space is broken into little pieces. External fragmentation exists when enough total memory space exists to satisfy a request, but it is not contiguous; storage is fragmented into a number of holes. Internal fragmentation is memory that is internal to a partition, but is not being used.
Paging
Physical memory is broken into fixed sized blocks called frames. Logical memory is broken into blocks of the same size called pages. The backing store is divided into fixed-sized blocks that are of the same size as the memory frames. The user program views the memory as one single contiguous space containing only this one program. In fact, the user program is scattered throughout the physical memory, which also holds other programs. When a process arrives in the system to be executed, its size expressed in pages, is examined. Each page of the process needs one frame. Thus if the process requires n pages, there must be at least n frames available in memory. If there are n frames available in the memory, they are allocated in this arriving process. A page table is maintained which stores the frame no: corresponding to each page. Every address generated by the CPU is divided into 2 parts: a page no: (p) and a page offset (d). The page no: is used to index into the page table. The page table contains the base address of each page in physical memory. This base address is combined with the page offset to obtain the physical memory address that is sent to the memory unit. PAGING HARDWARE Logical address Physical address
CPU
p d
Physical memory
Page table
Operating Systems - Main memory management 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 A B C D E F G H I J K L M N O P Total physical memory = 24 bytes Page size = 4 bytes 20 A B C D 0 M N O P
PAGING EXAMPLE
0 1 2 3
5 2 3 0
4 1 8 E F G H I J K L
12
16 4
Eg. The logical address 6 is page 1, offset 2. Indexing into the page table we find that page 1 is in frame 2. Thus logical address 6 (content G) maps to physical address 10 (2*4 + 2) (content G).
Segmentation
In paging, the users view is not the same as the actual physical memory. The users view is mapped onto physical memory. The user prefers to view memory as a collection of variable-sized segments, with no memory ordering among segments.
Symbol table
Each of these segments is of variable length. Elements within the segment are identified by their offset from the beginning of the segment e.g. the first statement of the program, the 5th instruction of the Sqrt function, the 17th entry in the symbol table, and so on. Segmentation is a memory management scheme that supports this user view of memory. A logical address space is a collection of segments. Each segment has a name and a length. The addresses specify both the segment name and the offset within the segment. The user therefore specifies each address by two quantities: a segment name and an offset. For simplicity of implementation, segments are numbered and are referred by segment no. the loader takes all the program segments and assigns them numbers. Therefore, a logical address consists of <segment no. , offset> SEGMENTATION HARDWARE Logical address s CPU s d d Physical address ________ _____ ________ _____ __ __bas limit e + _____ _____ _____ ___ Segment table < yes no Trap: addressing error
Physical memory
SEGMENTATION EXAMPLE Logical address s CPU s 2 d d 53 1000 400 400 _____ _____ 1400 6300 4300 _____ ___ 0 1 2 +
Seg 2
4300 4700
Virtual Memory
Virtual memory is a technique that allows the execution of a program that may not be completely in memory. The main visible advantage of the scheme is that programs can be larger than physical memory. Virtual memory is the separation of user logical memory from physical memory. This separation allows extremely large virtual memory to be provided for programmers when only a small physical memory is available. Virtual memory is commonly implemented by demand paging. (Demand segmentation can also be used.) A demand paging system is similar to a paging system with swapping. Processes reside on the secondary memory. When we want to execute a process, the pager guesses which pages will be used and brings in those pages into the memory. If a process tries to use a page not in memory (if the pager does not guess correctly), the hardware traps to the Operating System (page fault). The OS reads the desired pages into the memory and restarts the process as though the page had always been in memory.