Silberschatz, Galvin and Gagne  2002 9.1 Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Memory Management.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Main Memory CS Memory Management1. Background Program must be brought (from disk) into memory and placed within a process for it to be run Main.
Module 9: Memory Management
Modified from Silberschatz, Galvin and Gagne Lecture 16 Chapter 8: Main Memory.
Chapter 9: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Memory Management Background.
Background A program must be brought into memory and placed within a process for it to be executed. Input queue – collection of processes on the disk that.
Memory Management.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
03/10/2004CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Memory Management Gordon College Stephen Brinton.
Chapter 8: Main Memory.
Chapter 7: Main Memory CS 170, Fall Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
Main Memory. Background Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
03/05/2008CSCI 315 Operating Systems Design1 Memory Management Notice: The slides for this lecture have been largely based on those accompanying the textbook.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 8: Memory Management Background.
Chapter 8: Main Memory.
 Background  Swapping  Contiguous Allocation  Paging  Segmentation  Segmentation with Paging.
Chap 8 Memory Management. Background Program must be brought into memory and placed within a process for it to be run Input queue – collection of processes.
XE33OSA Chapter 8: Memory Management. 8.2XE33OSA Silberschatz, Galvin and Gagne ©2005 Chapter 8: Memory Management Background Swapping Contiguous Allocation.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Chapter 8: Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Background Program must be brought.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Silberschatz and Galvin  Operating System Concepts Module 8: Memory Management Background Logical versus Physical Address Space Swapping Contiguous.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 8: Main Memory.
Chapter 8 Main Memory. 8.2 Modified By Dr. Khaled Wassif Operating System Concepts – 7 th Edition Silberschatz, Galvin and Gagne ©2005 Background Swapping.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 8 Operating Systems.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
8.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 8: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Lecture 8: Memory Management. Lecture 8 / Page 2AE4B33OSS Silberschatz, Galvin and Gagne ©2005 Contents Problems of memory management Dynamic allocation.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 8: Memory Management Background.
Chapter 8: Memory-Management Strategies. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 8: Memory-Management Strategies.
Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation Example: The.
Chapter 8: Memory-Management Strategies. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 8: Memory-Management Strategies.
Chapter 8: Memory-Management Strategies. 8.2Operating System Principles Chapter 8: Memory-Management Strategies Background Swapping Contiguous Memory.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Chapter 8: Main Memory. Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 8: Memory Management Background.
9.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 8: Memory Management n.
Memory Management. Background Memory consists of a large array of words or bytes, each with its own address. The CPU fetches instructions from memory.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
8.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Fragmentation External Fragmentation – total memory space exists to satisfy.
Background Program must be brought into memory and placed within a process for it to be run. Input queue – collection of processes on the disk that are.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 8: Main Memory.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 8: Main Memory.
Chapter 8: Memory Management. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Chapter 2: Memory Management Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging Operating System Concepts.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 8: Memory Management Background.
1 Chapter 8: Main Memory. 2 Chapter 8: Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition, Chapter 8: Memory- Management Strategies.
Ghsong  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation Segmentation with.
8.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 8: Memory-Management Strategies.
Presentation transcript:

Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation Segmentation with Paging

Silberschatz, Galvin and Gagne  Operating System Concepts Background Process is running program  Process must be in memory Input queue: collection of processes on the disk waiting to be brought into memory to run program goes through several steps before being run

Silberschatz, Galvin and Gagne  Operating System Concepts Binding of Instructions and Data to Memory Compile time:  memory location fixed  generate absolute code  must recompile code if starting location changes Load time:  memory location not known  generate relocatable code Execution time:  Process can be moved  Code uses logical addresses  Logical to physical translation done as part of execution  Need hardware support (e.g., base and limit registers) 3 points in time

Silberschatz, Galvin and Gagne  Operating System Concepts Multistep Processing of a User Program

Silberschatz, Galvin and Gagne  Operating System Concepts Logical vs. Physical Address Space Crucial separation for proper memory management:  Logical address  generated by the CPU  also referred to as virtual address  Physical address  address seen by the memory unit Logical and physical addresses are the same in compile-time and load-time address-binding schemes Logical (virtual) and physical addresses differ in execution-time address-binding scheme

Silberschatz, Galvin and Gagne  Operating System Concepts Memory-Management Unit ( MMU ) Hardware device that maps virtual to physical address relocation register:  Contains address to be added to every address generated by a user process at the time it is sent to memory user process deals with logical addresses it never sees the real physical addresses

