From patchwork Thu Oct 10 15:22:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yukaixiong X-Patchwork-Id: 13830196 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 53EFFCF11F5 for ; Thu, 10 Oct 2024 14:11:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B84786B0093; Thu, 10 Oct 2024 10:11:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B34B06B0095; Thu, 10 Oct 2024 10:11:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B1D16B0096; Thu, 10 Oct 2024 10:11:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6FC7B6B0093 for ; Thu, 10 Oct 2024 10:11:53 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 44805ABED9 for ; Thu, 10 Oct 2024 14:11:46 +0000 (UTC) X-FDA: 82657881306.27.21ECFC2 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf20.hostedemail.com (Postfix) with ESMTP id 3EB1B1C0008 for ; Thu, 10 Oct 2024 14:11:48 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.188 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=1728569359; 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=4g5npcGMjrxR7dKjkJ+VwsQ/8xMhxDYDk22gcM7vC7U=; b=cqw2pB4tIhxb5jnGTat3cTBAE5wcVxVLKZ/gx81qTYF0XudshvaHiyqGJFUx3MUAk2fttH esKsCeJs+LjSYagZ4LbyaKFSSPn0pETspcy4tavt3HqRC7b+Xn/QZs8uWo1jMR+l1Z0zbN 79HeZHg0mZRWPZm/yEUgILgGcXy7BDU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728569359; a=rsa-sha256; cv=none; b=IFuhAUlpRQpq9w4gjKAjRguVyzvSZ2QU7r0C2hu2Bhy3w1ZMigLHnziB4ykMC4SjLgWgHs N2KY79jcrFT8+TI1F60QrphmEEcjnvlBeacHH/WZ+PLiquvhSuMXGUIsnAJOEV3DuAyJ+S MZ51QsHyqKxuXQG8OjtFl+gLb0LXJfg= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=yukaixiong@huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4XPWpV3pGKzfdB3; Thu, 10 Oct 2024 22:09:22 +0800 (CST) Received: from kwepemh100016.china.huawei.com (unknown [7.202.181.102]) by mail.maildlp.com (Postfix) with ESMTPS id C5727180105; Thu, 10 Oct 2024 22:11:46 +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; Thu, 10 Oct 2024 22:11:43 +0800 From: Kaixiong Yu To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 -next 05/15] mm: util: move sysctls to mm/util.c Date: Thu, 10 Oct 2024 23:22:05 +0800 Message-ID: <20241010152215.3025842-6-yukaixiong@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241010152215.3025842-1-yukaixiong@huawei.com> References: <20241010152215.3025842-1-yukaixiong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemh100016.china.huawei.com (7.202.181.102) X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 3EB1B1C0008 X-Stat-Signature: b7pti9j9co6n5dka98e494kordau3y6j X-Rspam-User: X-HE-Tag: 1728569508-7404 X-HE-Meta: U2FsdGVkX196Ew78ADvbAkEhYEhzGQN7L7rhj3UwxNQmEUT3XvViuvKBkxEv29bRCiihwnX0kBhfmJTcI/Lr6qg3qXIrKTHGVuvk8OE6LjkjDZB3gRCq3KzoBMlTRcS6Ag5/ajRUeb8U0UJ1Z2ccGcXB6bfO/0I+J0I3D5DOCO74ROYLnr3MxfGPTXT/i0D+ovXtw+3ZoR+08Y/y2wJtHVLeVWX8TLEFGdldvVls6kPDhwBjM7ECj/iy9bS0NMtrrI3BQlLqUbGTnHyacxWw490Xp+aR0UhCIShGl6Fg1xj+1yeC21DyKo5ud1hLeMeQ4gkMdYDfUa8ZExeo7BiT15A3KVuTQ3QghZEAS+YJiUw9PRcDfLbySoIqT5TxHhPmzlmH90IBr5kdA3NdsFhHuYiNZE0askF5oZ4UrACeilfqk5KSkJnH1iPhZXecgvfpNfrRWVqIhRX3nLhDFHJv/cUkmKSJ88vUB6knTZM2Frx1dbR4VY0JLF9n8iKamwyLTcWNva1gSzLCMFGcX/twLssRK4nCTgsql6Jr2xRpy7/1AQoFaI9VXeWf4FmE3Ncyc4WKMtVynWqtNTLXv6O4QW8U+S2ZIsWVppSZs+zovNTm3uIo3xMcIh2cR+VV6AY/PA9tDv9CIG6mxJjDckvVV2uRjw2qBpb8EWDEejeQoNIZpnv8dohN0BVt3Xep/j7JmcjoLEOWcMq2BEBNNhlzcZXsGoOs1QT20NTuUxpZ0i+m5ydCPDbg7OfFKvOX6SdHYgGuSxmnDqQzW1+qtg4eDhM2qjXbB6VCwk8gYtyXYLRrez2+l/CzugCC45BhurZ8FaIGBIYCv5bqQid3cGSircXiNtlYdTrBA5jgTVCaohLbSt6F2RawuwdIgr4QX/QewEdCk6tJ/SgGjkFQNzjP6O1enr52vSKmHDWCLbUugjtiHKrdnI0JnHFH2na6PvBTEcz1Putv/gGAjEea0Ov RB9pcZpq 29nVN8MU48eheACGxOm5Z1xdPomlpr1+cDEKPyOFKON9ZYEqSHfi+SbGCepqbwk8Vmp6idhg5OlO5TFeeeAX/edoXCh4/g8sEGSoASWkrsz+PXHc5bnxq6Wx8cXk7A98bDEL5iFRS/Z2ghKLyNIFvL/7+GDAhJsclF6pyQy9V4zLj+gk= 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 mm/util.c, 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 --- v3: - change the title --- 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 7c46de4290da..50f0069280f4 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -204,17 +204,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 c1c3b06ab4f9..d0c5f5110aa1 100644 --- a/mm/util.c +++ b/mm/util.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -894,14 +895,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; @@ -916,8 +919,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; @@ -952,8 +955,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; @@ -963,6 +966,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 */