Skip to content

Commit 6f75723

Browse files
Mikulas Patockaaxboe
authored andcommitted
dm: remove the pending IO accounting
Remove the "pending" atomic counters, that duplicate block-core's in_flight counters, and update md_in_flight() to look at percpu in_flight counters. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e016b78 commit 6f75723

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

drivers/md/dm-core.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ struct mapped_device {
6565
*/
6666
struct work_struct work;
6767
wait_queue_head_t wait;
68-
atomic_t pending[2];
6968
spinlock_t deferred_lock;
7069
struct bio_list deferred;
7170

@@ -119,7 +118,6 @@ struct mapped_device {
119118
struct srcu_struct io_barrier;
120119
};
121120

122-
int md_in_flight(struct mapped_device *md);
123121
void disable_write_same(struct mapped_device *md);
124122
void disable_write_zeroes(struct mapped_device *md);
125123

drivers/md/dm.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -646,25 +646,30 @@ static void free_tio(struct dm_target_io *tio)
646646
bio_put(&tio->clone);
647647
}
648648

649-
int md_in_flight(struct mapped_device *md)
649+
static bool md_in_flight(struct mapped_device *md)
650650
{
651-
return atomic_read(&md->pending[READ]) +
652-
atomic_read(&md->pending[WRITE]);
651+
int cpu;
652+
struct hd_struct *part = &dm_disk(md)->part0;
653+
654+
for_each_possible_cpu(cpu) {
655+
if (part_stat_local_read_cpu(part, in_flight[0], cpu) ||
656+
part_stat_local_read_cpu(part, in_flight[1], cpu))
657+
return true;
658+
}
659+
660+
return false;
653661
}
654662

655663
static void start_io_acct(struct dm_io *io)
656664
{
657665
struct mapped_device *md = io->md;
658666
struct bio *bio = io->orig_bio;
659-
int rw = bio_data_dir(bio);
660667

661668
io->start_time = jiffies;
662669

663670
generic_start_io_acct(md->queue, bio_op(bio), bio_sectors(bio),
664671
&dm_disk(md)->part0);
665672

666-
atomic_inc(&md->pending[rw]);
667-
668673
if (unlikely(dm_stats_used(&md->stats)))
669674
dm_stats_account_io(&md->stats, bio_data_dir(bio),
670675
bio->bi_iter.bi_sector, bio_sectors(bio),
@@ -676,8 +681,6 @@ static void end_io_acct(struct dm_io *io)
676681
struct mapped_device *md = io->md;
677682
struct bio *bio = io->orig_bio;
678683
unsigned long duration = jiffies - io->start_time;
679-
int pending;
680-
int rw = bio_data_dir(bio);
681684

682685
generic_end_io_acct(md->queue, bio_op(bio), &dm_disk(md)->part0,
683686
io->start_time);
@@ -687,16 +690,11 @@ static void end_io_acct(struct dm_io *io)
687690
bio->bi_iter.bi_sector, bio_sectors(bio),
688691
true, duration, &io->stats_aux);
689692

690-
/*
691-
* After this is decremented the bio must not be touched if it is
692-
* a flush.
693-
*/
694-
pending = atomic_dec_return(&md->pending[rw]);
695-
pending += atomic_read(&md->pending[rw^0x1]);
696-
697693
/* nudge anyone waiting on suspend queue */
698-
if (!pending)
699-
wake_up(&md->wait);
694+
if (unlikely(waitqueue_active(&md->wait))) {
695+
if (!md_in_flight(md))
696+
wake_up(&md->wait);
697+
}
700698
}
701699

702700
/*
@@ -1915,8 +1913,6 @@ static struct mapped_device *alloc_dev(int minor)
19151913
if (!md->disk)
19161914
goto bad;
19171915

1918-
atomic_set(&md->pending[0], 0);
1919-
atomic_set(&md->pending[1], 0);
19201916
init_waitqueue_head(&md->wait);
19211917
INIT_WORK(&md->work, dm_wq_work);
19221918
init_waitqueue_head(&md->eventq);

0 commit comments

Comments
 (0)