Skip to content

Commit 20cf903

Browse files
committed
Merge tag 'for-6.0/dm-changes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull more device mapper updates from Mike Snitzer: - Add flags argument to dm_bufio_client_create and introduce DM_BUFIO_CLIENT_NO_SLEEP flag to have dm-bufio use spinlock rather than mutex for its locking. - Add optional "try_verify_in_tasklet" feature to DM verity target. This feature gives users the option to improve IO latency by using a tasklet to verify, using hashes in bufio's cache, rather than wait to schedule a work item via workqueue. But if there is a bufio cache miss, or an error, then the tasklet will fallback to using workqueue. - Incremental changes to both dm-bufio and the DM verity target to use jump_label to minimize cost of branching associated with the niche "try_verify_in_tasklet" feature. DM-bufio in particular is used by quite a few other DM targets so it doesn't make sense to incur additional bufio cost in those targets purely for the benefit of this niche verity feature if the feature isn't ever used. - Optimize verity_verify_io, which is used by both workqueue and tasklet based verification, if FEC is not configured or tasklet based verification isn't used. - Remove DM verity target's verify_wq's use of the WQ_CPU_INTENSIVE flag since it uses WQ_UNBOUND. Also, use the WQ_HIGHPRI flag if "try_verify_in_tasklet" is specified. * tag 'for-6.0/dm-changes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm verity: have verify_wq use WQ_HIGHPRI if "try_verify_in_tasklet" dm verity: remove WQ_CPU_INTENSIVE flag since using WQ_UNBOUND dm verity: only copy bvec_iter in verity_verify_io if in_tasklet dm verity: optimize verity_verify_io if FEC not configured dm verity: conditionally enable branching for "try_verify_in_tasklet" dm bufio: conditionally enable branching for DM_BUFIO_CLIENT_NO_SLEEP dm verity: allow optional args to alter primary args handling dm verity: Add optional "try_verify_in_tasklet" feature dm bufio: Add DM_BUFIO_CLIENT_NO_SLEEP flag dm bufio: Add flags argument to dm_bufio_client_create
2 parents c993e07 + 12907ef commit 20cf903

File tree

9 files changed

+187
-33
lines changed

9 files changed

+187
-33
lines changed

drivers/md/dm-bufio.c

Lines changed: 28 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

@@ -81,6 +82,8 @@
8182
*/
8283
struct dm_bufio_client {
8384
struct mutex lock;
85+
spinlock_t spinlock;
86+
unsigned long spinlock_flags;
8487

8588
struct list_head lru[LIST_SIZE];
8689
unsigned long n_buffers[LIST_SIZE];
@@ -90,6 +93,7 @@ struct dm_bufio_client {
9093
s8 sectors_per_block_bits;
9194
void (*alloc_callback)(struct dm_buffer *);
9295
void (*write_callback)(struct dm_buffer *);
96+
bool no_sleep;
9397

9498
struct kmem_cache *slab_buffer;
9599
struct kmem_cache *slab_cache;
@@ -161,23 +165,34 @@ struct dm_buffer {
161165
#endif
162166
};
163167

168+
static DEFINE_STATIC_KEY_FALSE(no_sleep_enabled);
169+
164170
/*----------------------------------------------------------------*/
165171

166172
#define dm_bufio_in_request() (!!current->bio_list)
167173

168174
static void dm_bufio_lock(struct dm_bufio_client *c)
169175
{
170-
mutex_lock_nested(&c->lock, dm_bufio_in_request());
176+
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
177+
spin_lock_irqsave_nested(&c->spinlock, c->spinlock_flags, dm_bufio_in_request());
178+
else
179+
mutex_lock_nested(&c->lock, dm_bufio_in_request());
171180
}
172181

173182
static int dm_bufio_trylock(struct dm_bufio_client *c)
174183
{
175-
return mutex_trylock(&c->lock);
184+
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
185+
return spin_trylock_irqsave(&c->spinlock, c->spinlock_flags);
186+
else
187+
return mutex_trylock(&c->lock);
176188
}
177189

178190
static void dm_bufio_unlock(struct dm_bufio_client *c)
179191
{
180-
mutex_unlock(&c->lock);
192+
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
193+
spin_unlock_irqrestore(&c->spinlock, c->spinlock_flags);
194+
else
195+
mutex_unlock(&c->lock);
181196
}
182197

183198
/*----------------------------------------------------------------*/
@@ -1715,7 +1730,8 @@ static unsigned long dm_bufio_shrink_count(struct shrinker *shrink, struct shrin
17151730
struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsigned block_size,
17161731
unsigned reserved_buffers, unsigned aux_size,
17171732
void (*alloc_callback)(struct dm_buffer *),
1718-
void (*write_callback)(struct dm_buffer *))
1733+
void (*write_callback)(struct dm_buffer *),
1734+
unsigned int flags)
17191735
{
17201736
int r;
17211737
struct dm_bufio_client *c;
@@ -1745,12 +1761,18 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign
17451761
c->alloc_callback = alloc_callback;
17461762
c->write_callback = write_callback;
17471763

1764+
if (flags & DM_BUFIO_CLIENT_NO_SLEEP) {
1765+
c->no_sleep = true;
1766+
static_branch_inc(&no_sleep_enabled);
1767+
}
1768+
17481769
for (i = 0; i < LIST_SIZE; i++) {
17491770
INIT_LIST_HEAD(&c->lru[i]);
17501771
c->n_buffers[i] = 0;
17511772
}
17521773

17531774
mutex_init(&c->lock);
1775+
spin_lock_init(&c->spinlock);
17541776
INIT_LIST_HEAD(&c->reserved_buffers);
17551777
c->need_reserved_buffers = reserved_buffers;
17561778

@@ -1877,6 +1899,8 @@ void dm_bufio_client_destroy(struct dm_bufio_client *c)
18771899
kmem_cache_destroy(c->slab_buffer);
18781900
dm_io_client_destroy(c->dm_io);
18791901
mutex_destroy(&c->lock);
1902+
if (c->no_sleep)
1903+
static_branch_dec(&no_sleep_enabled);
18801904
kfree(c);
18811905
}
18821906
EXPORT_SYMBOL_GPL(dm_bufio_client_destroy);

drivers/md/dm-ebs-target.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ static int ebs_ctr(struct dm_target *ti, unsigned int argc, char **argv)
313313
goto bad;
314314
}
315315

