I read a book about paging (memory-management schemes).
As I understand, each virtual memory is convert to physical memory.
But I don’t understand two really basic things:
-
If we have process A and process B, how can we sure that it doesn’t convert their linear address to the same physical address?
-
How can we sure that the page, which is now in the physical memory, doesn’t belong to two processes?
When a process wants to access an address, it is using a virtual address. That address is converted by the processor into a physical one. The way to do so is by means of using page tables. Each process has an associated page table that translates its virtual addresses into physical ones. Since each process has a different page table, the OS can enforce that two virtual addresses (even if potentially equal) from different processes will not be mapped into the same physical addresses.
Moreover, most current processors contain a structure called Translation Lookaside Buffer (TLB). That structure is a cache for the page tables mentioned before. Accessing a page table is a costly operation and a TLB makes that operation faster.
There are other possibilities to enforce separation between processes’ address spaces, such as segmentation. You can read more about virtual memory in general here.