8.1. Memory Management
8.1. Memory Management
8.1. Memory Management
Memory Operations
• Fetch instruction from the Memory
• Operands fetching from the memory
• Store the result back into the memory
Swapping
Relocating in
memory
Execution Swap
Allocating
Input memory space
Queue
Process
accesses
The collection of processes instructions and
waiting to be brought into data from
Termination
memory Freeing memory
memory for execution
Address Binding
• Most systems allow a user process to reside in any part of the physical
memory.
• Although the address space of the computer starts at 00000, the first
address of the user process does not need to be 00000.
• The linkage editor or loader will in turn bind these relocatable addresses
to absolute addresses (such as 74014).
How to implement
• We first need to make sure that each process has a
separate memory space
• and can access only that memory space
• we need the ability to determine the range of
legal addresses
• We can provide this protection by using two
registers, usually a base and a limit
• The base register holds the smallest legal
physical memory address;
• the limit register specifies the size of the
range
• This protection must be provided by the hardware.
Memory Protection Hardware
• hardware compares every address generated in user mode with the registers.
• Any attempt by a program executing in user mode to access operating-system
memory or other users' memory results in a trap to the operating system, which treats
the attempt as a fatal error.
• This scheme prevents a user program from (accidentally or deliberately) modifying
the code or data structures of either the operating system or other users.
• The base and limit registers can be loaded only by the operating system, which uses a special
privileged instruction.
• The operating system, executing in kernel mode, is given unrestricted access to both operating
system memory and users' memory.
• This provision allows the operating system to load users' programs into users' memory, to dump out
those programs in case of errors, to access and modify parameters of system calls, and so on.
Memory Protection and
• How Relocation
many Hardware
relocation and limit registers we
need for 3 processes running concurrently on
• With relocation and limit registers one CPU?
• each logical address must be less than the limit register;
• the MMU maps the logical• address dynamically
How many by adding
relocation and the value
limit in the we
registers
relocation register. This mapped address is sent to memory
•
need for 3 processes running on two CPUs?
When the CPU scheduler selects a process for execution, the dispatcher loads the
relocation and limit registers with the correct values as part of the context switch.
• Can the user program change the relocation
74600 and limit registers values to access the
Max logical physical storage wherever it needs?
address 100040
0-74600 100040
100145
105
100040 + 74600
Dynamic Loading
Loading of some modules or libraries is being postponed until their
execution time.
• Routine is not loaded until it is called
• Better memory-space utilization; unused routine is never loaded.
• Useful when large amounts of code are needed to handle infrequently occurring
cases.
• OS not involved in the modules organization. The user program is responsible for it.
So module sharing between different protected processes is not possible
Symbol
Table
Common
Routines
Linked final Linked final
binary module binary module
Relocatable
loader
Module
1 Module
Modules are not loaded 2
until they are called
Dynamic Linking and Shared Libraries
Rather than loading being postponed until execution time, linking is postponed.
OS involved in the modules organization. So module sharing between different protected
processes is possible. This is shared libraries approach.
Advantages of DLL
Fast loading of the main module and of the modules needed at this moment
Saving resources using one library instead of many
Modular architecture
Flexibility of module update
Disadvantage: The sharing of the same library between different processes and the
frequent updates cause version conflict and complexity of update implementation.
Swapping
• A process needs to be in memory to be executed.
• A process, however, can be swapped temporarily out of memory to a backing
store
• and then brought back into memory for continued execution
• Normally a process that is swapped out will be swapped back into the same
memory space that it occupied previously.
• If execution-time binding is
being used, then a process can
be swapped into a different
memory space, because the
physical addresses are
computed during execution
time.