JDS
JDS

Reputation: 16978

When could 2 virtual addresses map to the same physical address?

An operating system/computer architecture question here. I was reading about caches, about how virtually indexing the cache is an option to reduce address translation time. I came across the following:

"Virtual cache difficulties include:
    Aliasing
        Two different virtual addresses may have the same physical address."

I can't think of a scenario when this can occur. It's been a while since my O/S days and I'm drawing a blank.

Could someone provide an example? Thanks

Upvotes: 5

Views: 6837

Answers (4)

user660783
user660783

Reputation: 31

shmat() is a typical example of same physical address being mapped as two different virtual address in two different processes. If you do pmap -x pid_A . you will you see the virtual mem map for process A similarly for Process B. Actual Phy mem is not exposed to the user-space program.

Now SayProcess A and B share a shared memory segment and shared memory pointer be sh_mem_ptr_A and Sh_mem_ptr_B. If you print these pointers their address(virtual) will be different. Because Sh_mem_ptr_A is a part of memory map of Process A, Similarly sh_mem_ptr_B for Process B.

Kernel maintains the maaping of Virtual-to- phy addr. By page table and offset. Higher bits map to the page table and offset maps to offset in the page table. So If you notice the Lower order bits of sh_mem_ptr_A and sh_mem_ptr_B they will be same(but may not be true always).

Upvotes: 3

peeyush
peeyush

Reputation: 2921

Also each process is allocated 4GB of virtual space (in 32 bit system), out of which 1 GB (depends upon Os to Os) is mapped for OS. Since OS is common for all processes, so the lower 1GB of virtual addresses are common for all the process, which are mapped to same OS physical pages.

Upvotes: 1

Fred Foo
Fred Foo

Reputation: 363547

Two processes might have a shared mapping. E.g., in Unix, executable code is typically mapped into a region shared between all processes that execute the same program. (In fact, a single process might have several mappings of the same underlying memory, e.g. when it mmap's the same file twice.)

Upvotes: 7

Geoff Montee
Geoff Montee

Reputation: 2597

I believe that the executable sections of programs can possibly be shared between processes--thus being mapped twice.

For example: if you load two instances of vim, there will be two processes. Both process will likely map to the same executable code in physical memory.

Upvotes: 3

Related Questions