For example, if there are 3 processes, each using the virtual address 0x400000
for text section. And there is only one 4KB
physical page for user process.
Suppose process 0 is using the physical page (virtual address 0x400000
). Assume that the physical page data is page_pid_0_0x400000
.
When process 1 is scheduled by the OS, and page_pid_1_0x400000
of process 1 would be loaded into physical page from executable. Then page_pid_0_0x400000
data should be swapped out to disk.
When process 2 is also loaded, the page_pid_2_0x400000
data on physical page should also be swapped out to disk.
Now, on disk, we have 2 copies of the same virtual address space, i.e. 0x400000
: page_pid_1_0x400000
and page_pid_0_0x400000
.
If process 1 is scheduled now, how can I (OS) identify the page_pid_1_0x400000
from virtual address 0x400000
(since memory accessing instructions only know the virtual address 0x400000
but not process id)?