Address binding can occur when;
- Its compiled
- When loaded – when a programme is first executed it works out the position in the memory code to find the correct physical address.
- At run time – If a process is moved in the memory during execution then the address will need to be modified so the link can remain active.
The mapping of logical to physical addresses is done at run time (run time is the time when code is running therefore cannot be altered). This process is controlled by the memory management unit, also know as the MMU.
Dynamic Loading and Linking
The operating system memory management is also capable of dynamic loading and linking, this is a process required by the state of address binding. Each process can not exceed its physical memory size. Further, code that is representing data in the memory will only remain for the moments which they are required. It also allows for more code to be entered on top of what was originally there.
The Relocation Register
There are three rules to the relocation register. This diagram bellow shows how a process is taken from the CPU and sent to the memory.
- The relocation register will hold the value at the base address which is owned by the process
- The relocation registers contents are added to each memory address before it is sent to the memory.
- A process can never see the physical address – it will just manipulate the logical address
It is clear to see that the register has a limit, and if the process exceeds the register limit it will result in an address fault. If the total is less than the limit it will proceed to the base and is added to the logical address. This is how new logical addresses are designed.
Fixed and Dynamic Partitioning
It is also possible for memory to be partitioned when it is within its stored elements. This is for efficient storage and avoids clustering of the memory system. The memory can be partitioned in two differing ways. Firstly is fixed partitioning. Fixed memory partitioning ensures that memory blocks are split up into fixed sizes. When a process is sent for execution a space is created and a new process can enter. There are however down sides to this process. Elementally, processes are never the same size; this means that a process block may consist of 100kb of size; however the process is only 20kb in size. Over 10 or 20 fixed partitions this is a dramatic waste of resources and can be condemned as very in efficient. On the reverse a process may be bigger than the fixed partition this would mean that it would need to split, again loosing space.
Dynamically partitioning means that the spaces/sizes keep changing. They are made to fit exactly to the size of the process. If a new process enters when one is sent the space will not be exactly the same (unless the new process entering was the same size of the one exiting) this means that there is a need for methods of entry.
- First fit – the memory management stops searching as soon as big enough hole is found
- Best fit – Memory management finds a hole that leaves minimum empty space
- Worst fit – It allocates the largest hole using more memory.
Above is an example of external fragmentation. The issue can be seen where P6 cannot enter. The problem is that all available spaces are too small. So what can be done? The free space must be compacted this would then leave enough available space for p6 to enter the queue.
Above is an example of what the memory queued storage would look like if the process were compacted. Mainly it is far more efficient. Processes can enter and leave at a far greater rate and means turnover is increased.
Paging
Paging is a process that avoids using different sized memory slots as can be seen in the images above and will use fixed size throughout. This is what is known as a frame. It has the same structure in the logical memory but this is called a page. Pages require hardware support.
Physical Memory/Frame Logical Memory/Page (fixed size) (fixed size)
Each fixed size partition is allocated its own protection. This is done by assigning it a bit, 1 bit is for writing, 1 bit is for reading and another for execution. It can therefore be said that this process is similar to that of the linking process described earlier. The only difference is that the dynamic linking always had to reside somewhere within the R.A.M, this process however can allocate virtual memory. This is done by what is known as the paging table. This then gives the logical memory two identities, the first being a page number and the second would be an offset within that page. Then when a process is to be run the memory management must look up the page number and offset and extracts the pair of them. From this is can translate the two and turn it in to the physical memory location. This then allows the process to be run.
Segmentation
Segmentation is where memory resides in the logical address space in groups. There are many benefits to this, but the most important is the protection. Memory can be protected in its groups rather that each individual address space. This improves efficiency of the system and makes memory allocation far easier. From here the need for external fragmentation is not needed although there is an additional need for context switching. It can also be said that there is a clear separation between the user and the system.