Skip to content

Commit eabafaa

Browse files
Kefeng Wangakpm00
authored andcommitted
mm: convert to should_zap_page() to should_zap_folio()
Make should_zap_page() take a folio and rename it to should_zap_folio() as preparation for converting mm counter functions to take a folio. Saves a call to compound_head() hidden inside PageAnon(). [wangkefeng.wang@huawei.com: fix used-uninitialized warning] Link: https://lkml.kernel.org/r/962a7993-fce9-4de8-85cd-25e290f25736@huawei.com Link: https://lkml.kernel.org/r/20240111152429.3374566-9-willy@infradead.org Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 530c2a0 commit eabafaa

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

mm/memory.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,19 +1369,20 @@ static inline bool should_zap_cows(struct zap_details *details)
13691369
return details->even_cows;
13701370
}
13711371

1372-
/* Decides whether we should zap this page with the page pointer specified */
1373-
static inline bool should_zap_page(struct zap_details *details, struct page *page)
1372+
/* Decides whether we should zap this folio with the folio pointer specified */
1373+
static inline bool should_zap_folio(struct zap_details *details,
1374+
struct folio *folio)
13741375
{
1375-
/* If we can make a decision without *page.. */
1376+
/* If we can make a decision without *folio.. */
13761377
if (should_zap_cows(details))
13771378
return true;
13781379

1379-
/* E.g. the caller passes NULL for the case of a zero page */
1380-
if (!page)
1380+
/* E.g. the caller passes NULL for the case of a zero folio */
1381+
if (!folio)
13811382
return true;
13821383

1383-
/* Otherwise we should only zap non-anon pages */
1384-
return !PageAnon(page);
1384+
/* Otherwise we should only zap non-anon folios */
1385+
return !folio_test_anon(folio);
13851386
}
13861387

13871388
static inline bool zap_drop_file_uffd_wp(struct zap_details *details)
@@ -1434,7 +1435,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,
14341435
arch_enter_lazy_mmu_mode();
14351436
do {
14361437
pte_t ptent = ptep_get(pte);
1437-
struct folio *folio;
1438+
struct folio *folio = NULL;
14381439
struct page *page;
14391440

14401441
if (pte_none(ptent))
@@ -1447,7 +1448,10 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,
14471448
unsigned int delay_rmap;
14481449

14491450
page = vm_normal_page(vma, addr, ptent);
1450-
if (unlikely(!should_zap_page(details, page)))
1451+
if (page)
1452+
folio = page_folio(page);
1453+
1454+
if (unlikely(!should_zap_folio(details, folio)))
14511455
continue;
14521456
ptent = ptep_get_and_clear_full(mm, addr, pte,
14531457
tlb->fullmm);
@@ -1460,7 +1464,6 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,
14601464
continue;
14611465
}
14621466

1463-
folio = page_folio(page);
14641467
delay_rmap = 0;
14651468
if (!folio_test_anon(folio)) {
14661469
if (pte_dirty(ptent)) {
@@ -1492,7 +1495,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,
14921495
is_device_exclusive_entry(entry)) {
14931496
page = pfn_swap_entry_to_page(entry);
14941497
folio = page_folio(page);
1495-
if (unlikely(!should_zap_page(details, page)))
1498+
if (unlikely(!should_zap_folio(details, folio)))
14961499
continue;
14971500
/*
14981501
* Both device private/exclusive mappings should only
@@ -1513,10 +1516,10 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,
15131516
if (unlikely(!free_swap_and_cache(entry)))
15141517
print_bad_pte(vma, addr, ptent, NULL);
15151518
} else if (is_migration_entry(entry)) {
1516-
page = pfn_swap_entry_to_page(entry);
1517-
if (!should_zap_page(details, page))
1519+
folio = pfn_swap_entry_folio(entry);
1520+
if (!should_zap_folio(details, folio))
15181521
continue;
1519-
rss[mm_counter(page)]--;
1522+
rss[mm_counter(&folio->page)]--;
15201523
} else if (pte_marker_entry_uffd_wp(entry)) {
15211524
/*
15221525
* For anon: always drop the marker; for file: only

0 commit comments

Comments
 (0)