Commit f742829d authored by Lance Yang's avatar Lance Yang Committed by Andrew Morton

mm/mlock: implement folio_mlock_step() using folio_pte_batch()

Let's make folio_mlock_step() simply a wrapper around folio_pte_batch(),
which will greatly reduce the cost of ptep_get() when scanning a range of
contptes.

Link: https://lkml.kernel.org/r/20240611010418.70797-1-ioworker0@gmail.comSigned-off-by: default avatarLance Yang <ioworker0@gmail.com>
Acked-by: default avatarDavid Hildenbrand <david@redhat.com>
Reviewed-by: default avatarBaolin Wang <baolin.wang@linux.alibaba.com>
Suggested-by: default avatarBarry Song <21cnbao@gmail.com>
Suggested-by: default avatarMatthew Wilcox <willy@infradead.org>
Cc: Bang Li <libang.li@antgroup.com>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Yin Fengwei <fengwei.yin@intel.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent c63f210d
......@@ -307,26 +307,15 @@ void munlock_folio(struct folio *folio)
static inline unsigned int folio_mlock_step(struct folio *folio,
pte_t *pte, unsigned long addr, unsigned long end)
{
unsigned int count, i, nr = folio_nr_pages(folio);
unsigned long pfn = folio_pfn(folio);
const fpb_t fpb_flags = FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DIRTY;
unsigned int count = (end - addr) >> PAGE_SHIFT;
pte_t ptent = ptep_get(pte);
if (!folio_test_large(folio))
return 1;
count = pfn + nr - pte_pfn(ptent);
count = min_t(unsigned int, count, (end - addr) >> PAGE_SHIFT);
for (i = 0; i < count; i++, pte++) {
pte_t entry = ptep_get(pte);
if (!pte_present(entry))
break;
if (pte_pfn(entry) - pfn >= nr)
break;
}
return i;
return folio_pte_batch(folio, addr, pte, ptent, count, fpb_flags, NULL,
NULL, NULL);
}
static inline bool allow_mlock_munlock(struct folio *folio,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment