mm: shmem: add mTHP counters for anonymous shmem
authorBaolin Wang <baolin.wang@linux.alibaba.com>
Tue, 11 Jun 2024 10:11:10 +0000 (18:11 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 4 Jul 2024 02:30:04 +0000 (19:30 -0700)
Add mTHP counters for anonymous shmem.

[baolin.wang@linux.alibaba.com: update Documentation/admin-guide/mm/transhuge.rst]
Link: https://lkml.kernel.org/r/d86e2e7f-4141-432b-b2ba-c6691f36ef0b@linux.alibaba.com
Link: https://lkml.kernel.org/r/4fd9e467d49ae4a747e428bcd821c7d13125ae67.1718090413.git.baolin.wang@linux.alibaba.com
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
Reviewed-by: Lance Yang <ioworker0@gmail.com>
Cc: Barry Song <v-songbaohua@oppo.com>
Cc: Daniel Gomez <da.gomez@samsung.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Cc: Pankaj Raghav <p.raghav@samsung.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Yang Shi <shy828301@gmail.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Documentation/admin-guide/mm/transhuge.rst
include/linux/huge_mm.h
mm/huge_memory.c
mm/shmem.c

index e7232b46fe1412728a88126847fcf7247ffff86f..1f72b00af5d359caaeaaacd5bdf7a98768fb5dcb 100644 (file)
@@ -501,6 +501,19 @@ swpout_fallback
        Usually because failed to allocate some continuous swap space
        for the huge page.
 
+file_alloc
+       is incremented every time a file huge page is successfully
+       allocated.
+
+file_fallback
+       is incremented if a file huge page is attempted to be allocated
+       but fails and instead falls back to using small pages.
+
+file_fallback_charge
+       is incremented if a file huge page cannot be charged and instead
+       falls back to using small pages even though the allocation was
+       successful.
+
 As the system ages, allocating huge pages may be expensive as the
 system uses memory compaction to copy data around memory to free a
 huge page for use. There are some counters in ``/proc/vmstat`` to help
index 53b7a137f4603246e6406e6d37f98cd8672fcbc2..7ad41de5eaea40011d9031f585f6aff5dab91d57 100644 (file)
@@ -281,6 +281,9 @@ enum mthp_stat_item {
        MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE,
        MTHP_STAT_SWPOUT,
        MTHP_STAT_SWPOUT_FALLBACK,
+       MTHP_STAT_FILE_ALLOC,
+       MTHP_STAT_FILE_FALLBACK,
+       MTHP_STAT_FILE_FALLBACK_CHARGE,
        __MTHP_STAT_COUNT
 };
 
index af6f239b0f97a5d23e6600ead488125b566d2f01..f55362a73e2d1dfdb525a800e4c556ea76e78f86 100644 (file)
@@ -556,6 +556,9 @@ DEFINE_MTHP_STAT_ATTR(anon_fault_fallback, MTHP_STAT_ANON_FAULT_FALLBACK);
 DEFINE_MTHP_STAT_ATTR(anon_fault_fallback_charge, MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE);
 DEFINE_MTHP_STAT_ATTR(swpout, MTHP_STAT_SWPOUT);
 DEFINE_MTHP_STAT_ATTR(swpout_fallback, MTHP_STAT_SWPOUT_FALLBACK);
+DEFINE_MTHP_STAT_ATTR(file_alloc, MTHP_STAT_FILE_ALLOC);
+DEFINE_MTHP_STAT_ATTR(file_fallback, MTHP_STAT_FILE_FALLBACK);
+DEFINE_MTHP_STAT_ATTR(file_fallback_charge, MTHP_STAT_FILE_FALLBACK_CHARGE);
 
 static struct attribute *stats_attrs[] = {
        &anon_fault_alloc_attr.attr,
@@ -563,6 +566,9 @@ static struct attribute *stats_attrs[] = {
        &anon_fault_fallback_charge_attr.attr,
        &swpout_attr.attr,
        &swpout_fallback_attr.attr,
+       &file_alloc_attr.attr,
+       &file_fallback_attr.attr,
+       &file_fallback_charge_attr.attr,
        NULL,
 };
 
index 224162aa204bcdc6b397b0eecdf890b624e1bd01..d09c6bf1f28a669f016b5e3cc800a53529a75bc0 100644 (file)
@@ -1772,6 +1772,9 @@ static struct folio *shmem_alloc_and_add_folio(struct vm_fault *vmf,
 
                        if (pages == HPAGE_PMD_NR)
                                count_vm_event(THP_FILE_FALLBACK);
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+                       count_mthp_stat(order, MTHP_STAT_FILE_FALLBACK);
+#endif
                        order = next_order(&suitable_orders, order);
                }
        } else {
@@ -1791,9 +1794,15 @@ allocated:
                if (xa_find(&mapping->i_pages, &index,
                                index + pages - 1, XA_PRESENT)) {
                        error = -EEXIST;
-               } else if (pages == HPAGE_PMD_NR) {
-                       count_vm_event(THP_FILE_FALLBACK);
-                       count_vm_event(THP_FILE_FALLBACK_CHARGE);
+               } else if (pages > 1) {
+                       if (pages == HPAGE_PMD_NR) {
+                               count_vm_event(THP_FILE_FALLBACK);
+                               count_vm_event(THP_FILE_FALLBACK_CHARGE);
+                       }
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+                       count_mthp_stat(folio_order(folio), MTHP_STAT_FILE_FALLBACK);
+                       count_mthp_stat(folio_order(folio), MTHP_STAT_FILE_FALLBACK_CHARGE);
+#endif
                }
                goto unlock;
        }
@@ -2167,6 +2176,9 @@ repeat:
                if (!IS_ERR(folio)) {
                        if (folio_test_pmd_mappable(folio))
                                count_vm_event(THP_FILE_ALLOC);
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+                       count_mthp_stat(folio_order(folio), MTHP_STAT_FILE_ALLOC);
+#endif
                        goto alloced;
                }
                if (PTR_ERR(folio) == -EEXIST)