On Thu, Nov 10, 2022 at 8:31 AM Matthew Wilcox <willy@xxxxxxxxxxxxx> wrote: > > Ah. I've been trying to understand what that 'compound' really means, > and what the difference is to 'PageCompound()' and why we need both. Yeah, so the 'why' is: (a) to distinguish the case of "I'm mapping the first sub-page of a compound page as a _single_ page page entry in the pte" from "I'm mapping the whole compound/THP/HUGETLB page as a pmd" The actual 'page' pointer can be the same in both cases, so you can't tell from that: PageCompound() will be true in both cases. Of course, sometimes you *can* tell from the page pointer too (eg the HUGETLB case can never be mapped as a small page), but not always. (b) because we do completely different things from a page locking and statistics standpoint for the two cases. That (b) is obviously related to (a), but it's effectively the main reason why rmap needs to be able to tell the difference in the first place. > HugeTLB pages _are_ marked as Compound. Oh, ok. It's not clear why they would be, and historically I don't think they were, but I guess it's for random implementation details (probably to look up the head page logic). > There's some fairly horrific > code to manually make them compound when they have to be allocated > piecemeal (because they're 1GB and too large for the page allocator). Yeah, the HUGETLB case is a mess these days, but it made sense historically, because it was a much simpler thing than the THP pages that have all the fragmentation cases. Now that we handle pmd-sized pages anyway, the HUGETLB case is mostly just a nasty oddity, but we obviously also do the pud case with HUGETLB. And who knows what ia64 did with its completely random page-size thing. I don't even want to think about it, and thankfully these days I don't feel like I need to care any more ;) > > To make things more confusing, some places use PageHeadHuge() > > instead (but the folio version of said test is called > > "folio_test_hugetlb()", just so that nobody could possibly ever accuse > > the HUGETLB code to have consistency). > > That one's my fault, but it's a reaction to all the times that I and > others have got confused between PageHuge and PageTransHuge. I suppose > we could do a big sed s/PageHuge/PageHugeTLB/, but I'm hopeful the > entire hugetlb codebase is either converted to folios or unified with > THP handling. Yeah, it would be lovely to make HUGETLB some THP special case some day. Linus