How does Linux's Virtual Memory system handle the following case:Process 1 maps one of its virtual page to physical frame 1.  Context switches to process 2.Process 2 swaps out frame 1 and replace with its own content.Context switches back to process 1.How does process 1 knows that it does not own the content of frame 1 and needs to do a swap in?
how does linux update page table after context switch
linux
Technically, process1 doesn't know this. There is a set of page-tables for each process. The kernel knows which process it will switch to, and switch the page-tables around. A part of these page-tables is the kernel, which is shared between ALL processes (so, a certain part of the address range, typically in the range of 0xc0000000 to 0xffffffff - although not ALL of those pages will be present). Typically, this shared section is achieved by simply making all the page-table sets point at the same shared section of kernel page-table bits. Having this shared section allows the kernel calls, traps and interrupts to go into the kernel, no matter which process is currently running, or what that process is doing. Exactly how this works depends on the architecture the kernel is built for, but for example in x86(32 and 64 bit), CR3 is the register that points to the current page-table. So for each process, there is a pointer to the page-table, and it is loaded into CR3, as part of the switch to the new process, just like the register values (at least the stack-pointer) is restored for the process 1 when it is being switched in. 