316-
ec->bufio = dm_bufio_client_create(ec->dev->bdev, to_bytes(ec->u_bs), 1, 0, NULL, NULL);
316+
ec->bufio = dm_bufio_client_create(ec->dev->bdev, to_bytes(ec->u_bs), 1,
317+
0, NULL, NULL, 0);
317318
if (IS_ERR(ec->bufio)) {
318319
ti->error = "Cannot create dm bufio client";
319320
r = PTR_ERR(ec->bufio);

drivers/md/dm-integrity.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4439,7 +4439,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
44394439
}
44404440

44414441
ic->bufio = dm_bufio_client_create(ic->meta_dev ? ic->meta_dev->bdev : ic->dev->bdev,
4442-
1U << (SECTOR_SHIFT + ic->log2_buffer_sectors), 1, 0, NULL, NULL);
4442+
1U << (SECTOR_SHIFT + ic->log2_buffer_sectors), 1, 0, NULL, NULL, 0);
44434443
if (IS_ERR(ic->bufio)) {
44444444
r = PTR_ERR(ic->bufio);
44454445
ti->error = "Cannot initialize dm-bufio";

drivers/md/dm-snap-persistent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ static int read_exceptions(struct pstore *ps,
493493

494494
client = dm_bufio_client_create(dm_snap_cow(ps->store->snap)->bdev,
495495
ps->store->chunk_size << SECTOR_SHIFT,
496-
1, 0, NULL, NULL);
496+
1, 0, NULL, NULL, 0);
497497

498498
if (IS_ERR(client))
499499
return PTR_ERR(client);

drivers/md/dm-verity-fec.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ int verity_fec_ctr(struct dm_verity *v)
749749

750750
f->bufio = dm_bufio_client_create(f->dev->bdev,
751751
f->io_size,
752-
1, 0, NULL, NULL);
752+
1, 0, NULL, NULL, 0);
753753
if (IS_ERR(f->bufio)) {
754754
ti->error = "Cannot initialize FEC bufio client";
755755
return PTR_ERR(f->bufio);
@@ -765,7 +765,7 @@ int verity_fec_ctr(struct dm_verity *v)
765765

766766
f->data_bufio = dm_bufio_client_create(v->data_dev->bdev,
767767
1 << v->data_dev_block_bits,
768-
1, 0, NULL, NULL);
768+
1, 0, NULL, NULL, 0);
769769
if (IS_ERR(f->data_bufio)) {
770770
ti->error = "Cannot initialize FEC data bufio client";
771771
return PTR_ERR(f->data_bufio);

0 commit comments

Comments
 (0)