Skip to content

Commit 6b27cc6

Browse files
Kefeng Wangakpm00
authored andcommitted
mm: convert mm_counter_file() to take a folio
Now all callers of mm_counter_file() have a folio, convert mm_counter_file() to take a folio. Saves a call to compound_head() hidden inside PageSwapBacked(). Link: https://lkml.kernel.org/r/20240111152429.3374566-11-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 a23f517 commit 6b27cc6

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

include/linux/mm.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,10 +2595,10 @@ static inline void dec_mm_counter(struct mm_struct *mm, int member)
25952595
mm_trace_rss_stat(mm, member);
25962596
}
25972597

2598-
/* Optimized variant when page is already known not to be PageAnon */
2599-
static inline int mm_counter_file(struct page *page)
2598+
/* Optimized variant when folio is already known not to be anon */
2599+
static inline int mm_counter_file(struct folio *folio)
26002600
{
2601-
if (PageSwapBacked(page))
2601+
if (folio_test_swapbacked(folio))
26022602
return MM_SHMEMPAGES;
26032603
return MM_FILEPAGES;
26042604
}
@@ -2607,7 +2607,7 @@ static inline int mm_counter(struct folio *folio)
26072607
{
26082608
if (folio_test_anon(folio))
26092609
return MM_ANONPAGES;
2610-
return mm_counter_file(&folio->page);
2610+
return mm_counter_file(folio);
26112611
}
26122612

26132613
static inline unsigned long get_mm_rss(struct mm_struct *mm)

kernel/events/uprobes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr,
188188
dec_mm_counter(mm, MM_ANONPAGES);
189189

190190
if (!folio_test_anon(old_folio)) {
191-
dec_mm_counter(mm, mm_counter_file(old_page));
191+
dec_mm_counter(mm, mm_counter_file(old_folio));
192192
inc_mm_counter(mm, MM_ANONPAGES);
193193
}
194194

mm/huge_memory.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,7 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
19311931
} else {
19321932
if (arch_needs_pgtable_deposit())
19331933
zap_deposited_table(tlb->mm, pmd);
1934-
add_mm_counter(tlb->mm, mm_counter_file(&folio->page),
1934+
add_mm_counter(tlb->mm, mm_counter_file(folio),
19351935
-HPAGE_PMD_NR);
19361936
}
19371937

@@ -2456,7 +2456,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
24562456
folio_remove_rmap_pmd(folio, page, vma);
24572457
folio_put(folio);
24582458
}
2459-
add_mm_counter(mm, mm_counter_file(&folio->page), -HPAGE_PMD_NR);
2459+
add_mm_counter(mm, mm_counter_file(folio), -HPAGE_PMD_NR);
24602460
return;
24612461
}
24622462

mm/khugepaged.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr,
16341634
/* step 3: set proper refcount and mm_counters. */
16351635
if (nr_ptes) {
16361636
folio_ref_sub(folio, nr_ptes);
1637-
add_mm_counter(mm, mm_counter_file(&folio->page), -nr_ptes);
1637+
add_mm_counter(mm, mm_counter_file(folio), -nr_ptes);
16381638
}
16391639

16401640
/* step 4: remove empty page table */
@@ -1665,7 +1665,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr,
16651665
if (nr_ptes) {
16661666
flush_tlb_mm(mm);
16671667
folio_ref_sub(folio, nr_ptes);
1668-
add_mm_counter(mm, mm_counter_file(&folio->page), -nr_ptes);
1668+
add_mm_counter(mm, mm_counter_file(folio), -nr_ptes);
16691669
}
16701670
if (start_pte)
16711671
pte_unmap_unlock(start_pte, ptl);

mm/memory.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma,
966966
} else if (page) {
967967
folio_get(folio);
968968
folio_dup_file_rmap_pte(folio, page);
969-
rss[mm_counter_file(page)]++;
969+
rss[mm_counter_file(folio)]++;
970970
}
971971

972972
/*
@@ -1873,7 +1873,7 @@ static int insert_page_into_pte_locked(struct vm_area_struct *vma, pte_t *pte,
18731873
return -EBUSY;
18741874
/* Ok, finally just insert the thing.. */
18751875
folio_get(folio);
1876-
inc_mm_counter(vma->vm_mm, mm_counter_file(page));
1876+
inc_mm_counter(vma->vm_mm, mm_counter_file(folio));
18771877
folio_add_file_rmap_pte(folio, page, vma);
18781878
set_pte_at(vma->vm_mm, addr, pte, mk_pte(page, prot));
18791879
return 0;
@@ -3178,7 +3178,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf)
31783178
if (likely(vmf->pte && pte_same(ptep_get(vmf->pte), vmf->orig_pte))) {
31793179
if (old_folio) {
31803180
if (!folio_test_anon(old_folio)) {
3181-
dec_mm_counter(mm, mm_counter_file(&old_folio->page));
3181+
dec_mm_counter(mm, mm_counter_file(old_folio));
31823182
inc_mm_counter(mm, MM_ANONPAGES);
31833183
}
31843184
} else {
@@ -4483,7 +4483,7 @@ vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page)
44834483
if (write)
44844484
entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma);
44854485

4486-
add_mm_counter(vma->vm_mm, mm_counter_file(page), HPAGE_PMD_NR);
4486+
add_mm_counter(vma->vm_mm, mm_counter_file(folio), HPAGE_PMD_NR);
44874487
folio_add_file_rmap_pmd(folio, page, vma);
44884488

44894489
/*
@@ -4546,7 +4546,7 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio,
45464546
folio_add_new_anon_rmap(folio, vma, addr);
45474547
folio_add_lru_vma(folio, vma);
45484548
} else {
4549-
add_mm_counter(vma->vm_mm, mm_counter_file(page), nr);
4549+
add_mm_counter(vma->vm_mm, mm_counter_file(folio), nr);
45504550
folio_add_file_rmap_ptes(folio, page, nr, vma);
45514551
}
45524552
set_ptes(vma->vm_mm, addr, vmf->pte, entry, nr);

mm/rmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
19031903
*
19041904
* See Documentation/mm/mmu_notifier.rst
19051905
*/
1906-
dec_mm_counter(mm, mm_counter_file(&folio->page));
1906+
dec_mm_counter(mm, mm_counter_file(folio));
19071907
}
19081908
discard:
19091909
if (unlikely(folio_test_hugetlb(folio)))

0 commit comments

Comments
 (0)