Skip to content

Commit 3c1c875

Browse files
author
Mike Snitzer
committed
dm bufio: conditionally enable branching for DM_BUFIO_CLIENT_NO_SLEEP
Use jump_label to limit the need for branching unless the optional DM_BUFIO_CLIENT_NO_SLEEP is used. Signed-off-by: Mike Snitzer <[email protected]>
1 parent df326e7 commit 3c1c875

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/md/dm-bufio.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/module.h>
1919
#include <linux/rbtree.h>
2020
#include <linux/stacktrace.h>
21+
#include <linux/jump_label.h>
2122

2223
#define DM_MSG_PREFIX "bufio"
2324

@@ -164,29 +165,31 @@ struct dm_buffer {
164165
#endif
165166
};
166167

168+
static DEFINE_STATIC_KEY_FALSE(no_sleep_enabled);
169+
167170
/*----------------------------------------------------------------*/
168171

169172
#define dm_bufio_in_request() (!!current->bio_list)
170173

171174
static void dm_bufio_lock(struct dm_bufio_client *c)
172175
{
173-
if (c->no_sleep)
176+
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
174177
spin_lock_irqsave_nested(&c->spinlock, c->spinlock_flags, dm_bufio_in_request());
175178
else
176179
mutex_lock_nested(&c->lock, dm_bufio_in_request());
177180
}
178181

179182
static int dm_bufio_trylock(struct dm_bufio_client *c)
180183
{
181-
if (c->no_sleep)
184+
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
182185
return spin_trylock_irqsave(&c->spinlock, c->spinlock_flags);
183186
else
184187
return mutex_trylock(&c->lock);
185188
}
186189

187190
static void dm_bufio_unlock(struct dm_bufio_client *c)
188191
{
189-
if (c->no_sleep)
192+
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
190193
spin_unlock_irqrestore(&c->spinlock, c->spinlock_flags);
191194
else
192195
mutex_unlock(&c->lock);
@@ -1760,8 +1763,10 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign
17601763
c->alloc_callback = alloc_callback;
17611764
c->write_callback = write_callback;
17621765

1763-
if (flags & DM_BUFIO_CLIENT_NO_SLEEP)
1766+
if (flags & DM_BUFIO_CLIENT_NO_SLEEP) {
17641767
c->no_sleep = true;
1768+
static_branch_inc(&no_sleep_enabled);
1769+
}
17651770

17661771
for (i = 0; i < LIST_SIZE; i++) {
17671772
INIT_LIST_HEAD(&c->lru[i]);
@@ -1895,6 +1900,8 @@ void dm_bufio_client_destroy(struct dm_bufio_client *c)
18951900
kmem_cache_destroy(c->slab_buffer);
18961901
dm_io_client_destroy(c->dm_io);
18971902
mutex_destroy(&c->lock);
1903+
if (c->no_sleep)
1904+
static_branch_dec(&no_sleep_enabled);
18981905
kfree(c);
18991906
}
19001907
EXPORT_SYMBOL_GPL(dm_bufio_client_destroy);

0 commit comments

Comments
 (0)