Adam Sh
Adam Sh

Reputation: 8577

Operating System - paging

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:

  1. 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?

  2. How can we sure that the page, which is now in the physical memory, doesn't belong to two processes?

Upvotes: 1

Views: 2622

Answers (2)

srking
srking

Reputation: 4732

Regarding questions 1 and 2, Mapping multiple virtual addresses to the same physical page is sometimes the desired behavior, especially for code sections. For example, a shared library may be in use by many independent processes. Rather than redundant copies of the same library eating up RAM, the OS can load the library just once and map the same physical pages into each processes virtual address space. For read/write data pages, some inter-process communication methods use shared physical memory.

Upvotes: 0

betabandido
betabandido

Reputation: 19704

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.

Upvotes: 2

Related Questions