Background - Swapping - Contiguous Allocation - Paging - Segmentation - Segmentation With Paging
Background - Swapping - Contiguous Allocation - Paging - Segmentation - Segmentation With Paging
Background - Swapping - Contiguous Allocation - Paging - Segmentation - Segmentation With Paging
Memory Management
• Background
• Swapping
• Contiguous Allocation
• Paging
• Segmentation
• Program must be brought into memory and placed within a process for it to
be run.
• 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).
• 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.
• The user program deals with logical addresses; it never sees the real
physical addresses.
• 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.
• Keep in memory only those instructions and data that are needed at any given
time.
• 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.
• Single-partition allocation
– Relocation-register scheme used to protect user processes from each other, and
from changing operating-system code and data.
– Relocation register contains value of smallest physical address; limit register
contains range of logical addresses – each logical address must be less than the
limit register.
• 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 8 process 10
First-fit and best-fit better than worst-fit in terms of speed and storage
utilization.
– Page offset (d) – combined with base address to define the physical
memory address that is sent to the memory unit.
• 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)
• Hit ratio – percentage of times that a page number is found in the associative
registers; ration related to number of associative registers.
• Hit ratio =
• Hierarchical Paging
• 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.
10 10 12
• Virtual page numbers are compared in this chain searching for a match.
If a match is found, the corresponding physical frame is extracted.
• 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.
• Shared code
– One copy of read-only (reentrant) code shared among processes
(i.e., text editors, compilers, window systems).
– Shared code must appear in same location in the logical address space of
all processes.
4
1
3 2
4
• 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.
• Relocation.
– dynamic
– by segment table
• Sharing.
– shared segments
– same segment number
• Allocation.
– first fit/best fit
– external fragmentation
• Protection bits associated with segments; code sharing occurs at segment level.
• 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.