Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 11: Memory Management

Similar presentations

Presentation on theme: "Lecture 11: Memory Management"— Presentation transcript:

1 Lecture 11: Memory Management

2 Example memory configuration before and after allocation of a 16KB block
First Fit (16K) 22K 6K Best Fit (16K) 18K 2K Last allocated block (14K) 8K 8K 6K 6K 14K 14K Next Fit (16K) 36K 20K

3 Hardware support for relocation
Relative Address Process Control Block Base register Program Adder Absolute Address Data Bounds register Comparator Stack Interrupt to Operating System

4 Logical addresses Logical Address: Page# = 1, Offset = 478 Logical Address: Segment# = 1, Offset = 752 Relative Address = 1502 Page 0 Segment bytes 478 752 Page 1 User process 2700 bytes Segment bytes Page 2

5 Paging 6-Bit page 10-Bit offset Process Page Table 000101 000110 011001 1 2 16-Bit physical address

6 Segment 4-Bit segment 10-Bit offset Process Segment Table Length Base 1 + 16-Bit physical address

7 Memory Management Techniques
Description Strengths Weaknesses Fixed Partioning Main memory is divided into a number of static partitions at system generation time. A process may be loaded into a partition of equal or greater size Simple to implement; little operating-system overhead Inefficient use of memory due to internal fragmenation; number of active processes is fixed Dynamic Partitioning Partitions are crerated dynamically, so that each process is loaded into a partition of exactly the same size as that process No internal fragmentation; more efficient use of main memory Inefficient use of processor due to the need for compaction to counter external fragmentation Simple paging Main memory is divided into a number of equal size frames. Each process is divided into a number of equal size pages of the same length as frames. A process is loaded by loading all of its pages into available, not necessarily contiguous frames No external fragmentation A small ammount of internal fragmentation Simple segmentation Each process is divided into a number of segments. A process is loaded by loading all of its segments into dynamic partitions that need not be contiguous No internal fragmentation Need for compaction

8 Paging Technique Overlays Paging
When a program is too big to fit in the available memory, the programmer has to split it into pieces The swapping is done by the OS Paging The physical memory is partitioned into small equal fixed-size chunks (called frames) The logical memory is also divided into small and equal fixed-size chunks (called pages)

9 Paging Technique (ctd)
Features Internal fragmentation: only a fraction of the last page of a process No external fragmentation In order to load the pages of a process into non contiguous frames the OS needs page table for each process Logical address consists of a page number and an offset within the page Translation logical-to-physical address is done by the processor hardware

10 Paging Hardware P d F d P CPU Physical Memory Logical Address Physical
Page table

11 Paging Hardware CPU P d Physical Memory F d P Logical Address Address
Page table P d F d P Logical Address Address TLB hit TLB miss

12 Analysis Definition Performance
Hit ratio: percentage of times that a page number is found in the associative registers Performance Effective Access Time: Hit ratio x TLB access time + Miss ratio x Memory access time

13 Segmentation Technique
The logical memory is divided into a number of segments of different length Logical address consists of two parts: segment number and an offset Features With segmentation a process may occupy more than one partition Internal fragmentation: solved External fragmentation: Not solved

14 trap: addressing error
CPU Physical Memory Segment table S d S + < limit Base Yes No trap: addressing error

15 Virtual Memory

16 Real Programs An examination of real programs shows as that a program can be divided into two parts: part of code rarely or never executed code handling unusual error conditions code handling certain options and features rarely used allocation of much more memory needed (arrays, lists, tables) part of code usually executed Benefit of executing a program that is partially in physical memory

17 Virtual Memory Characteristics of paging and segmentation:
Process may be broken up into a number of pieces (pages or segments) Memory references within a process are logical addresses Logical addresses are dynamically translated into physical addresses Pages or segments of a process do not need to be contiguously located in main memory by using page or segment table With these characteristics it is not necessary that all pages or all segments of a process be in main memory during execution

18 Virtual Memory (ctd) Definition
Virtual memory is an illusion supported by system hardware and software that a user has a vast linear expanse of useful storage In fact, a much smaller real memory is used to hold portions of a user’s program during execution

19 Virtual Memory (ctd) Advantages
A program is not constrained by the physical memory space available Users can write an extremely large virtual address space The increase in CPU utilisation and throughput Less I/O would be needed to load or swap each user program into memory

