@@ -552,63 +552,17 @@ different reverse map mechanisms.
552
552
is really unevictable or not. In this case, try_to_unmap_anon() will
553
553
return SWAP_AGAIN.
554
554
555
- (*) try_to_unmap_file() - linear mappings
555
+ (*) try_to_unmap_file()
556
556
557
557
Unmapping of a mapped file page works the same as for anonymous mappings,
558
558
except that the scan visits all VMAs that map the page's index/page offset
559
- in the page's mapping's reverse map priority search tree. It also visits
560
- each VMA in the page's mapping's non-linear list, if the list is
561
- non-empty.
559
+ in the page's mapping's reverse map interval search tree.
562
560
563
561
As for anonymous pages, on encountering a VM_LOCKED VMA for a mapped file
564
562
page, try_to_unmap_file() will attempt to acquire the associated
565
563
mm_struct's mmap semaphore to mlock the page, returning SWAP_MLOCK if this
566
564
is successful, and SWAP_AGAIN, if not.
567
565
568
- (*) try_to_unmap_file() - non-linear mappings
569
-
570
- If a page's mapping contains a non-empty non-linear mapping VMA list, then
571
- try_to_un{map|lock}() must also visit each VMA in that list to determine
572
- whether the page is mapped in a VM_LOCKED VMA. Again, the scan must visit
573
- all VMAs in the non-linear list to ensure that the pages is not/should not
574
- be mlocked.
575
-
576
- If a VM_LOCKED VMA is found in the list, the scan could terminate.
577
- However, there is no easy way to determine whether the page is actually
578
- mapped in a given VMA - either for unmapping or testing whether the
579
- VM_LOCKED VMA actually pins the page.
580
-
581
- try_to_unmap_file() handles non-linear mappings by scanning a certain
582
- number of pages - a "cluster" - in each non-linear VMA associated with the
583
- page's mapping, for each file mapped page that vmscan tries to unmap. If
584
- this happens to unmap the page we're trying to unmap, try_to_unmap() will
585
- notice this on return (page_mapcount(page) will be 0) and return
586
- SWAP_SUCCESS. Otherwise, it will return SWAP_AGAIN, causing vmscan to
587
- recirculate this page. We take advantage of the cluster scan in
588
- try_to_unmap_cluster() as follows:
589
-
590
- For each non-linear VMA, try_to_unmap_cluster() attempts to acquire the
591
- mmap semaphore of the associated mm_struct for read without blocking.
592
-
593
- If this attempt is successful and the VMA is VM_LOCKED,
594
- try_to_unmap_cluster() will retain the mmap semaphore for the scan;
595
- otherwise it drops it here.
596
-
597
- Then, for each page in the cluster, if we're holding the mmap semaphore
598
- for a locked VMA, try_to_unmap_cluster() calls mlock_vma_page() to
599
- mlock the page. This call is a no-op if the page is already locked,
600
- but will mlock any pages in the non-linear mapping that happen to be
601
- unlocked.
602
-
603
- If one of the pages so mlocked is the page passed in to try_to_unmap(),
604
- try_to_unmap_cluster() will return SWAP_MLOCK, rather than the default
605
- SWAP_AGAIN. This will allow vmscan to cull the page, rather than
606
- recirculating it on the inactive list.
607
-
608
- Again, if try_to_unmap_cluster() cannot acquire the VMA's mmap sem, it
609
- returns SWAP_AGAIN, indicating that the page is mapped by a VM_LOCKED
610
- VMA, but couldn't be mlocked.
611
-
612
566
613
567
try_to_munlock() REVERSE MAP SCAN
614
568
---------------------------------
@@ -625,23 +579,16 @@ introduced a variant of try_to_unmap() called try_to_munlock().
625
579
try_to_munlock() calls the same functions as try_to_unmap() for anonymous and
626
580
mapped file pages with an additional argument specifying unlock versus unmap
627
581
processing. Again, these functions walk the respective reverse maps looking
628
- for VM_LOCKED VMAs. When such a VMA is found for anonymous pages and file
629
- pages mapped in linear VMAs, as in the try_to_unmap() case, the functions
630
- attempt to acquire the associated mmap semaphore, mlock the page via
631
- mlock_vma_page() and return SWAP_MLOCK. This effectively undoes the
582
+ for VM_LOCKED VMAs. When such a VMA is found, as in the try_to_unmap() case,
583
+ the functions attempt to acquire the associated mmap semaphore, mlock the page
584
+ via mlock_vma_page() and return SWAP_MLOCK. This effectively undoes the
632
585
pre-clearing of the page's PG_mlocked done by munlock_vma_page.
633
586
634
587
If try_to_unmap() is unable to acquire a VM_LOCKED VMA's associated mmap
635
588
semaphore, it will return SWAP_AGAIN. This will allow shrink_page_list() to
636
589
recycle the page on the inactive list and hope that it has better luck with the
637
590
page next time.
638
591
639
- For file pages mapped into non-linear VMAs, the try_to_munlock() logic works
640
- slightly differently. On encountering a VM_LOCKED non-linear VMA that might
641
- map the page, try_to_munlock() returns SWAP_AGAIN without actually mlocking the
642
- page. munlock_vma_page() will just leave the page unlocked and let vmscan deal
643
- with it - the usual fallback position.
644
-
645
592
Note that try_to_munlock()'s reverse map walk must visit every VMA in a page's
646
593
reverse map to determine that a page is NOT mapped into any VM_LOCKED VMA.
647
594
However, the scan can terminate when it encounters a VM_LOCKED VMA and can
0 commit comments