From patchwork Wed Mar 22 02:46:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ye.xingchen@zte.com.cn X-Patchwork-Id: 73168 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2138390wrt; Tue, 21 Mar 2023 20:26:49 -0700 (PDT) X-Google-Smtp-Source: AK7set+0vcLgn2jfIobOo0FFCXoLJGQ6SS35bm01JK6pIr2G7RZ0o1kwohvVNxjlnlyGG1pfJYdB X-Received: by 2002:a17:90b:1c91:b0:233:f354:e7df with SMTP id oo17-20020a17090b1c9100b00233f354e7dfmr2266620pjb.18.1679455609273; Tue, 21 Mar 2023 20:26:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679455609; cv=none; d=google.com; s=arc-20160816; b=H+q9tGrXlxe3T8jovm0R9+XKSRazUt+sNwY77gzvXhXcdrwk9J61x2+zhHDAXBBEYw xd+vEvuB1rCwypA2GhnqoOdacfifr/SiC7q7gXjzMXiBh//yyWkf7pWnxxsXqb4bI1fL 0Z782EIV80TNmSl3+A608WrCErkmAiq7C4kJGqPvmptGRxW8f1laLgobN8Gt9yrIBWi8 meZM2pukIrOCyH/WOMmsHGno98LB4O6S6CG0cnv7reueTy48g7ywwm9HzawIdKl7m0SA 6kqpIq/gnGpHDqeAUVvS3dosqK/SFRHIknmeeuZPGtvBKxprEVlLJTq6tb//hcP7w4Si HKjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:mime-version:message-id:date; bh=h4eXdseVQHCueVIdTvWcCo22wjdPkl5aqM1WdfQA7c0=; b=YP99l1J5tdq9ZlChjfd6qsbLL4yVBFGc1MV68ksUMPzgPokhL5jS/wfgKpBtFcLl6E 57ubi+ik9tyKKzyyRcr1GJkADXq2Vvd7VlEna26Sp+9CN7bMj9n27c9EXCsdZiFnzrnv 0mi5yLupHByHp0YS7+4CA8hcc4iJRlUxNbmFMIogwVIsLc9be15tGtn0gJ5RQmhUOBTr p3qFtZw7z6hRz82sV8RbrgFu0xycvlfWl0pQcrV9Aiy3BI6MYN5hTK/p647Hnokwirel EW7iIUKG0ihISJr78yVZk9fLn4X4QIxh2yPNDtRgl0VXEmxvgnciW0HJYvUk7RU9gMHQ 83wA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h21-20020a17090ac39500b002341bdd031fsi18989436pjt.69.2023.03.21.20.26.36; Tue, 21 Mar 2023 20:26:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229762AbjCVCql (ORCPT + 99 others); Tue, 21 Mar 2023 22:46:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbjCVCqj (ORCPT ); Tue, 21 Mar 2023 22:46:39 -0400 Received: from mxct.zte.com.cn (mxct.zte.com.cn [183.62.165.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B1424DBC7; Tue, 21 Mar 2023 19:46:37 -0700 (PDT) Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (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 4PhCXq6f09z501RZ; Wed, 22 Mar 2023 10:46:35 +0800 (CST) Received: from xaxapp01.zte.com.cn ([10.88.99.176]) by mse-fl2.zte.com.cn with SMTP id 32M2kRx0071270; Wed, 22 Mar 2023 10:46:27 +0800 (+08) (envelope-from ye.xingchen@zte.com.cn) Received: from mapi (xaxapp02[null]) by mapi (Zmail) with MAPI id mid31; Wed, 22 Mar 2023 10:46:28 +0800 (CST) Date: Wed, 22 Mar 2023 10:46:28 +0800 (CST) X-Zmail-TransId: 2afa641a6c04ffffffff993-4d9af X-Mailer: Zmail v1.0 Message-ID: <202303221046286197958@zte.com.cn> Mime-Version: 1.0 From: To: Cc: , , , , , , , Subject: =?utf-8?q?=5BPATCH_V5_1/2=5D_mm=3A_compaction=3A_move_compaction_sy?= =?utf-8?q?sctl_to_its_own_file?= X-MAIL: mse-fl2.zte.com.cn 32M2kRx0071270 X-Fangmail-Gw-Spam-Type: 0 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 641A6C0B.002/4PhCXq6f09z501RZ X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761036844745578302?= X-GMAIL-MSGID: =?utf-8?q?1761036844745578302?= From: Minghao Chi This moves all compaction sysctls to its own file. Link: https://lore.kernel.org/lkml/9952bbf8-cf59-7bea-ce50-0200d4f4165e@suse.cz/ Signed-off-by: Minghao Chi Signed-off-by: Ye Xingchen --- include/linux/compaction.h | 7 ---- kernel/sysctl.c | 59 ----------------------------- mm/compaction.c | 77 ++++++++++++++++++++++++++++++++++---- 3 files changed, 69 insertions(+), 74 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 ce0297acf97c..e23061f33237 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..ad5838c7fce7 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1728,7 +1728,9 @@ 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; +unsigned int sysctl_compaction_proactiveness; +static int sysctl_extfrag_threshold = 500; static inline void update_fast_start_pfn(struct compact_control *cc, unsigned long pfn) @@ -2052,7 +2054,7 @@ static unsigned int fragmentation_score_node(pg_data_t *pgdat) return score; } - +unsigned int sysctl_compaction_proactiveness; static unsigned int fragmentation_score_wmark(pg_data_t *pgdat, bool low) { unsigned int wmark_low; @@ -2228,7 +2230,7 @@ static enum compact_result __compaction_suitable(struct zone *zone, int order, return COMPACT_CONTINUE; } - +static int sysctl_extfrag_threshold; /* * compaction_suitable: Is this suitable to run compaction on this zone now? * Returns @@ -2584,8 +2586,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 @@ -2748,8 +2748,7 @@ static void compact_nodes(void) * 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 +2778,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 +3074,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 +3148,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)