Operating System | Memory management – mapping virtual address to physical addresses



Memory consists of large array of words or arrays, each of which has address associated with it. Now the work of CPU is to fetch instructions from the memory based program counter. Now further these instruction may cause loading or storing to specific memory address.

Address binding is the process of mapping from one address space to another address space. Logical address is address generated by CPU during execution whereas Physical Address refers to location in memory unit(the one that is loaded into memory).Note that user deals with only logical address(Virtual address). The logical address undergoes translation by the MMU or address translation unit in particular. The output of this process is the appropriate physical address or the location of code/data in RAM.

An address binding can be done in three different ways:

Compile Time – If you know that during compile time where process will reside in memory then absolute address is generated i.e physical address is embedded to the executable of the program during compilation. Loading the executable as a process in memory is very fast. But if the generated address space is preoccupied by other process, then the program crashes and it becomes necessary to recompile the program to change the address space.

Load time – If it is not known at the compile time where process will reside then relocatable address will be generated. Loader translates the relocatable address to absolute address. The base address of the process in main memory is added to all logical addresses by the loader to generate absolute address. In this if the base address of the process changes then we need to reload the process again.



Execution time- The instructions are in memory and are being processed by the CPU. Additional memory may be allocated and/or deallocated at this time. This is used if process can be moved from one memory to another during execution(dynamic linking-Linking that is done during load or run time). e.g – Compaction.

MMU(Memory Management Unit)-
The run time mapping between Virtual address and Physical Address is done by hardware device known as MMU.

In memory management, Operating System will handle the processes and moves the processes between disk and memory for execution . It keeps the track of available and used memory.

Instruction-execution cycle Follows steps:

  1. First instruction is fetched from memory e.g. ADD A,B
  2. Then these instructions are decoded i.e., Addition of A and B
  3. And further loading or storing at some particular memory location takes place.

Basic Hardware

As main memory and registers are built into processor and CPU can access these only.So every instructions should be written in direct access storage
devices.

  1. If CPU access instruction from register then it can be done in one CPU clock cycle as registers are built into CPU.
  2. If instruction resides in main memory then it will be accessed via memory bus that will take lot of time. So remedy to this add fast memory in between CPU and main memory i.e. adding cache for transaction.
  3. Now we should insure that process resides in legal address.
  4. Legal address consists of base register(holds smallest physical address) and limit register(size of range).

For example:

Base register = 300040
limit register = 120900 
then legal address = (300040+120900)= 420940(inclusive).
legal address = base register+ limit register

How processes are mapped from disk to memory

  1. Usually process resides in disk in form of binary executable file.
  2. So to execute process it should reside in main memory.
  3. Process is moved from disk to memory based on memory management in use.
  4. The processes waits in disk in form of ready queue to acquire memory.

Procedure of mapping of disk and memory

Normal procedure is that process is selected from input queue and loaded in memory. As process executes it accesses data and instructions from memory and as soon as it completes it will release memory and now memory will be available for other processes.

MMU scheme –

 CPU------- MMU------Memory 

MMU scheme

  1. CPU will generate logical address for eg: 346
  2. MMU will generate relocation register(base register) for eg:14000
  3. In Memory physical address is located eg:(346+14000= 14346)

Reference and Image Source:
https://users.dimi.uniud.it/~antonio.dangelo/OpSys/materials/Operating_System_Concepts.pdf
This article is contributed by Vaishali Bhatia.If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.



My Personal Notes arrow_drop_up

Improved By : NEERAJ NEGI

Article Tags :
Practice Tags :



Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.