Re: [RFC PATCH] mm: Avoiding split large folios if swap has no space

From: Barry Song

Date: Tue Jul 07 2026 - 08:47:51 EST


On Fri, Jun 26, 2026 at 6:02 PM Johannes Weiner <hannes@xxxxxxxxxxx> wrote:
>
> On Fri, Jun 26, 2026 at 02:15:58PM +0800, Barry Song wrote:
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -5578,7 +5578,7 @@ int __init mem_cgroup_init(void)
> > *
> > * Returns 0 on success, -ENOMEM on failure.
> > */
> > -int __mem_cgroup_try_charge_swap(struct folio *folio)
> > +int __mem_cgroup_try_charge_swap(struct folio *folio, long *left_space)
> > {
> > unsigned int nr_pages = folio_nr_pages(folio);
> > struct swap_cluster_info *ci;
> > @@ -5611,6 +5611,10 @@ int __mem_cgroup_try_charge_swap(struct folio *folio)
> > memcg_memory_event(memcg, MEMCG_SWAP_MAX);
> > memcg_memory_event(memcg, MEMCG_SWAP_FAIL);
> > mem_cgroup_private_id_put(memcg, nr_pages);
> > + if (folio_test_large(folio))
> > + *left_space = mem_cgroup_get_nr_swap_pages(memcg);
>
> It's a bit awkward to walk up the whole hierarchy again when we
> already have the counter that failed. Please do something like this
> (not tested!), then use page_counter_margin() against @counter:

Thanks very much for your suggestion, Johannes! Sorry for the late
reply. I've been quite busy recently, so I asked Xueyuan Chen (Cc'ed)
to help send RFC v2, which will include your suggestion.

Best Regards
Barry