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 56B62C3DA5D for ; Fri, 19 Jul 2024 08:18:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76B2E6B0082; Fri, 19 Jul 2024 04:18:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 71B266B0083; Fri, 19 Jul 2024 04:18:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E2656B0088; Fri, 19 Jul 2024 04:18:44 -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 40E066B0082 for ; Fri, 19 Jul 2024 04:18:44 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D5562404C6 for ; Fri, 19 Jul 2024 08:18:43 +0000 (UTC) X-FDA: 82355800926.24.04CB9EC Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf14.hostedemail.com (Postfix) with ESMTP id D304D100010 for ; Fri, 19 Jul 2024 08:18:41 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf14.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=1721377081; 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=5wUPHQAYMz40mlOjGaGx8gtHk72votd67XYT13A2b2A=; b=6tpsvpSLO7ozbywQPJ66ZVn6biu0OKITkA7frO0ibpIAvfoT23eK3ycbaRmon8CJ2pFJn2 dA7wWU0G3wcmDot3hZeo17eozHbCqSp2wtBfpID/jWSdownT0U9UORoMZRNg4Auya6vL79 ovRYNwIE80s87mrP6SWzid2MN53zl4U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721377081; a=rsa-sha256; cv=none; b=dHZJTXdl2A8x8VG8uuYDb7HIOedE/VYmiXUL9n4UGHv6M1gMg37ZcWWRDHyAvxkM3AGmnl g+LS9EOhxI3RcuSIFAzGxU79yPBilE+I5IvVUXxmjUOxV3BsYd2pG9CiAapIC6WV/OqdbN wHJy0SjICyuVHk4j8g9EtVQMmxzmAjU= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf14.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 1A44F1042; Fri, 19 Jul 2024 01:19:06 -0700 (PDT) Received: from [10.57.76.151] (unknown [10.57.76.151]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B07823F766; Fri, 19 Jul 2024 01:18:38 -0700 (PDT) Message-ID: Date: Fri, 19 Jul 2024 09:18:37 +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: Barry Song Cc: Andrew Morton , Hugh Dickins , Jonathan Corbet , "Matthew Wilcox (Oracle)" , David Hildenbrand , Lance Yang , Baolin Wang , Gavin Shan , Pankaj Raghav , Daniel Gomez , 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: 8bit X-Rspamd-Queue-Id: D304D100010 X-Stat-Signature: 8qs8jmmpmtxq7zg5dqxcgt4pwrgem4sy X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1721377121-254800 X-HE-Meta: U2FsdGVkX19W9UJIIPst7/22xCWeV9RmX8KWxYRk0Fduft7gn5C3gJxV/lSETILR2UPaXuDyhpD7A3kdqdXa1Z3/9vxwBlBXd+y/F1heS8uZ6/5XNs96i8uRXtZ7hA/CQ1q+62zvp4TbIqo3Un7a7fB9DvZ9e5Kx9WwoIG/k/MwmIRkIbHWB1B1XdLbyCw3T2Hy7ShCZy/Ij9VJTcVW3RKtOyzX5BOAGsefEx1Sm0qwSY4vvlceMlazATfTM5q47moq14PCxCYqpnMAiiE8vZ+LVxkxP29WjGw/rL9kLpe71hEEZa2bqEVpETUekZN+IjFhlpUTcbYqLgNhWuL8tkKKreiBPcAR6I/mCLAImNY23rP8XIXdCc5+Lmil68jRG7IqID4s0s0h3rApvlrIaHR6L2xaxAE9TZ03SyObjlCWnU1XCCBlHD8lnC4/NyBkkVsJmRIOV+ZkCgfeRUh00E1zxkbISx33516XwGNyDF+D7rnG1qFec8/OxJFG5uZbkJvKcHD7err88FfmcMo57E9TV4syaJhTlOUSW4QjnNei5KmKy7qmzW6M1WGDtsV3CYN0eXDXoBiGmaM4h8HoFRqROtzjx+e1R68qARD5cgJXjxEuO/XrAsr+TpeZur1HFBYsf96klBPJ/oApIzNoxVkjOuk8KCelnsQBqKEBt3AUCrkksevvwKwqgF9T3qV/QamGgm2037eX/QiIHLyQmgT4NlLGmSjjPB/M4h3Mnm64oNWbHI61chskKZtjc/wbkohlwNkHGMsbDhU/zW1U04eBIOua67kWMRyq8RZUWXIgo9D0R13Ci439p5R9pHQ0qTf1wgS3zuaHenurbzUPxwQmBsfz+L6bTqO6Q0+41F5K0YVtieIbCD0RFLQjDrf3EEL1lG8xI377cFgeUkw7v35lgNQitX7iQftjPp7OZRhV8CbtXqt0iFzvUZYbY4ED7SfRd7hrHZQoVFjyfAI+ OYYdcLhv 2io3OrXzGyfsAXKfdbo8TMHuDuDTnlffNeZ7v94dUrieUyNAsNijDD2XR8pmHwVU3CkVD2UDPocZAz24XZl7mtgeA203v/Q4KEAR5gpP+4FQLNQBoGsyYsF1xH2os71CnqkoADA66rkV7lwje2jnKJ9AqpVKPsGccR0mAJizMfUwbZjm0rGsLonOm6sUZ9cpuWb8db5YkjQpqyaULqFfJAWwTxfGOnVqBbaXRKCF7fYfHOrZtFG06TZm2hDaDxeYxAKK/vEpz2GWjcPA= 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 19/07/2024 08:52, Barry Song wrote: > On Fri, Jul 19, 2024 at 7:48 PM Ryan Roberts wrote: >> >> On 19/07/2024 01:46, Barry Song wrote: >>> On Wed, Jul 17, 2024 at 7:13 PM 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]: >>>> >>>> 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. >>> >>> This is exactly what I need and want to implement, as the current behavior >>> is problematic. We need to boot up the system and reach the point where >>> we can set up the sys interfaces to enable mTHP. Many processes miss the >>> opportunity to use mTHP. >>> >>> On the other hand, userspace might have been tuned to detect that mTHP >>> is enabled, such as a .so library. However, it turns out we have had >>> inconsistent settings between the two stages - before and after setting >>> mTHP enabled by sys interfaces. >> >> Good feedback - sounds like I should separate out this patch from the rest of >> the series to get it reviewed and merged faster? > > +1 OK I'll wait a couple of days to see if anyone has any feedback against this version, then I'll re-post this on its own. > >> >>> >>>> >>>> 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)) >>>> -- >>>> 2.43.0 >>>> >>> >>> Thanks >>> Barry >> >>