Skip to content

Commit 1bf7ba4

Browse files
Eric BiggersMikulas Patocka
authored andcommitted
dm-bufio: merge cache_put() into cache_put_and_wake()
Merge cache_put() into its only caller, cache_put_and_wake(). Signed-off-by: Eric Biggers <ebiggers@kernel.org> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
1 parent f93bc86 commit 1bf7ba4

1 file changed

Lines changed: 10 additions & 22 deletions

File tree

drivers/md/dm-bufio.c

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ struct dm_buffer {
369369
* - IO
370370
* - Eviction or cache sizing.
371371
*
372-
* cache_get() and cache_put() are threadsafe, you do not need to
373-
* protect these calls with a surrounding mutex. All the other
372+
* cache_get() and cache_put_and_wake() are threadsafe, you do not need
373+
* to protect these calls with a surrounding mutex. All the other
374374
* methods are not threadsafe; they do use locking primitives, but
375375
* only enough to ensure get/put are threadsafe.
376376
*/
@@ -619,24 +619,6 @@ static struct dm_buffer *cache_get(struct dm_buffer_cache *bc, sector_t block)
619619

620620
/*--------------*/
621621

622-
/*
623-
* Returns true if the hold count hits zero.
624-
* threadsafe
625-
*/
626-
static bool cache_put(struct dm_buffer_cache *bc, struct dm_buffer *b)
627-
{
628-
bool r;
629-
630-
cache_read_lock(bc, b->block);
631-
BUG_ON(!atomic_read(&b->hold_count));
632-
r = atomic_dec_and_test(&b->hold_count);
633-
cache_read_unlock(bc, b->block);
634-
635-
return r;
636-
}
637-
638-
/*--------------*/
639-
640622
typedef enum evict_result (*b_predicate)(struct dm_buffer *, void *);
641623

642624
/*
@@ -1745,12 +1727,18 @@ static void __check_watermark(struct dm_bufio_client *c,
17451727

17461728
static void cache_put_and_wake(struct dm_bufio_client *c, struct dm_buffer *b)
17471729
{
1730+
bool wake;
1731+
1732+
cache_read_lock(&c->cache, b->block);
1733+
BUG_ON(!atomic_read(&b->hold_count));
1734+
wake = atomic_dec_and_test(&b->hold_count);
1735+
cache_read_unlock(&c->cache, b->block);
1736+
17481737
/*
17491738
* Relying on waitqueue_active() is racey, but we sleep
17501739
* with schedule_timeout anyway.
17511740
*/
1752-
if (cache_put(&c->cache, b) &&
1753-
unlikely(waitqueue_active(&c->free_buffer_wait)))
1741+
if (wake && unlikely(waitqueue_active(&c->free_buffer_wait)))
17541742
wake_up(&c->free_buffer_wait);
17551743
}
17561744

0 commit comments

Comments
 (0)