Ch05 Memory MGT
Ch05 Memory MGT
⚫ Background
⚫ Swapping
⚫ Contiguous Allocation
⚫ Paging
⚫ Segmentation
⚫ Segmentation with Paging
3/7/2017
Background
⚫ Address Binding:
◦ Program resides on disk.
◦ 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
3/7/2017
Binding of Instructions and Data to Memory
⚫ 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).
3/7/2017
Dynamic Loading
⚫ Routine is not loaded until it is called
3/7/2017
Dynamic Linking
⚫ Linking postponed until execution time.
3/7/2017
Memory-Management Unit (MMU)
⚫ Hardware device that maps virtual to physical address.
⚫ The user program deals with logical addresses; it never sees the
real physical addresses.
3/7/2017
Dynamic relocation using a relocation register
⚫ Major part of swap time is transfer time; total transfer time is directly
proportional to the amount of memory swapped.
3/7/2017
Contiguous Allocation
⚫ Main memory usually into two partitions:
◦ Resident operating system, usually held in low memory with interrupt
vector.
⚫ Single-partition allocation
◦ OS is need to be protected from malicious user processes & protect processes
from each other.
OS
◦ Relocation-register scheme used to protect user processes from each other, and
User
from changing operating-system code and data.
3/7/2017
Contiguous Allocation (Cont.)
⚫ Multiple-partition allocation
3/7/2017
Multiple partition Allocation
3/7/2017
Dynamic Storage-Allocation Problem
How to satisfy a request of size n from a list of free holes.
⚫ Best-fit: Allocate the smallest hole that is big enough; must search
entire list, unless ordered by size. Produces the smallest leftover hole.
⚫ Worst-fit: Allocate the largest hole; must also search entire list.
Produces the largest leftover hole.
3/7/2017
Fragmentation
⚫ External Fragmentation – total memory
space exists to satisfy a request, but it is not
contiguous. It is fragmented into a large
number of small holes.
3/7/2017
Fragmentation
⚫ Internal Fragmentation – allocated memory
may be slightly larger than requested memory;
this size difference is memory internal to a
partition, but not being used.
3/7/2017
External fragmentation: Solution
3/7/2017
Paging
⚫ Logical address space of a process can be noncontiguous; process is
allocated physical memory whenever the latter is available.
⚫ To run a program of size n pages, need to find n free frames and load
program.
3/7/2017
Paging Example
3/7/2017
Paging Example:
for a 32-byte memory with 4 byte pages
3/7/2017
● As a concrete (although minuscule) example, consider the
memory in Figure 8.9.
⚫ One bit can define a page to be read-write or read only. Every reference
to memory goes through the page table to find correct frame number.
While computing physical address, protection bits are checked to verify,
no writers are being made to read-only page.
⚫ Illegal attempts are trapped by OS. One more bit is Valid-invalid bit
◦ “invalid” indicates that the page is not in the process’ logical address
3/7/2017
space.
Valid (v) or Invalid (i) Bit In A Page Table
Consider a system with 14 bit address space (0 - 16383)
1 page = 2 KB = 211 = 2048 bytes
A program requires address space 0 - 10468
3/7/2017
Segmentation
⚫ Memory-management scheme that supports user view of memory.
⚫ User prefer to see memory as collection of variable length segments than logical
main program,
procedure,
common block,
stack,
3/7/2017
Logical View of Segmentation
1
1
4
2
3
4
2
<segment-number, offset>,
⚫ Segment table – maps two-dimensional physical addresses; each table entry has:
◦ Segment base – contains the starting physical address where the segments
reside in memory.
memory.
Offset must be
less than limit
3/7/2017
Example of Segmentation
3/7/2017
Segment Protection and Sharing
⚫ With each entry of segment table associate:
◦ Validation bit = 0 => illegal segment
◦ Read/write/execute privilege
3/7/2017
Fragmentation
⚫ Segmentation cause external fragmentation, when all blocks of free
memory are too small to accommodate a segment.
⚫ Solution:
⚫ At the other extreme, each byte as segment . Then every byte need a base
register for its relocation, doubling memory use!
3/7/2017
Segmentation with Paging – Intel 386
⚫ The 386 uses segmentation with paging for memory management.
3/7/2017
Segmentation with Paging – Intel 386
⚫ Each segment is paged.
S g P
3/7/2017
Intel 30386 Address Translation
Segmentation
mechanism
Paging mechanism