From patchwork Mon Aug 26 12:04:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yukaixiong X-Patchwork-Id: 13777720 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 5730BC5321E for ; Mon, 26 Aug 2024 12:06:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80E316B049F; Mon, 26 Aug 2024 08:06:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BE666B04D7; Mon, 26 Aug 2024 08:06:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59D1B6B04D6; Mon, 26 Aug 2024 08:06:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 298F86B0419 for ; Mon, 26 Aug 2024 08:06:12 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E5C941A0F7B for ; Mon, 26 Aug 2024 12:06:11 +0000 (UTC) X-FDA: 82494268542.16.8DCA6AE Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf14.hostedemail.com (Postfix) with ESMTP id 66B5E100019 for ; Mon, 26 Aug 2024 12:06:09 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=yukaixiong@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724673884; 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=HrKI7erI4VazFQjhpNNh/lpiowOH/5EUqA52pV6DQaw=; b=aDl33LzEzLMVK/T0BcynaJO09xTGB1kyuqMPYsXjDM/a90TP1mpkUxE39H72Fs570IcFWp vwMwSqGsg8pIyG3EJ9I2/abnRH1rK5QNXMqSZ5au436ZvpywLXuXKhb3mFULn/eBrDjyRp bf+GLG4nMQq/SskprQKShlnHSmCfuGU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724673884; a=rsa-sha256; cv=none; b=GjyiKUxE6nCckZdWd5TVL3Zs/7L5YdHK9PFIFIFTJ79App34ZDEYM1NCB1EdEjaTTIOmAA d16RvZ3LSGwCpTAw5e3/Jn6tm1Lw1c+rw9H8CHEoqogqh7P12YabzPDBaC3YquvsHjjQ9v cL1Ccm7gxHOMluqKA8l1wCrXueNDVok= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=yukaixiong@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Wsq9r2SqhzyRCP; Mon, 26 Aug 2024 20:05:04 +0800 (CST) Received: from kwepemh100016.china.huawei.com (unknown [7.202.181.102]) by mail.maildlp.com (Postfix) with ESMTPS id 7E5691800D0; Mon, 26 Aug 2024 20:05:32 +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; Mon, 26 Aug 2024 20:05:30 +0800 From: Kaixiong Yu To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH -next 05/15] mm: util: move sysctls into it own files Date: Mon, 26 Aug 2024 20:04:39 +0800 Message-ID: <20240826120449.1666461-6-yukaixiong@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240826120449.1666461-1-yukaixiong@huawei.com> References: <20240826120449.1666461-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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 66B5E100019 X-Stat-Signature: dyr1mowbfxqgwdy65ipjn68jtsa33qpj X-HE-Tag: 1724673969-630246 X-HE-Meta: U2FsdGVkX1/MZD0R+EvD3roYV6LNbqoto8Aytj2fE85L9B0PlTYmEpUo3QqsZJOdG9L01F4i11KfN9VB2keo9CJCpN6nLXxThLupR9iBwtyCYuo2mA+633WtIMifrv+7ZPK4k/ikaoA54IIYHJaUuZKtM98FljkCnss8CA3mnLhypHH1XVtPYPx2nJ3SYVCFi/9WtHD6qpCXy/FVU0iq/1IfdfAttSrYnGUIyKHOdOPAjFiYCcDjFfdJQ/+vEN9R22avuW+W4TTJpQdnHKo0w9MltMxeyziSNeu5mxiZIRLKC5nsTDWG5nITTwsqZlZB2ZZKgp+NkirHVfkGwzm5wBhxkkLDPJ/XOEhHCWdrvfW7ewUtOAWwGPRw7FpBeiaxJA+fx57By/STDhmXI/UNi0Agfug7WwJMjGn7s+pG5FeMMblvIaoE/WDYpM0Ea4hpRJCvcCMBfo9BMdY4egk6lN68Qds27qc7qNJZATMOF8Uu9/eAkpw+eQxqISDHB9kS1/L6wkScRCHtOqVde9cfXKyDqtAvqKQKLuOzw9SeOOlU6xUY3gPIsaK4SnEFui+q6uUruZjpJXxAphDs8CKWIJ2mMH3amxEF5Xnhsufs/O1CjnHAnW+xAvuWrI4ZHovz8P08aiR9rsEityWTKAJbAa1DJdrfjOIn4eW/EDlOv3+MCu2LrGpNILVsS+trzhXe5IFMTQp0yr8SHBHUoG1eYgJdpQhFwbA/5Ii7/XaUusxCp52HbrqVzuZPZoMVzoRIz7CrV+/G+3ZC0vraVplpIcuZSN4UIYyniknFILTekREGcvs5yrw58YTgOx5SGpnmy7MwFhAZTCQAjAIEM02HqsB8RZaxxSvuuMnxKRc3CHZYhyNleXWi/IOFnFai+kqGHojgTt6zZuGdQp70AesLOSvcbzMDPpGLNSLekg4ajKm/SY7BrD/vNddsd1MlH2hqYTgMQSdG2McT9bMfxIN cR4UNRaC H1QCYetQh5BMwQ5CPu0R/7c1CQ5LIExrogeMUAmthCpRfXH19NCnlPjc+2803n+aIiWxsFfPYrMdpy7zjVnkzF9B5nHbf07iDDGbCh23D4KGu4CScXPbb0kcXBYcIgeJVkhOT6Fb0MNIpW68C8a5X/thZ4w== 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 --- 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 ae41092f4328..a04543984a46 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 2bfae12ade7e..04a677f04ca9 100644 --- a/mm/util.c +++ b/mm/util.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -903,14 +904,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; @@ -925,8 +928,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; @@ -961,8 +964,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; @@ -972,6 +975,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 */