15
votes

What is the purpose of logical address? Why should CPU generate logical address? it can directly access relocatable register base address and limit to exe a process. Why should MMU make a mapping between logical and physical address?

4

4 Answers

20
votes

Why?

Because this gives the Operating System a way to securely manage memory.

Why is secure memory management necessary?

Imagine if there was no logical addressing. All processes were given direct access to physical addresses. A multi-process OS runs several different programs simultaneously. Imagine you are editing an important letter in MS Word while listening to music on YouTube on a very recently released browser. The browser is buggy and writes bogus values to a range of physical addresses that were being used by the Word program to store the edits of your letter. All of that information is corrupt!

Highly undesirable situation.

How can the OS prevent this?

Maintain a mapping of physical addresses allocated to each process and make sure one process cannot access the memory allocated to another process!

Clearly, having actual physical addresses exposed to programs is not a good idea. Since memory is then handled totally by the OS, we need an abstraction that we can provide to processes with a simple API that would make it seem that the process was dealing with physical memory, but all allocations would actually be handled by the OS.

Here comes virtual memory!

4
votes

In execution time binding, the MMU makes a mapping from logical address to physical address because in this type of binding:

logical address is specifically referred to as virtual address

The address actually has no meaning because it is there to illusion the user that it has a large memory for its processes. The address actually bear meaning when mapping occurs and they get some real addresses which are present in physical memory.

Also I would like to mention that the base register and limit register are loaded by executing privileged instructions and privileged instructions are executed in kernel mode and only operating system has access to kernel mode and therefore CPU cannot directly access the registers.

So first the CPU will generate the logical address then the MMU of Operating system will take over and do the mapping.

2
votes

The need of logical address is to securely manage our physical memory. Logical address is used to reference to access the physical memory location. A logical address is generated so that a user program never directly access the physical memory and the process donot occupies memory which is acquired by another process thus corrupting that process. A logical address gives us a surety that a new process will not occupy memory space occupied by any other process.

0
votes

The binding of instruction and data of a process to memory is done at compile time, load time or at execution time. Logical address comes into picture, only if the process moved during its execution time from one memory segment to another. logical address is the address of a process, before any relocation happens(memory address = 10). Once relocation happened for a process(moved to memory address = 100), just to redirect the cpu to correct memory location=> memory management unit(MMU), maintains the difference between relocated address and original address(100-10 = 90) in relocation register(base register acts as relocation register here) . once CPU have to access data in memory address 10, MMU add 90(value in relocation register) to the address, and fetch data from memory address 100.