From mboxrd@z Thu Jan 1 00:00:00 1970 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 5A6C6C3DA5D for ; Mon, 22 Jul 2024 09:36:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF35D6B0089; Mon, 22 Jul 2024 05:36:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA4BB6B008A; Mon, 22 Jul 2024 05:36:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6B956B008C; Mon, 22 Jul 2024 05:36:55 -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 B82256B0089 for ; Mon, 22 Jul 2024 05:36:55 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 74C9CA5861 for ; Mon, 22 Jul 2024 09:36:55 +0000 (UTC) X-FDA: 82366884390.11.A9C8372 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf18.hostedemail.com (Postfix) with ESMTP id 8E5BF1C0020 for ; Mon, 22 Jul 2024 09:36:53 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.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=1721640968; 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=QI2Uaemp6H4MnzA6n9PVR4AkfNyd368trzc0nsfUtgo=; b=TJdjYj/0NcdpeUOrly8ZrL4wNkYzPcSf75AOQnXIpgZoLzPN6MrQM+FPWrCv7Om8EQDCMX uZ6bFCc4JJWKBBuWd/Gew7UDy2WcJN3BoAc0/piFa2tk1HOyavIG3knRCUr0DhEb23DqlT kz7xjLNaSwNBFpwFjTobmWK7vTr4HDk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721640968; a=rsa-sha256; cv=none; b=zaU+ogoFYZg9tCfmZvPzkmZYATLl5XFg3jJdWDdDTQMunGaqWqtgxJNXJ0rRAHRyxbvE0/ hmTGxGB5Dgm9Y4jLWytlMv/H5Gp8K1Ad3xglLOIr+PfnXYLxL8fnrRqx7dGSFO3JGUUeFg LGo3kxv4x+QUVjLKIMOXD+7a1pd16d0= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.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 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 E96F1FEC; Mon, 22 Jul 2024 02:37:17 -0700 (PDT) Received: from [10.1.27.165] (XHFQ2J9959.cambridge.arm.com [10.1.27.165]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9E0113F766; Mon, 22 Jul 2024 02:36:50 -0700 (PDT) Message-ID: Date: Mon, 22 Jul 2024 10:36:49 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v1 3/4] mm: Override mTHP "enabled" defaults at kernel cmdline Content-Language: en-GB To: Daniel Gomez Cc: Andrew Morton , Hugh Dickins , Jonathan Corbet , "Matthew Wilcox (Oracle)" , David Hildenbrand , Barry Song , Lance Yang , Baolin Wang , Gavin Shan , Pankaj Raghav , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" References: <20240717071257.4141363-1-ryan.roberts@arm.com> <20240717071257.4141363-4-ryan.roberts@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: icnaj5kx9fiw1ru9uj9oh3okybpja6qs X-Rspamd-Queue-Id: 8E5BF1C0020 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1721641013-445359 X-HE-Meta: U2FsdGVkX1/0yMf/QTzBfFEdoftr1OfII3+WYUWUIP8UF2i1X4+7UfxP/hLDJE2vPvZjH6VGG2UfvsjJewihQdsSP0qn12NRSWTKqEtMOwcb7wSBBhk4OCFTtlkeYL3yu+asBF+uQ2JqOZjknaowfLGC2X7WZgcoC2QkpQY1P08c9tY6u9zyurifg5iSINWo/NOBENtuPzdnkqci6g0R6cN/DmsPl2Cb7FvRmOxouKQlPSJtDhlv107TKn0th/ARPiXPsDMVY6R3TYsCnvppMMerP6JFDRoNTpW8uWGAgj6IyrDOy1OdyDeHOuAsRirCd41MkmMqnh0LX+k6nk8hVUygdggqrUkPnCWAt74badCm/lVX+9nWFpSEIuOin/BhG6H3wMiuRZL44WGzZEvHau3seFZ6g0DS0BjOrMNIGSUaDz023mky1yK76OKebUgNPlFO4P1NlGN5v5q5zXpIVmcm39Gip/8ftpamWW3ZqlrG7kQxsq4vXFNUKnA1vSr6vSxgOMdGkInE9xQoeW57Bjs9yBsK3s4xxGAia6v6gJqHyWDstK3KtvchjwnjnfqOGCUtYEYIyR3new3RVFEkL/5+dzoNsGKUD3ENo+bOfz+cscwv/pvaXWlb8HitR+V1L4mB/rhgk5WRAbel4wi8x//3PyCOu6nqzsPQI9Hw4p/PkeF4aZeWBR/prhgQvL9Dh2vrofn7bhjNdL17DtS6QLE24oPBCS/EneFwNHiH8Cvqc46FuCxHeSYkZvWczDNxH7buHq9QQtKogZgM1M3UNBQNevxyWhTO47Vw6DwJ5IabYxuYSVky40uKfxxxpsTAX81vl+Huitt8Q2cCMEn1mh/RQc6/GnRqEl4SfenkFJP+sub5z5V/y1MaSETmbD4SyrompfqfGnVQvfA5Y6htY9BopHVrrgtmb3OW4a8Y6YOmyzOxb8LL8rPOYrz8SM+9QIHHz8DTk5PuQ49DP8n 1J6V91Ps +vrvmS7CP4GQAon9/AlMvIPujRqtzPbTBGeAz+Pj/6e6xkRC85lrO7lgSdUFzrFM8oWBKIH14ltG+U1ZoWILKwUR+6zCrGdLd13tby5vBj8zFzEptzieL0k8/KpzkeDHCztBFnXcnVKIw3LnVw9RVJRz8c2tvVw6EtE9eOh9fm6iSE29+AzY7kXFahXDYvGnbH0idxQ+Nps1zMz+SRBcmd1OhfyaEha4+jaL1SIlht/VPROvFotj/bseZbyA9JDzzsXKNr4W0F55qN/jDsak8mnVGzEgwoU+OrAoMeCMoJLo/te1VFXg5nKmdI2WaVfiCqzipG08GDtkzL70= 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: On 22/07/2024 10:13, Daniel Gomez wrote: > On Wed, Jul 17, 2024 at 08:12:55AM GMT, Ryan Roberts wrote: >> 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]: > > Minor suggestion. Should this be renamed to hp_anon= or hugepages_anon= instead? > This would align with the values under /sys/kernel/mm/transparent_hugepage/ > hugepages-*kB. "hp" doesn't feel right; that's not an abreviation we use today to my knowledge. But I'd be happy to change it to "hugepages_anon", if that's the concensus. > >> >> 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); > > PMD_ORDER for 64k base PS systems would result in a 512M value, which exceeds > the xarray limit [1]. Therefore, I think we need to avoid PMD-size orders by > checking if PMD_ORDER > MAX_PAGECACHE_ORDER. This is for anon memory, which isn't installed in the page cache so its independent of MAX_PAGECACHE_ORDER. I don't believe there is a problem here. > > [1] https://lore.kernel.org/all/20240627003953.1262512-1-gshan@redhat.com/ > >> + 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)) >> -- >> 2.43.0