Chapter 9' Memory Management - PowerPoint PPT Presentation

1 / 53
About This Presentation
Title:

Chapter 9' Memory Management

Description:

Compile time binding. ??? ?? ??? ??? ?. absolute (??, ????)code generated ... Execution time binding. ??? ??? ???? ????? ????? ?? ??? ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 54
Provided by: marily227
Category:

less

Transcript and Presenter's Notes

Title: Chapter 9' Memory Management


1
Chapter 9. Memory Management
  • Logical versus Physical Address Space
  • Swapping
  • Contiguous Allocation
  • Paging
  • Segmentation
  • Segmentation with Paging

2
Multistep Processing of a User Program
User programs go through several steps before
being run on memory.
3
Binding Symbolic Identifier Binary Number
  • Compile time binding
  • ??? ?? ??? ??? ?
  • absolute (??, ????)code generated
  • must recompile code if starting location changes.
  • Load time binding
  • Loader ?? ?? address ??? (?? ? ????)
  • Compiler ? relocatable code ? ?????
  • (?? ????? ???? given base address)
  • Execution time binding
  • ??? ??? ???? ????? ????? ?? ???
  • CPU ? ??? ??? ??? binding ? ?? (address mapping
    table)
  • binding ? run time.
  • need hardware support
  • (e.g., base and limit registers, MMU).

4
memory
CPU? ? ??? MMU ? ??
Add 10, 20
Add 10, 20 10 100 20 330 Jump 30 30 exit
Add A, B A 100 B 330 Jump C C exit
index
Binary on Disk
Source
Reference ?? load
Any Place
5
Address Mapping Table
CPU? ??? ?? ?? ??? ? ?? logical
physical
Memory
500 ??
0 ??
0
CPU
500
500 ??
20000 ??
6
Logical vs. Physical Address Space
  • Logical address
  • generated by the CPU
  • also referred to as virtual address.
  • Physical address
  • address seen by the memory unit.

7
Memory-Management Unit (MMU)
  • MMU (Memory-Management Unit)
  • is a Hardware device that maps
  • virtual address to physical address.
  • In MMU scheme
  • the value in the relocation register is added
  • to every address generated by a user process
  • at the time it is sent to memory (from CPU).
  • The user program
  • deals with logical addresses
  • never sees the real physical addresses.

8
Dynamic relocation using a relocation register
9
Some Terminologies
  • Dynamic Loading
  • Dynamic Linking
  • Overlays
  • Swapping

10
Dynamic Loading
  • Routine is not loaded until it is called
  • Better memory-space utilization
  • 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.
  • Dynamic Linking? ??? ?? ?? ??? ????
  • Loading occupy memory space

11
Dynamic Linking
  • ??? ??? ?? ??? ??? ?????? -- no!
  • ?? ???? ??? ? ??? (to where, from where, is
    where)
  • 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 processes memory
    address.
  • Linking Symbolic address v.s. Physical
    address

12
Overlays
  • Keep in memory only those part when actually
    needed.
  • Useful when process is larger than memory.
  • Coded by user Manual Overlay.

13
Overlays for a Two-Pass Assembler
14
Swapping
  • Swapping
  • A process can be swapped temporarily out of
    memory to a backing store
  • and then brought back into memory sometime
    later.
  • Backing store
  • disk fast, large enough to accommodate all
    images for all users
  • Roll out, roll in
  • lower-priority process is swapped out
  • so higher-priority process can be loaded and
    executed.
  • swapping variant used for priority-based
    scheduling algorithms
  • Major part of swap time is transfer time
  • total transfer time is proportional to the
    amount of memory swapped.

15
Schematic View of Swapping
hwp
web
16
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
  • to protect user processes from each other, and
    OS.
  • Relocation register
  • contains value of smallest physical address.
  • Limit register
  • contains range of logical addresses
  • each logical address bound by limit register.

