linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [patch 1/2] mm, shmem: add vmstat for hugepage fallback
@ 2020-03-06 22:22 David Rientjes
  2020-03-06 22:22 ` [patch 2/2] mm, thp: track fallbacks due to failed memcg charges separately David Rientjes
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: David Rientjes @ 2020-03-06 22:22 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Yang Shi, Kirill A. Shutemov, Kirill A. Shutemov, Mike Rapoport,
	Jeremy Cline, Linux Kernel Mailing List, Linux MM

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>
---
 Documentation/admin-guide/mm/transhuge.rst |  4 ++++
 include/linux/vm_event_item.h              |  2 ++
 mm/shmem.c                                 | 10 ++++++----
 mm/vmstat.c                                |  1 +
 4 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst
--- a/Documentation/admin-guide/mm/transhuge.rst
+++ b/Documentation/admin-guide/mm/transhuge.rst
@@ -319,6 +319,10 @@ thp_file_alloc
 	is incremented every time a file huge page is successfully
 	allocated.
 
+thp_file_fallback
+	is incremented if a file huge page is attempted to be allocated
+	but fails and instead falls back to using small pages.
+
 thp_file_mapped
 	is incremented every time a file huge page is mapped into
 	user address space.
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -76,6 +76,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
 		THP_COLLAPSE_ALLOC,
 		THP_COLLAPSE_ALLOC_FAILED,
 		THP_FILE_ALLOC,
+		THP_FILE_FALLBACK,
 		THP_FILE_MAPPED,
 		THP_SPLIT_PAGE,
 		THP_SPLIT_PAGE_FAILED,
@@ -115,6 +116,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
 
 #ifndef CONFIG_TRANSPARENT_HUGEPAGE
 #define THP_FILE_ALLOC ({ BUILD_BUG(); 0; })
+#define THP_FILE_FALLBACK ({ BUILD_BUG(); 0; })
 #define THP_FILE_MAPPED ({ BUILD_BUG(); 0; })
 #endif
 
diff --git a/mm/shmem.c b/mm/shmem.c
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1472,9 +1472,6 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp,
 	pgoff_t hindex;
 	struct page *page;
 
-	if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGE_PAGECACHE))
-		return NULL;
-
 	hindex = round_down(index, HPAGE_PMD_NR);
 	if (xa_find(&mapping->i_pages, &hindex, hindex + HPAGE_PMD_NR - 1,
 								XA_PRESENT))
@@ -1486,6 +1483,8 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp,
 	shmem_pseudo_vma_destroy(&pvma);
 	if (page)
 		prep_transhuge_page(page);
+	else
+		count_vm_event(THP_FILE_FALLBACK);
 	return page;
 }
 
@@ -1871,8 +1870,11 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
 
 	error = mem_cgroup_try_charge_delay(page, charge_mm, gfp, &memcg,
 					    PageTransHuge(page));
-	if (error)
+	if (error) {
+		if (PageTransHuge(page))
+			count_vm_event(THP_FILE_FALLBACK);
 		goto unacct;
+	}
 	error = shmem_add_to_page_cache(page, mapping, hindex,
 					NULL, gfp & GFP_RECLAIM_MASK);
 	if (error) {
diff --git a/mm/vmstat.c b/mm/vmstat.c
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1257,6 +1257,7 @@ const char * const vmstat_text[] = {
 	"thp_collapse_alloc",
 	"thp_collapse_alloc_failed",
 	"thp_file_alloc",
+	"thp_file_fallback",
 	"thp_file_mapped",
 	"thp_split_page",
 	"thp_split_page_failed",


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [patch 2/2] mm, thp: track fallbacks due to failed memcg charges separately
  2020-03-06 22:22 [patch 1/2] mm, shmem: add vmstat for hugepage fallback David Rientjes
@ 2020-03-06 22:22 ` David Rientjes
  2020-03-07  4:13   ` Yang Shi
  2020-03-09 15:48   ` Kirill A. Shutemov
  2020-03-07  4:10 ` [patch 1/2] mm, shmem: add vmstat for hugepage fallback Yang Shi
  2020-03-09 15:48 ` Kirill A. Shutemov
  2 siblings, 2 replies; 6+ messages in thread
From: David Rientjes @ 2020-03-06 22:22 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Yang Shi, Kirill A. Shutemov, Kirill A. Shutemov, Mike Rapoport,
	Jeremy Cline, Linux Kernel Mailing List, Linux MM

