RCU Archive on lore.kernel.org
 help / color / Atom feed
From: Kent Overstreet <kent.overstreet@gmail.com>
To: "Paul E. McKenney" <paulmck@kernel.org>, rcu@vger.kernel.org
Subject: SRCU question
Date: Thu, 12 Nov 2020 15:15:47 -0500
Message-ID: <20201112201547.GF3365678@moria.home.lan> (raw)

Hi to Paul & the rcu mailing list,

I've got a problem I'm trying to figure out if I can adapt SRCU for.

Within bcachefs, currently struct btree obects, and now also btree_cached_key,
aren't freed until the filesystem is torn down, because btree iterators contain
pointers to them and will drop and retake locks (iff a sequence number hasn't
changed) without holding a ref. With the btree key cache code, this is now
something I need to fix.

What I plan on doing is having struct btree_trans (container for btree
iterators) hold an srcu read lock while it's alive. But, I don't want to just
use call_srcu to free the btree/btree_cached_key objects, because btree trans
objects can at times be fairly long lived and the existing code can reuse these
objects for other btree nodes/btree cached keys immediately. Freeing them with
call_srcu() would break that; I could have my callback function check if the
object has been reused before freeing, but I'd still have a problem when the
object gets freed a second time before the first call_scru() has finished.

What I'm wondering is if the SRCU code has a well defined notion of a clock that
I could make use of. What I would like to do is, instead of doing call_srcu() to
free the object - just mark that object with the current SRCU context time, and
then when my shrinkers run they can free objects that haven't been reused and
are old enough according the the current SRCU time.

Thoughts?

             reply index

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-12 20:15 Kent Overstreet [this message]
2020-11-15 20:11 ` Paul E. McKenney
2020-11-15 20:20   ` Paul E. McKenney
2020-11-15 20:35     ` Kent Overstreet
2020-11-15 20:53       ` Paul E. McKenney
2020-11-16  1:25         ` Kent Overstreet
2020-11-16  4:14           ` Paul E. McKenney

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=20201112201547.GF3365678@moria.home.lan \
    --to=kent.overstreet@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=rcu@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

RCU Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/rcu/0 rcu/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 rcu rcu/ https://lore.kernel.org/rcu \
		rcu@vger.kernel.org
	public-inbox-index rcu

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.rcu


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git