Re: [RFC PATCH] mm: Avoiding split large folios if swap has no space
From: David Hildenbrand (Arm)
Date: Thu Jun 25 2026 - 03:52:31 EST
>>
>> But now I wonder whether we would also want to check "is there any free swap
>> space", not just "is there any swap".
>
> I don't quite understand you. get_nr_swap_pages() returns
> nr_swap_pages, which increases or decreases as swap is allocated or
> freed. I guess it just reflects how many swaps we currently have
> available?
Indeed, I was confused by the function name it's "free swap pages". So all goof :)
>
>>
>>
>> Essentially, try returning -E2BIG if there is the chance to swap out after
>> split, and -ENOSPC / -ENOMEM if a split wouldn't help.
>>
>>> }
>>>
>>> again:
>>> @@ -1769,11 +1772,13 @@ int folio_alloc_swap(struct folio *folio)
>>> }
>>>
>>> /* Need to call this even if allocation failed, for MEMCG_SWAP_FAIL. */
>>> - if (unlikely(mem_cgroup_try_charge_swap(folio)))
>>> + if (unlikely(mem_cgroup_try_charge_swap(folio))) {
>>> swap_cache_del_folio(folio);
>>> + return -ENOMEM;
>>
>> Here we wouldn't have the information whether we could charge after a split.
>>
>> So that would require a rework to signal this more cleanly to the caller.
>
> Yep. The tricky part is that mem_cgroup_try_charge_swap() cannot
> return how much swap quota is available in the memcg. Do you prefer to
> add an output argument to mem_cgroup_try_charge_swap() to expose
> that
That would probably be cleanest, if that is easily possible. We would want to
get memcg maintainer feedback on that.
@memcg folks: we'd like to know whether splitting a large folio would make
mem_cgroup_try_charge_swap() succeed on a split (smaller) part, to distinguish
"there is no way we can swap out anything, don't split" vs. "we could swap out,
split".
What's the best way to obtain that information?
--
Cheers,
David