I am exploring the memory management in Linux operating system.
As far as I know, MMU is a hardware integrated in the modern CPU to handle address translation. If a virtual address is not in the TLB, the MMU will first get the address of a process's page table through page table base register (PTBR), then retrieve the physical address from the page table which is located in physical memory.
My question is: how does MMU notify the operating system that the physical page has been accessed or modified, as the operating system is responsible for page replacement? I see a function in Linux/mm/swap.c. But I am not sure if this function is called every time the page table is updated.
void mark_page_accessed(struct page *page)
{
if (!PageActive(page) && !PageUnevictable(page) && PageReferenced(page)) {
/*
* If the page is on the LRU, queue it for activation via
* activate_page_pvecs. Otherwise, assume the page is on a
* pagevec, mark it active and it'll be moved to the active
* LRU on the next drain.
*/
if (PageLRU(page))
activate_page(page);
else
__lru_cache_activate_page(page);
ClearPageReferenced(page);
if (page_is_file_cache(page))
workingset_activation(page);
} else if (!PageReferenced(page)) {
SetPageReferenced(page);
}
}
I think MMU will possibly modify the PTE flag of the page table. But the operating system will not know only if the OS does a page table walking, right? And the page replacement is performed on physical pages, is there also some flag on the physical pages? I must be missing something really important..
Thanks