07 MM
07 MM
Memory Management
Background
Swapping
Contiguous Allocation
Paging
Segmentation
Segmentation with Paging
8.2
1
Background
Program must be brought into memory and placed within a process for it to be run
Input queue – collection of processes on the disk that are waiting to be brought into memory
to run the program
8.3
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).
8.4
2
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
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
8.5
In MMU scheme, the value in the relocation register is added to every address generated by
a user process at the time it is sent to memory
The user program deals with logical addresses; it never sees the real physical addresses
8.6
3
Dynamic relocation using a relocation register
8.7
Dynamic Loading
8.8
4
Dynamic Linking
8.9
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
Major part of swap time is transfer time; total transfer time is directly proportional to the
amount of memory swapped
8.10
10
5
Schematic View of Swapping
8.11
11
Contiguous Allocation
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
8.12
12
6
A base and a limit register define a logical address space
8.13
13
8.14
14
7
Contiguous Allocation (Cont.)
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
8.15
15
8.16
16
8
Fragmentation
External Fragmentation
– total memory space
exists to satisfy a
request, but it is not
contiguous
Internal Fragmentation
– allocated memory may
be slightly larger than
requested memory; this
size difference is memory
internal to a partition, but
not being used
Reduce external
fragmentation by
compaction
8.17
17
Paging
8.18
18
9
Address Translation Scheme
Page number (p) – used as an index into a page table which contains base
address of each page in physical memory
Page offset (d) – combined with base address to define the physical memory
address that is sent to the memory unit
8.19
19
8.20
20
10
Paging Example
8.21
21
Paging Example
8.22
22
11
Free Frames
8.23
23
8.24
24
12
Associative Memory
8.25
25
8.26
26
13
Effective Access Time
8.27
27
Memory Protection
8.28
28
14
Valid (v) or Invalid (i) Bit In A Page Table
8.29
29
Hierarchical Paging
8.30
30
15
Hierarchical Page Tables
8.31
31
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
Thus, a logical address is as follows:
10 10 12
where pi is an index into the outer page table, and p2 is the displacement within the page of the outer
page table
8.32
32
16
Two-Level Page-Table Scheme
8.33
33
8.34
34
17
Inverted Page Table
8.35
35
8.36
36
18
Shared Pages
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
8.37
37
8.38
38
19
Segmentation
8.39
39
8.40
40
20
Logical View of Segmentation
4
1
3 2
4
8.41
41
Segmentation Architecture
8.42
42
21
Segmentation Architecture (Cont.)
Relocation.
dynamic
by segment table
Sharing.
shared segments
same segment number
Allocation.
first fit/best fit
external fragmentation
8.43
43
8.44
44
22
Address Translation Architecture
8.45
45
Example of Segmentation
8.46
46
23
Sharing of Segments
8.47
47
8.48
48
24
MULTICS Address Translation Scheme
8.49
49
End
50
25