Skip to content

Commit de55be4

Browse files
ryncsnakpm00
authored andcommitted
mm/shmem, swap: fix major fault counting
If the swapin failed, don't update the major fault count. There is a long existing comment for doing it this way, now with previous cleanups, we can finally fix it. Link: https://lkml.kernel.org/r/20250728075306.12704-9-ryncsn@gmail.com Signed-off-by: Kairui Song <kasong@tencent.com> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> Cc: Baoquan He <bhe@redhat.com> Cc: Barry Song <baohua@kernel.org> Cc: Chris Li <chrisl@kernel.org> Cc: Dev Jain <dev.jain@arm.com> Cc: Hugh Dickins <hughd@google.com> Cc: Kemeng Shi <shikemeng@huaweicloud.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Nhat Pham <nphamcs@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 93c0476 commit de55be4

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

mm/shmem.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,13 +2356,6 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
23562356
/* Look it up and read it in.. */
23572357
folio = swap_cache_get_folio(swap, NULL, 0);
23582358
if (!folio) {
2359-
/* Or update major stats only when swapin succeeds?? */
2360-
if (fault_type) {
2361-
*fault_type |= VM_FAULT_MAJOR;
2362-
count_vm_event(PGMAJFAULT);
2363-
count_memcg_event_mm(fault_mm, PGMAJFAULT);
2364-
}
2365-
23662359
if (data_race(si->flags & SWP_SYNCHRONOUS_IO)) {
23672360
/* Direct swapin skipping swap cache & readahead */
23682361
folio = shmem_swap_alloc_folio(inode, vma, index,
@@ -2381,6 +2374,11 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
23812374
goto failed;
23822375
}
23832376
}
2377+
if (fault_type) {
2378+
*fault_type |= VM_FAULT_MAJOR;
2379+
count_vm_event(PGMAJFAULT);
2380+
count_memcg_event_mm(fault_mm, PGMAJFAULT);
2381+
}
23842382
}
23852383

23862384
if (order > folio_order(folio)) {

0 commit comments

Comments
 (0)