OS
user process
17
Hardware Support for Relocation and Limit
Registers
18
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
OS
OS
OS
process 5
process 5
process 5
process 5
process 9
process 9
partitions
process 8
process 10
process 2
process 2
process 2
process 2
19
Dynamic Storage-Allocation Problem
How to satisfy a request of size n from a list of
free holes.
  • 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 many small leftover hole.
  • Worst-fit
  • Allocate the largest hole
  • must also search entire list.
  • Produces the largest leftover hole.
  • Buddy system

First-fit and best-fit better than worst-fit in
terms of speed and storage utilization.
20
Fragmentation
  • External fragmentation
  • total memory space exists to satisfy a request,
    but it is not contiguous.
  • Internal fragmentation
  • allocated memory may be slightly larger than
    requested memory this size difference is memory
    internal to a partition, but not being used.
  • Reduce external fragmentation by compaction
  • Shuffle memory contents to place all free memory
    together in one large block.
  • Compaction is possible only if relocation is
    dynamic, and is done at execution time.
  • I/O problem
  • Latch job in memory while it is involved in I/O.
  • Do I/O only into OS buffers
  • Graceful degradation? (Very expensive especially
    at peak load?)
  • .

21
Paging
  • Entire program image resides on disk
  • Divide (memory, disk) into fixed size
  • (page frame in memory, page in disk)
  • When the program starts, just load 1st page only
  • Rest of the pages are loaded in memory on-demand
    page mapping table
  • Pages can be placed anywhere in memory
  • A particular page X of the program can be either
  • already loaded in memory page-frame Y
  • or
  • never been loaded before, it is in disk
  • Whenever CPU presents an address, MMU looks up
    page mapping table

X
Y
disk address
22
Paging Example
23
Paging
  • Paging
  • is a scheme that permits address space to be
    noncontiguous
  • Basic Method
  • 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.
  • Set up a page table to translate logical to
    physical addresses.
  • Internal fragmentation.

24
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.

p
d
25
Address Translation Architecture
26
Paging Example
27
Paging Example
28
Free Frames
Before allocation
After allocation
29
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 table.
  • Every memory access requires two memory accesses.
  • One for the page table and one for the
    data/instruction.
  • To speed up, a special fast-lookup hardware
    cache called associative registers
  • or
  • translation look-aside buffers (TLBs)

30
Associative Register
  • Two types of memory
  • ?? memory (? ??? ???)
  • give address -- return record
  • Associative memory (? ?????)
  • give field of record -- return record
  • Parallel search ? ??? ?? ??? (?? index ??)
  • ??? implementation? ????.
  • Associative registers (TLB) parallel search
  • Since only part of page table is in TLB ?
  • Address translation (A, A)
  • Try portion of page table in associative register
    first
  • If A is in associative register, get frame
    out.
  • Otherwise get frame from page table in main
    memory
  • context switch ? flush (remove old
    entries)

Page
Frame
You need frame here
record
31
Paging Hardware With TLB
32
Effective Access Time
  • Associative lookup ? time unit
  • memory cycle time 1 microsecond
  • Hit ratio ?
  • percentage found in the associative
    registers
  • Effective Access Time (EAT)
  • lthitgt ltmissgt
  • EAT (1 ?) ? (2 ?)(1 ?)
  • 2 ? ?

33
Memory Protection
  • Protection bit with each frame. (? rwx)
  • Valid-invalid bit - each entry in the page
    table
  • valid indicates the page is legal (not a valid
    page).
  • invalid indicates otherwise (access not allowed)

34
Valid (v) or Invalid (i) Bit In A Page Table
35
Two-Level Page-Table Scheme
  • Program has a large address space.
  • Use 32 bit address
  • ? 1 million page table entries (if page size
    4K)
  • 4 MB page table (if each entry -- 4B)
  • ?? page table ? disk?
  • Page table ??? page ??? on-demand load

