Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating Systems Chapter 8

Similar presentations


Presentation on theme: "Operating Systems Chapter 8"— Presentation transcript:

1 Operating Systems Chapter 8
Memory Management

2 Logical vs. Physical Address Space
The concept of a logical address space that is bound to a separate physical address space is central to proper memory management. Logical address – generated by the CPU; also referred to as virtual address. Physical address – address seen by the memory unit.

3 Memory-Management Unit (MMU)
Hardware device that maps virtual to physical address. The user program deals with logical addresses. it never sees the real physical addresses

4 Contiguous Allocation
Main memory usually into two partitions: Resident operating system, usually held in low memory with interrupt vector. User processes then held in high memory. Single-partition allocation Relocation-register scheme used to protect user processes from each other, and from changing operating-system code and data. Relocation register contains value of smallest physical address; limit register contains range of logical addresses – each logical address must be less than the limit register.

5 Hardware Support for Relocation and Limit Registers

6 Contiguous Allocation (Cont.)
Multiple-partition allocation Hole – block of available memory; holes of various size are scattered throughout memory. When a process arrives, it is allocated memory from a hole large enough to accommodate it. Operating system maintains information about: a) allocated partitions b) free partitions (hole) OS process 5 process 8 process 2 process 9 process 10

7 Fragmentation External Fragmentation - total memory space exists to satisfy request but it is not contiguous OS process 2 process 3 process 8 50k 100k Process 9 125k ?

8 Compaction Process 9 OS process 2 process 3 process 8 50k 100k 90k 60k
Shuffle memory contents to place all free memory together in one large block 128 MB RAM, 100 nsec/access  1.5 seconds to compact! Process 9 OS process 2 process 3 process 8 50k 100k 90k 60k 125k

9 Paging Logical address space of a process can be noncontiguous; process is allocated physical memory whenever the latter is available. Divide physical memory into fixed-sized blocks called frames (size is power of 2, between 512 bytes and 8192 bytes). Divide logical memory into blocks of same size called pages. Keep track of all free frames. To run a program of size n pages, need to find n free frames and load program. Set up a page table to translate logical to physical addresses. Internal fragmentation.

10 Address Translation Scheme
Address generated by CPU is divided into: Page number (p) – used as an index into a page table which contains base address of each page in physical memory. Page offset (d) – combined with base address to define the physical memory address that is sent to the memory unit.

11 Paging Example

12 Paging Example Physical Memory Offset 000 000 Page 0 001 001 1 1 1 010
1 1 1 010 010 Page Frame Page 1 011 011 00 01 100 100 01 11 Page 2 101 101 10 00 110 110 11 10 Page 3 111 111 Page Table

13 Another Paging Example
1 4 Page Table Page 0 Page 1 Process A Page 1A Page 1B Page 0A Page 0B 2 3 5 6 7 Process B page number p page offset d m-n n

14 Implementation of Page Table
Page table is kept in main memory. Page-table base register (PTBR) points to the page table. Page-table length register (PRLR) indicates size of the page table. In this scheme every data/instruction access requires two memory accesses. One for the page table and one for the data/instruction. The two memory access problem can be solved by the use of a special fast-lookup hardware cache called associative memory or translation look-aside buffers (TLBs)

15 Paging Hardware With TLB

16 Memory Protection Memory protection implemented by associating protection bit with each frame. Valid-invalid bit attached to each entry in the page table: “valid” indicates that the associated page is in the process’ logical address space, and is thus a legal page. “invalid” indicates that the page is not in the process’ logical address space.

17 Large Address Spaces Typical logical address spaces:
4 Gbytes => 232 address bits (4-byte address) Typical page size: 4 Kbytes = 212 bits Page table may have: 232 / 212 = 220 = 1million entries Each entry 3 bytes => 3MB per process! Do not want that all in RAM Solution? Page the page table Multilevel paging

18 Multilevel Paging Page Table page number p1 page offset d 10 12 p2
... Page 0 ... ... ... ... Logical Memory ... Outer Page Table

19 Segmentation Memory-management scheme that supports user view of memory. A program is a collection of segments. A segment is a logical unit such as: main program, procedure, function, method, object, local variables, global variables, common block, stack, symbol table, arrays

20 Segmentation with Paging – Intel 386

21 Virtual Memory Background
Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical address space can therefore be much larger than physical address space. Allows address spaces to be shared by several processes. Allows for more efficient process creation.

22 Demand Paging Bring a page into memory only when it is needed
With each page table entry a valid–invalid bit is associated (1  in-memory, 0  not-in-memory) During address translation, if valid–invalid bit in page table entry is 0  page fault. 1 Frame # valid-invalid bit

23 Page Table When Some Pages Are Not in Main Memory

24 Steps in Handling a Page Fault

25 What happens if there is no free frame?
Page replacement – find some page in memory, but not really in use, swap it out. algorithm performance – want an algorithm which will result in minimum number of page faults. Basic Page Replacement Find the location of the desired page on disk. Find a free frame: - If there is a free frame, use it If there is no free frame, use a page replacement algorithm to select a victim frame. Read the desired page into the (newly) free frame. Update the page and frame tables. Restart the process.

26 FIFO Page Replacement

27 Least Recently Used (LRU) Algorithm

28 Second-Chance (clock) Page-Replacement Algorithm


Download ppt "Operating Systems Chapter 8"

Similar presentations


Ads by Google