INTRODUCTION
TO
OPERATING SYSTEMS
Lecture 10: MEMORY MANAGEMENT (1)
CHRIS STAFF
Dept. of Computer Science and Artificial Intelligence
University of Malta
Lecture Outline
Aims and Objectives
Issues
Objectives of a Memory Management (MM) System
Virtual Memory
Address Translation Mechanism
Aims and Objectives
- Issues
- Objectives
- Virtual Memory
- Converting Virtual Memory Addresses into Physical Addresses
Issues
- Function of Layer 3, in hierarchical model of OS
- Processes and data need to be in Primary Memory (PM) in order to be operated
on, so processes compete for this resource.
- PM is finite, but must be available for the best runnable process
- Poor usage of PM can detrimentally effect usage of other resources and user
response times
- In a multiprogramming environment, many processes and their data can be
simultaneously co-resident in PM. Need to protect them from each other
Objectives of a Memory Management (MM) System
Relocation
- Relocatability - the ability to move process around in memory without
it affecting its execution
- OS manages memory, not programmer, and processes may be moved around in
memory
- MM must convert program's logical addresses into physical addresses
- Process's first address is stored as virtual address 0
- Static Relocation - Program must be relocated before or during loading
of process into memory. Program must always be loaded into same address space
in memory, or relocator must be run again.
- Dynamic Relocation - Process can be freely moved around in memory.
Virtual-to-physical address space mapping is done at run-time.
Protection
- Write Protection - to prevent data & instructions from being
over-written.
- Read Protection - To ensure privacy of data & instructions.
- OS needs to be protected from user processes, and user processes need to be
protected from each other.
- Memory protection (to prevent memory overlaps) is usually supported by the
hardware (limit registers), because most languages allow memory addresses to be
computed at run-time.
Sharing
- Sometimes distinct processes may need to execute the same process (e.g., many
users executing same editor), or even the same data (when one process prepares
data for another process).
- When different processes signal or wait the same semaphore, they need to
access the same memory address.
- OS has to allow sharing, while at the same time ensure protection.
Logical Organisation of Memory
Virtual Memory
- OS manages the location of processes in memory. Programmer does not need to
know where process is - Virtual Machine.
- Compiler / Interpreter calculates program addresses in relation to the
virtual address 0 (first instruction).
- Dynamic Address Translation Mechanism - transforms virtual addresses
into physical addresses. Virtual address space can be smaller or same size as
PM.
Address Translation Mechanism
- DAT mechanism must maintain address translation maps, to indicate where in PM
are the virtual storage locations
- Organisation of Virtual Memory and PM can be completely different
- Blocks of addresses are mapped, because of overhead of mapping invididual
addresses - the block mapping system
- The larger the block, the smaller the address map, but the fewer the number
of processes that can be resident in PM (one process to a block, but many
blocks to a process)
- If all blocks are the same size, then the block is called a Page
- If blocks can be different sizes, then each block is called a
segment
- A segment can be composed of pages - this is called a
Paging/Segmentation System
Addressing in a block mapping system
- Relocation can be provided by putting the base address of the process into
the base register after a context switch
- Protection of memory space is provided by adding a limit register
which contains the length of the address space available to the process.
- This scheme allows for processes (and all of a process) to be resident in
PM
- only one block of instructions of the current process are required to be in
memory. If only these were in PM, with the rest occupying the slower Virtual
Memory extension in secondary storage, then more PM space would be available
for other processes
- Address map now has to say where in secondary storage the block containing
the address can be found if it is not in PM.
Next Lecture...
Memory Management (2)