From: Valentin Schneider <vschneid@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
Matthew Wilcox <willy@infradead.org>,
Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>,
Frederic Weisbecker <frederic@kernel.org>,
Leonardo Bras <leobras@redhat.com>,
Yair Podemsky <ypodemsk@redhat.com>, P J P <ppandit@redhat.com>
Subject: Re: [PATCH v4] fs/buffer.c: update per-CPU bh_lru cache via RCU
Date: Mon, 22 May 2023 16:18:39 +0100 [thread overview]
Message-ID: <xhsmha5xwqtrk.mognet@vschneid.remote.csb> (raw)
In-Reply-To: <ZCXipBvmhAC1+eRi@tpad>
On 30/03/23 16:27, Marcelo Tosatti wrote:
> +/*
> + * invalidate_bh_lrus() is called rarely - but not only at unmount.
> + */
> void invalidate_bh_lrus(void)
> {
> - on_each_cpu_cond(has_bh_in_lru, invalidate_bh_lru, NULL, 1);
> + int cpu, oidx;
> +
> + mutex_lock(&bh_lru_invalidate_mutex);
> + cpus_read_lock();
> + oidx = bh_lru_idx;
> + bh_lru_idx++;
> + if (bh_lru_idx >= 2)
> + bh_lru_idx = 0;
> +
You could make this a bool and flip it:
bh_lru_idx = !bh_lru_idx
> + /* Assign the per-CPU bh_lru pointer */
> + for_each_online_cpu(cpu)
> + rcu_assign_pointer(per_cpu(bh_lrup, cpu),
> + per_cpu_ptr(&bh_lrus[bh_lru_idx], cpu));
> + synchronize_rcu_expedited();
> +
> + for_each_online_cpu(cpu) {
> + struct bh_lru *b = per_cpu_ptr(&bh_lrus[oidx], cpu);
> +
> + bh_lru_lock();
> + __invalidate_bh_lrus(b);
> + bh_lru_unlock();
Given the bh_lrup has been updated and we're past the synchronize_rcu(),
what is bh_lru_lock() used for here?
> + }
> + cpus_read_unlock();
> + mutex_unlock(&bh_lru_invalidate_mutex);
Re scalability, this is shifting a set of per-CPU-IPI callbacks to a single
CPU, which isn't great. Can we consider doing something like [1], i.e. in
the general case send an IPI to:
rcu_assign_pointer() + call_rcu(/* invalidation callback */)
and in the case we're NOHZ_FULL and the target CPU is not executing in the
kernel, we do that remotely to reduce interference. We might want to batch
the synchronize_rcu() for the remote invalidates, maybe some abuse of the
API like so?
bool do_local_invalidate(int cpu, struct cpumask *mask)
{
if (cpu_in_kernel(cpu)) {
__cpumask_clear_cpu(cpu, mask);
return true;
}
return false;
}
void invalidate_bh_lrus(void)
{
cpumask_var_t cpumask;
cpus_read_lock();
cpumask_copy(&cpumask, cpu_online_mask);
on_each_cpu_cond(do_local_invalidate, invalidate_bh_lru, &cpumask, 1);
for_each_cpu(cpu, &cpumask)
rcu_assign_pointer(per_cpu(bh_lrup, cpu),
per_cpu_ptr(&bh_lrus[bh_lru_idx], cpu));
synchronize_rcu_expedited();
for_each_cpu(cpu, &cpumask) {
// Do remote invalidate here
}
}
[1]: https://lore.kernel.org/lkml/20230404134224.137038-4-ypodemsk@redhat.com/
> }
> EXPORT_SYMBOL_GPL(invalidate_bh_lrus);
>
> @@ -1465,8 +1505,10 @@ void invalidate_bh_lrus_cpu(void)
> struct bh_lru *b;
>
> bh_lru_lock();
> - b = this_cpu_ptr(&bh_lrus);
> + rcu_read_lock();
> + b = rcu_dereference(per_cpu(bh_lrup, smp_processor_id()));
> __invalidate_bh_lrus(b);
> + rcu_read_unlock();
> bh_lru_unlock();
> }
>
> @@ -2968,15 +3010,25 @@ void free_buffer_head(struct buffer_head *bh)
> }
> EXPORT_SYMBOL(free_buffer_head);
>
> +static int buffer_cpu_online(unsigned int cpu)
> +{
> + rcu_assign_pointer(per_cpu(bh_lrup, cpu),
> + per_cpu_ptr(&bh_lrus[bh_lru_idx], cpu));
> + return 0;
> +}
What serializes this against invalidate_bh_lrus()? Are you relying on this
running under cpus_write_lock()?
prev parent reply other threads:[~2023-05-22 15:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-30 19:27 [PATCH v4] fs/buffer.c: update per-CPU bh_lru cache via RCU Marcelo Tosatti
2023-05-03 13:52 ` Marcelo Tosatti
2023-05-22 15:18 ` Valentin Schneider [this message]
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=xhsmha5xwqtrk.mognet@vschneid.remote.csb \
--to=vschneid@redhat.com \
--cc=axboe@kernel.dk \
--cc=frederic@kernel.org \
--cc=hch@lst.de \
--cc=leobras@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=ppandit@redhat.com \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
--cc=ypodemsk@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).