Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 509
JDS Avatar asked Oct 13 '12 22:10

JDS


People also ask

Can references to two different virtual addresses map to the same physical address?

Multiple programs or processes can share the main memory without reading or writing into each other's address space. This is enforced by virtual memory. Virtual memory also allows for sharing of data or code between programs by having two virtual addresses point to the same physical memory location.

Can two different virtual addresses map to the same physical address in Linux?

Disk A virtual address can be mapped to either physical memory or disk. Because different processes will have different mappings from virtual to physical addresses, two programs can freely use the same virtual address.

Can 2 processes map to the same physical address how and in which case?

Yes, it's definitely possible for the same address to map to different physical memory depending on the process that's referencing it. This is in fact the case under Windows. Save this answer.

What happens if you map multiple virtual memory pages to same physical memory address?

By mapping the same physical memory into multiple processes, the memory is shared. This is particularly useful for code libraries, which can be put into physical memory only once, and then used by any process that needs the library by mapping the physical memory into the process' logical space.


2 Answers

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.)

like image 164
Fred Foo Avatar answered Jan 04 '23 10:01

Fred Foo


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.

like image 45
Geoff Montee Avatar answered Jan 04 '23 12:01

Geoff Montee