Difference between logical addresses, and physical addresses?
Asked Answered
W

11

38

I am reading Operating Systems Concept and I am on the 8th chapter! However I could use some clarification, or reassurance that my understanding is correct.

Logical Addresses: Logical addresses are generated by the CPU, according to the book. What exactly does this mean? (In an execute-generated address system..) I assume when code is compiled for a program, the program has no idea where the code will be loaded in memory. All the compiler does is set up a general sketch of the program layout and how the image should be laid out, but doesn't assign any real addresses to it. When the program is executed the CPU takes this layout image that the compiler made and hands out some addresses (logical ones) to the ones generated from the code.

Physical Addresses: The physical addresses are not generated until after the CPU generates some set of logical addresses (consisting of a base address and an offset). The logical addresses go through the MMU or another device and somewhere along the line the logical addresses are mapped to physical RAM addresses.

What then is the actual difference? I can see one benefit. Using logical addresses gives more freedom to the applications. If the physical addresses were hard coded, then the program success would depend heavily on the physical computer machine, available RAM addresses etc.

Doesn't the use of logical addresses converted to physical address impose two steps instead of a one to one, and therefore more over head?

Where then do the logical addresses reside after generation? They may exist in a register on the CPU while the CPU is servicing a process, but before and after, where do they go? I understand this is implementation dependent. I assume they may be stored in some special register space or buffer on the CPU such as a TLB, correct? If not, then the table may exist in the actual RAM itself, and the CPU only holds a pointer/address to the base address of the table in RAM, correct?

It seems holding the addresses in RAM is counter productive to the purpose of logical memory addresses. I can only assume my understanding is incorrect.

Whensoever answered 13/9, 2010 at 3:43 Comment(2)
I would suggest reading the Wikipedia article on "Page table" or some such.Unbound
Thanks, the page table entry is pretty usefulWhensoever
S
49

This answer is by no means exhaustive but it may explain it enough to make things click.

In virtual memory systems, there is a disconnect between logical and physical addresses.

