Module 7 - Main Memory
Module 7 - Main Memory
26/12/2021
College of Computing and Informatics
OPERATING SYSTEMS
Operating Systems
Module 7
Paging
Swapping
WEEKLY LEARNING OUTCOMES
the instructions to loading the base and limit registers are privileged
MEMORY BINDING
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)
PROCESSING OF USER PROGRAM
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
Logical address space is the set of all logical addresses generated by a program
Physical address space is the set of all physical addresses generated by a program
MEMORY MANAGEMENT UNIT (MMU)
Hardware device that at run time maps virtual to physical address
MEMORY MANAGEMENT UNIT (MMU)
Consider simple scheme. which is a generalization of the base-register scheme.
The base register now called relocation register
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
Execution-time binding occurs when reference is made to location in memory
Logical address bound to physical addresses
MEMORY MANAGEMENT UNIT (MMU)
Consider simple scheme. which is a generalization of the base-register scheme.
The base register now called relocation register
The value in the relocation register is added to every address generated by a user
process at the time it is sent to memory
CONTIGUOUS ALLOCATION
Main memory must support both OS and user processes
Limited resource, must allocate efficiently
Contiguous allocation is one early method
Main memory usually into two partitions:
Resident operating system, usually held in low memory with interrupt vector
User processes then held in high memory
Each process contained in single contiguous section of memory
CONTIGUOUS ALLOCATION
Relocation registers used to protect user processes from each other, and from
changing operating-system code and data
Base register contains value of smallest physical address
Limit register contains range of logical addresses – each logical address must be
less than the limit register
MMU maps logical address dynamically
Can then allow actions such as kernel code being transient and kernel changing
size
HARDWARE SUPPORT
VARIABLE PARTITION
Multiple-partition allocation
Degree of multiprogramming limited by number of partitions
Variable-partition sizes for efficiency (sized to a given process’ needs)
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
Process exiting frees its partition, adjacent free partitions combined
Operating system maintains information about:
a) allocated partitions b) free partitions (hole)
DYNAMIC STORAGE ALLOCATION
First-fit: Allocate the first hole that is big enough
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
First-fit and best-fit better than worst-fit in terms of speed and storage
utilization
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
First fit analysis reveals that given N blocks allocated, 0.5 N blocks lost to
fragmentation
1/3 may be unusable -> 50-percent rule
ADDRESS SPACE
Reduce external fragmentation by Compaction
Shuffle memory 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
Now consider that backing store has same fragmentation problems
PAGING
Physical address space of a process can be noncontiguous; process is allocated physical
memory whenever the latter is available
Avoids external fragmentation
Avoids problem of varying sized memory chunks
Divide physical memory into fixed-sized blocks called frames
Size is power of 2, between 512 bytes and 16 Mbytes
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
Backing store likewise split into pages
Still have Internal fragmentation
ADDRESS TRANSLATION
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
Page offset (d) – combined with base address to define the physical memory
address that is sent to the memory unit
P a ge # F ra m e #
Chapter 3.1
Chapter 3.2
Chapter 3.7
(Modern Operating Systems by Andrew S. Tanenbaum and Herbert Bos. 4th
ed., ISBN-10: 0-13-359162-X, ISBN-13: 978-0-13-359162-0, 2015)
sentation is mainly dependent on the textbook: Operating System Concepts by Silberschatz, Abrah
Thank You