Skip to content

Commit 563a225

Browse files
author
Mike Snitzer
committed
dm: introduce dm_{get,put}_live_table_bio called from dm_submit_bio
If a bio is marked REQ_NOWAIT optimize dm_submit_bio()'s dm_table RCU usage to dm_{get,put}_live_table_fast. DM core offers protection against blocking (via suspend) if REQ_NOWAIT. Signed-off-by: Mike Snitzer <[email protected]>
1 parent 982b48a commit 563a225

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

drivers/md/dm.c

+24-4
Original file line numberDiff line numberDiff line change
@@ -661,14 +661,16 @@ static void queue_io(struct mapped_device *md, struct bio *bio)
661661
* function to access the md->map field, and make sure they call
662662
* dm_put_live_table() when finished.
663663
*/
664-
struct dm_table *dm_get_live_table(struct mapped_device *md, int *srcu_idx) __acquires(md->io_barrier)
664+
struct dm_table *dm_get_live_table(struct mapped_device *md,
665+
int *srcu_idx) __acquires(md->io_barrier)
665666
{
666667
*srcu_idx = srcu_read_lock(&md->io_barrier);
667668

668669
return srcu_dereference(md->map, &md->io_barrier);
669670
}
670671

671-
void dm_put_live_table(struct mapped_device *md, int srcu_idx) __releases(md->io_barrier)
672+
void dm_put_live_table(struct mapped_device *md,
673+
int srcu_idx) __releases(md->io_barrier)
672674
{
673675
srcu_read_unlock(&md->io_barrier, srcu_idx);
674676
}
@@ -694,6 +696,24 @@ static void dm_put_live_table_fast(struct mapped_device *md) __releases(RCU)
694696
rcu_read_unlock();
695697
}
696698

699+
static inline struct dm_table *dm_get_live_table_bio(struct mapped_device *md,
700+
int *srcu_idx, struct bio *bio)
701+
{
702+
if (bio->bi_opf & REQ_NOWAIT)
703+
return dm_get_live_table_fast(md);
704+
else
705+
return dm_get_live_table(md, srcu_idx);
706+
}
707+
708+
static inline void dm_put_live_table_bio(struct mapped_device *md, int srcu_idx,
709+
struct bio *bio)
710+
{
711+
if (bio->bi_opf & REQ_NOWAIT)
712+
dm_put_live_table_fast(md);
713+
else
714+
dm_put_live_table(md, srcu_idx);
715+
}
716+
697717
static char *_dm_claim_ptr = "I belong to device-mapper";
698718

699719
/*
@@ -1612,7 +1632,7 @@ static void dm_submit_bio(struct bio *bio)
16121632
int srcu_idx;
16131633
struct dm_table *map;
16141634

1615-
map = dm_get_live_table(md, &srcu_idx);
1635+
map = dm_get_live_table_bio(md, &srcu_idx, bio);
16161636

16171637
/* If suspended, or map not yet available, queue this IO for later */
16181638
if (unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags)) ||
@@ -1635,7 +1655,7 @@ static void dm_submit_bio(struct bio *bio)
16351655

16361656
dm_split_and_process_bio(md, map, bio);
16371657
out:
1638-
dm_put_live_table(md, srcu_idx);
1658+
dm_put_live_table_bio(md, srcu_idx, bio);
16391659
}
16401660

16411661
static bool dm_poll_dm_io(struct dm_io *io, struct io_comp_batch *iob,

0 commit comments

Comments
 (0)