0

I'm refering to those links:

Page table content when the physical page we are looking for is in swap area

how does linux update page table after context switch

How does the kernel address swapped memory pages on swap partition\file?

I'm still confused how a process knows if one of its pages is swapped to the secondary memory.

Example:

Process A1 allocates 1 frame of physical memory, writes on it. The preset, modify and recent bit will be set to 1 in the PTE.

It's process A2 turn now - it need more memory and the MMU kernel decides to write process A1's page to secondary memory, because the modify bit was set.

Process A1 is back again - restores his context and PT and is now ready to read/write its page (assumed the present bit still set to 1) and will access process A2s page.(?)

I understand that the process does not directly knows which pages is located where and the somehow the MMU knows that a page is on secondary memory - but somehow the PTE of process A1 has to be modified? There must be some information to the MMU or in the PT that the page is now swapped out and has to be restored from it. Edit: Will the present bit get changed to 0, even if the PT / PTE are on the stack?

1 Answer 1

2

Processes don’t know, the kernel does.

the MMU decides to write process A1's page to secondary memory

The MMU doesn’t decide this, the kernel does: if A2 needs more memory, the kernel is told about it, and looks for pages to give to A2. If there aren’t any free, it will run its page reclaim. Whatever pages end up evicted to their backing store will have their “present” bits cleared, regardless of which process (if any) they “belong” to — the kernel keeps track of this kind of information.

When control is given back to A1, A1’s PTEs will be restored, by the kernel, using the information the kernel has. Thus the pages that were evicted will have their PTE present bit cleared. If A1 accesses one of those pages, the MMU will fault and the kernel will be involved again to resolve the situation.

1
  • 1
    Thanks! That was the information I needed. You are right, the MMU can't decide, it only translate. So when a page gets written back to disk the kernel holds the needed information and clears the preset bit. When the process want to read that page, it faults and the kernel got the needed information, that this page was swapped and restores it.
    – brot
    Aug 28, 2021 at 11:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .