From patchwork Mon Dec 23 14:15:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaixiong Yu X-Patchwork-Id: 13918973 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 D6D62E7718D for ; Mon, 23 Dec 2024 14:20:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 62E0C6B00DC; Mon, 23 Dec 2024 09:20:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5DD3D6B00DD; Mon, 23 Dec 2024 09:20:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 409556B00DE; Mon, 23 Dec 2024 09:20:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1E12D6B00DC for ; Mon, 23 Dec 2024 09:20:50 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D5C03A1830 for ; Mon, 23 Dec 2024 14:20:49 +0000 (UTC) X-FDA: 82926433254.19.0306D6F Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf12.hostedemail.com (Postfix) with ESMTP id D866D40007 for ; Mon, 23 Dec 2024 14:20:30 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.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=1734963619; 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=taIXuv5KVzGPe7WXZE30ImYwJcKhcAjffBsGPsVIWcY=; b=m48iNbAW3LpnXUnV3MmCVq6BFlv1DIBbb9dIMWSBcUMjT6mV5MgdnBC6a4XnmcHkCZb8qL unh0BqfQXdTlorNKYidaHaVqyAa/1wfcJ3pPQG6HwcXIOuWyhKfgTRHFi9YV/cLQgpNQ1y vqf6ZfAcL+cRf72hY4ahaQpZuH2qZ98= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=yukaixiong@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734963619; a=rsa-sha256; cv=none; b=MSjg+OZLKb3Y5t3gNH6VptcfkhQ3wzWRnaPQPEztu8x7MZ4HfdONj0jQEjq0tjUv34XLAa ak9aP7weZ7jB/w3ZvYwH+aFEVIjAuqp/vgKpeURLBhieb3fR3zLRs14plhD7035er9PKUq TkKM7GKUmMpKWBIG7eA5Kff8Px8js1I= Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4YH0WR0wDbzrRn0; Mon, 23 Dec 2024 22:18:59 +0800 (CST) Received: from kwepemh100016.china.huawei.com (unknown [7.202.181.102]) by mail.maildlp.com (Postfix) with ESMTPS id D86EE1800D1; Mon, 23 Dec 2024 22:20:43 +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, 23 Dec 2024 22:20:40 +0800 From: Kaixiong Yu To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v4 -next 05/15] mm: util: move sysctls to mm/util.c Date: Mon, 23 Dec 2024 22:15:40 +0800 Message-ID: <20241223141550.638616-22-yukaixiong@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241223141550.638616-1-yukaixiong@huawei.com> References: <20241223141550.638616-1-yukaixiong@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemh100016.china.huawei.com (7.202.181.102) X-Rspamd-Queue-Id: D866D40007 X-Rspamd-Server: rspam12 X-Stat-Signature: wxdg6i4kr1poktbqwjs54knfki13outm X-Rspam-User: X-HE-Tag: 1734963630-516085 X-HE-Meta: U2FsdGVkX18cMw1XByKDTqmlgpEQ0Ac/0gzNc7xObX2lE+yScurh2/5opgnpCAxnEYvhczt7TXNiHCCsKt7Qfb+nBfGaIRr5YNUGNXd4wrxUFm+DPV+WgjEUPc0pKfFZGI42fC5Kig4iQw/MFqelU7T8SzkIn5M2r8EMw3wNq5OlmmxqrpbrELZCNrUFKOds3IyM7z7oz72IOEM3MdaEuGPq5Rq6AKlXGzG7f7T2kZETQVQeiO3BzUwk5OZzYh1qt0FS2uKPERJ8rjqTHDAJDT+ZjqH7rRNw3QwQHBcq7mvifohs9ZdP8125fQQ97ymGqmeCMsvQ4xSMCeWFKj/59BwMUr7vn2Vayd0iJjsWzZbuLrM+Ya8u1ignWIq2B4JWHXH3eiSSf024+/QC+qm7IkDmGxcLJxuRq/lAoogeW8Z/zebMC7puDfJ3hizIjF+Ok3pYoBlEUv4vqoY44rFc8emf/Z+cXMYupmZ+8lNUEMjQK1/N+rexoqfxKViV1stgsTFnGH73+AwLsgQa/58FYtRZ304wKfdHz+I32I1x9fQZnCIFadiKzVyNKX0zWAj21GU4h9honVNsnQW7HKwjEniNk7mcQGFcYbFHeilJOGsSsHbjThmc08XD+y2D8EcDhaN963a0p3xOeXOZf4kEXNrHMxlKitO9w8oW898Zmx6mPMlpWmVRTh8BGwkgIM0Sa+2a/JiVUQXgM3yLMmUpK5/IUzR/F63PDqohEpMRKHsa42MLVyVtPOJloQZP3pCYuKvHj7D6axyueJoXW8Qi+a83EY/K0XeZPJyeizkgLUZ+fTW7J7lf8x0OR2YoF15yKHHFRynqrsLvlz7+XYLMTFPfp7A7wvwRcD4J3Coi14xlmwsR2oVHn6K7AYh0V2onYfqO1pjw3xyl8gy1D0DxQ0T295MnCMtjmjwOr0Sl6xPF2s02X6vv58QPm7AIraRt6Dv4+3rugiZCzzqAVkG HGAr/9vX e+gWX5w7qTvBNQXFh0+n3091NGH4FFUvlIe3qPmcHmi4IXtLAGx0Sd/Rn/PvSdm+HaESISRuM8USVXF5s//s0uE1J7yGXGfPMaJ5a23qwJ8LrMkVKT/xY25OnpgiRYHFRXiGpU/Sq3wRC82eQrX66ZVndz6pl/63pPuvSL1D/1ic0Dtc= 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 --- v4: - const qualify struct ctl_table util_sysctl_table 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 8941ba3d9a77..b3b87c1dc1e4 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -205,17 +205,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 a842783ffa62..bce214fece16 100644 --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -59,8 +59,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 cb6ca272fe9f..aea3482106e0 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2020,29 +2020,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, @@ -2123,20 +2100,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 b7dc6fabaae5..6c64664937b3 100644 --- a/mm/util.c +++ b/mm/util.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -911,14 +912,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; @@ -933,8 +936,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; @@ -969,8 +972,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; @@ -980,6 +983,54 @@ int overcommit_kbytes_handler(const struct ctl_table *table, int write, void *bu return ret; } +static const 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 */