Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Shakeel Butt <shakeel.butt@linux.dev>
To: Boris Burkov <boris@bur.io>
Cc: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: Re: [PATCH] btrfs: use lockless read in nr_cached_objects shrinker callback
Date: Fri, 29 May 2026 15:11:50 -0700	[thread overview]
Message-ID: <ahoPCcC_2RZROBcq@linux.dev> (raw)
In-Reply-To: <4c64ed769cbb827b8c55de8f89372fc27290feea.1780089816.git.boris@bur.io>

On Fri, May 29, 2026 at 02:23:46PM -0700, Boris Burkov wrote:
> From: Ben Maurer <bmaurer@meta.com>
> 
> Under heavy memcg-driven slab reclaim with many memcgs and CPUs,
> shrink_slab_memcg() invokes the per-superblock count callback once
> per (memcg, NUMA node) tuple. For btrfs that callback reaches
> percpu_counter_sum_positive() on fs_info->evictable_extent_maps,
> which takes the percpu_counter's raw spinlock with IRQs disabled and
> walks every online CPU. With hundreds of memcgs driving reclaim on a
> host with dozens of CPUs, this counter lock becomes a global
> serialization point: profiles show CPU pinned in the spin_lock_irqsave
> acquire under __percpu_counter_sum, with cross-CPU IPIs hitting
> csd_lock_wait_toolong while waiting for spinning vCPUs.
> 
> The shrinker count is advisory -- super_cache_count() already notes
> "counts can change between super_cache_count and super_cache_scan, so
> we really don't need locks here." Use percpu_counter_read_positive(),
> which is lockless. Worst-case skew is bounded by batch * num_online_cpus
> (a few thousand), negligible compared to the millions of extent maps a
> busy filesystem accumulates and well within the noise that the shrinker
> already tolerates.
> 
> Tested-by: Boris Burkov <boris@bur.io>
> Signed-off-by: Ben Maurer <bmaurer@meta.com>

Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>

  reply	other threads:[~2026-05-29 22:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-29 21:23 [PATCH] btrfs: use lockless read in nr_cached_objects shrinker callback Boris Burkov
2026-05-29 22:11 ` Shakeel Butt [this message]
2026-05-29 22:23 ` Qu Wenruo

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=ahoPCcC_2RZROBcq@linux.dev \
    --to=shakeel.butt@linux.dev \
    --cc=boris@bur.io \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.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