linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Ryan Roberts <ryan.roberts@arm.com>, Yu Zhao <yuzhao@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Matthew Wilcox <willy@infradead.org>,
	Yin Fengwei <fengwei.yin@intel.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Anshuman Khandual <anshuman.khandual@arm.com>,
	Yang Shi <shy828301@gmail.com>,
	"Huang, Ying" <ying.huang@intel.com>, Zi Yan <ziy@nvidia.com>,
	Luis Chamberlain <mcgrof@kernel.org>,
	Itaru Kitayama <itaru.kitayama@gmail.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	John Hubbard <jhubbard@nvidia.com>,
	David Rientjes <rientjes@google.com>,
	Vlastimil Babka <vbabka@suse.cz>, Hugh Dickins <hughd@google.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v6 6/9] mm: thp: Add "recommend" option for anon_orders
Date: Mon, 9 Oct 2023 16:43:29 +0200	[thread overview]
Message-ID: <f1e24131-07b7-c6bf-10ea-8860f055d131@redhat.com> (raw)
In-Reply-To: <25d1cdee-3da8-4728-aa0d-dc07eb28ea95@arm.com>

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 <david@redhat.com> 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 <ryan.roberts@arm.com>
>>>> ---
>>>>    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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2023-10-09 14:44 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-29 11:44 [PATCH v6 0/9] variable-order, large folios for anonymous memory Ryan Roberts
2023-09-29 11:44 ` [PATCH v6 1/9] mm: Allow deferred splitting of arbitrary anon large folios Ryan Roberts
2023-10-05  8:19   ` David Hildenbrand
2023-09-29 11:44 ` [PATCH v6 2/9] mm: Non-pmd-mappable, large folios for folio_add_new_anon_rmap() Ryan Roberts
2023-09-29 13:45   ` Kirill A. Shutemov
2023-09-29 14:39     ` Ryan Roberts
2023-09-29 11:44 ` [PATCH v6 3/9] mm: thp: Account pte-mapped anonymous THP usage Ryan Roberts
2023-09-29 11:44 ` [PATCH v6 4/9] mm: thp: Introduce anon_orders and anon_always_mask sysfs files Ryan Roberts
2023-09-29 22:55   ` Andrew Morton
2023-10-02 10:15     ` Ryan Roberts
2023-10-07 22:54     ` Michael Ellerman
2023-10-10  0:20       ` Andrew Morton
2023-10-12  9:31         ` David Hildenbrand
2023-10-12 11:07         ` Michael Ellerman
2023-10-11  6:02   ` kernel test robot
2023-09-29 11:44 ` [PATCH v6 5/9] mm: thp: Extend THP to allocate anonymous large folios Ryan Roberts
     [not found]   ` <CGME20231005120507eucas1p13f50fa99f52808818840ee7db194e12e@eucas1p1.samsung.com>
2023-10-05 12:05     ` Daniel Gomez
2023-10-05 12:49       ` Ryan Roberts
2023-10-05 14:59         ` Daniel Gomez
2023-10-27 23:04   ` John Hubbard
2023-10-30 11:43     ` Ryan Roberts
2023-10-30 23:25       ` John Hubbard
2023-11-01 13:56         ` Ryan Roberts
2023-09-29 11:44 ` [PATCH v6 6/9] mm: thp: Add "recommend" option for anon_orders Ryan Roberts
2023-10-06 20:08   ` David Hildenbrand
2023-10-06 22:28     ` Yu Zhao
2023-10-09 11:45       ` Ryan Roberts
2023-10-09 14:43         ` David Hildenbrand [this message]
2023-10-09 20:04         ` Yu Zhao
2023-10-10 10:16           ` Ryan Roberts
2023-09-29 11:44 ` [PATCH v6 7/9] arm64/mm: Override arch_wants_pte_order() Ryan Roberts
2023-10-02 15:21   ` Catalin Marinas
2023-10-03  7:32     ` Ryan Roberts
2023-10-03 12:05       ` Catalin Marinas
2023-09-29 11:44 ` [PATCH v6 8/9] selftests/mm/cow: Generalize do_run_with_thp() helper Ryan Roberts
2023-09-29 11:44 ` [PATCH v6 9/9] selftests/mm/cow: Add tests for small-order anon THP Ryan Roberts
2023-10-06 20:06 ` [PATCH v6 0/9] variable-order, large folios for anonymous memory David Hildenbrand
2023-10-09 11:28   ` Ryan Roberts
2023-10-09 16:22     ` David Hildenbrand
2023-10-10 10:47       ` Ryan Roberts
2023-10-13 20:14         ` David Hildenbrand
2023-10-20 12:33   ` Ryan Roberts
2023-10-25 16:24     ` Ryan Roberts
2023-10-25 18:47       ` David Hildenbrand
2023-10-25 19:11         ` Yu Zhao
2023-10-26  9:53           ` Ryan Roberts
2023-10-26 15:19             ` David Hildenbrand
2023-10-25 19:10       ` John Hubbard
2023-10-31 11:50   ` Ryan Roberts
2023-10-31 11:55     ` Ryan Roberts
2023-10-31 12:03       ` David Hildenbrand
2023-10-31 13:13         ` Ryan Roberts
2023-10-31 18:29       ` Yang Shi
2023-11-01 14:02         ` Ryan Roberts
2023-11-01 18:11           ` Yang Shi
2023-10-31 11:58     ` David Hildenbrand
2023-10-31 13:12       ` Ryan Roberts
2023-11-13  3:57 ` John Hubbard
2023-11-13  5:18   ` Matthew Wilcox
2023-11-13 10:19     ` Ryan Roberts
2023-11-13 11:52       ` Kefeng Wang
2023-11-13 12:12         ` Ryan Roberts
2023-11-13 14:52           ` Kefeng Wang
2023-11-13 14:52       ` John Hubbard
2023-11-13 15:04       ` Matthew Wilcox
2023-11-14 10:57         ` Ryan Roberts
2023-12-05 16:05           ` Matthew Wilcox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f1e24131-07b7-c6bf-10ea-8860f055d131@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=catalin.marinas@arm.com \
    --cc=fengwei.yin@intel.com \
    --cc=hughd@google.com \
    --cc=itaru.kitayama@gmail.com \
    --cc=jhubbard@nvidia.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mcgrof@kernel.org \
    --cc=rientjes@google.com \
    --cc=ryan.roberts@arm.com \
    --cc=shy828301@gmail.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    --cc=ying.huang@intel.com \
    --cc=yuzhao@google.com \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).