1.main Memory
1.main Memory
Unit – 3
1. Main Memory
Swapping
Contiguous Memory Allocation
Paging
Structure of the Page Table
Segmentation
2. Virtual Memory
Demand Paging
Process Creation
Page Replacement
Allocation of Frames
Thrashing
Operating System Concepts – 7th Edition, Feb 22, 2005 8.2 Silberschatz, Galvin and Gagne ©2005
Objectives
Operating System Concepts – 7th Edition, Feb 22, 2005 8.3 Silberschatz, Galvin and Gagne ©2005
Logical vs. Physical Address Space
Operating System Concepts – 7th Edition, Feb 22, 2005 8.4 Silberschatz, Galvin and Gagne ©2005
Memory-Management Unit (MMU)
The user program deals with logical addresses; it never sees the
real physical addresses
Operating System Concepts – 7th Edition, Feb 22, 2005 8.5 Silberschatz, Galvin and Gagne ©2005
Swapping
Major part of swap time is transfer time; total transfer time is directly
proportional to the amount of memory swapped
Operating System Concepts – 7th Edition, Feb 22, 2005 8.6 Silberschatz, Galvin and Gagne ©2005
Schematic View of Swapping
Operating System Concepts – 7th Edition, Feb 22, 2005 8.7 Silberschatz, Galvin and Gagne ©2005
Contiguous Allocation
Operating System Concepts – 7th Edition, Feb 22, 2005 8.8 Silberschatz, Galvin and Gagne ©2005
CPUs two modes:
supervisor mode: The supervisor mode is used by
the operating system's kernel for low level tasks
that need unrestricted access to hardware, such
as controlling how memory is written and erased,
and communication with devices like graphics
cards.
protected mode : Protected mode, in contrast, is
used for almost everything else. Applications
operate within protected mode, and can only use
hardware by communicating with the kernel, which
controls everything in supervisor mode
Operating System Concepts – 7th Edition, Feb 22, 2005 8.9 Silberschatz, Galvin and Gagne ©2005
Contiguous Allocation (Cont.)
Partitioning :
1. Fixed Sized Partitioning
2. Variable Sized Partitioning
100KB
50KB
375KB
150KB
75KB
Operating System Concepts – 7th Edition, Feb 22, 2005 8.10 Silberschatz, Galvin and Gagne ©2005
Fragments - Holes
Internal Fragmentation – Within a partition the left out memory after
placing a process in the partition is said to be “Internal
Fragmentation”
P1 = 50KB
P1 100KB
100KB
Hole=50KB
P2 100KB 100KB
Operating System Concepts – 7th Edition, Feb 22, 2005 8.11 Silberschatz, Galvin and Gagne ©2005
Fragments - Holes
External Fragmentation – total memory space exists to satisfy a
request, but it is not contiguous is said to be “External
Fragmentation”
p2
Hole=50KB
Operating System Concepts – 7th Edition, Feb 22, 2005 8.12 Silberschatz, Galvin and Gagne ©2005
Compaction or Garbage Collection
Compaction: Collecting all internal fragments to form a free block
which is contiguous is called compaction or Garbage Collection.
Holes or Internal fragments can be used only after compaction
P1 = 50KB P1 = 50KB
p1 Allocated
Partitions
Hole=50KB P2 = 50KB
P2 = 50KB
Contiguous Free
p2 block of contiguous
100KB Block
Hole=50KB
Operating System Concepts – 7th Edition, Feb 22, 2005 8.13 Silberschatz, Galvin and Gagne ©2005
Dynamic Storage-Allocation Problem
Operating System Concepts – 7th Edition, Feb 22, 2005 8.14 Silberschatz, Galvin and Gagne ©2005
Dynamic Storage-Allocation Problem
Given Memory Partitions of 100KB, 500KB, 200KB, 300KB, & 600KB(in order), how would each of the
(i)First – fit
(ii)Best – fit
(iii)Worst – fit
algorithms place processes of 212KB, 417KB,112KB & 426KB (in order)?. Which algorithm makes the most
Operating System Concepts – 7th Edition, Feb 22, 2005 8.15 Silberschatz, Galvin and Gagne ©2005
Problems
Operating System Concepts – 7th Edition, Feb 22, 2005 8.16 Silberschatz, Galvin and Gagne ©2005
Fragmentation
Operating System Concepts – 7th Edition, Feb 22, 2005 8.17 Silberschatz, Galvin and Gagne ©2005
Paging
Operating System Concepts – 7th Edition, Feb 22, 2005 8.18 Silberschatz, Galvin and Gagne ©2005
No External fragmentation but there may be Internal
fragmentation.
Example:
Page Size = 2,048 Bytes
Process Size = 72,766 Bytes
Frames Required = 72,766 / 2,048
= 35 + 1,086 Bytes
Total Frames needed = (35 + 1) = 36
Internal Fragmentation in 36th Frame ?
= 2048 – 1086 = 962Bytes
Operating System Concepts – 7th Edition, Feb 22, 2005 8.19 Silberschatz, Galvin and Gagne ©2005
Address Translation Scheme
Operating System Concepts – 7th Edition, Feb 22, 2005 8.20 Silberschatz, Galvin and Gagne ©2005
Paging Hardware
Operating System Concepts – 7th Edition, Feb 22, 2005 8.21 Silberschatz, Galvin and Gagne ©2005
Paging Model of Logical and Physical Memory
Operating System Concepts – 7th Edition, Feb 22, 2005 8.22 Silberschatz, Galvin and Gagne ©2005
Paging Example
Operating System Concepts – 7th Edition, Feb 22, 2005 8.24 Silberschatz, Galvin and Gagne ©2005
User’s View of a Program
Operating System Concepts – 7th Edition, Feb 22, 2005 8.25 Silberschatz, Galvin and Gagne ©2005
Logical View of Segmentation
4
1
3 2
4
Operating System Concepts – 7th Edition, Feb 22, 2005 8.26 Silberschatz, Galvin and Gagne ©2005
Segmentation Architecture
Operating System Concepts – 7th Edition, Feb 22, 2005 8.27 Silberschatz, Galvin and Gagne ©2005
Segmentation Hardware
Operating System Concepts – 7th Edition, Feb 22, 2005 8.28 Silberschatz, Galvin and Gagne ©2005
Example of Segmentation
1. Segment 2 is 400 bytes long
and begins at location 4300.
Thus a reference to a byte 53
of segment 2 is mapped on to
the location 4300+53 = 4353
2. Segment 3 – Reference 852
Is mapped to 3200 + 852 =
4052
Operating System Concepts – 7th Edition, Feb 22, 2005 8.29 Silberschatz, Galvin and Gagne ©2005
Free Frames
Operating System Concepts – 7th Edition, Feb 22, 2005 8.30 Silberschatz, Galvin and Gagne ©2005
Memory Protection
Operating System Concepts – 7th Edition, Feb 22, 2005 8.31 Silberschatz, Galvin and Gagne ©2005
Valid (v) or Invalid (i) Bit In A Page Table
Operating System Concepts – 7th Edition, Feb 22, 2005 8.32 Silberschatz, Galvin and Gagne ©2005
Shared Pages
Shared code
Operating System Concepts – 7th Edition, Feb 22, 2005 8.33 Silberschatz, Galvin and Gagne ©2005
Shared Pages Example
Operating System Concepts – 7th Edition, Feb 22, 2005 8.34 Silberschatz, Galvin and Gagne ©2005
Implementation of Page Table
Operating System Concepts – 7th Edition, Feb 22, 2005 8.35 Silberschatz, Galvin and Gagne ©2005
Associative Memory
Operating System Concepts – 7th Edition, Feb 22, 2005 8.36 Silberschatz, Galvin and Gagne ©2005
Paging Hardware With TLB
Operating System Concepts – 7th Edition, Feb 22, 2005 8.37 Silberschatz, Galvin and Gagne ©2005
Effective Access Time
Operating System Concepts – 7th Edition, Feb 22, 2005 8.38 Silberschatz, Galvin and Gagne ©2005
Structure of the Page Table
Hierarchical Paging
Operating System Concepts – 7th Edition, Feb 22, 2005 8.39 Silberschatz, Galvin and Gagne ©2005
Hierarchical Page Tables
Operating System Concepts – 7th Edition, Feb 22, 2005 8.40 Silberschatz, Galvin and Gagne ©2005
Two-Level Page-Table Scheme
Operating System Concepts – 7th Edition, Feb 22, 2005 8.41 Silberschatz, Galvin and Gagne ©2005
Two-Level Paging Example
A logical address (on 32-bit machine with 1K page size) is divided into:
a page number consisting of 22 bits
a page offset consisting of 10 bits
Since the page table is paged, the page number is further divided into:
a 12-bit page number
a 10-bit page offset
Thus, a logical address is as follows:
12 10 10
where pi is an index into the outer page table, and p2 is the displacement within
the page of the outer page table
Operating System Concepts – 7th Edition, Feb 22, 2005 8.42 Silberschatz, Galvin and Gagne ©2005
Address-Translation Scheme
Operating System Concepts – 7th Edition, Feb 22, 2005 8.43 Silberschatz, Galvin and Gagne ©2005
Three-level Paging Scheme
Operating System Concepts – 7th Edition, Feb 22, 2005 8.44 Silberschatz, Galvin and Gagne ©2005
Hashed Page Tables
The virtual page number is hashed into a page table. This page
table contains a chain of elements hashing to the same location.
Operating System Concepts – 7th Edition, Feb 22, 2005 8.45 Silberschatz, Galvin and Gagne ©2005
Hashed Page Table
Operating System Concepts – 7th Edition, Feb 22, 2005 8.46 Silberschatz, Galvin and Gagne ©2005
Inverted Page Table
Operating System Concepts – 7th Edition, Feb 22, 2005 8.47 Silberschatz, Galvin and Gagne ©2005
Inverted Page Table Architecture
Operating System Concepts – 7th Edition, Feb 22, 2005 8.48 Silberschatz, Galvin and Gagne ©2005