36
Two-Level Page-Table Scheme
37
Two-Level Paging Example
  • A logical 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.
  • Since the page table is paged, the page number is
    further divided into
  • a 10-bit page number.
  • a 10-bit page offset.
  • Thus, a logical address is as follows
  • where pi is an index into the outer page table,
    and
  • p2 is the displacement within the page of the
    outer page table.

page number
page offset
p2
pi
d
10
12
10
38
Address-Translation Scheme
  • Address-translation scheme for a two-level 32-bit
    paging architecture

39
Multilevel Paging and Performance
  • Address space ? ? ??? ??? disk block ? (like
    B-tree)
  • (not data block, but next
    level page table)
  • Since each level is stored as a separate table in
    memory, covering a logical address to a physical
    one may take three, four memory accesses.
  • ? if address is 64 bits
  • Even though time needed for one memory access is
    quintupled, caching permits performance to remain
    reasonable.
  • Cache hit rate of 98 percent yields
  • effective access time 0.98 x 120 0.02 x 520
  • 128 nanoseconds.which is only a 28 percent
    slowdown in memory access time.

40
Inverted Page Table
  • ?? page table ?? ? ??? page ??? (disk size) ???
    table ??
  • one page-table-entry per page,
  • ??? ? ???? ??? ???? (?? .AND. Memory
    Resident)
  • Cure let one page-table-entry per page frame
    (?? ??? ?? ??)
  • ??? ? page table entry ? process-id ? ????
  • one page table system-wide -- page frame ????
    entry? ??
  • ?? It is associative search and need to search
    entire table.
  • ?? Either use hash table to limit the search
    (slower)
  • Or use associative registers (expensive)

41
Inverted Page Table Architecture
42
Shared Pages
?oop?? ??? ??? (? address?) increment ???
  • Shared code
  • Re-entrant Code, Non-self-modifying Code eg
    inc memory_address
  • One copy of read-only (re-entrant) code shared
    among processes
  • (eg, 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 data.
  • Private data can appear anywhere in logical
    address space.

P??? P.C. ???? font
P??? P.C. ???? font
P?? P.C. ???? font
hwp code
43
Shared Pages Example
Editor is shared Editor consists of 3 pages --
ed1, ed2, ed3
44
Segmentation
  • A program is a collection of segments.
  • A segment is a logical unit such as
  • main (),
  • function,
  • global variables,
  • stack,
  • symbol table, arrays

45
Users View of a Program
46
Segmentation Architecture
  • Logical address consists of a two tuple
  • lt segment-number, offset gt,
  • Segment table
  • maps two dimensional physical addresses
  • each table entry has
  • base contains the starting physical address
    where the segments reside in memory.
  • limit specifies the length of the segment.
  • Segment-table base register (STBR)
  • points to the segment tables location in memory.
  • Segment-table length register (STLR)
  • indicates number of segments used by a program
  • segment number s is legal if s
    lt STLR.

47
Segmentation Architecture (Cont.)
  • Protection
  • Protection bits associated with segments
  • Each entry
  • validation bit 0 ? illegal segment
  • R/W/X bits
  • Sharing
  • shared segments
  • same segment number
  • Allocation
  • first fit / best fit
  • external fragmentation
  • Since segments vary in length, memory allocation
    is
  • a dynamic storage-allocation problem.

S D L valid rwxa disk_??
Segment length
48
Segmentation Hardware
49
Example of Segmentation
50
Sharing of Segments
51
MULTICS Address Translation Scheme
52
Segmentation with Paging MULTICS
  • The MULTICS system solved problems of external
    fragmentation and lengthy search times
  • by paging the segments.
  • Solution differs from pure segmentation in that
    the segment-table entry contains
  • not the base address of the segment
  • but rather the base address of a page table for
    this segment.

53
Segmentation with Paging Intel 386
segmentation with paging for memory management
with a two-level paging scheme.
Write a Comment
User Comments (0)
About PowerShow.com