Skip to content

Commit f742829

Browse files
ioworker0akpm00
authored andcommitted
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/[email protected] Signed-off-by: Lance Yang <[email protected]> Acked-by: David Hildenbrand <[email protected]> Reviewed-by: Baolin Wang <[email protected]> Suggested-by: Barry Song <[email protected]> Suggested-by: Matthew Wilcox <[email protected]> Cc: Bang Li <[email protected]> Cc: "Huang, Ying" <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Yin Fengwei <[email protected]> Cc: Zi Yan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent c63f210 commit f742829

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

mm/mlock.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -307,26 +307,15 @@ void munlock_folio(struct folio *folio)
307307
static inline unsigned int folio_mlock_step(struct folio *folio,
308308
pte_t *pte, unsigned long addr, unsigned long end)
309309
{
310-
unsigned int count, i, nr = folio_nr_pages(folio);
311-
unsigned long pfn = folio_pfn(folio);
310+
const fpb_t fpb_flags = FPB_IGNORE_DIRTY | FPB_IGNORE_SOFT_DIRTY;
311+
unsigned int count = (end - addr) >> PAGE_SHIFT;
312312
pte_t ptent = ptep_get(pte);
313313

314314
if (!folio_test_large(folio))
315315
return 1;
316316

317-
count = pfn + nr - pte_pfn(ptent);
318-
count = min_t(unsigned int, count, (end - addr) >> PAGE_SHIFT);
319-
320-
for (i = 0; i < count; i++, pte++) {
321-
pte_t entry = ptep_get(pte);
322-
323-
if (!pte_present(entry))
324-
break;
325-
if (pte_pfn(entry) - pfn >= nr)
326-
break;
327-
}
328-
329-
return i;
317+
return folio_pte_batch(folio, addr, pte, ptent, count, fpb_flags, NULL,
318+
NULL, NULL);
330319
}
331320

332321
static inline bool allow_mlock_munlock(struct folio *folio,

0 commit comments

Comments
 (0)