Re: [PATCH v2] mm/readahead: Fix large folio support in async readahead

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Nov 13, 2024 at 4:28 PM David Hildenbrand <david@xxxxxxxxxx> wrote:
>
> On 13.11.24 03:16, Yafang Shao wrote:
> > On Tue, Nov 12, 2024 at 11:19 PM David Hildenbrand <david@xxxxxxxxxx> wrote:
> >>
> >>>> Sorry, but this code is getting quite confusing, especially with such
> >>>> misleading "large folio" comments.
> >>>>
> >>>> Even without MADV_HUGEPAGE we will be allocating large folios, as
> >>>> emphasized by Willy [1]. So the only thing MADV_HUGEPAGE controls is
> >>>> *which* large folios we allocate. .. as Willy says [2]: "We were only
> >>>> intending to breach the 'max' for the MADV_HUGE case, not for all cases."
> >>>>
> >>>> I have no idea how *anybody* should derive from the code here that we
> >>>> treat MADV_HUGEPAGE in a special way.
> >>>>
> >>>> Simply completely confusing.
> >>>>
> >>>> My interpretation of "I don't know if we should try to defend a stupid
> >>>> sysadmin against the consequences of their misconfiguration like this"
> >>>> means" would be "drop this patch and don't change anything".
> >>>
> >>> Without this change, large folios won’t function as expected.
> >>> Currently, to support MADV_HUGEPAGE, you’d need to set readahead_kb to
> >>> 2MB, 4MB, or more. However, many applications run without
> >>   > MADV_HUGEPAGE, and a larger readahead_kb might not be optimal for> them.
> >>
> >> Someone configured: "Don't readahead more than 128KiB"
> >>
> >> And then we complain why we "don't readahead more than 128KiB".
> >
> > That is just bikeshielding.
>
> It's called "reading the documentation and trying to make sense of a
> patch". ;)
>
> >
> > So, what’s your suggestion? Simply setting readahead_kb to 2MB? That
> > would almost certainly cause issues elsewhere.
>
> I'm not 100% sure. I'm trying to make sense of it all.
>
> And I assume there is a relevant difference now between "readahead 2M
> using all 4k pages" and "readahead 2M using a single large folio".
>
> I agree that likely readahead using many 4k pages is a worse idea than
> just using a single large folio ... if we manage to allocate one. And
> it's all not that clear in the code ...
>
> FWIW, I looked at "read_ahead_kb" values on my Fedora40 notebook and
> they are all set to 128KiB. I'm not so sure if they really should be
> that small ...

It depends on the use case. For our hardop servers, we set it to 4MB,
as they prioritize throughput over latency. However, for our
Kubernetes servers, we keep it at 128KB since those services are more
latency-sensitive, and increasing it could lead to more frequent
latency spikes.

> or if large folio readahead code should just be able to
> exceed it.
>
> >> "mm/filemap: Support VM_HUGEPAGE for file mappings" talks about "even if
> >> we have no history of readahead being successful".
> >>
> >> So not about exceeding the configured limit, but exceeding the
> >> "readahead history".
> >>
> >> So I consider VM_HUGEPAGE the sign here to "ignore readahead history"
> >> and not to "violate the config".
> >
> > MADV_HUGEPAGE is definitely a new addition to readahead, and its
> > behavior isn’t yet defined in the documentation. All we need to do is
> > clarify its behavior there. The documentation isn’t set in stone—we
> > can update it as long as it doesn’t disrupt existing applications.
>
> If Willy thinks this is the way to go, then we should document that
> MADV_HUGEPAGE may ignore the parameter, agreed.

I'll submit an additional patch to update the documentation for MADV_HUGEPAGE.

>
> I still don't understand your one comment:
>
> "It's worth noting that if read_ahead_kb is set to a larger value that
> isn't aligned with huge page sizes (e.g., 4MB + 128KB), it may still
> fail to map to hugepages."
>
> Do you mean that MADV_HUGEPAGE+read_ahead_kb<=4M will give you 2M pages,
> but MADV_HUGEPAGE+read_ahead_kb>4M won't? Or is this the case without
> MADV_HUGEPAGE?

Typically, users set read_ahead_kb to aligned sizes, such as 128KB,
256KB, 512KB, 1MB, 2MB, 4MB, or 8MB. With this patch, MADV_HUGEPAGE
functions well for all these settings. However, if read_ahead_kb is
set to a non-hugepage-aligned size (e.g., 4MB + 128KB), MADV_HUGEPAGE
won’t work. This is because the initial readahead size for
MADV_HUGEPAGE is set to 4MB, as established in commit 4687fdbb805a:

   ra->size = HPAGE_PMD_NR;
   if (!(vmf->vma->vm_flags & VM_RAND_READ))
       ra->size *= 2;

However, as Willy noted, non-aligned settings are quite stupid, so we
should disregard them.

>
> If MADV_HUGEPAGE ignores read_ahead_kb completely, it's easy to document.

Perhaps, but documenting the behavior of every unusual setting doesn’t
seem practical.

>
> >
> >>
> >> But that's just my opinion.
> >>
> >>>
> >>>>
> >>>> No changes to API, no confusing code.
> >>>
> >>> New features like large folios can often create confusion with
> >>> existing rules or APIs, correct?
> >>
> >> We should not try making it even more confusing, if possible.
> >
> > A quick tip for you: the readahead size already exceeds readahead_kb
> > even without MADV_HUGEPAGE. You might want to spend some time tracing
> > that behavior.
>
> Care to save me some time and point me at what you mean?

I reached this conclusion by tracing ra->size in each
page_cache_ra_order() call, but I’m not fully equipped to provide all
the details ;)

--
Regards

Yafang





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux