Reputation: 31
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
Upvotes: 2
Views: 1518
Reputation: 31
I read some related books on Linux memory management. I think the basic steps include:
The OS keeps an active_list to contain physical pages those are recently referenced, and an inactive_list to contain reclaim candidates. The policy for page replacement is implemented in the swap.c file.
For a page in the active_list, if it reaches the bottom of the list, the referenced flag is checked. If it is set, the page is moved back to the top of the list and the next page is to be checked; Otherwise, the page is moved to the inactive_list.
In conclusion, I guess, the answer to my question
How does the memory management unit (MMU) notify the operating system that the page table is updated?
is that
MMU doesn't notify the operating system that the page table is updated directly. It updates the flag of a physical page (flag in struct page). When the OS is performing page replacement, if a physical page reaches the tail of active_list or inactive_list, the page's flag is checked to determine whether the page needs replaced or moved to the head of the two lists.
Upvotes: 1