An application can be given a virtual address space of (let's say) 4G. This is its usable memory and it's free to use it as it sees fit. It's a nice contiguous block of memory (from the point of view of the application).

However, it is not the only application running, and the OS has to mediate between them all. Underneath that nice contiguous model, there is a lot of mapping going on to convert logical to physical addresses.

With this mapping, the OS and hardware (I'll just call these the lower layers from here on in) is free to put the application pages anywhere it wants (either in physical memory or swapped out to secondary storage).

When the application tries to access memory at logical address 50, the lower levels can translate that to a physical address using translation tables. And, if it tries to access logical memory that's been swapped out to disk, a page fault is raised and the lower levels can bring the relevant data back into memory, at whatever physical address it wants.

In the bad old days when physical addresses were all you had, code had to be relocatable (or fixed up on load) since it could load anywhere. With virtual memory, that code (and data) can be at logical memory location 50 in a dozen different processes at the same time - it's actual physical address will be different however.

It can even be shared so that one physical copy exists in the address space of many processes at once. This is the crux of shared code (so we don't use more physical memory than we need) and shared memory to allow easy inter-process communication).

It is, of course, less efficient than a pure physical-address environment but the CPU manufacturers try to make it as insanely efficient as possible, since it's used heavily. The advantages far outweigh the disadvantages.

Sumerlin answered 13/9, 2010 at 3:50 Comment(6)
Thanks that makes a lot click. I also think swapping is kind of archaic. Is it used much these days? RAM is rather cheap. I don't know when swap is really needed on PCs. Laptops may use swap for sleep/hibernation. Are there other uses of it?Whensoever
RAM is cheap but not so cheap that you can give 100 processes on your machine 4G each :-) Also note that there's often a distinction between swapping (the whole process is swapped out) and paging (small pages are swapped out). The latter is much more efficient. It also means that you don't even load into physical memory the things you don't need.Sumerlin
Ahh, swapping out pages makes more sense. I suppose that is what 'segmentation' is, where they divide pages into different segments and only load into RAM the segments needed? Thus not using more RAM than is really needed?Whensoever
Could we say the main difference between the types of address is 'relocatability?'Whensoever
I would say more "abstraction level". Logical addresses are no more relocatable than physical ones in terms of what you relate them to. You can't use an arbitrary logical address for your logical address although you can use an arbitrary physical address for your logical address. The mapping between the two is what provides relocatability, rather than it being a property of any particular level. It's no different to mapping filenames to logical disk sectors, or logical disk sectors to a (cylinder,head,sector) tuple.Sumerlin
+1 @Sumerlin nice answer it helped me to understand something even after reading Galvin book.Cobia
I
10

logical address is address relative to program. It tells how much memory a particular process will take, not tell what will the exact location of the process and this exact location will we generated by using some mapping, and is known as physical address.

Iridescent answered 20/11, 2010 at 16:14 Comment(0)
F
4

Logical address:- Logical address generated by the CPU . when we are give the problem to the computer then our computer pass the problem to the processor through logical address , which we are not seen this address called logical address .

Physical address :- when our processor create process and solve our problem then we store data in secondary memory through address called physical address

Frankiefrankincense answered 15/5, 2012 at 7:45 Comment(0)
D
4
  1. An address generated by the CPU is commonly referred to as a logical address. The set of all logical addresses generated by a program is known as logical address space. Whereas, an address seen by the memory unit- that is, the one loaded into the memory-address register of the memory- is commonly referred to as physical address. The set of all physical addresses corresponding to the logical addresses is known as physical address space.
  2. The compile-time and load-time address-binding methods generate identical logical and physical addresses. However, in the execution-time address-binding scheme, the logical and physical-address spaces differ.
  3. The user program never sees the physical addresses. The program creates a pointer to a logical address, say 346, stores it in memory, manipulate it, compares it to other logical addresses- all as the number 346. Only when a logical address is used as memory address, it is relocated relative to the base/relocation register. The memory-mapping hardware device called the memory- management unit(MMU) converts logical addresses into physical addresses.
  4. Logical addresses range from 0 to max. User program that generates logical address thinks that the process runs in locations 0 to max. Logical addresses must be mapped to physical addresses before they are used. Physical addresses range from (R+0) to (R + max) for a base/relocation register value R.
  5. Example: enter image description here Mapping from logical to physical addresses using memory management unit (MMU) and relocation/base register The value in relocation/base register is added to every logical address generated by a user process, at the time it is sent to memory, to generate corresponding physical address. In the above figure, base/ relocation value is 14000, then an attempt by the user to access the location 346 is mapped to 14346.
Diploblastic answered 9/1, 2016 at 12:38 Comment(1)
Why are the logical and physical addresses identical in the case of load-time address-binding?Yardmaster
K
1

Logical Vs Physical Address space

An address generated by the CPU is commonly refereed as Logical Address,whereas the address seen by the memory unit,that is one loaded into the memory address register of the memory is commonly refereed as the Physical Address.The compile time and load time address binding generates the identical logical and physical addresses.However, the execution time address binding scheme results in differing logical and physical addresses.

The set of all logical addresses generated by a program is known as Logical Address Space,whereas the set of all physical addresses corresponding to these logical addresses is Physical Address Space.Now, the run time mapping from virtual address to physical address is done by a hardware device known as Memory Management Unit.Here in the case of mapping the base register is known as relocation register.The value in the relocation register is added to the address generated by a user process at the time it is sent to memory.Let's understand this situation with the help of example:If the base register contains the value 1000,then an attempt by the user to address location 0 is dynamically relocated to location 1000,an access to location 346 is mapped to location 1346.

The user program never sees the real physical address space,it always deals with the Logical addresses.As we have two different type of addresses Logical address in the range (0 to max) and Physical addresses in the range(R to R+max) where R is the value of relocation register.The user generates only logical addresses and thinks that the process runs in location to 0 to max.As it is clear from the above text that user program supplies only logical addresses,these logical addresses must be mapped to physical address before they are used.

Kordofan answered 23/8, 2012 at 1:48 Comment(3)
What are the chances you plagiarized this content from here?Orvieto
Or any one of a dozen other sites where people can't tell the difference between referred and refereed. It appears this particular answer is in the Plagiarism Top 100 :-)Sumerlin
I upvoted the question, cause it has good explanation! The link you provided @AndrewBarber is not working anymoreCut
H
1

A logical address is a reference to memory location independent of the current assignment of data to memory. A physical address or absolute address is an actual location in main memory.

It is in chapter 7.2 of Stallings.

Hegemony answered 15/6, 2015 at 3:57 Comment(0)
F
0

To the best of my memory, a physical address is an explicit, set in stone address in memory, while a logical address consists of a base pointer and offset.

The reason is as you have basically specified. It allows for not only the segmentation of programs and processes into threads and data, but also for the dynamic loading of such programs, and the allowance for at least pseudo-parallelism, without any actual interlacing of instructions in memory needing to take place.

Flipper answered 13/9, 2010 at 3:47 Comment(0)
A
0

I found a article about Logical vs Physical Address in Operating System, which clearly explains about this.

Logical Address is generated by CPU while a program is running. The logical address is virtual address as it does not exist physically therefore it is also known as Virtual Address. This address is used as a reference to access the physical memory location by CPU. The term Logical Address Space is used for the set of all logical addresses generated by a programs perspective. The hardware device called Memory-Management Unit is used for mapping logical address to its corresponding physical address.

Physical Address identifies a physical location of required data in a memory. The user never directly deals with the physical address but can access by its corresponding logical address. The user program generates the logical address and thinks that the program is running in this logical address but the program needs physical memory for its execution therefore the logical address must be mapped to the physical address bu MMU before they are used. The term Physical Address Space is used for all physical addresses corresponding to the logical addresses in a Logical address space.

Logical and Physical Address comparision

Source: www.geeksforgeeks.org

Atavistic answered 20/3, 2019 at 3:32 Comment(0)
A
0

In simple terms, the logical address is seen by the processor as a continuous block of accessible memory, but underneath it is discontinuous blocks of physical memory.

Underneath there is a lot of mapping between logical address and physical address. The runtime mapping from virtual to physical address is done by a hardware device called the memory-management unit(MMU).

Aubreir answered 8/8, 2022 at 17:13 Comment(0)
O
0

Physical address is the precise location of data in computer memory and logical address is a virtual address that a computer program uses to access memory. While newer processors seamlessly handle both physical and logical addresses, older ones like the Intel 8080/8085 directly generates physical addresses. It doesn't have a separate Memory Management Unit (MMU) or support virtual memory.

Overage answered 6/1 at 5:10 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Robet
C
-1

A logical address is the address at which an item (memory cell, storage element, network host) appears to reside from the perspective of an executing application program.

Contraction answered 22/3, 2013 at 13:46 Comment(1)
Saif your answer is incomplete, the questioner asked the difference between logical and physical addresses, not just logical address!Cut

© 2022 - 2024 — McMap. All rights reserved.