The thp_fault_fallback and thp_file_fallback vmstats are incremented if
either the hugepage allocation fails through the page allocator or the
hugepage charge fails through mem cgroup.

This patch leaves this field untouched but adds two new fields,
thp_{fault,file}_fallback_charge, which is incremented only when the mem
cgroup charge fails.

This distinguishes between attempted hugepage allocations that fail due to
fragmentation (or low memory conditions) and those that fail due to mem
cgroup limits.  That can be used to determine the impact of fragmentation
on the system by excluding faults that failed due to memcg usage.

Signed-off-by: David Rientjes <rientjes@google.com>
---
 Documentation/admin-guide/mm/transhuge.rst | 10 ++++++++++
 include/linux/vm_event_item.h              |  3 +++
 mm/huge_memory.c                           |  2 ++
 mm/shmem.c                                 |  4 +++-
 mm/vmstat.c                                |  2 ++
 5 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst
--- a/Documentation/admin-guide/mm/transhuge.rst
+++ b/Documentation/admin-guide/mm/transhuge.rst
@@ -310,6 +310,11 @@ thp_fault_fallback
 	is incremented if a page fault fails to allocate
 	a huge page and instead falls back to using small pages.
 
+thp_fault_fallback_charge
+	is incremented if a page fault fails to charge a huge page and
+	instead falls back to using small pages even though the
+	allocation was successful.
+
 thp_collapse_alloc_failed
 	is incremented if khugepaged found a range
 	of pages that should be collapsed into one huge page but failed
@@ -323,6 +328,11 @@ thp_file_fallback
 	is incremented if a file huge page is attempted to be allocated
 	but fails and instead falls back to using small pages.
 
+thp_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.
+
 thp_file_mapped
 	is incremented every time a file huge page is mapped into
 	user address space.
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -73,10 +73,12 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 		THP_FAULT_ALLOC,
 		THP_FAULT_FALLBACK,
+		THP_FAULT_FALLBACK_CHARGE,
 		THP_COLLAPSE_ALLOC,
 		THP_COLLAPSE_ALLOC_FAILED,
 		THP_FILE_ALLOC,
 		THP_FILE_FALLBACK,
+		THP_FILE_FALLBACK_CHARGE,
 		THP_FILE_MAPPED,
 		THP_SPLIT_PAGE,
 		THP_SPLIT_PAGE_FAILED,
@@ -117,6 +119,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
 #ifndef CONFIG_TRANSPARENT_HUGEPAGE
 #define THP_FILE_ALLOC ({ BUILD_BUG(); 0; })
 #define THP_FILE_FALLBACK ({ BUILD_BUG(); 0; })
+#define THP_FILE_FALLBACK_CHARGE ({ BUILD_BUG(); 0; })
 #define THP_FILE_MAPPED ({ BUILD_BUG(); 0; })
 #endif
 
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -597,6 +597,7 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf,
 	if (mem_cgroup_try_charge_delay(page, vma->vm_mm, gfp, &memcg, true)) {
 		put_page(page);
 		count_vm_event(THP_FAULT_FALLBACK);
+		count_vm_event(THP_FAULT_FALLBACK_CHARGE);
 		return VM_FAULT_FALLBACK;
 	}
 
@@ -1406,6 +1407,7 @@ vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd)
 			put_page(page);
 		ret |= VM_FAULT_FALLBACK;
 		count_vm_event(THP_FAULT_FALLBACK);
+		count_vm_event(THP_FAULT_FALLBACK_CHARGE);
 		goto out;
 	}
 
