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
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.
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.
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.
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.
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.)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With