From patchwork Wed Jul 17 07:12:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Roberts X-Patchwork-Id: 13735173 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 22118C3DA4B for ; Wed, 17 Jul 2024 07:13:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 958556B008C; Wed, 17 Jul 2024 03:13:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 907E16B0092; Wed, 17 Jul 2024 03:13:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75A516B0095; Wed, 17 Jul 2024 03:13:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 510CC6B008C for ; Wed, 17 Jul 2024 03:13:15 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0A1C9A33C3 for ; Wed, 17 Jul 2024 07:13:15 +0000 (UTC) X-FDA: 82348378350.10.BBD1FC4 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf09.hostedemail.com (Postfix) with ESMTP id 6797914000A for ; Wed, 17 Jul 2024 07:13:13 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf09.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721200349; 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=Jv2Czli6NbyrYYvJj84Kky/Y0Ig8CMule9sgZLnnjW0=; b=VgLD5Mv1hnDHNfTtxAytxcOlJpaEuSioRpAc+k0En+X/4OOx/wiCxV0kqsgTXYWfAmqbJo 3AZyARQadC778VB/q9IxGAzSSqRumxaKDKm097mnTsGWcaipidv+qTAeuMBLmaF2QZq96Z mv6egh8hsBdkoMgdu6GPhb+nDXZrUFs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721200349; a=rsa-sha256; cv=none; b=vkk1Z5cWa/iXU3dpA8g6M/kaNXnsRuC2FuNBFuuR7MG+aiIiRrIDvlhmRvlJ9shcpu8/oO 4E55L1pUlFTqMHu/enApZe8MKON64I3r9yhqasi1y+dMhTBRH0qnE/vrJwRdBRhsDBohP0 xaGhgZkfvJVY54nkgqtmYeAxGCOQYLI= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf09.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com 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 237961480; Wed, 17 Jul 2024 00:13:38 -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 228DD3F762; Wed, 17 Jul 2024 00:13:11 -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 3/4] mm: Override mTHP "enabled" defaults at kernel cmdline Date: Wed, 17 Jul 2024 08:12:55 +0100 Message-ID: <20240717071257.4141363-4-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: rspam07 X-Rspamd-Queue-Id: 6797914000A X-Stat-Signature: 5xtgo6f6wdfgoi3ieh366fgkcsyts39t X-Rspam-User: X-HE-Tag: 1721200393-919213 X-HE-Meta: U2FsdGVkX1+hJbQBAXvcKjOT8GenqgbXIRXyw2LLCTDKocQ2bOLBHfXMOAENNTxbK0CTY41DgqkRSNr9X921iBxnl0SXQnoIpsDvwx8LP5l7PQ6/XnOi7zfrZR91GASgCcpd54bkd0RJhaDIA2w7qmQvjjntn6uCqT/geA2x4vAklyc1NbTsD0vdY9JYlPEuu9eZDdXI3nijlQ77LW/AqTzllsyaTPmgqtIfVxmaVxVIyOziI8nLiuJyVV3v9fhW8l2OO0rETZ3+ydSeQ+XVa3gZOaOyKV9SQ8eUlQDFW699hsTGFaGlfqIDxTNNym0YbVs8HBXe/lKftFWeDDUIzkWLbXma510yRxfFXDlO4Mc6HKl6xArNioOnuHg04CVBXuswucodhPMHKAtQDtUSWYzP1/HWBFlIMPJUTqblis63FEZg/hOW9mSVvYXrpSGa7ER7/yn5br8r0jXzDaV22Zrm97KxNqy/yMnRv7w1VrlD5k1/Y8H5KR2+lZ2JpGoeh5AzXGRQs2qFPmkVc6T6iOVS35wtcXgvDn7DaSqggjZBeWcNSG2Wfw8Gghjbmfmoiv5kztT02iZHJmt4sZqCB0zxJiIGsKW/cfVIKfR9qhgyT8SGBYRN7oDG1Dcm3pFk+ISRNGVdauYPKh5iK5VJtF2SAtU2IOl+25jdc+eOqeC7n/Rri/FBCEmwZfIS5veHXbHQuMKPSpdIhxpA4uiaSLXfvtoUhtRt5LeIZ+R+moSr/eEdEXmg9nm+5r6FrdRvH8OQFmLknj2zHIbH8urcytRcchuEwdlCiaE8C5mn5CmjBs1vUeYY9csJ2/ijY5Io6BMxpbn8H5PkriB8HDSDPUkAaGWBoMupChQCQaVPmPj0e8GhbAqqIPMVg7zbRBRsvYhIscobiiSe/8KI+7RM1d/Raqt/JSH/NYDm308+Hd1wnsvdc8x89Kxs47S/loly12KQ7E2b04MvvGLcUZl vLNi4Dy3 CyyUjclHMWBl5PztKECME8Q6si8KTk9ZgQ3JLDyQprKLNlMlMxV7qwZ5Oud6mqMBq334HQ7LXOmkPUJ1Rkgm7mNOWRGXFqqSkcKigR8Pe1G5cqdAIkVIsWXMHmK0M+6oi9nlhcEy6NpM3DzrdS/HsFhUwStPl8EMX0++g 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_anon= cmdline parameter to allow specifying the default enablement of each supported anon THP size. The parameter accepts the following format and can be provided multiple times to configure each size: thp_anon=[KMG]: See Documentation/admin-guide/mm/transhuge.rst for more details. Configuring the defaults at boot time is useful to allow early user space to take advantage of mTHP before its been configured through sysfs. Signed-off-by: Ryan Roberts --- .../admin-guide/kernel-parameters.txt | 8 +++ Documentation/admin-guide/mm/transhuge.rst | 26 +++++++-- mm/huge_memory.c | 55 ++++++++++++++++++- 3 files changed, 82 insertions(+), 7 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index bc55fb55cd26..48443ad12e3f 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6592,6 +6592,14 @@ : poll all this frequency 0: no polling (default) + thp_anon= [KNL] + Format: [KMG]:always|madvise|never|inherit + Can be used to control the default behavior of the + system with respect to anonymous transparent hugepages. + Can be used multiple times for multiple anon 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 1aaf8e3a0b5a..f53d43d986e2 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -311,13 +311,27 @@ performance. Note that any changes to the allowed set of sizes only applies to future file-backed THP allocations. -Boot parameter -============== +Boot parameters +=============== -You can change the sysfs boot time defaults of Transparent Hugepage -Support by passing the parameter ``transparent_hugepage=always`` or -``transparent_hugepage=madvise`` or ``transparent_hugepage=never`` -to the kernel command line. +You can change the sysfs boot time default for the top-level "enabled" +control by passing the parameter ``transparent_hugepage=always`` or +``transparent_hugepage=madvise`` or ``transparent_hugepage=never`` to the +kernel command line. + +Alternatively, each supported anonymous THP size can be controlled by +passing ``thp_anon=[KMG]:``, where ```` is the THP size +and ```` is one of ``always``, ``madvise``, ``never`` or +``inherit``. + +For example, the following will set 64K THP to ``always``:: + + thp_anon=64K:always + +``thp_anon=`` may be specified multiple times to configure all THP sizes as +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``. Hugepages in tmpfs/shmem ======================== diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 4249c0bc9388..794d2790d90d 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -82,6 +82,7 @@ unsigned long huge_anon_orders_madvise __read_mostly; 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; unsigned long __thp_vma_allowable_orders(struct vm_area_struct *vma, unsigned long vm_flags, @@ -763,7 +764,10 @@ static int __init hugepage_init_sysfs(struct kobject **hugepage_kobj) * disable all other sizes. powerpc's PMD_ORDER isn't a compile-time * constant so we have to do this here. */ - huge_anon_orders_inherit = BIT(PMD_ORDER); + if (!anon_orders_configured) { + huge_anon_orders_inherit = BIT(PMD_ORDER); + anon_orders_configured = true; + } /* * For pagecache, default to enabling all orders. powerpc's PMD_ORDER @@ -955,6 +959,55 @@ static int __init setup_transparent_hugepage(char *str) } __setup("transparent_hugepage=", setup_transparent_hugepage); +static int __init setup_thp_anon(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_ANON)) + goto out; + + state++; + + if (!strcmp(state, "always")) { + clear_bit(order, &huge_anon_orders_inherit); + clear_bit(order, &huge_anon_orders_madvise); + set_bit(order, &huge_anon_orders_always); + ret = 1; + } else if (!strcmp(state, "inherit")) { + clear_bit(order, &huge_anon_orders_always); + clear_bit(order, &huge_anon_orders_madvise); + set_bit(order, &huge_anon_orders_inherit); + ret = 1; + } else if (!strcmp(state, "madvise")) { + clear_bit(order, &huge_anon_orders_always); + clear_bit(order, &huge_anon_orders_inherit); + set_bit(order, &huge_anon_orders_madvise); + ret = 1; + } else if (!strcmp(state, "never")) { + clear_bit(order, &huge_anon_orders_always); + clear_bit(order, &huge_anon_orders_inherit); + clear_bit(order, &huge_anon_orders_madvise); + ret = 1; + } + + if (ret) + anon_orders_configured = true; +out: + if (!ret) + pr_warn("thp_anon=%s: cannot parse, ignored\n", str); + return ret; +} +__setup("thp_anon=", setup_thp_anon); + pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma) { if (likely(vma->vm_flags & VM_WRITE))