Address Translation Contiguous Memory - operating system tutorial


We have already discussed about one major issue with contiguous memory allocation which was space allocation. Now today we will be looking at the second major issue with contiguous memory allocation which is Address Translation in Contiguous Memory - operating system tutorial. So, let's see how this address translation is done:

A brief Idea 

Before getting to address translation remember that CPU generates a Logical Address for Secondary Memory. But since the access time of secondary memory is very high so we break the logical address into Physical Address and give that address to main memory. So we place the important data from secondary memory to main memory and break the logical address into physical address.

Address Translation in Contiguous Memory

Address Translation in contiguous memory is an easy task because if you pick a data from secondary memory and push it into the main memory then you pick the data in a contiguous fashion which means if you know the base address of data then you can decode the entire address. However this is not so in non-contiguous memory allocation.
So in contiguous memory you just need a base address of the process and then you can compute the entire address of the process and you'll get the Physical Address which can be used to access the main memory.

Address Translation Contiguous Memory - operating system tutorial

Now let's understand the diagram.
1. Suppose there is a process P placed in the main memory with its base address as 100. Process P has i, i+1, i+2, i+3......., i+99 instructions.
2. Now suppose CPU wants to access instruction number 52.
3. Now we know that the 1st instruction is placed at address 100 and we want to compute instruction number 52 which will be at 100+52=152th position.
4. We have a relocation register which stores the base address of the process in the main memory.
5. This register helps in computing the exact physical address of the instruction. Like we wanted to compute instruction number 52 then we will add 52 with the value of relocation register which is 100 or 152.

6. But there is a issue in the above process.
7. If there were 100 instructions in the process in main memory, base address was 100 and CPU wanted the physical address of instruction 112. Then it is an invalid request because at-most we can have 100+100=200 as physical address but in the above scenario the physical address comes out to be 100+112=312.

8. So to avoid this problem we have the limit register part in the diagram which is a security mechanism.
9. The limit register stores the size of the process. Let say our size of process was 100.
10. Now the less than sign (<) implies that we can generate addresses from 0 - 99. The address will passed on and added to base address and you will get the corresponding physical address.
11. But if someone wants to access an address greater than 99 than the system will generate a trap.

Question:

Address Translation Contiguous Memory - operating system tutorial

We are given the limit register values and relocation register values for processes. We have the following request made be processes :
P0 - 450
P1 - 300
P2 - 210
P3 - 450
P4 - 80
Now you have to check if the requests are legal or not.

sol

Limit of P0 = 500
Base address value = 1200
Request made = 450
450<500, hence it is a legal request. Thus, the physical address becomes 1200+450=1650.

Limit of P1 = 275
Base address value = 550
Request made = 300
300>275, hence it is an illegal request.

Limit of P2 = 212
Base address value = 880
Request made = 210
210<212, hence it is a legal request. Thus, the physical address becomes 880+210=1090.

Limit of P3 = 420
Base address value = 1400
Request made = 450
450>420, hence it is an  illegal request.

Limit of P4 = 118
Base address value = 200
Request made = 80
80<118, hence it is a legal request. Thus, the physical address becomes 200+80=280.

Conclusion

Address Translation in Contiguous Memory - operating system tutorial is very easy because the processes are in contiguous fashion. but the 2 major issues in contiguous memory allocation are Internal Fragmentation and External Fragmentation. Now Internal Fragmentation is not a big issue because it is internal to the process and generally smaller but the external fragmentation is a problem because a lot of memory is wasted. 
Post a Comment (0)
Previous Post Next Post