From patchwork Wed Jul 17 07:12:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13735174 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 91DD3C3DA42 for ; Wed, 17 Jul 2024 07:13:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D4FC46B0092; Wed, 17 Jul 2024 03:13:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB3676B0095; Wed, 17 Jul 2024 03:13:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B2BCF6B0096; Wed, 17 Jul 2024 03:13:17 -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 92D4C6B0092 for ; Wed, 17 Jul 2024 03:13:17 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 3DE541A0960 for ; Wed, 17 Jul 2024 07:13:17 +0000 (UTC) X-FDA: 82348378434.16.71F9DBC Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf26.hostedemail.com (Postfix) with ESMTP id 8FAE3140003 for ; Wed, 17 Jul 2024 07:13:15 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721200343; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6hY3/BEWPCr0kuWB2FOfe3gRaMPXC6ulqe4XpbSGqDw=; b=YeaT07GdGKYDtBHna3t9H07Oo0QzygHYBd2wy4AmlRDaRI3EjpYD9QcmiQaoXam75ZH1y7 +Pb6EWwPnpUhtokqEwhP7M0uNUAx/Dhmmxtu24H5WMoHybwNNL60ikcwHKSRTCArkTmfXl w7szHZTRj6oXd2Emg27B/xKtETDACAo= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721200343; a=rsa-sha256; cv=none; b=TeT4uTw8HwsWtreuCeciTfFDwvSasbhr7Sj8YS40J33bkqlwnAlctt6i1dX0tIOqWvIrHG yJZgGkEXJr4vJXIjNbbJOw/36rApNFQSwz3oRALv85hvW6oxPuFRFFLi5pC3/aGSyEp/PH EyFLz2s2OMN3jzRgwQEE4lkTt2aPw/c= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0FE991063; Wed, 17 Jul 2024 00:13:40 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0F1E43F762; Wed, 17 Jul 2024 00:13:12 -0700 (PDT) From: Ryan Roberts To: Andrew Morton , Hugh Dickins , Jonathan Corbet , "Matthew Wilcox (Oracle)" , David Hildenbrand , Barry Song , Lance Yang , Baolin Wang , Gavin Shan , Pankaj Raghav , Daniel Gomez Cc: Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v1 4/4] mm: Override mTHP "file_enabled" defaults at kernel cmdline Date: Wed, 17 Jul 2024 08:12:56 +0100 Message-ID: <20240717071257.4141363-5-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240717071257.4141363-1-ryan.roberts@arm.com> References: <20240717071257.4141363-1-ryan.roberts@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8FAE3140003 X-Stat-Signature: usq1cjocpzghc1jyty5ccx3s4mipwijk X-Rspam-User: X-HE-Tag: 1721200395-693342 X-HE-Meta: U2FsdGVkX19KYNDYySAOGvfNz2IWZgPG95W768hpNh1eRjpJwwZjVFWExPYcY6ASVXT1kxGuPa6k/rz03aXfSqcdQjUF9CUNEzYHNGiFZJjeqtn7H7J0nh44Od70fsD4UNOPOFhLGXGcMSSN6xr+OFD4ePcHNZV9tdpVkdJM5ahEYNn3wxV3CTEsQZC/TBwv+Pt/4Tyd8t7/mSK7BTbWpV4pGH9F2I0buOTGPtboVxZvV/FzJR5ycwF7Zz7OrATKMAIsre7tkbh7wc+oefQGzUPpE3JOuhlJxokqXPzM8RYdet3m7TQUZG2y9In5uolfmfWUHqvAks1Eqx/yAcxA1hTg1O3DE5mWfRBKoBLpReFoKHEwTZXPHFs6X4/8iEmU7r4/aTl/+3dOxdQDjJHW4Q+6Fd4gnK0QQMrFRRjSkXFnfHrjvxIKNJHw8afCsF78JcsQvMaxEiSMf4Tr0AcYUfzoM3Al/jqYQfu4DukY32RKAJhsahWzvHm+dIIYyK10RYBx3WGGMT5+lehmtsE7HUm8P9gW5EOgZ6MxYEqqrf/xnwJPgB6yg0U9PSTS094Uwxkn5pgZItDZftaJD6uKjLsTUAPFy1Yp2YPj756xs/2K61cv2z+hAfKxOwMQG2+/KF3jL7nF1jUvfPACiu424Osg1gwXWCPr/K0ACrjIP6iCRSMAmCj8uLvPmsFzAI8mAtH5sqgXSfwPsf/nKEwLsqHRv/ULwrKRl9zI/mJeGdhbibs7tpLRCR+0qBLqMs7duSQdfNJTDt9eHYiKtTjjLcziknLReuku6bgz6Xh8DBxjHXaVwEMkOzn84k5QEwg3wkjB7+8HHK5JNJs5e1AlkUaVLMqP8svZ0uZGgzMli6ELdq8UJP9evIWdc0SO4CgSVvXhS0d+6j0PqVFipFZOTkGuoQK84x86do94XnVyzHYsdSNBp/yyN6VtkflNy112WuMaCisBa/Aot0ByQNp 7OUuKUJ9 1dV5v0wHu5P5EC5xciU15NV+OpmyE0G1Lwaz8TjXxvbC+vmqK2443XcSktDAHe15not3+Tb56zGgVnmG+SqgJbQDV65dpSHPGDSusTo937Q8Wzc/z0F3xWTw9q8VNM2866Ishlrz8cEEG0i2R3eUwJK428dOBtlXlW0s8MLlIx03xmBZDX1qVupYr4cZfBPOTOgAchVjvIiBz1pw= 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: Add thp_file= cmdline parameter to allow specifying the default enablement of each supported file-backed THP size. The parameter accepts the following format and can be provided multiple times to configure each size: thp_file=[KMG]: See Documentation/admin-guide/mm/transhuge.rst for more details. Configuring the defaults at boot time is often necessary because its not always possible to drop active executable pages from the page cache, especially if they are well used like libc. The command line parameter allows configuring the values before the first page is installed in the page cache. Signed-off-by: Ryan Roberts --- .../admin-guide/kernel-parameters.txt | 8 ++++ Documentation/admin-guide/mm/transhuge.rst | 13 ++++++ mm/huge_memory.c | 45 ++++++++++++++++++- 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 48443ad12e3f..e3e99def5691 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6600,6 +6600,14 @@ See Documentation/admin-guide/mm/transhuge.rst for more details. + thp_file= [KNL] + Format: [KMG]:always|always+exec|never + Can be used to control the default behavior of the + system with respect to file-backed transparent hugepages. + Can be used multiple times for multiple file-backed THP + sizes. See Documentation/admin-guide/mm/transhuge.rst + for more details. + threadirqs [KNL,EARLY] Force threading of all interrupt handlers except those marked explicitly IRQF_NO_THREAD. diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst index f53d43d986e2..2379ed4ad085 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -333,6 +333,19 @@ required. If ``thp_anon=`` is specified at least once, any anon THP sizes not explicitly configured on the command line are implicitly set to ``never``. +Each supported file-backed THP size can be controlled by passing +``thp_file=[KMG]:``, where ```` is the THP size and +```` is one of ``always``, ``always+exec`` or ``never``. + +For example, the following will set 64K THP to ``always+exec``:: + + thp_file=64K:always+exec + +``thp_file=`` may be specified multiple times to configure all THP sizes as +required. If ``thp_file=`` is specified at least once, any file-backed THP +sizes not explicitly configured on the command line are implicitly set to +``never``. + Hugepages in tmpfs/shmem ======================== diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 794d2790d90d..4d963dde7aea 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -83,6 +83,7 @@ unsigned long huge_anon_orders_inherit __read_mostly; unsigned long huge_file_orders_always __read_mostly; int huge_file_exec_order __read_mostly = -1; static bool anon_orders_configured; +static bool file_orders_configured; unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma, unsigned long vm_flags, @@ -774,7 +775,10 @@ static int __init hugepage_init_sysfs(struct kobject **hugepage_kobj) * (and therefore THP_ORDERS_ALL_FILE_DEFAULT) isn't a compile-time * constant so we have to do this here. */ - huge_file_orders_always = THP_ORDERS_ALL_FILE_DEFAULT; + if (!file_orders_configured) { + huge_file_orders_always = THP_ORDERS_ALL_FILE_DEFAULT; + file_orders_configured = true; + } *hugepage_kobj = kobject_create_and_add("transparent_hugepage", mm_kobj); if (unlikely(!*hugepage_kobj)) { @@ -1008,6 +1012,45 @@ static int __init setup_thp_anon(char *str) } __setup("thp_anon=", setup_thp_anon); +static int __init setup_thp_file(char *str) +{ + unsigned long size; + char *state; + int order; + int ret = 0; + + if (!str) + goto out; + + size = (unsigned long)memparse(str, &state); + order = ilog2(size >> PAGE_SHIFT); + if (*state != ':' || !is_power_of_2(size) || size <= PAGE_SIZE || + !(BIT(order) & THP_ORDERS_ALL_FILE_DEFAULT)) + goto out; + + state++; + + if (!strcmp(state, "always")) { + set_bit(order, &huge_file_orders_always); + ret = 1; + } else if (!strcmp(state, "always+exec")) { + set_bit(order, &huge_file_orders_always); + huge_file_exec_order = order; + ret = 1; + } else if (!strcmp(state, "never")) { + clear_bit(order, &huge_file_orders_always); + ret = 1; + } + + if (ret) + file_orders_configured = true; +out: + if (!ret) + pr_warn("thp_file=%s: cannot parse, ignored\n", str); + return ret; +} +__setup("thp_file=", setup_thp_file); + pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma) { if (likely(vma->vm_flags & VM_WRITE))