Memory management - Part 1 : Sharing
The OS provides 4 major functions to manage the virtual memory:
- Replacement : which page should be deleted to make room for other pages
- Allocation : how many pages per process should be allocated
- Fetching : when bring a page into memory
- Placement : where in memory we should place a page
Memory management has 2 purposes :
- memory protection
- memory sharing
Some challenges need to be considered while sharing memory :
- Transparency : processes must co-exist
- Safety
- Efficiency
- Relocation : program should run in different memory locations
To co-exist, memory is divided into categories:
- program & data
- read-only & read-write
- addresses & data
To execute the program, the system follows some procedures:
- compile (translate) : creates the object code
- link : combine into executable code
- load : copy code into memory
- execute : dynamic memory allocation
The main challenges with the linker are about :
- relocation : where to put pieces
- resolving references : where to find pieces
- re-organization
Relocation, one of the issues that might be encountered in memory sharing, is also a synonym of address binding: it’s mapping instructions and data into virtual memory.
There are 2 types of address binding:
- static : locations are predefined before execution
- dynamic : locations determined during execution
When the address binding is of a static type, 2 moments are noteworthy:
- compile time : translates symbolic addresses into absolute addresses
- load time : absolute addresses are mapped to relocatable addresses.
On a dynamic type address binding, the mapping it’s done by hardware components on running time.
We can have 3 types of loading :
- absolute loading : always in a designated place
- relocatable loading : loading in different locations
- dynamic loading : loads function when called.
The memory loading can occur in 3 ways:
- Direct placement : no relocation
- Overlays : tree-like structure (root is in the memory, sub-trees loaded as needed)
- Partitioning : several programs in memory in the same time (static: memory divided in fixed number of partitions, dynamic : loaded as long as there is room).
In the share memory process, fragmentation can occur. Fragmentation is unused memory that the memory management can’t allocate. You have 2 types of fragmentation:
- internal (severe in static partitioning schemes)
- external (severe in dynamic partitioning schemes)
A swapper has the responsibility of picking processes to swap in and out and manage the swap space.