diff --git a/mm/shmem.c b/mm/shmem.c
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1871,8 +1871,10 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
 	error = mem_cgroup_try_charge_delay(page, charge_mm, gfp, &memcg,
 					    PageTransHuge(page));
 	if (error) {
-		if (PageTransHuge(page))
+		if (PageTransHuge(page)) {
 			count_vm_event(THP_FILE_FALLBACK);
+			count_vm_event(THP_FILE_FALLBACK_CHARGE);
+		}
 		goto unacct;
 	}
 	error = shmem_add_to_page_cache(page, mapping, hindex,
diff --git a/mm/vmstat.c b/mm/vmstat.c
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1254,10 +1254,12 @@ const char * const vmstat_text[] = {
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 	"thp_fault_alloc",
 	"thp_fault_fallback",
+	"thp_fault_fallback_charge",
 	"thp_collapse_alloc",
 	"thp_collapse_alloc_failed",
 	"thp_file_alloc",
 	"thp_file_fallback",
+	"thp_file_fallback_charge",
 	"thp_file_mapped",
 	"thp_split_page",
 	"thp_split_page_failed",


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch 1/2] mm, shmem: add vmstat for hugepage fallback
  2020-03-06 22:22 [patch 1/2] mm, shmem: add vmstat for hugepage fallback David Rientjes
  2020-03-06 22:22 ` [patch 2/2] mm, thp: track fallbacks due to failed memcg charges separately David Rientjes
@ 2020-03-07  4:10 ` Yang Shi
  2020-03-09 15:48 ` Kirill A. Shutemov
  2 siblings, 0 replies; 6+ messages in thread
From: Yang Shi @ 2020-03-07  4:10 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, Kirill A. Shutemov, Kirill A. Shutemov,
	Mike Rapoport, Jeremy Cline, Linux Kernel Mailing List, Linux MM

On Fri, Mar 6, 2020 at 2:22 PM David Rientjes <rientjes@google.com> wrote:
>
> 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.

Looks good to me. Thanks for taking this suggestion. Reviewed-by: Yang
Shi <yang.shi@linux.alibaba.com>

>
> Signed-off-by: David Rientjes <rientjes@google.com>
> ---
>  Documentation/admin-guide/mm/transhuge.rst |  4 ++++
>  include/linux/vm_event_item.h              |  2 ++
>  mm/shmem.c                                 | 10 ++++++----
>  mm/vmstat.c                                |  1 +
>  4 files changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst
> --- a/Documentation/admin-guide/mm/transhuge.rst
> +++ b/Documentation/admin-guide/mm/transhuge.rst
> @@ -319,6 +319,10 @@ thp_file_alloc
>         is incremented every time a file huge page is successfully
>         allocated.
>
> +thp_file_fallback
> +       is incremented if a file huge page is attempted to be allocated
> +       but fails and instead falls back to using small pages.
> +
>  thp_file_mapped
>         is incremented every time a file huge page is mapped into
>         user address space.
> diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
> --- a/include/linux/vm_event_item.h
> +++ b/include/linux/vm_event_item.h
> @@ -76,6 +76,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
>                 THP_COLLAPSE_ALLOC,
>                 THP_COLLAPSE_ALLOC_FAILED,
>                 THP_FILE_ALLOC,
> +               THP_FILE_FALLBACK,
>                 THP_FILE_MAPPED,
>                 THP_SPLIT_PAGE,
>                 THP_SPLIT_PAGE_FAILED,
> @@ -115,6 +116,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
>
>  #ifndef CONFIG_TRANSPARENT_HUGEPAGE
>  #define THP_FILE_ALLOC ({ BUILD_BUG(); 0; })
> +#define THP_FILE_FALLBACK ({ BUILD_BUG(); 0; })
>  #define THP_FILE_MAPPED ({ BUILD_BUG(); 0; })
>  #endif
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -1472,9 +1472,6 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp,
>         pgoff_t hindex;
>         struct page *page;
>
> -       if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGE_PAGECACHE))
> -               return NULL;
> -
>         hindex = round_down(index, HPAGE_PMD_NR);
>         if (xa_find(&mapping->i_pages, &hindex, hindex + HPAGE_PMD_NR - 1,
>                                                                 XA_PRESENT))
> @@ -1486,6 +1483,8 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp,
>         shmem_pseudo_vma_destroy(&pvma);
>         if (page)
>                 prep_transhuge_page(page);
> +       else
> +               count_vm_event(THP_FILE_FALLBACK);
>         return page;
>  }
>
> @@ -1871,8 +1870,11 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
>
>         error = mem_cgroup_try_charge_delay(page, charge_mm, gfp, &memcg,
>                                             PageTransHuge(page));
> -       if (error)
> +       if (error) {
> +               if (PageTransHuge(page))
> +                       count_vm_event(THP_FILE_FALLBACK);
>                 goto unacct;
> +       }
>         error = shmem_add_to_page_cache(page, mapping, hindex,
>                                         NULL, gfp & GFP_RECLAIM_MASK);
>         if (error) {
> diff --git a/mm/vmstat.c b/mm/vmstat.c
> --- a/mm/vmstat.c
> +++ b/mm/vmstat.c
> @@ -1257,6 +1257,7 @@ const char * const vmstat_text[] = {
>         "thp_collapse_alloc",
>         "thp_collapse_alloc_failed",
>         "thp_file_alloc",
> +       "thp_file_fallback",
>         "thp_file_mapped",
>         "thp_split_page",
>         "thp_split_page_failed",


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch 2/2] mm, thp: track fallbacks due to failed memcg charges separately
  2020-03-06 22:22 ` [patch 2/2] mm, thp: track fallbacks due to failed memcg charges separately David Rientjes
@ 2020-03-07  4:13   ` Yang Shi
  2020-03-09 15:48   ` Kirill A. Shutemov
  1 sibling, 0 replies; 6+ messages in thread
From: Yang Shi @ 2020-03-07  4:13 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, Kirill A. Shutemov, Kirill A. Shutemov,
	Mike Rapoport, Jeremy Cline, Linux Kernel Mailing List, Linux MM

On Fri, Mar 6, 2020 at 2:22 PM David Rientjes <rientjes@google.com> wrote:
>
> The thp_fault_fallback and thp_file_fallback vmstats are incremented if
> either the hugepage allocation fails through the page allocator or the
> hugepage charge fails through mem cgroup.
>
> This patch leaves this field untouched but adds two new fields,
> thp_{fault,file}_fallback_charge, which is incremented only when the mem
> cgroup charge fails.
>
> This distinguishes between attempted hugepage allocations that fail due to
> fragmentation (or low memory conditions) and those that fail due to mem
> cgroup limits.  That can be used to determine the impact of fragmentation
> on the system by excluding faults that failed due to memcg usage.

Yes, it makes sense to me.

Reviewed-by: Yang Shi <yang.shi@linux.alibaba.com>

>
> Signed-off-by: David Rientjes <rientjes@google.com>
> ---
>  Documentation/admin-guide/mm/transhuge.rst | 10 ++++++++++
>  include/linux/vm_event_item.h              |  3 +++
>  mm/huge_memory.c                           |  2 ++
>  mm/shmem.c                                 |  4 +++-
>  mm/vmstat.c                                |  2 ++
>  5 files changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst
> --- a/Documentation/admin-guide/mm/transhuge.rst
> +++ b/Documentation/admin-guide/mm/transhuge.rst
> @@ -310,6 +310,11 @@ thp_fault_fallback
>         is incremented if a page fault fails to allocate
>         a huge page and instead falls back to using small pages.
>
> +thp_fault_fallback_charge
> +       is incremented if a page fault fails to charge a huge page and
> +       instead falls back to using small pages even though the
> +       allocation was successful.
> +
>  thp_collapse_alloc_failed
>         is incremented if khugepaged found a range
>         of pages that should be collapsed into one huge page but failed
> @@ -323,6 +328,11 @@ thp_file_fallback
>         is incremented if a file huge page is attempted to be allocated
>         but fails and instead falls back to using small pages.
>
> +thp_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.
> +
>  thp_file_mapped
>         is incremented every time a file huge page is mapped into
>         user address space.
> diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
> --- a/include/linux/vm_event_item.h
> +++ b/include/linux/vm_event_item.h
> @@ -73,10 +73,12 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
>  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>                 THP_FAULT_ALLOC,
>                 THP_FAULT_FALLBACK,
> +               THP_FAULT_FALLBACK_CHARGE,
>                 THP_COLLAPSE_ALLOC,
>                 THP_COLLAPSE_ALLOC_FAILED,
>                 THP_FILE_ALLOC,
>                 THP_FILE_FALLBACK,
> +               THP_FILE_FALLBACK_CHARGE,
>                 THP_FILE_MAPPED,
>                 THP_SPLIT_PAGE,
>                 THP_SPLIT_PAGE_FAILED,
> @@ -117,6 +119,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
>  #ifndef CONFIG_TRANSPARENT_HUGEPAGE
>  #define THP_FILE_ALLOC ({ BUILD_BUG(); 0; })
>  #define THP_FILE_FALLBACK ({ BUILD_BUG(); 0; })
> +#define THP_FILE_FALLBACK_CHARGE ({ BUILD_BUG(); 0; })
>  #define THP_FILE_MAPPED ({ BUILD_BUG(); 0; })
>  #endif
>
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -597,6 +597,7 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf,
>         if (mem_cgroup_try_charge_delay(page, vma->vm_mm, gfp, &memcg, true)) {
>                 put_page(page);
>                 count_vm_event(THP_FAULT_FALLBACK);
> +               count_vm_event(THP_FAULT_FALLBACK_CHARGE);
>                 return VM_FAULT_FALLBACK;
>         }
>
> @@ -1406,6 +1407,7 @@ vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd)
>                         put_page(page);
>                 ret |= VM_FAULT_FALLBACK;
>                 count_vm_event(THP_FAULT_FALLBACK);
> +               count_vm_event(THP_FAULT_FALLBACK_CHARGE);
>                 goto out;
>         }
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -1871,8 +1871,10 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
>         error = mem_cgroup_try_charge_delay(page, charge_mm, gfp, &memcg,
>                                             PageTransHuge(page));
>         if (error) {
> -               if (PageTransHuge(page))
> +               if (PageTransHuge(page)) {
>                         count_vm_event(THP_FILE_FALLBACK);
> +                       count_vm_event(THP_FILE_FALLBACK_CHARGE);
> +               }
>                 goto unacct;
>         }
>         error = shmem_add_to_page_cache(page, mapping, hindex,
> diff --git a/mm/vmstat.c b/mm/vmstat.c
> --- a/mm/vmstat.c
> +++ b/mm/vmstat.c
> @@ -1254,10 +1254,12 @@ const char * const vmstat_text[] = {
>  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>         "thp_fault_alloc",
>         "thp_fault_fallback",
> +       "thp_fault_fallback_charge",
>         "thp_collapse_alloc",
>         "thp_collapse_alloc_failed",
>         "thp_file_alloc",
>         "thp_file_fallback",
> +       "thp_file_fallback_charge",
>         "thp_file_mapped",
>         "thp_split_page",
>         "thp_split_page_failed",


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch 1/2] mm, shmem: add vmstat for hugepage fallback
  2020-03-06 22:22 [patch 1/2] mm, shmem: add vmstat for hugepage fallback David Rientjes
  2020-03-06 22:22 ` [patch 2/2] mm, thp: track fallbacks due to failed memcg charges separately David Rientjes
  2020-03-07  4:10 ` [patch 1/2] mm, shmem: add vmstat for hugepage fallback Yang Shi
@ 2020-03-09 15:48 ` Kirill A. Shutemov
  2 siblings, 0 replies; 6+ messages in thread
From: Kirill A. Shutemov @ 2020-03-09 15:48 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, Yang Shi, Kirill A. Shutemov, Mike Rapoport,
	Jeremy Cline, Linux Kernel Mailing List, Linux MM

On Fri, Mar 06, 2020 at 02:22:32PM -0800, David Rientjes wrote:
> 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>

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

-- 
 Kirill A. Shutemov


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch 2/2] mm, thp: track fallbacks due to failed memcg charges separately
  2020-03-06 22:22 ` [patch 2/2] mm, thp: track fallbacks due to failed memcg charges separately David Rientjes
  2020-03-07  4:13   ` Yang Shi
@ 2020-03-09 15:48   ` Kirill A. Shutemov
  1 sibling, 0 replies; 6+ messages in thread
From: Kirill A. Shutemov @ 2020-03-09 15:48 UTC (permalink / raw)
  To: David Rientjes
  Cc: Andrew Morton, Yang Shi, Kirill A. Shutemov, Mike Rapoport,
	Jeremy Cline, Linux Kernel Mailing List, Linux MM

On Fri, Mar 06, 2020 at 02:22:35PM -0800, David Rientjes wrote:
> The thp_fault_fallback and thp_file_fallback vmstats are incremented if
> either the hugepage allocation fails through the page allocator or the
> hugepage charge fails through mem cgroup.
> 
> This patch leaves this field untouched but adds two new fields,
> thp_{fault,file}_fallback_charge, which is incremented only when the mem
> cgroup charge fails.
> 
> This distinguishes between attempted hugepage allocations that fail due to
> fragmentation (or low memory conditions) and those that fail due to mem
> cgroup limits.  That can be used to determine the impact of fragmentation
> on the system by excluding faults that failed due to memcg usage.
> 
> Signed-off-by: David Rientjes <rientjes@google.com>

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> ---
>  Documentation/admin-guide/mm/transhuge.rst | 10 ++++++++++
>  include/linux/vm_event_item.h              |  3 +++
>  mm/huge_memory.c                           |  2 ++
>  mm/shmem.c                                 |  4 +++-
>  mm/vmstat.c                                |  2 ++
>  5 files changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst
> --- a/Documentation/admin-guide/mm/transhuge.rst
> +++ b/Documentation/admin-guide/mm/transhuge.rst
> @@ -310,6 +310,11 @@ thp_fault_fallback
>  	is incremented if a page fault fails to allocate
>  	a huge page and instead falls back to using small pages.
>  
> +thp_fault_fallback_charge
> +	is incremented if a page fault fails to charge a huge page and
> +	instead falls back to using small pages even though the
> +	allocation was successful.
> +
>  thp_collapse_alloc_failed
>  	is incremented if khugepaged found a range
>  	of pages that should be collapsed into one huge page but failed
> @@ -323,6 +328,11 @@ thp_file_fallback
>  	is incremented if a file huge page is attempted to be allocated
>  	but fails and instead falls back to using small pages.
>  
> +thp_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.
> +
>  thp_file_mapped
>  	is incremented every time a file huge page is mapped into
>  	user address space.
> diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
> --- a/include/linux/vm_event_item.h
> +++ b/include/linux/vm_event_item.h
> @@ -73,10 +73,12 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
>  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>  		THP_FAULT_ALLOC,
>  		THP_FAULT_FALLBACK,
> +		THP_FAULT_FALLBACK_CHARGE,
>  		THP_COLLAPSE_ALLOC,
>  		THP_COLLAPSE_ALLOC_FAILED,
>  		THP_FILE_ALLOC,
>  		THP_FILE_FALLBACK,
> +		THP_FILE_FALLBACK_CHARGE,
>  		THP_FILE_MAPPED,
>  		THP_SPLIT_PAGE,
>  		THP_SPLIT_PAGE_FAILED,
> @@ -117,6 +119,7 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
>  #ifndef CONFIG_TRANSPARENT_HUGEPAGE
>  #define THP_FILE_ALLOC ({ BUILD_BUG(); 0; })
>  #define THP_FILE_FALLBACK ({ BUILD_BUG(); 0; })
> +#define THP_FILE_FALLBACK_CHARGE ({ BUILD_BUG(); 0; })
>  #define THP_FILE_MAPPED ({ BUILD_BUG(); 0; })
>  #endif
>  
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -597,6 +597,7 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf,
>  	if (mem_cgroup_try_charge_delay(page, vma->vm_mm, gfp, &memcg, true)) {
>  		put_page(page);
>  		count_vm_event(THP_FAULT_FALLBACK);
> +		count_vm_event(THP_FAULT_FALLBACK_CHARGE);
>  		return VM_FAULT_FALLBACK;
>  	}
>  
> @@ -1406,6 +1407,7 @@ vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd)
>  			put_page(page);
>  		ret |= VM_FAULT_FALLBACK;
>  		count_vm_event(THP_FAULT_FALLBACK);
> +		count_vm_event(THP_FAULT_FALLBACK_CHARGE);
>  		goto out;
>  	}
>  
> diff --git a/mm/shmem.c b/mm/shmem.c
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -1871,8 +1871,10 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
>  	error = mem_cgroup_try_charge_delay(page, charge_mm, gfp, &memcg,
>  					    PageTransHuge(page));
>  	if (error) {
> -		if (PageTransHuge(page))
> +		if (PageTransHuge(page)) {
>  			count_vm_event(THP_FILE_FALLBACK);
> +			count_vm_event(THP_FILE_FALLBACK_CHARGE);
> +		}
>  		goto unacct;
>  	}
>  	error = shmem_add_to_page_cache(page, mapping, hindex,
> diff --git a/mm/vmstat.c b/mm/vmstat.c
> --- a/mm/vmstat.c
> +++ b/mm/vmstat.c
> @@ -1254,10 +1254,12 @@ const char * const vmstat_text[] = {
>  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>  	"thp_fault_alloc",
>  	"thp_fault_fallback",
> +	"thp_fault_fallback_charge",
>  	"thp_collapse_alloc",
>  	"thp_collapse_alloc_failed",
>  	"thp_file_alloc",
>  	"thp_file_fallback",
> +	"thp_file_fallback_charge",
>  	"thp_file_mapped",
>  	"thp_split_page",
>  	"thp_split_page_failed",

-- 
 Kirill A. Shutemov


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-03-09 15:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-06 22:22 [patch 1/2] mm, shmem: add vmstat for hugepage fallback David Rientjes
2020-03-06 22:22 ` [patch 2/2] mm, thp: track fallbacks due to failed memcg charges separately David Rientjes
2020-03-07  4:13   ` Yang Shi
2020-03-09 15:48   ` Kirill A. Shutemov
2020-03-07  4:10 ` [patch 1/2] mm, shmem: add vmstat for hugepage fallback Yang Shi
2020-03-09 15:48 ` Kirill A. Shutemov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).