Skip to content

Commit 82f6cdc

Browse files
author
Mike Snitzer
committed
dm: switch dm_io booleans over to proper flags
Add flags to dm_io and manage them using the same pattern used for bi_flags in struct bio. Signed-off-by: Mike Snitzer <[email protected]>
1 parent e956733 commit 82f6cdc

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

drivers/md/dm-core.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,36 @@ struct dm_io {
232232
struct mapped_device *md;
233233
struct bio *orig_bio;
234234
blk_status_t status;
235-
bool start_io_acct:1;
236-
int was_accounted;
235+
unsigned short flags;
237236
unsigned long start_time;
238237
void *data;
239238
struct hlist_node node;
240239
struct task_struct *map_task;
240+
spinlock_t startio_lock;
241241
spinlock_t endio_lock;
242242
struct dm_stats_aux stats_aux;
243243
/* last member of dm_target_io is 'struct bio' */
244244
struct dm_target_io tio;
245245
};
246246

247+
/*
248+
* dm_io flags
249+
*/
250+
enum {
251+
DM_IO_START_ACCT,
252+
DM_IO_ACCOUNTED
253+
};
254+
255+
static inline bool dm_io_flagged(struct dm_io *io, unsigned int bit)
256+
{
257+
return (io->flags & (1U << bit)) != 0;
258+
}
259+
260+
static inline void dm_io_set_flag(struct dm_io *io, unsigned int bit)
261+
{
262+
io->flags |= (1U << bit);
263+
}
264+
247265
static inline void dm_io_inc_pending(struct dm_io *io)
248266
{
249267
atomic_inc(&io->io_count);

drivers/md/dm.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -541,11 +541,18 @@ static void dm_start_io_acct(struct dm_io *io, struct bio *clone)
541541
* Expect no possibility for race unless is_duplicate_bio.
542542
*/
543543
if (!clone || likely(!clone_to_tio(clone)->is_duplicate_bio)) {
544-
if (WARN_ON_ONCE(io->was_accounted))
544+
if (WARN_ON_ONCE(dm_io_flagged(io, DM_IO_ACCOUNTED)))
545545
return;
546-
io->was_accounted = 1;
547-
} else if (xchg(&io->was_accounted, 1) == 1)
548-
return;
546+
dm_io_set_flag(io, DM_IO_ACCOUNTED);
547+
} else {
548+
unsigned long flags;
549+
if (dm_io_flagged(io, DM_IO_ACCOUNTED))
550+
return;
551+
/* Can afford locking given is_duplicate_bio */
552+
spin_lock_irqsave(&io->startio_lock, flags);
553+
dm_io_set_flag(io, DM_IO_ACCOUNTED);
554+
spin_unlock_irqrestore(&io->startio_lock, flags);
555+
}
549556

550557
__dm_start_io_acct(io, bio);
551558
}
@@ -575,11 +582,10 @@ static struct dm_io *alloc_io(struct mapped_device *md, struct bio *bio)
575582
io->orig_bio = NULL;
576583
io->md = md;
577584
io->map_task = current;
585+
spin_lock_init(&io->startio_lock);
578586
spin_lock_init(&io->endio_lock);
579-
580587
io->start_time = jiffies;
581-
io->start_io_acct = false;
582-
io->was_accounted = 0;
588+
io->flags = 0;
583589

584590
dm_stats_record_start(&md->stats, &io->stats_aux);
585591

@@ -868,7 +874,7 @@ static void dm_io_complete(struct dm_io *io)
868874
}
869875

870876
io_error = io->status;
871-
if (io->was_accounted)
877+
if (dm_io_flagged(io, DM_IO_ACCOUNTED))
872878
dm_end_io_acct(io, bio);
873879
else if (!io_error) {
874880
/*
@@ -1218,7 +1224,7 @@ void dm_submit_bio_remap(struct bio *clone, struct bio *tgt_clone)
12181224
*/
12191225
if (io->map_task == current) {
12201226
/* Still in target's map function */
1221-
io->start_io_acct = true;
1227+
dm_io_set_flag(io, DM_IO_START_ACCT);
12221228
} else {
12231229
/*
12241230
* Called by another thread, managed by DM target,
@@ -1288,7 +1294,7 @@ static void __map_bio(struct bio *clone)
12881294
case DM_MAPIO_SUBMITTED:
12891295
/* target has assumed ownership of this io */
12901296
if (!ti->accounts_remapped_io)
1291-
io->start_io_acct = true;
1297+
dm_io_set_flag(io, DM_IO_START_ACCT);
12921298
break;
12931299
case DM_MAPIO_REMAPPED:
12941300
/*
@@ -1297,7 +1303,7 @@ static void __map_bio(struct bio *clone)
12971303
*/
12981304
__dm_submit_bio_remap(clone, disk_devt(io->md->disk),
12991305
tio->old_sector);
1300-
io->start_io_acct = true;
1306+
dm_io_set_flag(io, DM_IO_START_ACCT);
13011307
break;
13021308
case DM_MAPIO_KILL:
13031309
case DM_MAPIO_REQUEUE:
@@ -1591,7 +1597,7 @@ static void dm_split_and_process_bio(struct mapped_device *md,
15911597
if (!orig_bio)
15921598
orig_bio = bio;
15931599
smp_store_release(&ci.io->orig_bio, orig_bio);
1594-
if (ci.io->start_io_acct)
1600+
if (dm_io_flagged(ci.io, DM_IO_START_ACCT))
15951601
dm_start_io_acct(ci.io, NULL);
15961602

15971603
/*

0 commit comments

Comments
 (0)