Memory Manager Flashcards
Memory Manager
Manages the main memory and ensures each process gets access to the memory it needs. Tasks include:
- preserves and protects space in memory occupied by OS
- checks validity of each request for memory space
- allocates free areas of memory to valid requests, and deallocates the memory when finished
- keeps track of which users and processes are using which memory
- provides syscalls and manages swap space
Memory Addressing/ Linear Store
Memory inside a system can be viewed in a linear sequence of bytes called linear store, or flat model, with memory being byte addressable starting from 0 to allowed amount of bytes.
Program Storing
A program exists on disk as a binary executable file, storing program instructions as a sequence of bytes.
Running A Program / Process Image
When a program is run:
- binary image/the sequence of bytes is loaded into main memory
- extra memory is reserved for variables and the stack
- this combined memory footprint, which is the amount of memory that is allocated and reserved for running a process, is called the process image
- the instruction pointer is set to the first byte of the image
Jumps
Jumps to labels are replaced by real memory addresses. They point towards a physical location within the process image, and the instruction pointer is set according to this address when the jump is made.
Heap
Memory available for the programmer to reserve.
Compile-Time Address Binding
A program is assumed to always occupy the same area of memory every time it is executed. This means loops and jump locations are turned into fixed memory addresses during compilation. This has some disadvantages, for example, the program could not move memory locations nor allows other processes to use memory address occupied.
Load-Time Address Binding
A program can be loaded anywhere in memory using relative addresses, allowing more flexibility and setting jumps and locations to relative addresses. So instead of using things like JUMP 800, meaning the program would jump to memory address 800, we can use JUMP -8, meaning it will, if we say that every memory address is 4 bytes, jump backwards twice.
Dynamic (Run-Time) Address Binding
Essentially, a program can be stored anywhere with virtual addresses but the physical addresses will be determined at runtime based on the available memory. So the virtual addresses will map onto real addresses at run-time by the MMU.
Memory Allocation Examples
Between the datum and the limit (the start and end) of the memory locations, there will be fragmentations since there is always deallocation of data. There also could be starvation of processes in memory because they cannot load anywhere due to a large amount of small gaps. This leaves the memory manager with:
First fit -> choosing first free space that’s big enough
Best Fit -> choose the smallest free space that’s big enough
Worst Fit -> choosing biggest area of free space on purpose
50% Rule
For First Fit, if n amount of bytes of memory is allocated, then amount of unusable memory due to fragmentation becomes n/2.
Moving Processes
We can move processes to defragment space, which is only possible with relative addresses, but even with this, we have a finite number of memory for a finite number of processes, so memory will eventually fill up.
Swapping
The solution of allocation in memory. A process can be swapped out to disk to make more room when it is not being used. The disk reserves some of its space for these swaps, called swap space, which allows RAM to be freed up for processes which need it. However, accessing disk is a lot slower, and a system will a lot of processes in swap space will run a lot more slowly.
Static Linking
Copies of library code are added to the final program image as a program is using a third-party library subroutine (import etc).
Can result in large images and wasteful disk storage and memory space.
Dynamic Linking
A small stub is included in final program image, which tells the memory manager where to find library code and allows re-entrant library code to be shared between processes.