FOR FREE MATERIALS

Relocation and Protection in Contiguous Memory Allocation

 

For contiguous memory allocation load time-binding at loading relocation (relocated address to absolute address) is not a good idea.

 

Let take an example to clear the concept.

 

 

# Here P1 allocated from memory location 100K, and in-progress P1, there are many relocatable addresses which convert to absolute address at run time.  Let P1 contain goto 4, then it converts to absolute address goto 100K+4.

 

And after sometime P1 swaps out from memory and may another process P2 swaps in at memory.  And may after a time interval P1 again swap in at memory but this time allocated at a different location in memory, may it start from 200K. Now again loader performs relocation change old address by new absolute address.

 

Now goto 4, should be goto 200k+4, but it is not happening in this way because the second-time loader is a little bit confuse, it sees the current address is goto 4+100K, it now adds 200K with current address goto 4+100K+200K and it gets wrong memory location.

 

# This relocation and all is totally a software process, it is not a hardware process.

 

# So, the general solution by OS is instead of use load time-binding, it uses runtime binding i.e. no relocatable address is converted to absolute address at load time, everything will be done at runtime.  Actually, how it will be done by the loader, it keeps as it is all relocatable addresses, at the runtime when it generated by CPU, the particular address map it to memory as the physical address.

 

# CPU generates logical address i.e. relocatable address i.e. CPU thinks that process starts with address line 0. So, when every time the CPU accesses the same instruction, then it maps from logical address to physical address (absolute address) to get the instruction or data from memory.

 

 

Let’s take an example of how runtime binding works for contiguous memory allocations

 

 

# Here process size is 100 and the process load at the memory of starting 100K.  So, relocation register = 100K and limit = 100 because size of process 100.

 

Now CPU assumes that the process is from 0 to 99 (because process size is 100).  So, beyond 99, it can't access anywhere of this memory, if it tries to access beyond 99 then OS not allowed i.e. called protection.  Now when the CPU tries to access instruction or data it sends a logical address (Relocatable address) and the memory manager map it to a converting absolute address by converting the logical address to a physical address.

 

Let if it tries to access data of address 10 (logical add) first it should be check that it is less than the limit register, if yes, then map it to memory by converting it to a physical address by adding Relocation register with logical address, so, it is 10 + 100K (absolute address).

 

# Unlike load time-binding, it has no confusion or not occur problem.

 

# Now if the process is swap out and after a while again it swaps in but in a different location like 200K. Still, it does not occur any problem because again Relocation Register- 200K and according to process size limit 100.  Now converting any logical address to a physical address by adding a relocation register, never occur problem, this is the beauty of this concept.

 

# These two registers set by the operating system, So, OS provides both the Relocation and protection here.  And this method is the hardware method.

 

So, in the case of contiguous memory allocation, it always uses the hardware method, not the software method.

 

# In dynamic/variable partition external fragmentation solved by compaction but compaction is costly because adjustment running process and re-allocation are time-consuming.

 

Another solution is non-contiguous memory allocation by paging & segmentation.