The aging walk no longer takes mmap_lock, and walks each VMA under its per-VMA read lock instead. Update the design doc, which says the walk calls walk_page_range() with each mm_struct, and describe the VMA lock handoff. Drop the warning in the admin guide that the page table walk can worsen mmap_lock contention, which no longer applies. Signed-off-by: Chuanhua Han --- Documentation/admin-guide/mm/multigen_lru.rst | 3 +-- Documentation/mm/multigen_lru.rst | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Documentation/admin-guide/mm/multigen_lru.rst b/Documentation/admin-guide/mm/multigen_lru.rst index 9cb54b4ff5d9..5bab313284ed 100644 --- a/Documentation/admin-guide/mm/multigen_lru.rst +++ b/Documentation/admin-guide/mm/multigen_lru.rst @@ -37,8 +37,7 @@ Values Components ====== =============================================================== 0x0001 The main switch for the multi-gen LRU. 0x0002 Clearing the accessed bit in leaf page table entries in large - batches, when MMU sets it (e.g., on x86). This behavior can - theoretically worsen lock contention (mmap_lock). If it is + batches, when MMU sets it (e.g., on x86). If this feature is disabled, the multi-gen LRU will suffer a minor performance degradation for workloads that contiguously map hot pages, whose accessed bits can be otherwise cleared by fewer larger diff --git a/Documentation/mm/multigen_lru.rst b/Documentation/mm/multigen_lru.rst index b532ce961371..f7d01ca152fc 100644 --- a/Documentation/mm/multigen_lru.rst +++ b/Documentation/mm/multigen_lru.rst @@ -118,8 +118,8 @@ generation when it finds them accessed through page tables; the demotion of cold pages happens consequently when it increments ``max_seq``. The aging uses page table walks and rmap walks to find young PTEs. For the former, it iterates ``lruvec_memcg()->mm_list`` -and calls ``walk_page_range()`` with each ``mm_struct`` on this list -to scan PTEs, and after each iteration, it increments ``max_seq``. For +and walks the page tables of each ``mm_struct`` on this list to scan +PTEs, and after each iteration, it increments ``max_seq``. For the latter, when the eviction walks the rmap and finds a young PTE, the aging scans the adjacent PTEs. For both, on finding a young PTE, the aging clears the accessed bit and updates the gen counter of the @@ -163,11 +163,19 @@ An ``mm_struct`` list is maintained for each memcg, and an ``mm_struct`` follows its owner task to the new memcg when this task is migrated. -A page table walker iterates ``lruvec_memcg()->mm_list`` and calls -``walk_page_range()`` with each ``mm_struct`` on this list to scan -PTEs. When multiple page table walkers iterate the same list, each of -them gets a unique ``mm_struct``, and therefore they can run in -parallel. +A page table walker iterates ``lruvec_memcg()->mm_list`` and walks +each ``mm_struct`` on this list one VMA at a time, calling +``walk_page_range_vma()`` on each VMA it locks to scan PTEs. When +multiple page table walkers iterate the same list, each of them gets a +unique ``mm_struct``, and therefore they can run in parallel. + +A page table walker holds the per-VMA read lock of the VMA it walks, +not ``mmap_lock``, so a writer to an ``mm_struct`` only waits for the +walk of the VMA it modifies. It skips a VMA that it cannot lock +instead of waiting for it, and a later walk ages its pages. Within a +page table, it hands the VMA lock off to the next VMA in that table: +it locks the next VMA before it releases the current one, so the +page table stays valid. Page table walkers ignore any misplaced pages, e.g., if an ``mm_struct`` was migrated, pages left in the previous memcg will be -- 2.34.1