linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: wenyang.linux@foxmail.com
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Wen Yang <wenyang.linux@foxmail.com>,
	Mel Gorman <mgorman@techsingularity.net>,
	Oscar Salvador <osalvador@suse.de>,
	William Lam <william.lam@bytedance.com>, Fu Wei <wefu@redhat.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH] mm: compaction: optimize compact_memory to comply with the admin-guide
Date: Wed, 12 Apr 2023 02:24:26 +0800	[thread overview]
Message-ID: <tencent_FD958236269FD3A7996FFCF29E9BAA4EA809@qq.com> (raw)

From: Wen Yang <wenyang.linux@foxmail.com>

For the /proc/sys/vm/compact_memory file, the admin-guide states:
When 1 is written to the file, all zones are compacted such that free
memory is available in contiguous blocks where possible. This can be
important for example in the allocation of huge pages although processes
will also directly compact memory as required

But it was not strictly followed, writing any value would cause all
zones to be compacted. In some critical scenarios, some applications
operating it, such as echo 0, have caused serious problems.

It has been slightly optimized to comply with the admin-guide.

Signed-off-by: Wen Yang <wenyang.linux@foxmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: William Lam <william.lam@bytedance.com>
Cc: Fu Wei <wefu@redhat.com>
Cc: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org
---
 mm/compaction.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/mm/compaction.c b/mm/compaction.c
index c8bcdea15f5f..3c4aa533d61c 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -2780,6 +2780,17 @@ static int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int
 static int sysctl_compaction_handler(struct ctl_table *table, int write,
 			void *buffer, size_t *length, loff_t *ppos)
 {
+	struct ctl_table t;
+	int compact;
+	int ret;
+
+	t = *table;
+	t.data = &compact;
+
+	ret = proc_dointvec_minmax(&t, write, buffer, length, ppos);
+	if (ret)
+		return ret;
+
 	if (write)
 		compact_nodes();
 
@@ -3099,6 +3110,8 @@ static struct ctl_table vm_compaction[] = {
 		.maxlen		= sizeof(int),
 		.mode		= 0200,
 		.proc_handler	= sysctl_compaction_handler,
+		.extra1		= SYSCTL_ONE,
+		.extra2		= SYSCTL_ONE,
 	},
 	{
 		.procname	= "compaction_proactiveness",
-- 
2.37.2



             reply	other threads:[~2023-04-11 18:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-11 18:24 wenyang.linux [this message]
2023-04-11 20:48 ` Andrew Morton
2023-04-12 16:54   ` Wen Yang
2023-04-15 17:42     ` Wen Yang
2023-04-17 11:13       ` Mel Gorman
2023-04-18 14:10         ` Wen Yang

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=tencent_FD958236269FD3A7996FFCF29E9BAA4EA809@qq.com \
    --to=wenyang.linux@foxmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=osalvador@suse.de \
    --cc=wefu@redhat.com \
    --cc=william.lam@bytedance.com \
    /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