Memory Mar 4
Memory Mar 4
Memory
Address binding of instructions and data to memory addresses can
happen at three different stages.
3/3/2004 1 3/3/2004 2
3/3/2004 5 3/3/2004 6
1
Schematic View of Swapping
Swapping
A process can be swapped temporarily out of
memory to a backing store, and then brought back
into memory for continued execution.
Backing store – fast disk large enough to
accommodate copies of all memory images for all
users; must provide direct access to these memory
images.
Roll out, roll in – swapping variant used for priority-
based scheduling algorithms; lower-priority process is
swapped out so higher-priority process can be loaded
and executed.
3/3/2004 7 3/3/2004 8
Single-partition allocation
Relocation-register scheme used to protect user
Dynamic Storage-Allocation
Contiguous Allocation (Cont.) Problem
Multiple-partition allocation How to satisfy a request of size n from a list of free holes.
Hole – block of available memory; holes of various size are
scattered throughout memory.
First-fit: Allocate the first hole that is big
When a process arrives, it is allocated memory from a hole
enough.
large enough to accommodate it.
Operating system maintains information about:
Best-fit: Allocate the smallest hole that is big
a) allocated partitions b) free partitions (hole) enough; must search entire list, unless ordered
OS OS OS OS
by size. Produces the smallest leftover hole.
process 5 process 5 process 5 process 5
Worst-fit: Allocate the largest hole; must also
process 9 process 9 search entire list. Produces the largest leftover
process 8 process 10
hole.
First-fit and best-fit better than worst-fit in
process 2 process 2 process 2 process 2
terms of speed and storage utilization.
3/3/2004 11 3/3/2004 12
2
Fragmentation Paging
External Fragmentation – total memory space exists to Logical address space of a process can be noncontiguous;
satisfy a request, but it is not contiguous. process is allocated physical memory whenever the latter is
Internal Fragmentation – allocated memory may be slightly available.
larger than requested memory; this size difference is memory Divide physical memory into fixed-sized blocks called frames
internal to a partition, but not being used.
(size is power of 2, between 512 bytes and 8192 bytes).
Reduce external fragmentation by compaction
Divide logical memory into blocks of same size called pages.
Shuffle memory contents to place all free memory together
in one large block. Keep track of all free frames.
Compaction is possible only if relocation is dynamic, and is To run a program of size n pages, need to find n free frames
done at execution time. and load program.
I/O problem Set up a page table to translate logical to physical addresses.
Latch job in memory while it is involved in I/O. Internal fragmentation.
Do I/O only into OS buffers.
3/3/2004 13 3/3/2004 14
Address Translation
Address Translation Scheme Architecture
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.
3/3/2004 17 3/3/2004 18
3
Free Frames 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
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
Before allocation After allocation called associative memory or translation look-aside
buffers (TLBs)
3/3/2004 19 3/3/2004 20
3/3/2004 23 3/3/2004 24