From patchwork Mon Aug 26 12:04:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yukaixiong X-Patchwork-Id: 13777707 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 3E848C5321D for ; Mon, 26 Aug 2024 12:05:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7E906B04C1; Mon, 26 Aug 2024 08:05:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A07DC6B04C2; Mon, 26 Aug 2024 08:05:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85BF26B04C3; Mon, 26 Aug 2024 08:05:42 -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 63C2C6B04C1 for ; Mon, 26 Aug 2024 08:05:42 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E6B4BC0F7C for ; Mon, 26 Aug 2024 12:05:41 +0000 (UTC) X-FDA: 82494267282.05.ECF9006 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf15.hostedemail.com (Postfix) with ESMTP id 646CAA0013 for ; Mon, 26 Aug 2024 12:05:39 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.189 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=1724673897; a=rsa-sha256; cv=none; b=TB+OWz1M4T/sGmZQLVAbCkg4BcqHKOsN45dqXQehhO9laWpF/afPtOURrqNxw86bNE8g1Z R3P3CbbGmsvBn81OIUC9q6hC45iIpJ12BtINlGq90/USL3o6HfFQtfqR7rHdlYJtfXd4yQ qih5xqb7XS0JdjmE035Yi+/g9xttmxg= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of yukaixiong@huawei.com designates 45.249.212.189 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=1724673897; 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=IBs3G9e492HLb6ZKCGmkOaQJB1nL0NU2xCOGrniITkY=; b=DuvsLHeO8DeBGGiTEVJX4dqlw/z6asMiYNSUMHVvAUDbSita+4+ELo9YRzfAtlszWxr5ef MxIaFxczfKER9GxVPGxceT+Jm0peEM9qdsp2FmsCVbksbnfmm2xaIxXs1mMFAX5skk9TAP Gb+8ChC1GF/IDJIAbv8wUBbtWKG69v8= Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Wsq4v1T1SzQqgW; Mon, 26 Aug 2024 20:00:47 +0800 (CST) Received: from kwepemh100016.china.huawei.com (unknown [7.202.181.102]) by mail.maildlp.com (Postfix) with ESMTPS id C95D01800A5; Mon, 26 Aug 2024 20:05:34 +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:32 +0800 From: Kaixiong Yu To: , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH -next 06/15] mm: mmap: move sysctl into its own file Date: Mon, 26 Aug 2024 20:04:40 +0800 Message-ID: <20240826120449.1666461-7-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-Stat-Signature: friscoko5t7bijszf73z7b8kgwcng1fu X-Rspamd-Queue-Id: 646CAA0013 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724673939-490537 X-HE-Meta: U2FsdGVkX1+zERcEPGv6u2TBOVsxHIg66gCIkVKT4RnE9CPi160cRT2jBQNJt0SKmhCf5F+Zwfso5ViT5o1sEoDgYcaNx5YZy3kpRLhR7d8/ezDHpCCiO3Bjraxo1yQr8qgutaqrlN/oh5gJF1ZkoMAUhioVcupYBXsz1gDb7KNfoeNGrH57ng23+4tSZ4Yidtrjg5Tltu+WfmGd5eFGgQQJ9KlOcHCdF+IxsIEc9D7f8EZrTQnGSjsfGlTAiIeI2ZSZ0vLBIrB71V7GiJD4j9hHAI5K8H0MmZjQgB/DFDNYYMFjkvFwTpN0BabKocfKXrj/cTqTqkd1+bfotqIcrKuw6hIkwxRZ3TVcNfVAbERXe/0jlVMpGyJ0rdJlPnv80vv7puh4dMH7yUcufhHO+tnPT0hxR+Lx3/xFPkYso0sGcT2zz5+UpDIZqneHlM7SD9O0+3Gql3bTTV3U+L2+Meaw+bZGF42VRaqlULM8Za/rTZ8Uga+wmMquaRqCquza29M5r7g90HzWnp+9wpB3EsbcAwuIL45tgEznmPZsxaDcK3G2qyRB6U3teG6ETmhIWjZbaT3yszEE7rGySH9uXResvVMrnvAwStU+EQpLykQNO1O2YQiRQAztIAm7IxmvQDE/5vJOkW6XIAEDYNKxbRP/DuSubfvE4llBlskOmKd+5PHVuLV2SwBWLIxMEXI5/qsVd3cO99UcTnSGZXmzli4hWAf0QuxOJsHPZO4nD2bxHAyS8vLjD2oH4HUCrDn7+U0Rxi+qYfnBfIlA8EScEyPEpPhFfdfCHzpo4mSoCvygcV2FSSHJivHC7KjtebV42ejtAgCICsFAmJnUXmmcI9hB0KpEa7XUVZiRzu87m9fyW1pY6kNNSJgZAV5U9W1rlcOIL8bIumUwTcxxvwEZcDpA5u8mZQGbJm5eoPlOZyxR6UbztwDZ7MqkxnbYurUt1+D9Q7sx0bD/7sB23U6 qoCFBiHN oA8wI6ncoFRiLGNEwiIwbeIisqHecXzY4zRnlgZz759vx69dOesrIMwPxpX+6jGXSgZ+a1S/7ZKH+JRHQNGMOvH/bfiehXnC+C6DEy62tZjod3KqJTXvnrtIxvf8v4wpWcWh2AAIbHBrebmksWDu8ZOpBhQ== 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 mmap related sysctls to its own file, as part of the kernel/sysctl.c cleaning, also move the variable declaration from kernel/sysctl.c into mm/mmap.c. Besides, move MAPCOUNT_ELF_CORE_MARGIN and DEFAULT_MAX_MAP_COUNT into mmap.c from mm.h. Signed-off-by: Kaixiong Yu --- include/linux/mm.h | 19 ------------ kernel/sysctl.c | 50 +------------------------------ mm/mmap.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++ mm/util.c | 1 - 4 files changed, 76 insertions(+), 69 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index a04543984a46..9400c92b4522 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -176,25 +176,6 @@ static inline void __mm_zero_struct_page(struct page *page) #define mm_zero_struct_page(pp) ((void)memset((pp), 0, sizeof(struct page))) #endif -/* - * Default maximum number of active map areas, this limits the number of vmas - * per mm struct. Users can overwrite this number by sysctl but there is a - * problem. - * - * When a program's coredump is generated as ELF format, a section is created - * per a vma. In ELF, the number of sections is represented in unsigned short. - * This means the number of sections should be smaller than 65535 at coredump. - * Because the kernel adds some informative sections to a image of program at - * generating coredump, we need some margin. The number of extra sections is - * 1-3 now and depends on arch. We use "5" as safe margin, here. - * - * ELF extended numbering allows more than 65535 sections, so 16-bit bound is - * not a hard limit any more. Although some userspace tools can be surprised by - * that. - */ -#define MAPCOUNT_ELF_CORE_MARGIN (5) -#define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN) - extern int sysctl_max_map_count; extern unsigned long sysctl_user_reserve_kbytes; diff --git a/kernel/sysctl.c b/kernel/sysctl.c index ad3ac6f6c808..41d4afc978e6 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -127,12 +127,6 @@ enum sysctl_writes_mode { static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT; #endif /* CONFIG_PROC_SYSCTL */ - -#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ - defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) -int sysctl_legacy_va_layout; -#endif - #endif /* CONFIG_SYSCTL */ /* @@ -2047,16 +2041,7 @@ static struct ctl_table vm_table[] = { .extra1 = SYSCTL_ONE, .extra2 = SYSCTL_FOUR, }, -#ifdef CONFIG_MMU - { - .procname = "max_map_count", - .data = &sysctl_max_map_count, - .maxlen = sizeof(sysctl_max_map_count), - .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = SYSCTL_ZERO, - }, -#else +#ifndef CONFIG_MMU { .procname = "nr_trim_pages", .data = &sysctl_nr_trim_pages, @@ -2074,17 +2059,6 @@ static struct ctl_table vm_table[] = { .proc_handler = proc_dointvec_minmax, .extra1 = SYSCTL_ZERO, }, -#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ - defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) - { - .procname = "legacy_va_layout", - .data = &sysctl_legacy_va_layout, - .maxlen = sizeof(sysctl_legacy_va_layout), - .mode = 0644, - .proc_handler = proc_dointvec_minmax, - .extra1 = SYSCTL_ZERO, - }, -#endif #ifdef CONFIG_MMU { .procname = "mmap_min_addr", @@ -2110,28 +2084,6 @@ static struct ctl_table vm_table[] = { .extra1 = SYSCTL_ZERO, }, #endif -#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS - { - .procname = "mmap_rnd_bits", - .data = &mmap_rnd_bits, - .maxlen = sizeof(mmap_rnd_bits), - .mode = 0600, - .proc_handler = proc_dointvec_minmax, - .extra1 = (void *)&mmap_rnd_bits_min, - .extra2 = (void *)&mmap_rnd_bits_max, - }, -#endif -#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS - { - .procname = "mmap_rnd_compat_bits", - .data = &mmap_rnd_compat_bits, - .maxlen = sizeof(mmap_rnd_compat_bits), - .mode = 0600, - .proc_handler = proc_dointvec_minmax, - .extra1 = (void *)&mmap_rnd_compat_bits_min, - .extra2 = (void *)&mmap_rnd_compat_bits_max, - }, -#endif }; int __init sysctl_init_bases(void) diff --git a/mm/mmap.c b/mm/mmap.c index 88524a3768f6..2b37d8fb997f 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -62,6 +62,27 @@ #define arch_mmap_check(addr, len, flags) (0) #endif +/* + * Default maximum number of active map areas, this limits the number of vmas + * per mm struct. Users can overwrite this number by sysctl but there is a + * problem. + * + * When a program's coredump is generated as ELF format, a section is created + * per a vma. In ELF, the number of sections is represented in unsigned short. + * This means the number of sections should be smaller than 65535 at coredump. + * Because the kernel adds some informative sections to a image of program at + * generating coredump, we need some margin. The number of extra sections is + * 1-3 now and depends on arch. We use "5" as safe margin, here. + * + * ELF extended numbering allows more than 65535 sections, so 16-bit bound is + * not a hard limit any more. Although some userspace tools can be surprised by + * that. + */ +#define MAPCOUNT_ELF_CORE_MARGIN (5) +#define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN) + +int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT; + #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS const int mmap_rnd_bits_min = CONFIG_ARCH_MMAP_RND_BITS_MIN; int mmap_rnd_bits_max __ro_after_init = CONFIG_ARCH_MMAP_RND_BITS_MAX; @@ -2171,6 +2192,57 @@ struct vm_area_struct *_install_special_mapping( &special_mapping_vmops); } +#ifdef CONFIG_SYSCTL +#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ + defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) +int sysctl_legacy_va_layout; +#endif + +static struct ctl_table mmap_table[] = { + { + .procname = "max_map_count", + .data = &sysctl_max_map_count, + .maxlen = sizeof(sysctl_max_map_count), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + }, +#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ + defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) + { + .procname = "legacy_va_layout", + .data = &sysctl_legacy_va_layout, + .maxlen = sizeof(sysctl_legacy_va_layout), + .mode = 0644, + .proc_handler = proc_dointvec_minmax, + .extra1 = SYSCTL_ZERO, + }, +#endif +#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS + { + .procname = "mmap_rnd_bits", + .data = &mmap_rnd_bits, + .maxlen = sizeof(mmap_rnd_bits), + .mode = 0600, + .proc_handler = proc_dointvec_minmax, + .extra1 = (void *)&mmap_rnd_bits_min, + .extra2 = (void *)&mmap_rnd_bits_max, + }, +#endif +#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS + { + .procname = "mmap_rnd_compat_bits", + .data = &mmap_rnd_compat_bits, + .maxlen = sizeof(mmap_rnd_compat_bits), + .mode = 0600, + .proc_handler = proc_dointvec_minmax, + .extra1 = (void *)&mmap_rnd_compat_bits_min, + .extra2 = (void *)&mmap_rnd_compat_bits_max, + }, +#endif +}; +#endif /* CONFIG_SYSCTL */ + /* * initialise the percpu counter for VM */ @@ -2180,6 +2252,9 @@ void __init mmap_init(void) ret = percpu_counter_init(&vm_committed_as, 0, GFP_KERNEL); VM_BUG_ON(ret); +#ifdef CONFIG_SYSCTL + register_sysctl_init("vm", mmap_table); +#endif } /* diff --git a/mm/util.c b/mm/util.c index 04a677f04ca9..7f687563b8c7 100644 --- a/mm/util.c +++ b/mm/util.c @@ -906,7 +906,6 @@ EXPORT_SYMBOL(folio_mc_copy); int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; 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 */