linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Charan Teja Reddy <charante@codeaurora.org>
To: akpm@linux-foundation.org, vbabka@suse.cz, bhe@redhat.com,
	nigupta@nvidia.com, khalid.aziz@oracle.com,
	mateusznosek0@gmail.com, sh_def@163.com, iamjoonsoo.kim@lge.com,
	mcgrof@kernel.org, keescook@chromium.org, yzaikin@google.com,
	mhocko@suse.com, rientjes@google.com,
	mgorman@techsingularity.net
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-mm@kvack.org, vinmenon@codeaurora.org,
	Charan Teja Reddy <charante@codeaurora.org>
Subject: [PATCH] mm: compaction: improve /proc trigger for full node memory compaction
Date: Thu, 22 Apr 2021 19:07:58 +0530	[thread overview]
Message-ID: <1619098678-8501-1-git-send-email-charante@codeaurora.org> (raw)

The existing /proc/sys/vm/compact_memory interface do the full node
compaction when user writes an arbitrary value to it and is targeted for
the usecases like an app launcher prepares the system before the target
application runs. The downside of it is that even if there are
sufficient higher order pages left in the system for the targeted
application to run, full node compaction will still be triggered thus
wasting few CPU cycles. This problem can be solved if it is known when
the sufficient higher order pages are available in the system thus full
node compaction can be stopped in the middle. The proactive
compaction[1] can give these details about the availability of higher
order pages in the system(it checks for COMPACTION_HPAGE_ORDER pages,
which usually be order-9) thus can be used to trigger for full node
compaction.

This patch adds a new /proc interface,
/proc/sys/vm/proactive_compact_memory, and on write of an arbitrary
value triggers the full node compaction but can be stopped in the middle
if sufficient higher order(COMPACTION_HPAGE_ORDER) pages available in
the system. The availability of pages that a user looking for can be
given as input through /proc/sys/vm/compaction_proactiveness.

[1]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=facdaa917c4d5a376d09d25865f5a863f906234a

Signed-off-by: Charan Teja Reddy <charante@codeaurora.org>
---
 include/linux/compaction.h |  3 +++
 kernel/sysctl.c            |  7 +++++++
 mm/compaction.c            | 25 ++++++++++++++++++++++---
 3 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/include/linux/compaction.h b/include/linux/compaction.h
index ed4070e..af8f6c5 100644
--- a/include/linux/compaction.h
+++ b/include/linux/compaction.h
@@ -82,9 +82,12 @@ static inline unsigned long compact_gap(unsigned int order)
 
 #ifdef CONFIG_COMPACTION
 extern int sysctl_compact_memory;
+extern int sysctl_proactive_compact_memory;
 extern unsigned int sysctl_compaction_proactiveness;
 extern int sysctl_compaction_handler(struct ctl_table *table, int write,
 			void *buffer, size_t *length, loff_t *ppos);
+extern int sysctl_proactive_compaction_handler(struct ctl_table *table,
+		int write, void *buffer, size_t *length, loff_t *ppos);
 extern int sysctl_extfrag_threshold;
 extern int sysctl_compact_unevictable_allowed;
 
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 62fbd09..ceb5c61 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2862,6 +2862,13 @@ static struct ctl_table vm_table[] = {
 		.proc_handler	= sysctl_compaction_handler,
 	},
 	{
+		.procname       = "proactive_compact_memory",
+		.data           = &sysctl_proactive_compact_memory,
+		.maxlen         = sizeof(int),
+		.mode           = 0200,
+		.proc_handler   = sysctl_proactive_compaction_handler,
+	},
+	{
 		.procname	= "compaction_proactiveness",
 		.data		= &sysctl_compaction_proactiveness,
 		.maxlen		= sizeof(sysctl_compaction_proactiveness),
diff --git a/mm/compaction.c b/mm/compaction.c
index e04f447..2b40b03 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -2588,13 +2588,13 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
  * due to various back-off conditions, such as, contention on per-node or
  * per-zone locks.
  */
-static void proactive_compact_node(pg_data_t *pgdat)
+static void proactive_compact_node(pg_data_t *pgdat, enum migrate_mode mode)
 {
 	int zoneid;
 	struct zone *zone;
 	struct compact_control cc = {
 		.order = -1,
-		.mode = MIGRATE_SYNC_LIGHT,
+		.mode = mode,
 		.ignore_skip_hint = true,
 		.whole_zone = true,
 		.gfp_mask = GFP_KERNEL,
@@ -2657,6 +2657,17 @@ static void compact_nodes(void)
 		compact_node(nid);
 }
 
+static void proactive_compact_nodes(void)
+{
+	int nid;
+
+	/* Flush pending updates to the LRU lists */
+	lru_add_drain_all();
+	for_each_online_node(nid)
+		proactive_compact_node(NODE_DATA(nid), MIGRATE_SYNC);
+}
+
+int sysctl_proactive_compact_memory;
 /* The written value is actually unused, all memory is compacted */
 int sysctl_compact_memory;
 
@@ -2680,6 +2691,14 @@ int sysctl_compaction_handler(struct ctl_table *table, int write,
 	return 0;
 }
 
+int sysctl_proactive_compaction_handler(struct ctl_table *table, int write,
+			void *buffer, size_t *length, loff_t *ppos)
+{
+	if (write)
+		proactive_compact_nodes();
+
+	return 0;
+}
 #if defined(CONFIG_SYSFS) && defined(CONFIG_NUMA)
 static ssize_t sysfs_compact_node(struct device *dev,
 			struct device_attribute *attr,
@@ -2881,7 +2900,7 @@ static int kcompactd(void *p)
 				continue;
 			}
 			prev_score = fragmentation_score_node(pgdat);
-			proactive_compact_node(pgdat);
+			proactive_compact_node(pgdat, MIGRATE_SYNC_LIGHT);
 			score = fragmentation_score_node(pgdat);
 			/*
 			 * Defer proactive compaction if the fragmentation
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a
member of the Code Aurora Forum, hosted by The Linux Foundation


             reply	other threads:[~2021-04-22 13:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-22 13:37 Charan Teja Reddy [this message]
2021-04-27  8:09 ` Mel Gorman
2021-04-28 15:32   ` Charan Teja Kalla
2021-05-03 11:37     ` Charan Teja Kalla

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=1619098678-8501-1-git-send-email-charante@codeaurora.org \
    --to=charante@codeaurora.org \
    --cc=akpm@linux-foundation.org \
    --cc=bhe@redhat.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=keescook@chromium.org \
    --cc=khalid.aziz@oracle.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mateusznosek0@gmail.com \
    --cc=mcgrof@kernel.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=nigupta@nvidia.com \
    --cc=rientjes@google.com \
    --cc=sh_def@163.com \
    --cc=vbabka@suse.cz \
    --cc=vinmenon@codeaurora.org \
    --cc=yzaikin@google.com \
    --subject='Re: [PATCH] mm: compaction: improve /proc trigger for full node memory compaction' \
    /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

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).