Silberschatz, Galvin and Gagne  Operating System Concepts Dynamic relocation using a register

Silberschatz, Galvin and Gagne  Operating System Concepts Dynamic Loading Routine is not loaded until it is called Better memory-space utilization; unused routine is never loaded Useful when large amounts of code are needed to handle infrequently occurring cases No special support from the operating system is required implemented through program design

Silberschatz, Galvin and Gagne  Operating System Concepts Dynamic Linking Linking postponed until execution time Small piece of code, stub, used to locate the appropriate memory-resident library routine Stub replaces itself with the address of the routine, and executes the routine Operating system needed to check if routine is in process’ memory space Dynamic linking is particularly useful for libraries

Silberschatz, Galvin and Gagne  Operating System Concepts Overlays Keep in memory only those instructions and data that are needed at any given time Needed when process is larger than amount of memory allocated to it Implemented by user, no special support needed from operating system, programming design of overlay structure is complex

Silberschatz, Galvin and Gagne  Operating System Concepts Overlays for a Two-Pass Assembler

Silberschatz, Galvin and Gagne  Operating System Concepts Swapping process is moved from memory to backing store, moved back later for continued execution Backing store:  fast large magnetic disk  must accommodate all processes  must provide direct access Roll out, roll in  swapping variant for priority-based scheduling algorithms  lower-priority process is swapped out  higher-priority process loaded and executed swap time is proportional to process size Common on: UNIX, Linux, and Windows

Silberschatz, Galvin and Gagne  Operating System Concepts Schematic View of Swapping

Silberschatz, Galvin and Gagne  Operating System Concepts Contiguous Allocation Main memory has two partitions: I. Resident operating system, in low memory, with interrupt vector II. User processes in high memory User process partition  Relocation-register scheme  protect user processes from each other, and from changing operating-system code and data.  holds smallest physical address  limit register contains range of logical addresses

Silberschatz, Galvin and Gagne  Operating System Concepts Hardware Support for Relocation and Limit Registers

Silberschatz, Galvin and Gagne  Operating System Concepts Contiguous Allocation (Cont.) Multiple user partition allocation  Hole – variable size block of available memory  new process is allocated memory from a hole  Operating system maintains information about: a) allocated partitions b) free partitions (holes) OS process 5 process 8 process 2 OS process 5 process 2 OS process 5 process 2 OS process 5 process 9 process 2 process 9 process 10

Silberschatz, Galvin and Gagne  Operating System Concepts Dynamic Storage-Allocation Problem First-fit: Allocate the first hole that is big enough Best-fit: Allocate the smallest hole that is big enough; must search entire list, unless ordered by size; Produces the smallest leftover hole Worst-fit: Allocate the largest hole; must also search entire list; Produces the largest leftover hole How to satisfy a request of size n from a list of free holes ? First-fit and best-fit better than worst-fit in terms of speed and storage utilization

Silberschatz, Galvin and Gagne  Operating System Concepts Fragmentation External Fragmentation  many small holes Internal Fragmentation  allocated memory larger than requested memory Reduce external fragmentation by compaction  move holes together into one large block  requires dynamic relocation at execution time  I/O problem  Latch job in memory while it is involved in I/O  Do I/O only into OS buffers

Silberschatz, Galvin and Gagne  Operating System Concepts Paging Process is allocated physical memory in pages Memory may be non-contiguous physical memory is fixed-sized blocks called frames (size is power of 2: 512, 1024, … 4MB …) logical memory is blocks of same size called pages To run a program of size n pages, need to find n free frames and load program translate logical to physical address via page table Also: internal fragmentation

Silberschatz, Galvin and Gagne  Operating System Concepts 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

Silberschatz, Galvin and Gagne  Operating System Concepts Address Translation Architecture

Silberschatz, Galvin and Gagne  Operating System Concepts Paging Example

Silberschatz, Galvin and Gagne  Operating System Concepts Paging Example

Silberschatz, Galvin and Gagne  Operating System Concepts Free Frames Before allocation After allocation

Silberschatz, Galvin and Gagne  Operating System Concepts Address Translation Architecture

Silberschatz, Galvin and Gagne  Operating System Concepts 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 (PTLR)  indicates size of the page table doubles memory accesses: I. page table II. data/instruction solution:  special fast-lookup hardware cache (associative memory)  translation look-aside buffer (TLB)  if not found in TLB  consult page table

Silberschatz, Galvin and Gagne  Operating System Concepts Paging Hardware With TLB

