From patchwork Tue Sep 3 03:30:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yukaixiong X-Patchwork-Id: 13787954 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 8A04CCD3427 for ; Tue, 3 Sep 2024 03:31:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 312D08D012B; Mon, 2 Sep 2024 23:31:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 299338D0119; Mon, 2 Sep 2024 23:31:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13EB08D012B; Mon, 2 Sep 2024 23:31:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E80258D0119 for ; Mon, 2 Sep 2024 23:31:18 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A80FE401CD for ; Tue, 3 Sep 2024 03:31:18 +0000 (UTC) X-FDA: 82522001436.12.D03F096 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf17.hostedemail.com (Postfix) with ESMTP id 51F8540008 for ; Tue, 3 Sep 2024 03:31:15 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=yukaixiong@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725334183; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SwRNGbfpwMbdyyvPRdQcI5dR+jj2JDC8mynWoyw5ybI=; b=Xk1FIVJG41zCJEKw5rXcyxueh6Y3ewBLE3kipw1bnNHc3lsDJDkj03/H3pnWRWZZFCE+bX cbU8jlz3KKzejC19uJgiPr37jSB4QYyPJfZx4tA5IjWPoNCU/6oEeaRI+Jl4QkVVb5taLe JZ1AAfF+cHrraTqCVMzw/YoAXG1Y1ss= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725334183; a=rsa-sha256; cv=none; b=HZ5N9lowDczU/m/TYJ2aVMj6KcFfRi6hrdvPcwB+lMN/ViCl+FAoGUuf/W1HfwzHHMrkeu pFn5oPEfcQ+0CgmolrF0+vnddbr5q2uYIxI6I6Jyq1E6UXSgQ1bioWimcmy9LC3auQ7WDG yMp6NKIIO6oCt+mz/+iimbfMTszIL4s= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=yukaixiong@huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4WyWLx1BsCz1xwrl; Tue, 3 Sep 2024 11:29:13 +0800 (CST) Received: from kwepemh100016.china.huawei.com (unknown [7.202.181.102]) by mail.maildlp.com (Postfix) with ESMTPS id 55E8A1402C6; Tue, 3 Sep 2024 11:31:13 +0800 (CST) Received: from huawei.com (10.175.113.32) by kwepemh100016.china.huawei.com (7.202.181.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 3 Sep 2024 11:31:10 +0800 From: Kaixiong Yu To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 -next 05/15] mm: util: move sysctls into it own files Date: Tue, 3 Sep 2024 11:30:01 +0800 Message-ID: <20240903033011.2870608-6-yukaixiong@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240903033011.2870608-1-yukaixiong@huawei.com> References: <20240903033011.2870608-1-yukaixiong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemh100016.china.huawei.com (7.202.181.102) X-Rspamd-Queue-Id: 51F8540008 X-Stat-Signature: afy3twy3twqxr55cnerixy168ympeedq X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1725334275-215260 X-HE-Meta: U2FsdGVkX18Po70sBwkSrSIWA4083dw3aAbzLm2tLRGzQw3TQorfiXapgKtY5+SC5du31h6GMoLrFURXNno1JCwtEiOGv4Lt3j/U5lPCWWuBI8mOSHY7Q19cdKslljVemRUaXghOlUeYzq2ah01Z4cVBSMxFuO6O7ul3YhAj6TbjLeBbvxtou9FkBkQWN5yEcCITUHeBpn+9XV39DH7LZlUZ2bGZUHNzxYHJ8cyZsBd7rOhJRDVKFClSPIHOGG9ajGkq4JxK1co8b4m9Oamooji9M0oGK8LQLzrNMmkQ1R4/ALFKChr74aMWS5pbT0aGfHNc+jDq31hSWJa06f4HG4IwCsTfaDPBGwo0Ust0aSrteT8Mt9MyMnLkDN9iliNru/tlQXIWkFWimQ2CPVuDP+P8CjY2TcHt1BeyQB1fXLHYNoHZVuAvjh1ViTUEtItyp7ZyoTuUQI4xm5TWdPH5mtLAbZo1c2gLUl2hhJ6SY6MO3Ne95qKI5WrZOr/V7q7ph3PpOUjvG1GZs34afuEVn4XMyJzWllWlnfKVGkBFTHU5dEsqm1razIjVw0Y/KDxuQ0S62EyuwBUS4gU0tZ8FL20pFJXYUrTIoGyM/So7c2TpwUkH1/vyRn7Lowo1oYtbcl3Q8WcVaAfLHUjnsSVNwi2nm5zfyScJrWrCf4zCC+hBv9VKYTth9uq0z5XYpXI+PXdzWMqmjsN7a0kKZvw1mM08twvRvm45/aeWIjGmydDEZFwbr/ntAgjYK3zUn3cRoiiNOlHW162fRr9K/7QUanLAQGFu4Gbgt3oE5892iVtz4z2z20l7r/hi3bmPVMZS5jVXXJRCIRNTSZnjx9LaLfiY4DFICQo/FndwUeC67gyBEf7gDeKw9ZKyaZ4Ak+nidsLhAp/z+vwNOXwNZnmkQ5Bx+A/E7cd3zKDBXnnrOL4lpsnx3XlUOr/adCcfYeWIQ1TZ6x2kp61hyX4MRtZ younDl2C ge/PQY9DhoXRO2ULqO2iPJagRQZyXuDz/ZxmTKBWE6TQWyl4I00e7NRklGqUrrc3MXt+6qa+Fvft3W5hd1bfnnwAFqjnGzbo0CTM04SbJ59va3YDG3BmKAjnX0xIAIJgZkGhO0XE7vrM6Ws0jXYwwuEXNVwJD+g+24wPbssK9E2cNRNg= 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: List-Subscribe: List-Unsubscribe: This moves all util related sysctls to its own file, as part of the kernel/sysctl.c cleaning, also removes redundant external variable declarations and function declarations. Signed-off-by: Kaixiong Yu Reviewed-by: Kees Cook --- include/linux/mm.h | 11 -------- include/linux/mman.h | 2 -- kernel/sysctl.c | 37 ------------------------ mm/util.c | 67 ++++++++++++++++++++++++++++++++++++++------ 4 files changed, 59 insertions(+), 58 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 99f3c84652d8..93ae80146ee2 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -200,17 +200,6 @@ extern int sysctl_max_map_count; extern unsigned long sysctl_user_reserve_kbytes; extern unsigned long sysctl_admin_reserve_kbytes; -extern int sysctl_overcommit_memory; -extern int sysctl_overcommit_ratio; -extern unsigned long sysctl_overcommit_kbytes; - -int overcommit_ratio_handler(const struct ctl_table *, int, void *, size_t *, - loff_t *); -int overcommit_kbytes_handler(const struct ctl_table *, int, void *, size_t *, - loff_t *); -int overcommit_policy_handler(const struct ctl_table *, int, void *, size_t *, - loff_t *); - #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP) #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n)) #define folio_page_idx(folio, p) (page_to_pfn(p) - folio_pfn(folio)) diff --git a/include/linux/mman.h b/include/linux/mman.h index bcb201ab7a41..e62ef272d140 100644 --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -58,8 +58,6 @@ | MAP_HUGE_1GB) extern int sysctl_overcommit_memory; -extern int sysctl_overcommit_ratio; -extern unsigned long sysctl_overcommit_kbytes; extern struct percpu_counter vm_committed_as; #ifdef CONFIG_SMP diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 184d39944e16..ad3ac6f6c808 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2030,29 +2030,6 @@ static struct ctl_table kern_table[] = { }; static struct ctl_table vm_table[] = { - { - .procname = "overcommit_memory", - .data = &sysctl_overcommit_memory, - .maxlen = sizeof(sysctl_overcommit_memory), - .mode = 0644, - .proc_handler = overcommit_policy_handler, - .extra1 = SYSCTL_ZERO, - .extra2 = SYSCTL_TWO, - }, - { - .procname = "overcommit_ratio", - .data = &sysctl_overcommit_ratio, - .maxlen = sizeof(sysctl_overcommit_ratio), - .mode = 0644, - .proc_handler = overcommit_ratio_handler, - }, - { - .procname = "overcommit_kbytes", - .data = &sysctl_overcommit_kbytes, - .maxlen = sizeof(sysctl_overcommit_kbytes), - .mode = 0644, - .proc_handler = overcommit_kbytes_handler, - }, { .procname = "dirtytime_expire_seconds", .data = &dirtytime_expire_interval, @@ -2133,20 +2110,6 @@ static struct ctl_table vm_table[] = { .extra1 = SYSCTL_ZERO, }, #endif - { - .procname = "user_reserve_kbytes", - .data = &sysctl_user_reserve_kbytes, - .maxlen = sizeof(sysctl_user_reserve_kbytes), - .mode = 0644, - .proc_handler = proc_doulongvec_minmax, - }, - { - .procname = "admin_reserve_kbytes", - .data = &sysctl_admin_reserve_kbytes, - .maxlen = sizeof(sysctl_admin_reserve_kbytes), - .mode = 0644, - .proc_handler = proc_doulongvec_minmax, - }, #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS { .procname = "mmap_rnd_bits", diff --git a/mm/util.c b/mm/util.c index 4f1275023eb7..27ae0365f5f7 100644 --- a/mm/util.c +++ b/mm/util.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -902,14 +903,16 @@ int folio_mc_copy(struct folio *dst, struct folio *src) EXPORT_SYMBOL(folio_mc_copy); int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; -int sysctl_overcommit_ratio __read_mostly = 50; -unsigned long sysctl_overcommit_kbytes __read_mostly; +static int sysctl_overcommit_ratio __read_mostly = 50; +static unsigned long sysctl_overcommit_kbytes __read_mostly; int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT; unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */ unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */ -int overcommit_ratio_handler(const struct ctl_table *table, int write, void *buffer, - size_t *lenp, loff_t *ppos) +#ifdef CONFIG_SYSCTL + +static int overcommit_ratio_handler(const struct ctl_table *table, int write, + void *buffer, size_t *lenp, loff_t *ppos) { int ret; @@ -924,8 +927,8 @@ static void sync_overcommit_as(struct work_struct *dummy) percpu_counter_sync(&vm_committed_as); } -int overcommit_policy_handler(const struct ctl_table *table, int write, void *buffer, - size_t *lenp, loff_t *ppos) +static int overcommit_policy_handler(const struct ctl_table *table, int write, + void *buffer, size_t *lenp, loff_t *ppos) { struct ctl_table t; int new_policy = -1; @@ -960,8 +963,8 @@ int overcommit_policy_handler(const struct ctl_table *table, int write, void *bu return ret; } -int overcommit_kbytes_handler(const struct ctl_table *table, int write, void *buffer, - size_t *lenp, loff_t *ppos) +static int overcommit_kbytes_handler(const struct ctl_table *table, int write, + void *buffer, size_t *lenp, loff_t *ppos) { int ret; @@ -971,6 +974,54 @@ int overcommit_kbytes_handler(const struct ctl_table *table, int write, void *bu return ret; } +static struct ctl_table util_sysctl_table[] = { + { + .procname = "overcommit_memory", + .data = &sysctl_overcommit_memory, + .maxlen = sizeof(sysctl_overcommit_memory), + .mode = 0644, + .proc_handler = overcommit_policy_handler, + .extra1 = SYSCTL_ZERO, + .extra2 = SYSCTL_TWO, + }, + { + .procname = "overcommit_ratio", + .data = &sysctl_overcommit_ratio, + .maxlen = sizeof(sysctl_overcommit_ratio), + .mode = 0644, + .proc_handler = overcommit_ratio_handler, + }, + { + .procname = "overcommit_kbytes", + .data = &sysctl_overcommit_kbytes, + .maxlen = sizeof(sysctl_overcommit_kbytes), + .mode = 0644, + .proc_handler = overcommit_kbytes_handler, + }, + { + .procname = "user_reserve_kbytes", + .data = &sysctl_user_reserve_kbytes, + .maxlen = sizeof(sysctl_user_reserve_kbytes), + .mode = 0644, + .proc_handler = proc_doulongvec_minmax, + }, + { + .procname = "admin_reserve_kbytes", + .data = &sysctl_admin_reserve_kbytes, + .maxlen = sizeof(sysctl_admin_reserve_kbytes), + .mode = 0644, + .proc_handler = proc_doulongvec_minmax, + }, +}; + +static int __init init_vm_util_sysctls(void) +{ + register_sysctl_init("vm", util_sysctl_table); + return 0; +} +subsys_initcall(init_vm_util_sysctls); +#endif /* CONFIG_SYSCTL */ + /* * Committed memory limit enforced when OVERCOMMIT_NEVER policy is used */