Re: [PATCH v2 1/2] zsmalloc: free a zspage's pages in one batch

From: Nhat Pham

Date: Tue Nov 24 2026 - 18:16:51 EST


On Sun, Nov 22, 2026 at 10:36 PM Sergey Senozhatsky
<senozhatsky@xxxxxxxxxxxx> wrote:
>
> __free_frozen_pages() and dec_zone_page_state() take about 22% of the
> profile [1].
>
> Collect the pages of a multi-page zspage in a folio_batch and free
> them with folios_put(), which takes the pcp lock once per run of
> same-zone pages, and update NR_ZSPAGES once per such run as well
> A zspage never has more pages than a folio_batch holds.
>
> Single-page zspages, incompressible or power of 2 size classes, use
> the current inline path. There is nothing to batch there, and
> folio_batch is not free, hence the batch path lives in its own
> noinline function.
>
> munmap() test:
> next-20261119 v7.4-rc3
> 256 MiB -2.0% .. -4.1% -4.4%
> 1 GiB -2.8% .. -4.4% -3.8%
>
> [1] https://lore.kernel.org/20261109105957.2577351-1-chenhongfeng0212@xxxxxxxxx
>
> Reported-by: Hongfeng Chen <hongfengchen@xxxxxxxxxx>
> Signed-off-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>

That's nice!

Reviewed-by: Nhat Pham <nphamcs@xxxxxxxxx>

[...]

> ---
> + zpdesc = get_first_zpdesc(zspage);
> + if (get_next_zpdesc(zpdesc)) {
> + free_page_chain(zpdesc);
> + } else {
> + /* Single-page zspage, e.g. a huge object: nothing to batch */

I wonder if it's worth keeping the old logic for incompressible case.

> VM_BUG_ON_PAGE(!zpdesc_is_locked(zpdesc), zpdesc_page(zpdesc));
> - next = get_next_zpdesc(zpdesc);
> reset_zpdesc(zpdesc);
> zpdesc_unlock(zpdesc);
> zpdesc_dec_zone_page_state(zpdesc);
> zpdesc_put(zpdesc);
> - zpdesc = next;
> - } while (zpdesc != NULL);
> + }