Silberschatz, Galvin and Gagne  Operating System Concepts Effective Access Time Associative lookup time:  Memory cycle time: τ Hit ratio:   percentage of times that a page number is found in TLB  depends on TLB size Effective Access Time (EAT) EAT = (τ +  )  + (2τ +  )(1 –  ) Example: EAT = (100ns + 20ns)*0.8 + (200ns + 20ns)*0.2 = 140ns

Silberschatz, Galvin and Gagne  Operating System Concepts Memory Protection page table has bit for each frame “valid”:  page is legal, i.e. belongs to address space “invalid”:  page is not in the process’ logical address space

Silberschatz, Galvin and Gagne  Operating System Concepts Valid (v) or Invalid (i) Bit In Page Table PTLR

Silberschatz, Galvin and Gagne  Operating System Concepts Page Table Structures Hierarchical Paging Hashed Page Tables Inverted Page Tables

Silberschatz, Galvin and Gagne  Operating System Concepts Hierarchical Page Tables Break up the logical address space into multiple page tables A simple technique is a two-level page table

Silberschatz, Galvin and Gagne  Operating System Concepts Two-Level Paging Example address (on 32-bit machine with 4K page size) is divided into:  a page number consisting of 20 bits  a page offset consisting of 12 bits page number is further divided into:  a 10-bit page number.  a 10-bit page offset logical address is as follows: p i is an index into the outer page table p 2 is the displacement within the page of the outer page table page numberpage offset pipi p2p2 d 10 12

Silberschatz, Galvin and Gagne  Operating System Concepts Two-Level Page-Table Scheme

Silberschatz, Galvin and Gagne  Operating System Concepts Address-Translation Scheme two-level paging architecture

Silberschatz, Galvin and Gagne  Operating System Concepts Hashed Page Tables Common in address spaces > 32 bits virtual page number is hashed into a page table page table contains a chain of elements hashing to the same location  virtual page numbers are compared in this chain searching for a match  If match is found, the corresponding physical frame is extracted

Silberschatz, Galvin and Gagne  Operating System Concepts Hashed Page Table

Silberschatz, Galvin and Gagne  Operating System Concepts Inverted Page Table One entry for each real page of memory Entry consists of:  virtual address of the page  information which process that owns the page decreases page table size increases search time  Use hash table to limit the search

Silberschatz, Galvin and Gagne  Operating System Concepts Inverted Page Table Architecture

Silberschatz, Galvin and Gagne  Operating System Concepts Shared Pages Shared code  One copy of read-only (reentrant) code shared among processes (i.e., text editors, compilers, window systems)  Shared code must appear in same location in the logical address space of all processes Private code and data  Each process keeps a separate copy of the code and data  pages for the private code and data can appear anywhere in the logical address space

Silberschatz, Galvin and Gagne  Operating System Concepts Shared Pages Example

Silberschatz, Galvin and Gagne  Operating System Concepts Segmentation Memory-management scheme that supports user view of memory A program is a collection of segments, segment is a logical unit such as: main program, procedure, function, method, object, local variables, global variables, common block, stack, symbol table, arrays

Silberschatz, Galvin and Gagne  Operating System Concepts User’s View of a Program

Silberschatz, Galvin and Gagne  Operating System Concepts Logical View of Segmentation user spacephysical memory space

Silberschatz, Galvin and Gagne  Operating System Concepts Segmentation Architecture Logical address consists of a two tuple: Segment table: each table entry has:  base – starting physical address of segments in memory  limit – length of the segment Segment-table base register (STBR)  segment table’s location in memory. Segment-table length register (STLR) segment number s is legal if s < STLR

Silberschatz, Galvin and Gagne  Operating System Concepts Segmentation Architecture Issues Relocation:  dynamic, via segment table Sharing:  shared segment have same segment number Allocation:  first fit/best fit  external fragmentation Protection:  validation bit = 0  illegal segment  read/write/execute privileges

Silberschatz, Galvin and Gagne  Operating System Concepts Segmentation Hardware

Silberschatz, Galvin and Gagne  Operating System Concepts Example of Segmentation

Silberschatz, Galvin and Gagne  Operating System Concepts Sharing of Segments

Silberschatz, Galvin and Gagne  Operating System Concepts Segmentation with Paging Segmentation problem:  external fragmentation  lengthy search times Solution: paged segmentation  segment-table entry contains  not base address of the segment  but base address of a page table for this segment

Silberschatz, Galvin and Gagne  Operating System Concepts Intel Address Translation segmentation 2 level paging