On 05.08.25 15:28, Linus Torvalds wrote:
On Tue, 5 Aug 2025 at 16:20, David Hildenbrand <david@xxxxxxxxxx> wrote:
I think that would work, and we could limit the section check to the
problematic case only (sparsemem without VMEMMAP).
We really don't need to, because unlike the nth_page() thing, the
compiler can see the logic and see "it's always zero".
Yeah, realized that later.
And in the complex case (ie actual sparsemem without VMEMMAP), the
page_section() test is at least trivial, unlike the whole "turn it
into a pfn and back".
Because that "turn it into a pfn and back" is actually a really quite
complicated operation (and the compiler won't be able to optimize that
one much, so I'm pretty sure it generates horrific code).
Yes, that's why I hate folio_page_idx() so much on !VMEMMAP
#define folio_page_idx(folio, p) (page_to_pfn(p) - folio_pfn(folio))
I wish we didn't have nth_page() at all. I really don't think it's a
valid operation. It's been around forever, but I think it was broken
as introduced, exactly because I don't think you can validly even have
allocations that cross section boundaries.
Ordinary buddy allocations cannot exceed a memory section, but hugetlb and
dax can with gigantic folios ... :(
We had some weird bugs with that, because people keep forgetting that you
cannot just use page++ unconditionally with such folios.
Anyhow, thanks Linus!
--
Cheers,
David / dhildenb