Difference between physical/logical/virtual memory address

前端 未结 9 961
无人及你
无人及你 2020-12-02 06:59

I am a little confused about the terms physical/logical/virtual addresses in an Operating System(I use Linux- open SUSE)

Here is what I understand:

相关标签:
9条回答
  • 2020-12-02 07:08

    Physical Address is the address that is seen by the memory unit, i.e., one loaded into memory address register. Logical Address is the address that is generated by the CPU. The user program can never see the real physical address.Memory mapping unit converts the logical address to physical address. Logical address generated by user process must be mapped to physical memory before they are used.

    0 讨论(0)
  • 2020-12-02 07:10

    Logical memory is relative to the respective program i.e (Start point of program + offset)

    Virtual memory uses a page table that maps to ram and disk. In this way each process can promise more memory for each individual process.

    0 讨论(0)
  • 2020-12-02 07:11

    when u write a small program eg:

    int a=10;
    int main()
    {
     printf("%d",a);
    }   
    
    
    compile: >gcc -c fname.c
    >ls 
    fname.o //fname.o is generated
    >readelf -a fname.o >readelf_obj.txt
    

    /readelf is a command to understand the object files and executabe file which will be in 0s and 1s. output is written in readelf_onj.txt file/

    `>vim readelf_obj.txt`
    

    /* under "section header" you will see .data .text .rodata sections of your object file. every starting or the base address is started from 0000 and grows to the respective size till it reach the size under the heading "size"----> these are the logical addresses.*/

    >gcc fname.c
    >ls
    a.out //your executabe
    >readelf -a a.out>readelf_exe.txt
    >vim readelf_exe.txt 
    

    /* here the base address of all the sections are not zero. it will start from particular address and end up to the particular address. The linker will give the continuous adresses to all the sections (observe in the readelf_exe.txt file. observe base address and size of each section. They start continuously) so only the base addresses are different.---> this is called the virtual address space.*/

    Physical address-> the memory ll have the physical address. when your executable file is loaded into memory it ll have physical address. Actually the virtual adresses are mapped to physical addresses for the execution.

    0 讨论(0)
  • 2020-12-02 07:18

    Physical Address- When the processor is in system mode, the address used by the processor is physical address.

    Not necessarily true. It depends on the particular CPU. On x86 CPUs, once you've enabled page translation, all code ceases to operate with physical addresses or addresses trivially convertible into physical addresses (except, SMM, AFAIK, but that's not important here).

    Logical Address- When the processor is in user mode, the address used is the logical address. these are anyways mapped to some physical address by adding a base register with the offset value.

    Logical addresses do not necessarily apply to the user mode exclusively. On x86 CPUs they exist in the kernel mode as well.

    I have come across discussion that virtual and logical addresses/address space are the same. Is it true?

    It depends on the particular CPU. x86 CPUs can be configured in such a way that segments aren't used explicitly. They are used implicitly and their bases are always 0 (except for thread-local-storage segments). What remains when you drop the segment selector from a logical address is a 32-bit (or 64-bit) offset whose value coincides with the 32-bit (or 64-bit) virtual address. In this simplified set-up you may consider the two to be the same or that logical addresses don't exist. It's not true, but for most practical purposes, good enough of an approximation.

    0 讨论(0)
  • 2020-12-02 07:23

    In the Usermode or UserSpace all the addresses seen by program are Virtual addresses. When in kernel mode addresses seen by kernel are still virtual but termed as logical as they are equal to physical + pageoffset . Physical addresses are the ones which are seen by RAM . With Virtual memory every address in program goes through page tables.

    0 讨论(0)
  • 2020-12-02 07:24

    User virtual addresses These are the regular addresses seen by user-space programs. User addresses are either 32 or 64 bits in length, depending on the underlying hardware architecture, and each process has its own virtual address space.

    Physical addresses The addresses used between the processor and the system's memory. Physical addresses are 32- or 64-bit quantities; even 32-bit systems can use 64-bit physical addresses in some situations.

    Bus addresses The addresses used between peripheral buses and memory. Often they are the same as the physical addresses used by the processor, but that is not necessarily the case. Bus addresses are highly architecture dependent, of course.

    Kernel logical addresses These make up the normal address space of the kernel. These addresses map most or all of main memory, and are often treated as if they were physical addresses. On most architectures, logical addresses and their associated physical addresses differ only by a constant offset. Logical addresses use the hardware's native pointer size, and thus may be unable to address all of physical memory on heavily equipped 32-bit systems. Logical addresses are usually stored in variables of type unsigned long or void *. Memory returned from kmalloc has a logical address.

    Kernel virtual addresses These differ from logical addresses in that they do not necessarily have a direct mapping to physical addresses. All logical addresses are kernel virtual addresses; memory allocated by vmalloc also has a virtual address (but no direct physical mapping). The function kmap returns virtual addresses. Virtual addresses are usually stored in pointer variables.

    If you have a logical address, the macro __pa() (defined in ) will return its associated physical address. Physical addresses can be mapped back to logical addresses with __va(), but only for low-memory pages.

    Reference.

    0 讨论(0)
提交回复
热议问题