From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C07CC77B60 for ; Tue, 28 Mar 2023 06:46:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A44E96B0072; Tue, 28 Mar 2023 02:46:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9CD9D900003; Tue, 28 Mar 2023 02:46:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86D8D900002; Tue, 28 Mar 2023 02:46:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 715956B0072 for ; Tue, 28 Mar 2023 02:46:43 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 38481ABAC3 for ; Tue, 28 Mar 2023 06:46:43 +0000 (UTC) X-FDA: 80617373886.05.F1D3767 Received: from mxct.zte.com.cn (mxct.zte.com.cn [183.62.165.209]) by imf27.hostedemail.com (Postfix) with ESMTP id 763BE40006 for ; Tue, 28 Mar 2023 06:46:40 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=zte.com.cn; spf=pass (imf27.hostedemail.com: domain of ye.xingchen@zte.com.cn designates 183.62.165.209 as permitted sender) smtp.mailfrom=ye.xingchen@zte.com.cn ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679986001; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references; bh=BZ5Nah2IgpKKXeRuJzH9BWwiAwkAasXBHY+IbIBaGn4=; b=f2Kp5w/NJTXoNTV7X1MX0lDPimSHg4a0ChC/AMvpqnRCFFGzfPvLbW0bSoPfUbFopgTgem +AzmB+q6Gj4E20dKjVig5h7mojE8kpYz7hV6j3kBPqVfOq3CGH9KS7spw1S/NTh5d8y7uQ iQoKZIXRcDFhvxFf1kx/QMiqjJBp54w= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=zte.com.cn; spf=pass (imf27.hostedemail.com: domain of ye.xingchen@zte.com.cn designates 183.62.165.209 as permitted sender) smtp.mailfrom=ye.xingchen@zte.com.cn ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679986001; a=rsa-sha256; cv=none; b=vPDzXPMsYxmUpMmmO5lAxXSBnmd2zykRifrMOcutAVBF3hAHtsCe2fCIcA+2vmgXTVay0G 8uThCtMOJbQRnEm3XvVieRQ3Db7NAj3zmUFYmr/dnQd4Q0YnLNKUQd88ngep3b3mMQkTjs XMX7mQHiNN/Rz+kc+WmFA+omcMVxN7Y= Received: from mse-fl1.zte.com.cn (unknown [10.5.228.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxct.zte.com.cn (FangMail) with ESMTPS id 4Pm0b029jxz501Rk; Tue, 28 Mar 2023 14:46:36 +0800 (CST) Received: from xaxapp01.zte.com.cn ([10.88.99.176]) by mse-fl1.zte.com.cn with SMTP id 32S6kPDL015126; Tue, 28 Mar 2023 14:46:25 +0800 (+08) (envelope-from ye.xingchen@zte.com.cn) Received: from mapi (xaxapp02[null]) by mapi (Zmail) with MAPI id mid31; Tue, 28 Mar 2023 14:46:28 +0800 (CST) Date: Tue, 28 Mar 2023 14:46:28 +0800 (CST) X-Zmail-TransId: 2afa64228d44ffffffff925-41e84 X-Mailer: Zmail v1.0 Message-ID: <202303281446280457758@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , , , , , , Subject: =?UTF-8?B?W1BBVENIIFY4IDEvMl0gbW06IGNvbXBhY3Rpb246IG1vdmUgY29tcGFjdGlvbiBzeXNjdGwgdG8gaXRzIG93biBmaWxl?= Content-Type: text/plain; charset="UTF-8" X-MAIL:mse-fl1.zte.com.cn 32S6kPDL015126 X-Fangmail-Gw-Spam-Type: 0 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 64228D4C.001/4Pm0b029jxz501Rk X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 763BE40006 X-Stat-Signature: fx93opzxaungjojjqc9opd5jn8fckyhc X-HE-Tag: 1679986000-381465 X-HE-Meta: U2FsdGVkX1/ezhCDNFSe5l++ZlvRASoMUyPhL9Bttt2R7xuiGzDt/n+uPouAWnozUhToxXuSFi7Vkc48UGDjHhSgltSQmjKZ6JiSGDgMbPm5kLisGn7cQlcxixy9lCw0wqeNp9jE4NIpJNEwyc8g6q6jeCmxCMAs8jHEuEom4/V4J8ZCmJ13HZHLXKVTPyl/yadfvTqQ194IU/vMAgnIk1YUmgg0MKP1ukQFcF0kZ4at/Fcfq+XQ1nWxNepDzYwl+XQoBfSKnRsceHZvO08lLIBlmN75Rj6ObAWwClbHBPGL5MjfWYexewYjmhBY5p8rxkPrtmh3Lhz1KKmdetLi/YGhcZ4mXsXHZDA/Nk0ZpF6uJ1ffs5USoeR/0s5Lwu4YLYOA5pducv2SXMkfZVYe7kJj2y8m6Y1aptWQXoVLk1Yx+LjsJ4VgJ/qaAUyI952SbLwqUaShYkQZ4ftBI0I5lo/tEELs/IK5NNBQLyeFzpQlCm5FaYqvPqckqBpbi/NYwiIp8lHCEFE6Gr27LDzCUOf2p2hGxmRQOxccmCFskaUE23NFMXPNvAQrurV4kIbR7GktmXqC2jiGIlH+Nu1SEH2W/mJFMt68MhXsrlzSTYScWgT6UsleJKLLaGIDzzljVCCE9XOxjln5jZukOA5SQH3Zl69KFVhMK7GA4jhLqA6KcMDij7b+M2w6eDeELM3lFVC0M55BlUzfZFEodg0LGLpaFr9miogh6Dm9JmGQcsbyDMxA6eLba55cgpVEkGdd42GtBRqZHAU0Wl5pOFVxUdVTyb7BqgBm5xVxOm1QgmBc3Yhkiv9Bjoem0tzRUVKzW50WANLXIiMi5DsvJaHxQcr590anCNilK9luK8OIW+rsI9hLEaKYUFu8Jj2cDZuAGhLP1xzbd1Maz3opwHWAIwZa4G2Eb2MaHq/HEepITr3AUYKchwOjkh50tCUB30kjkTDYhi+0V1aBNYiTcgH 4VyQ3Bbo zvVmHtxOeQ7ZjNTTd7g7PGqNYCtfJONoN67ZYI0+gXxPiBGplozjFqLirDSlt6ajngyWThTG0wsOGM7hz0BIfKnUtvsJZs42YZZ9mMYgeDGsIKEHrVtCoF/07++nIvduogs/ULAtbzLa2S/csigJXil+sekGgAgY7xhPThfVBBz8/kOTG35MAb029jf6ePEQhx5e7ATQpntZ/8Idwsh/wGqYLxXNKHPGwofHQpj3PQsi1xAGoE6PzlU2ORhdmzxOhTo1sw9Z3D1EJC/Ud/zPAPkq8MjnqCQW3rFd6KJj6BRIsGUE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Minghao Chi This moves all compaction sysctls to its own file. Move sysctl to where the functionality truly belongs to improve readability, reduce merge conflicts, and facilitate maintenance. I use x86_defconfig and linux-next-20230327 branch $ make defconfig;make all -jn CONFIG_COMPACTION=y add/remove: 1/0 grow/shrink: 1/1 up/down: 350/-256 (94) Function old new delta vm_compaction - 320 +320 kcompactd_init 180 210 +30 vm_table 2112 1856 -256 Total: Before=21119987, After=21120081, chg +0.00% Despite the addition of 94 bytes the patch still seems a worthwile cleanup. Link: https://lore.kernel.org/lkml/067f7347-ba10-5405-920c-0f5f985c84f4@suse.cz/ Signed-off-by: Minghao Chi --- include/linux/compaction.h | 7 ---- kernel/sysctl.c | 59 -------------------------- mm/compaction.c | 84 ++++++++++++++++++++++++++++++++------ 3 files changed, 72 insertions(+), 78 deletions(-) diff --git a/include/linux/compaction.h b/include/linux/compaction.h index 52a9ff65faee..a6e512cfb670 100644 --- a/include/linux/compaction.h +++ b/include/linux/compaction.h @@ -81,13 +81,6 @@ static inline unsigned long compact_gap(unsigned int order) } #ifdef CONFIG_COMPACTION -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 compaction_proactiveness_sysctl_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; extern unsigned int extfrag_for_order(struct zone *zone, unsigned int order); extern int fragmentation_index(struct zone *zone, unsigned int order); diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 0a8a3c9c82e4..bfe53e835524 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -746,27 +745,6 @@ int proc_dointvec(struct ctl_table *table, int write, void *buffer, return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL); } -#ifdef CONFIG_COMPACTION -static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table, - int write, void *buffer, size_t *lenp, loff_t *ppos) -{ - int ret, old; - - if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write) - return proc_dointvec_minmax(table, write, buffer, lenp, ppos); - - old = *(int *)table->data; - ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); - if (ret) - return ret; - if (old != *(int *)table->data) - pr_warn_once("sysctl attribute %s changed by %s[%d]\n", - table->procname, current->comm, - task_pid_nr(current)); - return ret; -} -#endif - /** * proc_douintvec - read a vector of unsigned integers * @table: the sysctl table @@ -2157,43 +2135,6 @@ static struct ctl_table vm_table[] = { .extra1 = SYSCTL_ONE, .extra2 = SYSCTL_FOUR, }, -#ifdef CONFIG_COMPACTION - { - .procname = "compact_memory", - .data = NULL, - .maxlen = sizeof(int), - .mode = 0200, - .proc_handler = sysctl_compaction_handler, - }, - { - .procname = "compaction_proactiveness", - .data = &sysctl_compaction_proactiveness, - .maxlen = sizeof(sysctl_compaction_proactiveness), - .mode = 0644, - .proc_handler = compaction_proactiveness_sysctl_handler, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE_HUNDRED, - }, - { - .procname = "extfrag_threshold", - .data = &sysctl_extfrag_threshold, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE_THOUSAND, - }, - { - .procname = "compact_unevictable_allowed", - .data = &sysctl_compact_unevictable_allowed, - .maxlen = sizeof(int), - .mode = 0644, - .proc_handler = proc_dointvec_minmax_warn_RT_change, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_ONE, - }, - -#endif /* CONFIG_COMPACTION */ { .procname = "min_free_kbytes", .data = &min_free_kbytes, diff --git a/mm/compaction.c b/mm/compaction.c index e689d66cedf4..3dfdb84b9c98 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1728,7 +1728,14 @@ typedef enum { * Allow userspace to control policy on scanning the unevictable LRU for * compactable pages. */ -int sysctl_compact_unevictable_allowed __read_mostly = CONFIG_COMPACT_UNEVICTABLE_DEFAULT; +static int sysctl_compact_unevictable_allowed __read_mostly = CONFIG_COMPACT_UNEVICTABLE_DEFAULT; +/* + * Tunable for proactive compaction. It determines how + * aggressively the kernel should compact memory in the + * background. It takes values in the range [0, 100]. + */ +static unsigned int __read_mostly sysctl_compaction_proactiveness = 20; +static int sysctl_extfrag_threshold = 500; static inline void update_fast_start_pfn(struct compact_control *cc, unsigned long pfn) @@ -2584,8 +2591,6 @@ static enum compact_result compact_zone_order(struct zone *zone, int order, return ret; } -int sysctl_extfrag_threshold = 500; - /** * try_to_compact_pages - Direct compact to satisfy a high-order allocation * @gfp_mask: The GFP mask of the current allocation @@ -2742,14 +2747,7 @@ static void compact_nodes(void) compact_node(nid); } -/* - * Tunable for proactive compaction. It determines how - * aggressively the kernel should compact memory in the - * background. It takes values in the range [0, 100]. - */ -unsigned int __read_mostly sysctl_compaction_proactiveness = 20; - -int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write, +static int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write, void *buffer, size_t *length, loff_t *ppos) { int rc, nid; @@ -2779,7 +2777,7 @@ int compaction_proactiveness_sysctl_handler(struct ctl_table *table, int write, * This is the entry point for compacting all nodes via * /proc/sys/vm/compact_memory */ -int sysctl_compaction_handler(struct ctl_table *table, int write, +static int sysctl_compaction_handler(struct ctl_table *table, int write, void *buffer, size_t *length, loff_t *ppos) { if (write) @@ -3075,6 +3073,65 @@ static int kcompactd_cpu_online(unsigned int cpu) return 0; } +static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table, + int write, void *buffer, size_t *lenp, loff_t *ppos) +{ + int ret, old; + + if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write) + return proc_dointvec_minmax(table, write, buffer, lenp, ppos); + + old = *(int *)table->data; + ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); + if (ret) + return ret; + if (old != *(int *)table->data) + pr_warn_once("sysctl attribute %s changed by %s[%d]\n", + table->procname, current->comm, + task_pid_nr(current)); + return ret; +} + +#ifdef CONFIG_SYSCTL +static struct ctl_table vm_compaction[] = { + { + .procname = "compact_memory", + .data = NULL, + .maxlen = sizeof(int), + .mode = 0200, + .proc_handler = sysctl_compaction_handler, + }, + { + .procname = "compaction_proactiveness", + .data = &sysctl_compaction_proactiveness, + .maxlen = sizeof(sysctl_compaction_proactiveness), + .mode = 0644, + .proc_handler = compaction_proactiveness_sysctl_handler, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE_HUNDRED, + }, + { + .procname = "extfrag_threshold", + .data = &sysctl_extfrag_threshold, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE_THOUSAND, + }, + { + .procname = "compact_unevictable_allowed", + .data = &sysctl_compact_unevictable_allowed, + .maxlen = sizeof(int), + .mode = 0644, + .proc_handler = proc_dointvec_minmax_warn_RT_change, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_ONE, + }, + { } +}; +#endif + static int __init kcompactd_init(void) { int nid; @@ -3090,6 +3147,9 @@ static int __init kcompactd_init(void) for_each_node_state(nid, N_MEMORY) kcompactd_run(nid); +#ifdef CONFIG_SYSCTL + register_sysctl_init("vm", vm_compaction); +#endif return 0; } subsys_initcall(kcompactd_init) -- 2.25.1