public inbox for dm-devel@redhat.com
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: dm-devel@lists.linux.dev, Alasdair Kergon <agk@redhat.com>,
	Mike Snitzer <snitzer@kernel.org>,
	Mikulas Patocka <mpatocka@redhat.com>,
	Benjamin Marzinski <bmarzins@redhat.com>
Cc: Sami Tolvanen <samitolvanen@google.com>,
	linux-kernel@vger.kernel.org, Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH 1/2] dm-bufio: merge cache_put() into cache_put_and_wake()
Date: Sun, 11 Jan 2026 13:38:20 -0800	[thread overview]
Message-ID: <20260111213821.94895-2-ebiggers@kernel.org> (raw)
In-Reply-To: <20260111213821.94895-1-ebiggers@kernel.org>

Merge cache_put() into its only caller, cache_put_and_wake().

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 drivers/md/dm-bufio.c | 32 ++++++++++----------------------
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index 5235f3e4924b..6e61982c9b92 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -367,12 +367,12 @@ struct dm_buffer {
  * It does *not* handle:
  *  - allocation/freeing of buffers.
  *  - IO
  *  - Eviction or cache sizing.
  *
- * cache_get() and cache_put() are threadsafe, you do not need to
- * protect these calls with a surrounding mutex.  All the other
+ * cache_get() and cache_put_and_wake() are threadsafe, you do not need
+ * to protect these calls with a surrounding mutex.  All the other
  * methods are not threadsafe; they do use locking primitives, but
  * only enough to ensure get/put are threadsafe.
  */
 
 struct buffer_tree {
@@ -617,28 +617,10 @@ static struct dm_buffer *cache_get(struct dm_buffer_cache *bc, sector_t block)
 	return b;
 }
 
 /*--------------*/
 
-/*
- * Returns true if the hold count hits zero.
- * threadsafe
- */
-static bool cache_put(struct dm_buffer_cache *bc, struct dm_buffer *b)
-{
-	bool r;
-
-	cache_read_lock(bc, b->block);
-	BUG_ON(!atomic_read(&b->hold_count));
-	r = atomic_dec_and_test(&b->hold_count);
-	cache_read_unlock(bc, b->block);
-
-	return r;
-}
-
-/*--------------*/
-
 typedef enum evict_result (*b_predicate)(struct dm_buffer *, void *);
 
 /*
  * Evicts a buffer based on a predicate.  The oldest buffer that
  * matches the predicate will be selected.  In addition to the
@@ -1743,16 +1725,22 @@ static void __check_watermark(struct dm_bufio_client *c,
  *--------------------------------------------------------------
  */
 
 static void cache_put_and_wake(struct dm_bufio_client *c, struct dm_buffer *b)
 {
+	bool wake;
+
+	cache_read_lock(&c->cache, b->block);
+	BUG_ON(!atomic_read(&b->hold_count));
+	wake = atomic_dec_and_test(&b->hold_count);
+	cache_read_unlock(&c->cache, b->block);
+
 	/*
 	 * Relying on waitqueue_active() is racey, but we sleep
 	 * with schedule_timeout anyway.
 	 */
-	if (cache_put(&c->cache, b) &&
-	    unlikely(waitqueue_active(&c->free_buffer_wait)))
+	if (wake && unlikely(waitqueue_active(&c->free_buffer_wait)))
 		wake_up(&c->free_buffer_wait);
 }
 
 /*
  * This assumes you have already checked the cache to see if the buffer
-- 
2.52.0


  reply	other threads:[~2026-01-11 21:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-11 21:38 [PATCH 0/2] Optimize dm-bufio cache lookups Eric Biggers
2026-01-11 21:38 ` Eric Biggers [this message]
2026-01-11 21:38 ` [PATCH 2/2] dm-bufio: avoid redundant buffer_tree lookups Eric Biggers
2026-01-19 14:45 ` [PATCH 0/2] Optimize dm-bufio cache lookups Mikulas Patocka

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=20260111213821.94895-2-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=agk@redhat.com \
    --cc=bmarzins@redhat.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=samitolvanen@google.com \
    --cc=snitzer@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