Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Silberschatz, Galvin and Gagne  2002 9.1 Operating System Concepts Chapter 9: Memory Management Background Swapping Contiguous Allocation Paging Segmentation."— Presentation transcript:

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

2 Silberschatz, Galvin and Gagne  2002 9.2 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

3 Silberschatz, Galvin and Gagne  2002 9.3 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

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

5 Silberschatz, Galvin and Gagne  2002 9.5 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

6 Silberschatz, Galvin and Gagne  2002 9.6 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

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

8 Silberschatz, Galvin and Gagne  2002 9.8 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

9 Silberschatz, Galvin and Gagne  2002 9.9 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

10 Silberschatz, Galvin and Gagne  2002 9.10 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

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

12 Silberschatz, Galvin and Gagne  2002 9.12 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

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

14 Silberschatz, Galvin and Gagne  2002 9.14 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

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

16 Silberschatz, Galvin and Gagne  2002 9.16 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

17 Silberschatz, Galvin and Gagne  2002 9.17 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

18 Silberschatz, Galvin and Gagne  2002 9.18 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

19 Silberschatz, Galvin and Gagne  2002 9.19 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

20 Silberschatz, Galvin and Gagne  2002 9.20 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

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

22 Silberschatz, Galvin and Gagne  2002 9.22 Operating System Concepts Paging Example

23 Silberschatz, Galvin and Gagne  2002 9.23 Operating System Concepts Paging Example

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

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

26 Silberschatz, Galvin and Gagne  2002 9.26 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

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

28 Silberschatz, Galvin and Gagne  2002 9.28 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

29 Silberschatz, Galvin and Gagne  2002 9.29 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

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

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

32 Silberschatz, Galvin and Gagne  2002 9.32 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

33 Silberschatz, Galvin and Gagne  2002 9.33 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

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

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

36 Silberschatz, Galvin and Gagne  2002 9.36 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

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

38 Silberschatz, Galvin and Gagne  2002 9.38 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

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

40 Silberschatz, Galvin and Gagne  2002 9.40 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

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

42 Silberschatz, Galvin and Gagne  2002 9.42 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

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

44 Silberschatz, Galvin and Gagne  2002 9.44 Operating System Concepts Logical View of Segmentation 1 3 2 4 1 4 2 3 user spacephysical memory space

45 Silberschatz, Galvin and Gagne  2002 9.45 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

46 Silberschatz, Galvin and Gagne  2002 9.46 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

47 Silberschatz, Galvin and Gagne  2002 9.47 Operating System Concepts Segmentation Hardware

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

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

50 Silberschatz, Galvin and Gagne  2002 9.50 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

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


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

Similar presentations


Ads by Google