Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/rmap: mlock large folios in try_to_unmap_one()

Currently, try_to_unmap_once() only tries to mlock small folios.

Use logic similar to folio_referenced_one() to mlock large folios: only do
this for fully mapped folios and under page table lock that protects all
page table entries.

[akpm@linux-foundation.org: s/CROSSSED/CROSSED/]
Link: https://lkml.kernel.org/r/20250923110711.690639-4-kirill@shutemov.name
Signed-off-by: Kiryl Shutsemau <kas@kernel.org>
Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kiryl Shutsemau and committed by
Andrew Morton
8c49fbaf a2880202

+28 -3
+28 -3
mm/rmap.c
··· 1870 1870 unsigned long nr_pages = 1, end_addr; 1871 1871 unsigned long pfn; 1872 1872 unsigned long hsz = 0; 1873 + int ptes = 0; 1873 1874 1874 1875 /* 1875 1876 * When racing against e.g. zap_pte_range() on another cpu, ··· 1911 1910 */ 1912 1911 if (!(flags & TTU_IGNORE_MLOCK) && 1913 1912 (vma->vm_flags & VM_LOCKED)) { 1913 + ptes++; 1914 + 1915 + /* 1916 + * Set 'ret' to indicate the page cannot be unmapped. 1917 + * 1918 + * Do not jump to walk_abort immediately as additional 1919 + * iteration might be required to detect fully mapped 1920 + * folio an mlock it. 1921 + */ 1922 + ret = false; 1923 + 1924 + /* Only mlock fully mapped pages */ 1925 + if (pvmw.pte && ptes != pvmw.nr_pages) 1926 + continue; 1927 + 1928 + /* 1929 + * All PTEs must be protected by page table lock in 1930 + * order to mlock the page. 1931 + * 1932 + * If page table boundary has been cross, current ptl 1933 + * only protect part of ptes. 1934 + */ 1935 + if (pvmw.flags & PVMW_PGTABLE_CROSSED) 1936 + goto walk_done; 1937 + 1914 1938 /* Restore the mlock which got missed */ 1915 - if (!folio_test_large(folio)) 1916 - mlock_vma_folio(folio, vma); 1917 - goto walk_abort; 1939 + mlock_vma_folio(folio, vma); 1940 + goto walk_done; 1918 1941 } 1919 1942 1920 1943 if (!pvmw.pte) {