20 Virtual Memory Features
Usually virtual memory systems use paging technique OS must maintain a page/segment table for each process OS must maintain a free frame list A page or segment number and the offset are used to calculate absolute address Not all pages or segments of a process need to be in main memory frames for the process to run Reading a page or segment into main memory may require writing a page or segment out to disk (called page fault or segment fault)

21 Page Table Structure N. Page Offset N. Frame Offset Pointer + F.No.
Page number Page table Process Main Memory Register Virtual Address Page Frame Offset

22 Page Fault Three major components of the page-fault service time are required: Service the page-fault interrupt Read in the page Restart the process

23 Page Fault (ctd) A page fault causes the following sequence to occur:
Trap to the OS Save the user registers and process state Determine that the interrupt is a page fault Check if the page reference is legal and determine its location in the disk Issue a read from the disk to a free frame While waiting, allocate the CPU to another process Interrupt form the disk (I/O completed)

24 Page Fault (ctd) Save the registers and the state of the current process Determine that the interrupt is from the disk Update the page table and other tables to show that the desired page is now in memory Wait for the CPU to be allocated to this process again Restore the process context (registers, state) and the new page table, then resume the interrupted instruction


26 Lecture 12: Memory Management

27 PAGING ONLY Page Number Offset P M Other Control Bits Frame Number
Virtual Address Page Number Offset Page Table Entry P M Other Control Bits Frame Number

28 SEGMENTATION ONLY Segment Number Offset
Virtual Address Segment Number Offset Segment Table Entry P M Other Control Bits Length Segment Base

Virtual Address Segment Number Page number Offset Segment Table Entry P M Other Control Bits Length Segment Base Page Table Entry P M Other Control Bits Frame Number

30 Address translation in a segmentation system
Virtual Address Real Address + Segment Number S# Offset d Base + d d Register Seg. Table Ptr Segment length + S Length Base Segment Table Main Memory

31 Address translation in a segmentation/paging system
Virtual Address Segment # Page # Offset Frame # Offset d Register Seg. Table Ptr Segment length P + + S Page Table Segment Table Main Memory

32 Page size Page Fault Rate Page Fault Rate P
Number of page frames allocated Page size

33 Protection relationships between segments
Main Memory 20 K All accesses not allowed Dispatcher 35 K Branch instruction not allowed 50 K Reference to data (not allowed) Process A Reference to data (allowed) 80 K 90 K Process B 140 K Process C 190 K

34 Replacement Policy Memory management concepts:
Deals with the selection of a page in memory to be replaced when a new page must be brought in Memory management concepts: The number of frames to be allocated to each active process The replacement can be limited to those of the process that caused the page fault encompass all frames in main memory Frame Locking: Much of the kernel and control structures of the OS is held on locked frames the particular page that should be selected for replacement The first 2 concepts are called “resident set management”

35 Basic Algorithms Optimal
replaces the page that will not be used for the longest period of time LRU (Least recently used) replaces the page in memory that has not been referenced for the longest time FIFO the pages are removed in round-robin style Clock policy When a page is referenced after a page fault its use bit is set to 1. When a page is replaced the pointer is set to indicate the next frame in the buffer. For replacement, the OS scans the buffer to find a frame with a use bit to 0

36 Example Consider the following page address stream: and a fixed frame allocation of 3 frames 2 4 3 1 5 Optimal 2 3 5 1 4 LRU

37 Example (ctd) 2 5 3 1 4 FIFO 2 2* 3 5 5* 1 4 CLOCK

38 Fetch policy: Process pages can be brought in on demand, or a pre-paging policy can be used; the latter clusters the input activity by bringing in a number of pages at once Placement policy: With a pure segmentation system, an incoming segment must be fit into an available space in memory Replacement policy: When memory is full, a decision must be made as to which page or pages are to be replaced Resident set management: The operating system must decide how much main memory to allocate to a particular process when that process is swapped in. This can be a static allocation made at process creation time, or it can change dynamically. Cleaning policy: Modified process pages can be written out at the time or replacement, or a pre-cleaning policy can be used; the latter clusters the output activity by writing out a number of pages at once Load control: Load control is concerned with determining the number of processes that will be resident in main memory at any given time

System/370 and MVS Windows NT Unix System V LINUX

Download ppt "Lecture 11: Memory Management"

Similar presentations

Ads by Google