Re: [RFC PATCH 02/12] khugepaged: Generalize alloc_charge_folio()

Ryan Roberts
2024-12-17T07:09:50Z

On 17/12/2024 04:17, Matthew Wilcox wrote:
> On Mon, Dec 16, 2024 at 10:20:55PM +0530, Dev Jain wrote:
>> static int alloc_charge_folio(struct folio **foliop, struct mm_struct *mm,
>> - struct collapse_control *cc)
>> + int order, struct collapse_control *cc)
>
> unsigned, surely?

I'm obviously feeling argumentative this morning...

There are plenty of examples of order being signed and unsigned in the code
base... it's a mess. Certainly the mTHP changes up to now have opted for
(signed) int. And get_order(), which I would assume to the authority, returns
(signed) int.

Personally I prefer int for small positive integers; it's more compact. But if
we're trying to establish a pattern to use unsigned int for all new uses of
order, that fine too, let's just document it somewhere?

>
>> if (!folio) {
>> *foliop = NULL;
>> count_vm_event(THP_COLLAPSE_ALLOC_FAILED);
>> + if (order != HPAGE_PMD_ORDER)
>> + count_mthp_stat(order, MTHP_STAT_ANON_COLLAPSE_ALLOC_FAILED);
>
> i don't understand why we need new statistics here. we already have a
> signal that memory allocation failures are preventing collapse from
> being successful, why do we care if it's mthp or actual thp?

We previously decided that all existing THP stats would continue to only count
PMD-sized THP for fear of breaking userspace in subtle ways, and instead would
introduce new mTHP stats that can count for each order. We already have
MTHP_STAT_ANON_FAULT_ALLOC and MTHP_STAT_ANON_FAULT_FALLBACK (amongst others) so
these new stats fit the pattern well, IMHO.

(except for the bug that I called out in the other mail; we should call
count_mthp_stat() for all orders and call count_vm_event() only for PMD_ORDER).

>
>> count_vm_event(THP_COLLAPSE_ALLOC);
>> + if (order != HPAGE_PMD_ORDER)
>> + count_mthp_stat(order, MTHP_STAT_ANON_COLLAPSE_ALLOC);
>
> similar question
>