Lecture (Chapter 9)
Lecture (Chapter 9)
Firoz Mahmud
Assistant Professor
Dept. of Computer Science & Engineering
Rajshahi University of Engineering & Technology
Background
Swapping
Contiguous Memory Allocation
Paging
Structure of the Page Table
Segmentation
Example: The Intel Pentium
To provide a detailed description of various
ways of organizing memory hardware.
To discuss various memory-management
techniques, including paging and segmentation.
To provide a detailed description of the Intel
Pentium, which supports both pure segmentation
and segmentation with paging.
Program must be brought (from disk) into memory
and placed within a process for it to be run.
Main memory and registers are only storage CPU can
access directly.
Register access in one CPU clock (or less).
Main memory can take many cycles.
Cache sits between main memory and CPU registers.
Protection of memory required to ensure correct
operation.
A pair of base and limit registers define the
logical address space
Address binding of instructions and data to memory
addresses can happen at three different stages:
Compile time: If memory location known a priori,
absolute code can be generated; must recompile code if
starting location changes.
Load time: Must generate relocatable code if memory
location is not known at compile time.
Execution time: Binding delayed until run time if the
process can be moved during its execution from one
memory segment to another. Need hardware support for
address maps (e.g., base and limit registers).
Source program
Dynamically
loaded system Loader
library
In-memory binary Execution time
Dynamic linking
memory image (run time)
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.
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
Hardware device that maps virtual to physical
address.
Backing store – fast disk large enough to accommodate copies of all memory
images for all users; must provide direct access to these memory images.
Major part of swap time is transfer time; total transfer time is directly
proportional to the amount of memory swapped
Modified versions of swapping are found on many systems (i.e., UNIX, Linux,
and Windows)
System maintains a ready queue of ready-to-run processes which have
memory images on disk
Main memory usually into two partitions:
Resident operating system, usually held in low memory with
interrupt vector.
User processes then held in high memory.
OS OS OS OS
process 8 process 10
Internal Fragmentation
External Fragmentation
300KB P1
P1
hole
hole 20KB
200KB P2
P2 512KB
180KB hole
180KB hole
P3
P3
185KB
hole
270KB
Reduce external fragmentation by compaction
Shufflememory 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
Logical address space of a process can be noncontiguous;
process is allocated physical memory whenever the latter is
available.
Divide physical memory into fixed-sized blocks called frames
(size is power of 2, between 512 bytes and 8,192 bytes).
Divide logical memory into blocks of same size called pages.
Keep track of all free frames.
To run a program of size n pages, need to find n free frames
and load program.
Set up a page table to translate logical to physical addresses.
Internal fragmentation.
Address generated by CPU is divided into:
7 Page 3
Physical memory
Before allocation After allocation
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 the
page table.
In this scheme every data/instruction access requires two
memory accesses. One for the page table and one for the
data/instruction.
The two memory access problem can be solved by the use
of a special fast-lookup hardware cache called associative
memory or translation look-aside buffers (TLBs).
Some TLBs store address-space identifiers (ASIDs) in
each TLB entry – uniquely identifies each process to provide
address-space protection for that process.
Associative memory – parallel search
Page # Frame #
4
1
3 2
4