Skip to content

Commit dcdf11e

Browse files
rientjestorvalds
authored andcommitted
mm, shmem: add vmstat for hugepage fallback
The existing thp_fault_fallback indicates when thp attempts to allocate a hugepage but fails, or if the hugepage cannot be charged to the mem cgroup hierarchy. Extend this to shmem as well. Adds a new thp_file_fallback to complement thp_file_alloc that gets incremented when a hugepage is attempted to be allocated but fails, or if it cannot be charged to the mem cgroup hierarchy. Additionally, remove the check for CONFIG_TRANSPARENT_HUGE_PAGECACHE from shmem_alloc_hugepage() since it is only called with this configuration option. Signed-off-by: David Rientjes <rientjes@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Yang Shi <yang.shi@linux.alibaba.com> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Mike Rapoport <rppt@linux.ibm.com> Cc: Jeremy Cline <jcline@redhat.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Mike Kravetz <mike.kravetz@oracle.com> Cc: Michal Hocko <mhocko@kernel.org> Cc: Vlastimil Babka <vbabka@suse.cz> Link: http://lkml.kernel.org/r/alpine.DEB.2.21.2003061421240.7412@chino.kir.corp.google.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6aeff24 commit dcdf11e

4 files changed

Lines changed: 13 additions & 4 deletions

File tree

‎Documentation/admin-guide/mm/transhuge.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ thp_file_alloc
319319
is incremented every time a file huge page is successfully
320320
allocated.
321321

322+
thp_file_fallback
323+
is incremented if a file huge page is attempted to be allocated
324+
but fails and instead falls back to using small pages.
325+
322326
thp_file_mapped
323327
is incremented every time a file huge page is mapped into
324328
user address space.

‎include/linux/vm_event_item.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
7676
THP_COLLAPSE_ALLOC,
7777
THP_COLLAPSE_ALLOC_FAILED,
7878
THP_FILE_ALLOC,
79+
THP_FILE_FALLBACK,
7980
THP_FILE_MAPPED,
8081
THP_SPLIT_PAGE,
8182
THP_SPLIT_PAGE_FAILED,
@@ -115,6 +116,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
115116

116117
#ifndef CONFIG_TRANSPARENT_HUGEPAGE
117118
#define THP_FILE_ALLOC ({ BUILD_BUG(); 0; })
119+
#define THP_FILE_FALLBACK ({ BUILD_BUG(); 0; })
118120
#define THP_FILE_MAPPED ({ BUILD_BUG(); 0; })
119121
#endif
120122

‎mm/shmem.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,9 +1472,6 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp,
14721472
pgoff_t hindex;
14731473
struct page *page;
14741474

1475-
if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGE_PAGECACHE))
1476-
return NULL;
1477-
14781475
hindex = round_down(index, HPAGE_PMD_NR);
14791476
if (xa_find(&mapping->i_pages, &hindex, hindex + HPAGE_PMD_NR - 1,
14801477
XA_PRESENT))
@@ -1486,6 +1483,8 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp,
14861483
shmem_pseudo_vma_destroy(&pvma);
14871484
if (page)
14881485
prep_transhuge_page(page);
1486+
else
1487+
count_vm_event(THP_FILE_FALLBACK);
14891488
return page;
14901489
}
14911490

@@ -1871,8 +1870,11 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
18711870

18721871
error = mem_cgroup_try_charge_delay(page, charge_mm, gfp, &memcg,
18731872
PageTransHuge(page));
1874-
if (error)
1873+
if (error) {
1874+
if (PageTransHuge(page))
1875+
count_vm_event(THP_FILE_FALLBACK);
18751876
goto unacct;
1877+
}
18761878
error = shmem_add_to_page_cache(page, mapping, hindex,
18771879
NULL, gfp & GFP_RECLAIM_MASK);
18781880
if (error) {

‎mm/vmstat.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,7 @@ const char * const vmstat_text[] = {
12591259
"thp_collapse_alloc",
12601260
"thp_collapse_alloc_failed",
12611261
"thp_file_alloc",
1262+
"thp_file_fallback",
12621263
"thp_file_mapped",
12631264
"thp_split_page",
12641265
"thp_split_page_failed",

0 commit comments

Comments
 (0)