]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm/shmem, swap: fix major fault counting
authorKairui Song <kasong@tencent.com>
Mon, 28 Jul 2025 07:53:06 +0000 (15:53 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 2 Aug 2025 19:06:13 +0000 (12:06 -0700)
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>
mm/shmem.c

index 33d30ee5bc8471cf183d231b50f81118bd8ba390..e1e5d5f7f58df7580b133144465e6d5b37eac511 100644 (file)
@@ -2356,13 +2356,6 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
        /* Look it up and read it in.. */
        folio = swap_cache_get_folio(swap, NULL, 0);
        if (!folio) {
-               /* Or update major stats only when swapin succeeds?? */
-               if (fault_type) {
-                       *fault_type |= VM_FAULT_MAJOR;
-                       count_vm_event(PGMAJFAULT);
-                       count_memcg_event_mm(fault_mm, PGMAJFAULT);
-               }
-
                if (data_race(si->flags & SWP_SYNCHRONOUS_IO)) {
                        /* Direct swapin skipping swap cache & readahead */
                        folio = shmem_swap_alloc_folio(inode, vma, index,
@@ -2381,6 +2374,11 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
                                goto failed;
                        }
                }
+               if (fault_type) {
+                       *fault_type |= VM_FAULT_MAJOR;
+                       count_vm_event(PGMAJFAULT);
+                       count_memcg_event_mm(fault_mm, PGMAJFAULT);
+               }
        }
 
        if (order > folio_order(folio)) {