From patchwork Sat Jan 11 07:07:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kaixiong Yu X-Patchwork-Id: 13935836 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 CEF59E7719C for ; Sat, 11 Jan 2025 07:12:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54FAD6B009C; Sat, 11 Jan 2025 02:12:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D6AD6B009E; Sat, 11 Jan 2025 02:12:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 350D86B009F; Sat, 11 Jan 2025 02:12:43 -0500 (EST) 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 1071D6B009C for ; Sat, 11 Jan 2025 02:12:43 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B6534160F20 for ; Sat, 11 Jan 2025 07:12:42 +0000 (UTC) X-FDA: 82994303364.07.7159197 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf05.hostedemail.com (Postfix) with ESMTP id 33CC4100007 for ; Sat, 11 Jan 2025 07:12:39 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; spf=pass (imf05.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736579560; a=rsa-sha256; cv=none; b=kJTDhZTBh+XAazebZcCJZ05k/PQgkVsqVStNSLeOWcqSqSBdtZ6sSdZtTqLBUUiNHUjTPF iTZrNi77b3UyVxjPjMwCEPzer/tgglcM5hM55ZnfiqiCJY7nkIdRki226DbhA0Qy1u/z/z KtwMA8HStS7Jp8TjyyifuiCQ5N8UVDU= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=pass (imf05.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=1736579560; 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=Pbxxt4FgRldAJDBZQ6CMOcIINQ/lGGXQBdXcREMiDgE=; b=r+XjCk67v+VMynyMeqnABpOMxstxHPahz2pflFewDDKSSugK0DqxQMlSa4QH0zyHI91cjv Cc2fvsjO4AGwcku6GIoX6n0azHhD2Ca68h38xtoOZGJzPbbJRwAcUsFjceATEzFvTJkfFt Je8t3bXZEitsWX8/JYfq4JXvqFoCx/Q= Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4YVV5G4mbpz11RmN; Sat, 11 Jan 2025 15:09:38 +0800 (CST) Received: from kwepemh100016.china.huawei.com (unknown [7.202.181.102]) by mail.maildlp.com (Postfix) with ESMTPS id 892DD180064; Sat, 11 Jan 2025 15:12:36 +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; Sat, 11 Jan 2025 15:12:30 +0800 From: Kaixiong Yu To: , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v5 -next 05/16] mm: util: move sysctls to mm/util.c Date: Sat, 11 Jan 2025 15:07:40 +0800 Message-ID: <20250111070751.2588654-6-yukaixiong@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250111070751.2588654-1-yukaixiong@huawei.com> References: <20250111070751.2588654-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-Queue-Id: 33CC4100007 X-Stat-Signature: 7b45nghukikif6bs79qcmsjdbgac8hg7 X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1736579559-592331 X-HE-Meta: U2FsdGVkX1/JFqzwsnclXxeXGmUfqUB5aSihAgZrQUNdm6aiP6zz+JnqAgWi2/q+NX0xBnl6P95f7VAt1zxmRT/MkLZe29qzw7O5/TvJm0Zz3Z8Uv7+dXDskYcfc30Hqh0W1++TOVdoP/gsBPDjHv1RM2TdmjsyKwQG3XiQDajNf5gENvzr7O56+cVrrXOTVzpXXUsPYCx7n5S06C7YIcI3O+WjXKav88zeymATYaLze/zLhu7s3hyC7KCKfS/A8khDWjmCDGZbgRRsTKcXT232gg3VbgBkufKui/4Pim9IIn1HGTyaLjDtro6lF8a+vXLUjlw7CsfuQRKGeILrGigKtH60qf1CPdO26xH8+X/AEHDx00NUOZEXeVy8r4AAPKST29LpdCITgXKAfV6iMBlYaS+Nyv9LkdwQ/9BpPOzmRNCRTSzKzd6DweqV0Ie9WNjMLyljsnfUjZ08AotRJnqlVXBamBh7tDpKNxpjLoSpJc3+GvbYU3n902L+eXJNIIJT0XnuIStVYLkZ27naGoLS7d70SczbxV6r1Co+tLt51X9hq1oshb1TwRwmXiRzQg2u1qA+7ql7bHVyK+vxwkxOtLBhZpz0hrof4j21dIk5kTOG9aQpRl6AfnVFOVGTeOwHOlTOoYzTX48LqyNzspmffdsdjgZF5uiY4zYrNuNgVXlIzJBgvs2nz+Ay2hRxObYC069YacvRgKgN+KpoHlUlbuSzIEuemyuzAdrtOQga/o+OtUqf//GjNwjwZfj8Hk3s2uWSdgcOfa5NCV75NSVcZs95HvIiA4BYr2T/fPx4nW+ghRTjEQx13VAw46K77q9bkvI32WKrqwbbwk1EINLYsGIFjgVVFWQBS9m5Fwx4FVZVulzM0nelK3P7RFz3lfBZHlb8tju4kJMjbjlK7X7CXGg6+W3eQ+eZB9KsP7KK5dPPhX9jCuIeSEfV9Vwp/0sN5SosgmImmoKlr+Ws wBphJVda hKbc2Ca28KMwoFGXZUiJd3AUDWkGy5sO1yyT1EYkaBgvNbKRcfgjG6AW8WhRF73UUd+K/Y3/IZjKiNtNkOH24AqV+wT50vsDC3IGbVu8ahGzt5uVAJo7Gr9er5b93gRNHN5KYIHxp+KyFTD2NRZfl1JuccdG7OfGZZ0q1Ekrl2+53wnE= 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 fb00ee129f77..5776bc524087 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -206,17 +206,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 b6b9684a1438..b3480f358d11 100644 --- a/mm/util.c +++ b/mm/util.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -906,14 +907,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; @@ -928,8 +931,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; @@ -964,8 +967,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; @@ -975,6 +978,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 */