Chapter 8 Update
Chapter 8 Update
Operating System Concepts – 9th Edition 8.2 Silberschatz, Galvin &Gagne ©2013
Objectives
To provide a detailed description of various ways of
organizing memory hardware.
Operating System Concepts – 9th Edition 8.3 Silberschatz, Galvin &Gagne ©2013
Background
Memory is central to the operation of a modern computer
system.
Memory consists of a large array of bytes, each with its own
address.
The CPU fetches instructions from memory according to the
value of the program counter.
Operating System Concepts – 9th Edition 8.5 Silberschatz, Galvin &Gagne ©2013
Basic Hardware
The general-purpose storage that the CPU access
directly are
Main memory
Registers built into the processors
And ensure that the process can access only these legal
addresses.
Main memory & registers are only storage CPU can access
directly.
Operating System Concepts – 9th Edition 8.10 Silberschatz, Galvin &Gagne ©2013
Base & Limit Registers
A pair of base & limit registers define the logical address space.
Operating System Concepts – 9th Edition 8.12 Silberschatz, Galvin &Gagne ©2013
Address Binding
A program resides on a disk as binary executable file.
Operating System Concepts – 9th Edition 8.13 Silberschatz, Galvin &Gagne ©2013
Address Binding
Addresses represented in
different ways at different
stages of a program’s life.
Operating System Concepts – 9th Edition 8.14 Silberschatz, Galvin &Gagne ©2013
Address Binding
Addresses binding of instructions and data to memory addresses can
happen at
three different stages:
Operating System Concepts – 9th Edition 8.16 Silberschatz, Galvin &Gagne ©2013
Binding of Instructions & Data to Memory
Address binding of instructions & data to memory addresses can
happen at
three different stages:
Compile time:
If the compiler is responsible for binding, then it is called
compile-time binding.
Operating System Concepts – 9th Edition 8.18 Silberschatz, Galvin &Gagne ©2013
Binding of Instructions &Data to Memory
Execution time:
If memory location is not known in the previous stages, then
binding delayed until run time.
If the process can be moved during its execution from one
memory segment to another, then binding delayed.
If the address is
known use absolute
Absolute address
generated by hardware
Operating System Concepts – 9th Edition 8.20 Silberschatz, Galvin &Gagne ©2013
Logical vs. Physical Address Space
The concept of a logical address space that is bound to a separate
physical address space is central to proper memory management.
Logical address
Generated by the CPU - also referred to as virtual address.
CPU will execute instruction so it will send the address to
memory.
Memory will convert it into a physical address.
Logical address is different for each process.
The starting is 0 the ending is the limit of the process.
Logical address is used as a reference to access the physical
memory location by CPU.
Physical address
Refers to an actual physical location located in the memory unit.
Address seen by the memory unit.
Operating System Concepts – 9th Edition 8.21 Silberschatz, Galvin &Gagne ©2013
Logical vs. Physical Address Space
Terms logical address physical address
Definitio The CPU generates the logical The physical address is a
n address while the program is location in memory.
running. Actual address of data in
Virtual address because it does memory.
not exist physically.
Location The logical address does not The physical address is a
exist physically in the memory, location in the memory
and therefore it is sometimes unit.
known as a virtual address.
Access The logical address is used as a The physical address
reference to access the physical cannot be accessed
address. directly.
User The user can use the logical Never deals with physical
address to access the physical addresses.
address.
Address The set of all the logical The set of all physical
space addresses generated by the CPU addresses corresponding
is called to the logical addresses in
logical address space. the logical address space
Operating System Concepts – 9th Edition 8.22 Silberschatz, Galvin &Gagne ©2013
Memory-Management Unit (MMU)
A memory management unit (MMU) is a
computer hardware component.
.
Operating System Concepts – 9th Edition 8.23 Silberschatz, Galvin &Gagne ©2013
Memory-Management Unit (MMU)
Operating System Concepts – 9th Edition 8.24 Silberschatz, Galvin &Gagne ©2013
Memory-Management Unit (MMU)
To start, consider simple scheme where the value in the
relocation register is added to every address generated by
a user process at the time it is sent to memory.
Operating System Concepts – 9th Edition 8.25 Silberschatz, Galvin &Gagne ©2013
Dynamic relocation using a relocation register
Routine is not loaded until it is
called. Base Register
Relocation Register
Better memory-space utilization-
unused routine is never loaded.
Operating System Concepts – 9th Edition 8.27 Silberschatz, Galvin &Gagne ©2013
Dynamic Linking
Dynamic loading
Operating System Concepts – 9th Edition 8.29 Silberschatz, Galvin &Gagne ©2013
Dynamic Linking
The advantages:
Useful for libraries – shared libraries.
A routine is loaded only when it is needed.
It is the responsibility of the users to design their
programs to advantage of such a method.
Not OS responsibility but OS help in providing library
routines.
Operating System Concepts – 9th Edition 8.30 Silberschatz, Galvin &Gagne ©2013
Swapping
A process must be in memory to be executed.
Operating System Concepts – 9th Edition 8.32 Silberschatz, Galvin &Gagne ©2013
Schematic View of Swapping
Operating System Concepts – 9th Edition 8.33 Silberschatz, Galvin &Gagne ©2013
Swapping
Operating System Concepts – 9th Edition 8.34 Silberschatz, Galvin &Gagne ©2013
Swapping
Operating System Concepts – 9th Edition 8.35 Silberschatz, Galvin &Gagne ©2013
Swapping
To get an idea of the context-switch time:
Operating System Concepts – 9th Edition 8.36 Silberschatz, Galvin &Gagne ©2013
Swapping (Cont.)
Does the swapped-out process need to swap back into same physical
addresses?
It requires too much swapping time & provides too little execution
time to be
a reasonable memory-management solution.
Operating System Concepts – 9th Edition 8.38 Silberschatz, Galvin &Gagne ©2013
Context Switch Time including Swapping
If next processes to be put on CPU is not in memory, need to
swap out a process & swap in target process – Context
switching.
User processes
Held in high memory.
Each process contained in single contiguous section
of memory.
Operating System Concepts
th
– 9 Edition 8.41 Silberschatz, Galvin &Gagne ©2013
Contiguous Allocation (Cont.)
Operating System Concepts – 9th Edition 8.43 Silberschatz, Galvin &Gagne ©2013
Single Memory allocation
Single Partition Allocation
Disadvantages:
It leads to poor utilization of processor &
memory.
Operating System Concepts – 9th Edition 8.45 Silberschatz, Galvin &Gagne ©2013
Multiple-partition allocation
Fixed Equal-size Partitions
Operating System Concepts – 9th Edition 8.46 Silberschatz, Galvin &Gagne ©2013
Multiple-partition allocation
Fixed Variable size Partitions
Operating System Concepts – 9th Edition 8.47 Silberschatz, Galvin &Gagne ©2013
Multiple-partition allocation
Multiple-partition allocation
Operating System Concepts – 9th Edition 8.48 Silberschatz, Galvin &Gagne ©2013
Dynamic Storage-Allocation Problem
How to satisfy a request of size n from a list of free holes?
Operating System Concepts – 9th Edition 8.51 Silberschatz, Galvin &Gagne ©2013
Fragmentation
Internal Fragmentation
Operating System Concepts – 9th Edition 8.52 Silberschatz, Galvin &Gagne ©2013
Fragmentation (Cont.)
Reduce external fragmentation by compaction.
I/O problem
Latch job in memory while it is involved in I/O
Operating System Concepts – 9th Edition 8.53 Silberschatz, Galvin &Gagne ©2013
Segmentation
Another way of dividing the addressable memory.
Memory-management scheme that supports user view of
memory.
It is a non-contiguous memory allocation technique.
A segment can be defined as a logical grouping of
instructions.
A program is a collection of segments.
A segment is a logical unit such as:
Main program
Function
Method
Object
Local variables, global variables
Common block
Stack
Symbol table
Arrays
Operating System 8.54 Silberschatz, Galvin &Gagne ©2013
Concepts – 9 Edition
th
User’s View of a Program
Operating System Concepts – 9th Edition 8.55 Silberschatz, Galvin &Gagne ©2013
Logical View of Segmentation
4
1
2
3
A segment can be
4 2
identified by:
•Segment number 3
•Segment offset
Operating System Concepts – 9th Edition 8.56 Silberschatz, Galvin &Gagne ©2013
Logical View of Segmentation
Operating System Concepts – 9th Edition 8.57 Silberschatz, Galvin &Gagne ©2013
Segmentation Architecture
Logical address consists of a two tuple:
< segment-number, offset >,
Operating System Concepts – 9th Edition 8.59 Silberschatz, Galvin &Gagne ©2013
Segmentation Hardware
Operating System Concepts – 9th Edition 8.61 Silberschatz, Galvin &Gagne ©2013
Paging
Segmentation permits the physical address space of a
process to be
non-contiguous memory allocation.
Paging is another memory management scheme that offers
this advantage.
Paging avoids:
External fragmentation
Compaction
Operating System Concepts – 9th Edition 8.63 Silberschatz, Galvin &Gagne ©2013
Paging
Operating System Concepts – 9th Edition 8.67 Silberschatz, Galvin &Gagne ©2013
Implementation of Page Table
Operating System Concepts – 9th Edition 8.68 Silberschatz, Galvin &Gagne ©2013
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.
Operating System Concepts – 9th Edition 8.69 Silberschatz, Galvin &Gagne ©2013
Address Translation Scheme
Physical Address is divided into:
Frame number ( f ): Number of bits required to represent
the frame of Physical Address Space or Frame number.
Operating System Concepts – 9th Edition 8.70 Silberschatz, Galvin &Gagne ©2013
Paging Hardware
How to implement are paging?
•We use Page no. and offset
•Page no index into a page table.
•Page table hold the Frame number
•The offset index into the byte itself within the Page
•For physical address, we have Frame no and offset no.
•Frame no. index into correct Frame in physical memory
Operating System Concepts – 9th Edition 8.71 Silberschatz, Galvin &Gagne ©2013
Paging Model of Logical & Physical Memory
Operating System Concepts – 9th Edition 8.72 Silberschatz, Galvin &Gagne ©2013
Paging Example
Frame no.
4 bytes or
Page 0
line in each 0
page
Page 1 P2
1
Page 2 2
Page 3 3
1.G is in Page 1 6 P1
2.Go to the table and find the frame no.
3.6 * page size 4 = 24.
4.Now go to address 24 in frame 6. 7
5.Inside page 1 it is offset d = 2 so it is the same d in
RAM
Operating System Concepts – 9th Edition 8.73 Silberschatz, Galvin &Gagne ©2013
Paging Example
• If page size = 2 bytes
Operating System Concepts – 9th Edition 8.74 Silberschatz, Galvin &Gagne ©2013
Paging Example
Operating System Concepts – 9th Edition 8.77 Silberschatz, Galvin &Gagne ©2013
Paging Example
• CPU generate
logical address
101,
• find the physical
address
• Which page?
• Which byte?
• This address
belongs to page
10 & byte 1.
• Go to the page
table.
• Frame no. 011
• Check the byte
no. 1. in
physical
memory
• The result is f.
• So the physical
address is 011 +
1 = 0111
Operating System Concepts – 9th Edition 8.78 Silberschatz, Galvin &Gagne ©2013
Paging (Cont.)
Calculating internal fragmentation:
Page size = 2,048 bytes
Process size = 72,766 bytes
35 pages (process size / Page size) + 1,086 bytes remaining so
we need 36 pages.
Internal fragmentation = page size 2,048 - 1,086 = 962 bytes.
Worst case fragmentation = 1 frame is 1 byte (page size + 1
byte) extra frame with 2047 bytes free space (internal
fragmentation)
On average fragmentation = ½ frame size (½ 1 MB or ½ 2KB)
Operating System Concepts – 9th Edition 8.80 Silberschatz, Galvin &Gagne ©2013
Implementation of Page Table
Page table is kept in main memory.
Operating System Concepts – 9th Edition 8.81 Silberschatz, Galvin &Gagne ©2013
Implementation of Page Table
Translation Lookaside Buffer (TLB).
Operating System Concepts – 9th Edition 8.82 Silberschatz, Galvin &Gagne ©2013
Paging Hardware With TLB
Operating System Concepts – 9th Edition 8.83 Silberschatz, Galvin &Gagne ©2013
Paging
Advantages of Paging
The memory management algorithm is easy to use.
External Fragmentation is not required.
Swapping between equal-sized pages and page frames
becomes easier.
Disadvantages of Paging
Internal fragmentation.
Additional memory consumption by page tables.
Memory reference overhead due to multi-level paging.
Operating System Concepts – 9th Edition 8.84 Silberschatz, Galvin &Gagne ©2013
Two-Level Page-Table Scheme
Operating System Concepts – 9th Edition 8.85 Silberschatz, Galvin &Gagne ©2013
Paging
Process size = 4 B
Operating System Concepts – 9th Edition 8.86 Silberschatz, Galvin &Gagne ©2013
Implementation of Page Table (Cont.)
Some TLBs store address-space identifiers (ASIDs)
in each TLB entry – uniquely identifies each
process to provide address-space protection for
that process
Otherwise need to flush at every context
switch
TLBs typically small (64 to 1,024 entries)
On a TLB miss, value is loaded into the TLB for
faster access next time
Replacement policies must be considered
Some entries can be wired down for permanent
fast access
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.87 Silberschatz, Galvin &Gagne ©2013
Associative Memory
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.88 Silberschatz, Galvin &Gagne ©2013
Paging Hardware With TLB
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.89 Silberschatz, Galvin &Gagne ©2013
Effective Access Time
Associative Lookup = time unit
Can be < 10% of memory access time
Hit ratio =
Hit ratio – percentage of times that a page number is
found in the associative registers; ratio related to
number of associative registers
Consider = 80%, = 20ns for TLB search, 100ns for
memory access
Effective Access Time (EAT)
EAT = (1 + ) + (2 + )(1 – )
=2+–
Consider = 80%, = 20ns for TLB search, 100ns for
memory access
EAT = 0.80 x 100 + 0.20 x 200 = 120ns
Consider more realistic hit ratio -> = 99%, = 20ns for
TLB search, 100ns for memory access
(Out of Syllabus)
EAT = 0.99 x 100 + 0.01 x 200 = 101ns
Operating System Concepts – 9th Edition 8.90 Silberschatz, Galvin &Gagne ©2013
Memory Protection
Memory protection implemented by associating
protection bit with each frame to indicate if read-
only or read-write access is allowed
Can also add more bits to indicate page
execute-only, &so on
Valid-invalid bit attached to each entry in the page
table:
“valid” indicates that the associated page is in
the process’ logical address space, &is thus a
legal page
“invalid” indicates that the page is not in the
process’ logical address space
Or use page-table length register (PTLR)
Any violations result in a trap to the kernel
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.91 Silberschatz, Galvin &Gagne ©2013
Valid (v) or Invalid (i) Bit In A Page Table
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.92 Silberschatz, Galvin &Gagne ©2013
Shared Pages
Shared code
One copy of read-only (reentrant) code shared
among processes (i.e., text editors, compilers,
window systems)
Similar to multiple threads sharing the same
process space
Also useful for interprocess communication if
sharing of read-write pages is allowed
Private code &data
Each process keeps a separate copy of the
code &data
The pages for the private code &data can
appear anywhere in the logical address space
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.93 Silberschatz, Galvin &Gagne ©2013
Shared Pages Example
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.94 Silberschatz, Galvin &Gagne ©2013
Structure of the Page Table
Memory structures for paging can get huge using
straight-forward methods
Consider a 32-bit logical address space as on
modern computers
Page size of 4 KB (212)
Page table would have 1 million entries (232 / 212)
If each entry is 4 bytes -> 4 MB of physical address
space / memory for page table alone
That amount of memory used to cost a lot
Don’t want to allocate that contiguously in main
memory
Hierarchical Paging
Hashed Page Tables
Inverted Page Tables
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.95 Silberschatz, Galvin &Gagne ©2013
Hierarchical Page Tables
Break up the logical address space into
multiple page tables
A simple technique is a two-level page
table
We then page the page table
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.96 Silberschatz, Galvin &Gagne ©2013
Two-Level Page-Table Scheme
Operating System Concepts – 9th Edition 8.97 Silberschatz, Galvin &Gagne ©2013
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
Operating System Concepts – 9th Edition 8.98 Silberschatz, Galvin &Gagne ©2013
Address-Translation Scheme
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.99 Silberschatz, Galvin &Gagne ©2013
64-bit Logical Address Space
Operating System Concepts – 9th Edition 8.100 Silberschatz, Galvin &Gagne ©2013
Three-level Paging Scheme
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.101 Silberschatz, Galvin &Gagne ©2013
Hashed Page Tables
Common in address spaces > 32 bits
The virtual page number is hashed into a page table
This page table contains a chain of elements hashing to
the same location
Each element contains (1) the virtual page number (2) the
value of the mapped page frame (3) a pointer to the next
element
Virtual page numbers are compared in this chain searching
for a match
If a match is found, the corresponding physical frame is
extracted
Variation for 64-bit addresses is clustered page tables
Similar to hashed but each entry refers to several pages
(such as 16) rather than 1
Especially useful for sparse address spaces (where
memory references are non-contiguous &scattered)
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.102 Silberschatz, Galvin &Gagne ©2013
Hashed Page Table
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.103 Silberschatz, Galvin &Gagne ©2013
Inverted Page Table
Rather than each process having a page table
&keeping track of all possible logical pages, track all
physical pages
One entry for each real page of memory
Entry consists of the virtual address of the page
stored in that real memory location, with information
about the process that owns that page
Decreases memory needed to store each page table,
but increases time needed to search the table when a
page reference occurs
Use hash table to limit the search to one — or at most
a few — page-table entries
TLB can accelerate access
But how to implement shared memory?
One mapping of a virtual address to the shared
(Out of Syllabus)
physical address
Operating System Concepts – 9th Edition 8.104 Silberschatz, Galvin &Gagne ©2013
Inverted Page Table Architecture
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.105 Silberschatz, Galvin &Gagne ©2013
Oracle SPARC Solaris
Consider modern, 64-bit operating system example
with tightly integrated HW
Goals are efficiency, low overhead
Based on hashing, but more complex
Two hash tables
One kernel &one for all user processes
Each maps memory addresses from virtual to
physical memory
Each entry represents a contiguous area of mapped
virtual memory,
More efficient than having a separate hash-table
entry for each page
Each entry has base address & span (indicating the
number of pages the entry represents)
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.106 Silberschatz, Galvin &Gagne ©2013
Oracle SPARC Solaris (Cont.)
TLB holds translation table entries (TTEs) for fast
hardware lookups
A cache of TTEs reside in a translation storage
buffer (TSB)
Includes an entry per recently accessed page
Virtual address reference causes TLB search
If miss, hardware walks the in-memory TSB looking
for the TTE corresponding to the address
If match found, the CPU copies the TSB entry into
the TLB &translation completes
If no match found, kernel interrupted to search
the hash table
– The kernel then creates a TTE from the
appropriate hash table &stores it in the TSB,
Interrupt handler returns control to the MMU,
(Out of Syllabus)
which completes the address translation.
Operating System Concepts – 9th Edition 8.107 Silberschatz, Galvin &Gagne ©2013
Example: The Intel 32 &64-bit Architectures
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.108 Silberschatz, Galvin &Gagne ©2013
Example: The Intel IA-32 Architecture
Supports both segmentation &segmentation with
paging
Each segment can be 4 GB
Up to 16 K segments per process
Divided into two partitions
First partition of up to 8 K segments are
private to process (kept in local descriptor
table (LDT))
Second partition of up to 8K segments shared
among all processes (kept in global descriptor
table (GDT))
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.109 Silberschatz, Galvin &Gagne ©2013
Example: The Intel IA-32 Architecture (Cont.)
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.110 Silberschatz, Galvin &Gagne ©2013
Logical to Physical Address Translation in IA-32
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.111 Silberschatz, Galvin &Gagne ©2013
Intel IA-32 Segmentation
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.112 Silberschatz, Galvin &Gagne ©2013
Intel IA-32 Paging Architecture
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.113 Silberschatz, Galvin &Gagne ©2013
Intel IA-32 Page Address Extensions
32-bit address limits led Intel to create page address extension (PAE),
allowing 32-bit apps access to more than 4GB of memory space
Paging went to a 3-level scheme
Top two bits refer to a page directory pointer table
Page-directory &page-table entries moved to 64-bits in size
Net effect is increasing address space to 36 bits – 64GB of
physical memory
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.114 Silberschatz, Galvin &Gagne ©2013
Intel x86-64
Current generation Intel x86 architecture
64 bits is ginormous (> 16 exabytes)
In practice only implement 48 bit addressing
Page sizes of 4 KB, 2 MB, 1 GB
Four levels of paging hierarchy
Can also use PAE so virtual addresses are 48 bits
&physical addresses are 52 bits
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.115 Silberschatz, Galvin &Gagne ©2013
Example: ARM Architecture
Dominant mobile platform
chip (Apple iOS &Google
Android devices for example)
Modern, energy efficient, 32-
bit CPU
4 KB &16 KB pages
1 MB &16 MB pages (termed
sections)
One-level paging for sections,
two-level for smaller pages
Two levels of TLBs
Outer level has two
micro TLBs (one data,
one instruction)
Inner is single main TLB
First inner is checked,
on miss outers are
checked, &on miss
page table walk
performed by CPU
(Out of Syllabus)
Operating System Concepts – 9th Edition 8.116 Silberschatz, Galvin &Gagne ©2013
End of Chapter 8