linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Sergei Trofimovich <slyfox@gentoo.org>
To: Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, Sergei Trofimovich <slyfox@gentoo.org>
Subject: [PATCH] mm: add page_owner_stack=off to make stack collection optional
Date: Sun, 21 Mar 2021 21:25:01 +0000	[thread overview]
Message-ID: <20210321212501.2504947-1-slyfox@gentoo.org> (raw)

On some architectures (like ia64) stack walking is slow
and currently requires memory allocation. This causes stack
collection for page_owner=on to fall into recursion.

This patch implements a page_owner_stack=off to allow page stats
collection.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
---
 .../admin-guide/kernel-parameters.txt         |  6 +++++
 mm/Kconfig.debug                              |  3 ++-
 mm/page_owner.c                               | 23 +++++++++++++------
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 04545725f187..3e710c4ab4df 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -3518,6 +3518,12 @@
 			we can turn it on.
 			on: enable the feature
 
+	page_owner_stack= [KNL] Boot-time parameter option disabling stack
+			collection of page allocation. Has effect only if
+			"page_owner=on" is set. Useful for cases when stack
+			collection is too slow or not feasible.
+			off: disable the feature
+
 	page_poison=	[KNL] Boot-time parameter changing the state of
 			poisoning on the buddy allocator, available with
 			CONFIG_PAGE_POISONING=y.
diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug
index 1e73717802f8..c1ecaf066c93 100644
--- a/mm/Kconfig.debug
+++ b/mm/Kconfig.debug
@@ -57,7 +57,8 @@ config PAGE_OWNER
 	  help to find bare alloc_page(s) leaks. Even if you include this
 	  feature on your build, it is disabled in default. You should pass
 	  "page_owner=on" to boot parameter in order to enable it. Eats
-	  a fair amount of memory if enabled. See tools/vm/page_owner_sort.c
+	  a fair amount of memory if enabled. Call chain tracking can be
+	  disabled with "page_owner_stack=off". See tools/vm/page_owner_sort.c
 	  for user-space helper.
 
 	  If unsure, say N.
diff --git a/mm/page_owner.c b/mm/page_owner.c
index d15c7c4994f5..2cc1113fa28d 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -31,6 +31,7 @@ struct page_owner {
 };
 
 static bool page_owner_enabled = false;
+static bool page_owner_stack_enabled = true;
 DEFINE_STATIC_KEY_FALSE(page_owner_inited);
 
 static depot_stack_handle_t dummy_handle;
@@ -41,21 +42,26 @@ static void init_early_allocated_pages(void);
 
 static int __init early_page_owner_param(char *buf)
 {
-	if (!buf)
-		return -EINVAL;
-
-	if (strcmp(buf, "on") == 0)
-		page_owner_enabled = true;
-
-	return 0;
+	return kstrtobool(buf, &page_owner_enabled);
 }
 early_param("page_owner", early_page_owner_param);
 
+static int __init early_page_owner_stack_param(char *buf)
+{
+	return kstrtobool(buf, &page_owner_stack_enabled);
+}
+early_param("page_owner_stack", early_page_owner_stack_param);
+
 static bool need_page_owner(void)
 {
 	return page_owner_enabled;
 }
 
+static bool need_page_owner_stack(void)
+{
+	return page_owner_stack_enabled;
+}
+
 static __always_inline depot_stack_handle_t create_dummy_stack(void)
 {
 	unsigned long entries[4];
@@ -122,6 +128,9 @@ static noinline depot_stack_handle_t save_stack(gfp_t flags)
 	depot_stack_handle_t handle;
 	unsigned int nr_entries;
 
+	if (!need_page_owner_stack())
+		return failure_handle;
+
 	nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 2);
 
 	/*
-- 
2.31.0



             reply	other threads:[~2021-03-21 21:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-21 21:25 Sergei Trofimovich [this message]
2021-03-27 21:37 ` [PATCH] mm: add page_owner_stack=off to make stack collection optional Sergei Trofimovich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210321212501.2504947-1-slyfox@gentoo.org \
    --to=slyfox@gentoo.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).