Wednesday, September 13, 2017

Memory Management – Mapping Virtual address to Physical addresses?

Memory Management – Mapping Virtual address to Physical addresses?

Memory is basically a large array of words or arrays. each of which has address associated with it. Now the work of CPU is to get the 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 – It work is to generate logical address(also known as virtual address). If you know that during compile time where process will reside in memory then absolute address is generated.

Load time – It will generate physical address.If at the compile time it is not known where process will reside then relocatable address will be generated. In this if address changes then we need to reload the user code.

Execution time- It helps in differing between physical and logical address.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).

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:

First instruction is fetched from memory e.g. ADD A,B

Then these instructions are decoded i.e., Addition of A and B

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.

If CPU access instruction from register then it can be done in one CPU clock cycle as registers are built into CPU.

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.

Now we should insure that process resides in legal address.
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

Usually process resides in disk in form of binary executable file.
So to execute process it should reside in main memory.
Process is moved from disk to memory based on memory management in use.
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



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






No comments: