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 22852E95A91 for ; Mon, 9 Oct 2023 14:43:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD41B8D0079; Mon, 9 Oct 2023 10:43:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A83998D0031; Mon, 9 Oct 2023 10:43:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 924F68D0079; Mon, 9 Oct 2023 10:43:37 -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 80C948D0031 for ; Mon, 9 Oct 2023 10:43:37 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 54A3F160289 for ; Mon, 9 Oct 2023 14:43:37 +0000 (UTC) X-FDA: 81326191674.09.80F5F16 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 100F280018 for ; Mon, 9 Oct 2023 14:43:34 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aj6DZli9; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696862615; 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:dkim-signature; bh=obL8b5QO0r5nb46hgjY2kK9LhSik8vXkxCpK9YUEIMo=; b=UJYYukNT9DMC3HZqVt2abVnfSYLw+BhsIVr7BLcwtKIaHG7uajdAyp8EY5AwFpObbJB7jT fK7qUMFQOc5qDbba4NhimuapGvZHOfEvyRYGdoy6ZNNaMWwWaM+6ZM4BApDStYuUFgIlwQ 7tqdyq3E6RRcEbYAbzmlNnCS1Z5/HGQ= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aj6DZli9; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf30.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696862615; a=rsa-sha256; cv=none; b=5a4WAkWGnwMeqX5VmGGt2kMzVhkGDZvlywDUJyPsVg7MMYMLzEyk/nIXUAaQMK8UXGxdC7 vZUf7mA2wb2UGmY+yjzktkn3BSau3/GxJJdFxYj5mo+K10QWxahmsL2z0ZCD4ax82Cc5bS pgYTKhNAD7MP1JMfbPgqTxGAC/ChBQE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696862614; h=from:from: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=obL8b5QO0r5nb46hgjY2kK9LhSik8vXkxCpK9YUEIMo=; b=aj6DZli96IvUkLwYfsikMbISYqlxWn9TdtOsp7J3FYJCqxhTb7IJYMeCDPeTGs26DJZDyM ZRpA4L9A9a5X8fBtgHnXWTMs1dX8jkAqvoqYmP3aX6arb2ViQhbkhPnsZ+o4Mby9mlWFtt IuColxZVnTXQy/RYWOxo/rc6YyYjgP0= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-10-De28kwPkMnygELTRfzjP4Q-1; Mon, 09 Oct 2023 10:43:33 -0400 X-MC-Unique: De28kwPkMnygELTRfzjP4Q-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-31f79595669so2429407f8f.0 for ; Mon, 09 Oct 2023 07:43:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696862612; x=1697467412; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=obL8b5QO0r5nb46hgjY2kK9LhSik8vXkxCpK9YUEIMo=; b=Mhg4HrmQFX8DAv26326+xvPMdUvebSlaCAj84Izy1AXrnvQVvHKgUBdqM6wjYQYhz5 QaZ8++PuN30Q3qfHAFG2nwCi0HDpLr3OZd2XpLbGP4gc76Sa2lvH8nEGVp5XMVDT94Wd dgjw85x3ewBK25+GMXwsvqYOOhIe9k+VSyMIQbyZHvqhQnzgas5jxjRVyITh46UWoolQ 7bJTIDoNquJ5bXyoqJmyXHJ8C9FYMpKg3/5sZsaI7Y6C2B4Qbi6A10n3UpbGzf28Sgxm M8X8H12XlUCmxKPcIpde8hb3eEVLGKc4EDf5JqfwFMrBqXnZ8rTNdZhjihu5cuTvjftn zlxA== X-Gm-Message-State: AOJu0YypqXhmqfIVbM5aRJ0hdg8nBYfkDpSUw8rnMPxUIOPiwMrEBPqU cbm7GIcAEdjZcuVwuaG2jUbhsFNrGGTCyobNz1DmCN1MAS0W6hioZWBIYUMDEfB/+LWn/H2X0Kk IXEXsLadmy/s= X-Received: by 2002:a5d:6b11:0:b0:323:1d0a:5562 with SMTP id v17-20020a5d6b11000000b003231d0a5562mr9289941wrw.6.1696862611770; Mon, 09 Oct 2023 07:43:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEeW4IDETa4hchcyUUnR7dHbiPpRDNVVpvGWn/vW/4fF0rfWQohZnx5d8DvvGGiwUmSto6e3A== X-Received: by 2002:a5d:6b11:0:b0:323:1d0a:5562 with SMTP id v17-20020a5d6b11000000b003231d0a5562mr9289918wrw.6.1696862611315; Mon, 09 Oct 2023 07:43:31 -0700 (PDT) Received: from ?IPV6:2003:cb:c733:6400:ae10:4bb7:9712:8548? (p200300cbc7336400ae104bb797128548.dip0.t-ipconnect.de. [2003:cb:c733:6400:ae10:4bb7:9712:8548]) by smtp.gmail.com with ESMTPSA id g8-20020a5d5408000000b0031c5b380291sm9838763wrv.110.2023.10.09.07.43.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Oct 2023 07:43:30 -0700 (PDT) Message-ID: Date: Mon, 9 Oct 2023 16:43:29 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v6 6/9] mm: thp: Add "recommend" option for anon_orders To: Ryan Roberts , Yu Zhao Cc: Andrew Morton , Matthew Wilcox , Yin Fengwei , Catalin Marinas , Anshuman Khandual , Yang Shi , "Huang, Ying" , Zi Yan , Luis Chamberlain , Itaru Kitayama , "Kirill A. Shutemov" , John Hubbard , David Rientjes , Vlastimil Babka , Hugh Dickins , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20230929114421.3761121-1-ryan.roberts@arm.com> <20230929114421.3761121-7-ryan.roberts@arm.com> <2f64809e-0d0d-cc61-71ac-8d9b072efc3a@redhat.com> <25d1cdee-3da8-4728-aa0d-dc07eb28ea95@arm.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <25d1cdee-3da8-4728-aa0d-dc07eb28ea95@arm.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 100F280018 X-Stat-Signature: 76ccnfppgh5zcsuo1xoqx1exoeakq4hw X-HE-Tag: 1696862614-353773 X-HE-Meta: U2FsdGVkX19d8qETB7jmeZkBRcjJ9lTiK3wRZ2SjGwbVKhKcWU/unTO6Mutr29gqeqpG3XEIbxGgXxv6t+pE4lxXjclWhtLggUfmZJs2Jmzx7sbXYQm10sp085uFtB4abK3W/+0gIbD+mFdb66yNyG6bp3OjjUa6P0DCXwiAIMl2jCfGYe5lnsvrSf7RyAVd8VWRB8rp97beJVFBnCCTtfECgFvBBw9c3qoMq10N3D6TUr4vC+xEaNCNFwIF26NIhkCvassBJ9jhcxqJZObeBF5OM92gn9ZRR09qKGeSja+j8WGdYSdFgKGlFU/sB0SCiRhE9fggrA+8K8quYMI2Cotu7hS5aQwI3NSGzW2XWnx+kjcQM/5b5anzkWYJK1eYLWYKEAjFzrl9We6E5SadQJ6O0PdMldxjffpviGy9XQMP1rp2HHH57t6zHeuqYSYjUD5BYA6mFaidMEBqWpl6O48I29A9i5c9897aJCbenUPaFNqxPJudx+9GZ08BesHWiefAVUmV+S3OPcFadV5nyZSJNByqUq6MOjlYwYnlqbMcZjg0FyR5nUM2/DmnQj2oS6flv1BBLA4DRuCcbSjQ5oA30RcRYIwgwIx3R3RCxvuiTJHFawLRkoVUX8bKR0Ndj51rfa7yB5ryaB5RafSZCfaGac65i4l+umNW8T62/e1dgi9V4GH2rSMxkFyIDXSZrbjkO4NH6E4srilxfgV+0RoWfQJxau1WJOFaJynIS1AwX/OrPzzEUh3rkGiQDCZmRxJc0CjlOAJUfDrC9iRXYasUGRLv+b/TCsMn3erjfNzbrS1NRfjHhL5/ESJ+9Fw3t3Mu7Bg2wbQYCINlgQHJrqy7NacK/8B4Yscrvz/s2L+6EY9WwESMeAwPzzUczXnjG6RA0srRdD2Uwq4Kh1C+oXP+8ULI4ElLI/8G8viOMkIrUlL6GsLDXS2voLOExuQrO95MhDEKGOrWFaIRoF7 yuvj8S9m Xn3KNDMTBGk7DcRLEFcxI+q6b1KqW3YZJR2pD58NDnCjiVk9339GZgyUybmOSVH8KEE0cJJ3eevwVWWC+WA04cdcZIX/JsRgG4GCcAxjrin74QIAleJWYIEDm9/HeQczWlr5Zpy+jh65RCMJRFq+r781hb/H2Wef2T+mJHl8Hi7vs27NWMBlUYuA2I0De7en1rU9rExeAMgragBDhE0NzFoTJE+HvaZ7/CIQbplkK5NuB6ZklLXNCfz6sKEyOPlBpdsBVCfcmNeS7O3L1rovfObSwKB+9C6ay6lexjasBAdLn7G328RUNl4CcwZCEOXCfhwIx1AuGZcE2SvVoxkavWKYbd3O23zTmCnsiYviqTfI/MgNBpKHEAFSIFn3vMhYmqWIYCPHHj2KzZI7TAMbTCF8SAD7CVpSw4pUkxr50vPBL8kpz5SaoBsS5wOfEzoGomeiPtX7uQpN5wpPlJ0oOJ3P9v79bqQXAesGkaSmhUbJ/gC9ja/qtxISd9/fZhexOIy5Y/jEmrAN7c67nC1iG20MnYpa31UK/11NMIn3HJr07XVjvZYrZDJqIJhUPWLt4wiUv28+EMK3OAs0= 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: On 09.10.23 13:45, Ryan Roberts wrote: > On 06/10/2023 23:28, Yu Zhao wrote: >> On Fri, Oct 6, 2023 at 2:08 PM David Hildenbrand wrote: >>> >>> On 29.09.23 13:44, Ryan Roberts wrote: >>>> In addition to passing a bitfield of folio orders to enable for THP, >>>> allow the string "recommend" to be written, which has the effect of >>>> causing the system to enable the orders preferred by the architecture >>>> and by the mm. The user can see what these orders are by subsequently >>>> reading back the file. >>>> >>>> Note that these recommended orders are expected to be static for a given >>>> boot of the system, and so the keyword "auto" was deliberately not used, >>>> as I want to reserve it for a possible future use where the "best" order >>>> is chosen more dynamically at runtime. >>>> >>>> Recommended orders are determined as follows: >>>> - PMD_ORDER: The traditional THP size >>>> - arch_wants_pte_order() if implemented by the arch >>>> - PAGE_ALLOC_COSTLY_ORDER: The largest order kept on per-cpu free list >>>> >>>> arch_wants_pte_order() can be overridden by the architecture if desired. >>>> Some architectures (e.g. arm64) can coalsece TLB entries if a contiguous >>>> set of ptes map physically contigious, naturally aligned memory, so this >>>> mechanism allows the architecture to optimize as required. >>>> >>>> Here we add the default implementation of arch_wants_pte_order(), used >>>> when the architecture does not define it, which returns -1, implying >>>> that the HW has no preference. >>>> >>>> Signed-off-by: Ryan Roberts >>>> --- >>>> Documentation/admin-guide/mm/transhuge.rst | 4 ++++ >>>> include/linux/pgtable.h | 13 +++++++++++++ >>>> mm/huge_memory.c | 14 +++++++++++--- >>>> 3 files changed, 28 insertions(+), 3 deletions(-) >>>> >>>> diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst >>>> index 732c3b2f4ba8..d6363d4efa3a 100644 >>>> --- a/Documentation/admin-guide/mm/transhuge.rst >>>> +++ b/Documentation/admin-guide/mm/transhuge.rst >>>> @@ -187,6 +187,10 @@ pages (=16K if the page size is 4K). The example above enables order-9 >>>> By enabling multiple orders, allocation of each order will be >>>> attempted, highest to lowest, until a successful allocation is made. >>>> If the PMD-order is unset, then no PMD-sized THPs will be allocated. >>>> +It is also possible to enable the recommended set of orders, which >>>> +will be optimized for the architecture and mm:: >>>> + >>>> + echo recommend >/sys/kernel/mm/transparent_hugepage/anon_orders >>>> >>>> The kernel will ignore any orders that it does not support so read the >>>> file back to determine which orders are enabled:: >>>> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h >>>> index af7639c3b0a3..0e110ce57cc3 100644 >>>> --- a/include/linux/pgtable.h >>>> +++ b/include/linux/pgtable.h >>>> @@ -393,6 +393,19 @@ static inline void arch_check_zapped_pmd(struct vm_area_struct *vma, >>>> } >>>> #endif >>>> >>>> +#ifndef arch_wants_pte_order >>>> +/* >>>> + * Returns preferred folio order for pte-mapped memory. Must be in range [0, >>>> + * PMD_ORDER) and must not be order-1 since THP requires large folios to be at >>>> + * least order-2. Negative value implies that the HW has no preference and mm >>>> + * will choose it's own default order. >>>> + */ >>>> +static inline int arch_wants_pte_order(void) >>>> +{ >>>> + return -1; >>>> +} >>>> +#endif >>>> + >>>> #ifndef __HAVE_ARCH_PTEP_GET_AND_CLEAR >>>> static inline pte_t ptep_get_and_clear(struct mm_struct *mm, >>>> unsigned long address, >>>> diff --git a/mm/huge_memory.c b/mm/huge_memory.c >>>> index bcecce769017..e2e2d3906a21 100644 >>>> --- a/mm/huge_memory.c >>>> +++ b/mm/huge_memory.c >>>> @@ -464,10 +464,18 @@ static ssize_t anon_orders_store(struct kobject *kobj, >>>> int err; >>>> int ret = count; >>>> unsigned int orders; >>>> + int arch; >>>> >>>> - err = kstrtouint(buf, 0, &orders); >>>> - if (err) >>>> - ret = -EINVAL; >>>> + if (sysfs_streq(buf, "recommend")) { >>>> + arch = max(arch_wants_pte_order(), PAGE_ALLOC_COSTLY_ORDER); >>>> + orders = BIT(arch); >>>> + orders |= BIT(PAGE_ALLOC_COSTLY_ORDER); >>>> + orders |= BIT(PMD_ORDER); >>>> + } else { >>>> + err = kstrtouint(buf, 0, &orders); >>>> + if (err) >>>> + ret = -EINVAL; >>>> + } >>>> >>>> if (ret > 0) { >>>> orders &= THP_ORDERS_ALL_ANON; >>> >>> :/ don't really like that. Regarding my proposal, one could have >>> something like that in an "auto" setting for the "enabled" value, or a >>> "recommended" setting [not sure]. >> >> Me either. >> >> Again this is something I call random -- we only discussed "auto", >> and yes, the commit message above explained why "recommended" here but >> it has never surfaced in previous discussions, has it? > > The context in which we discussed "auto" was for a future aspiration to > automatically determine the order that should be used for a given allocation to > balance perf vs internal fragmentation. > > The case we are talking about here is completely different; I had a pre-existing > feature from previous versions of the series, which would allow the arch to > specify its preferred order (originally proposed by Yu, IIRC). In moving the > allocation size decision to user space, I felt that we still needed a mechanism > whereby the arch could express its preference. And "recommend" is what I came up > with. > > All of the friction we are currently having is around this feature, I think? > Certainly all the links you provided in the other thread all point to > conversations skirting around it. How about I just drop it for this initial > patch set? Just let user space decide what sizes it wants (per David's interface > proposal)? I can see I'm trying to get a square peg into a round hole. Dropping it for the initial patch set sounds like a very good idea. Telling people what to enable initially when they want to play with it will work out just fine. [Ideally, we plan ahead to have such "auto" settings in the future, as I expressed.] -- Cheers, David / dhildenb