mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joshua Hahn <joshua.hahnjy@gmail.com>
To: Wenchao Hao <haowenchao22@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Nhat Pham <nphamcs@gmail.com>, Yosry Ahmed <yosry@kernel.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Minchan Kim <minchan@kernel.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Xueyuan Chen <xueyuan.chen21@gmail.com>,
	Wenchao Hao <haowenchao@xiaomi.com>
Subject: Re: [RFC PATCH v2 3/3] mm/zsmalloc: drop class lock before freeing zspage
Date: Thu, 28 May 2026 16:59:57 -0700	[thread overview]
Message-ID: <20260529000000.652785-1-joshua.hahnjy@gmail.com> (raw)
In-Reply-To: <20260527115930.3138213-4-haowenchao@xiaomi.com>

On Wed, 27 May 2026 19:59:30 +0800 Wenchao Hao <haowenchao22@gmail.com> wrote:

> From: Xueyuan Chen <xueyuan.chen21@gmail.com>
> 
> Currently in zs_free(), the class->lock is held until the zspage is
> completely freed and the counters are updated. However, freeing pages
> back to the buddy allocator requires acquiring the zone lock.
> 
> Under heavy memory pressure, zone lock contention can be severe. When
> this happens, the CPU holding the class->lock will stall waiting for
> the zone lock, thereby blocking all other CPUs attempting to acquire
> the same class->lock.
> 
> This patch shrinks the critical section of the class->lock to reduce
> lock contention. By moving the actual page freeing process outside the
> class->lock, we can improve the concurrency performance of zs_free().

Hello Wenchao and Xueyuan,

Thank you for the patch. This is a really cool idea and I think it makes
a lot of sense. 

LGTM aside from a few nits, with those resolved please feel free to add
Reviewed-by: Joshua Hahn <joshua.hahnjy@gmail.com>

>  	fullness = fix_fullness_group(class, zspage);
> -	if (fullness == ZS_INUSE_RATIO_0)
> -		free_zspage(pool, class, zspage);
> +	if (fullness == ZS_INUSE_RATIO_0) {
> +		if (trylock_zspage(zspage)) {
> +			remove_zspage(class, zspage);
> +			class_stat_sub(class, ZS_OBJS_ALLOCATED,
> +				class->objs_per_zspage);
> +			zspage_to_free = zspage;
> +		} else
> +			kick_deferred_free(pool);

NIT: We should probably add opening and closing braces here as well since the
if() case is more than one line. 

> +	}
>  
>  	spin_unlock(&class->lock);

Sashiko caught this in [1] and I was confused why the likely() doesn't make
sense here, but I finally realized that zspage_to_free is likely to be set
when comparing trylock_zspage() success vs. failure, but it's unlikely to
enter the ZS_INUSE_RATIO_0 case to begin with, so an unlikely() seems
correct here. 

Thanks again. I hope you have a great day!
Joshua

> +	if (likely(zspage_to_free)) {
> +		__free_zspage_lockless(pool, zspage_to_free);
> +		atomic_long_sub(class->pages_per_zspage, &pool->pages_allocated);
> +	}
>  	cache_free_handle(handle);
>  }
>  EXPORT_SYMBOL_GPL(zs_free);

[1] https://sashiko.dev/#/patchset/20260527115930.3138213-1-haowenchao%40xiaomi.com

  reply	other threads:[~2026-05-29  0:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-27 11:59 [RFC PATCH v2 0/3] mm/zsmalloc: reduce lock contention in zs_free() Wenchao Hao
2026-05-27 11:59 ` [RFC PATCH v2 1/3] mm/zsmalloc: encode class index in obj value for lockless class lookup Wenchao Hao
2026-05-29 22:49   ` Nhat Pham
2026-05-31  2:00   ` Barry Song
2026-05-27 11:59 ` [RFC PATCH v2 2/3] mm/zsmalloc: drop pool->lock from zs_free on 64-bit systems Wenchao Hao
2026-05-29 22:51   ` Nhat Pham
2026-05-27 11:59 ` [RFC PATCH v2 3/3] mm/zsmalloc: drop class lock before freeing zspage Wenchao Hao
2026-05-28 23:59   ` Joshua Hahn [this message]
2026-05-29 22:59   ` Nhat Pham
2026-05-31 14:16     ` Xueyuan Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260529000000.652785-1-joshua.hahnjy@gmail.com \
    --to=joshua.hahnjy@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=haowenchao22@gmail.com \
    --cc=haowenchao@xiaomi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=nphamcs@gmail.com \
    --cc=senozhatsky@chromium.org \
    --cc=xueyuan.chen21@gmail.com \
    --cc=yosry@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®