All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] block: improve iostat for md/bcache partitions
@ 2020-08-31 22:27 Song Liu
  2020-08-31 22:27 ` [PATCH v3 1/3] block: introduce part_[begin|end]_io_acct Song Liu
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Song Liu @ 2020-08-31 22:27 UTC (permalink / raw)
  To: linux-block, linux-raid, linux-bcache
  Cc: colyli, axboe, kernel-team, song, hch, Song Liu

Currently, devices like md, bcache uses disk_[start|end]_io_acct to report
iostat. These functions couldn't get proper iostat for partitions on these
devices.

This set resolves this issue by introducing part_[begin|end]_io_acct, and
using them in md and bcache code.

Changes v2 => v3:
1. Use EXPORT_SYMBOL_GPL() instead of EXPORT_SYMBOL().
2. Include Christoph's Reviewed-by tag.

Changes v1 => v2:
1. Refactor the code, as suggested by Christoph.
2. Include Coly's Reviewed-by tag.

Song Liu (3):
  block: introduce part_[begin|end]_io_acct
  md: use part_[begin|end]_io_acct instead of disk_[begin|end]_io_acct
  bcache: use part_[begin|end]_io_acct instead of
    disk_[begin|end]_io_acct

 block/blk-core.c            | 39 +++++++++++++++++++++++++++++++------
 drivers/md/bcache/request.c | 10 ++++++----
 drivers/md/md.c             |  8 ++++----
 include/linux/blkdev.h      |  5 +++++
 4 files changed, 48 insertions(+), 14 deletions(-)

--
2.24.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/3] block: introduce part_[begin|end]_io_acct
  2020-08-31 22:27 [PATCH v3 0/3] block: improve iostat for md/bcache partitions Song Liu
@ 2020-08-31 22:27 ` Song Liu
  2020-08-31 22:27 ` [PATCH v3 2/3] md: use part_[begin|end]_io_acct instead of disk_[begin|end]_io_acct Song Liu
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Song Liu @ 2020-08-31 22:27 UTC (permalink / raw)
  To: linux-block, linux-raid, linux-bcache
  Cc: colyli, axboe, kernel-team, song, hch, Song Liu, Christoph Hellwig

These functions can be used to enable iostat for partitions on devices
like md, bcache.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Song Liu <songliubraving@fb.com>
---
 block/blk-core.c       | 39 +++++++++++++++++++++++++++++++++------
 include/linux/blkdev.h |  5 +++++
 2 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index d9d632639bd18..abddf8d029b8d 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1460,10 +1460,9 @@ void blk_account_io_start(struct request *rq)
 	part_stat_unlock();
 }
 
-unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
-		unsigned int op)
+static unsigned long __part_start_io_acct(struct hd_struct *part,
+					  unsigned int sectors, unsigned int op)
 {
-	struct hd_struct *part = &disk->part0;
 	const int sgrp = op_stat_group(op);
 	unsigned long now = READ_ONCE(jiffies);
 
@@ -1476,12 +1475,26 @@ unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
 
 	return now;
 }
+
+unsigned long part_start_io_acct(struct gendisk *disk, struct hd_struct **part,
+				 struct bio *bio)
+{
+	*part = disk_map_sector_rcu(disk, bio->bi_iter.bi_sector);
+
+	return __part_start_io_acct(*part, bio_sectors(bio), bio_op(bio));
+}
+EXPORT_SYMBOL_GPL(part_start_io_acct);
+
+unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
+				 unsigned int op)
+{
+	return __part_start_io_acct(&disk->part0, sectors, op);
+}
 EXPORT_SYMBOL(disk_start_io_acct);
 
-void disk_end_io_acct(struct gendisk *disk, unsigned int op,
-		unsigned long start_time)
+static void __part_end_io_acct(struct hd_struct *part, unsigned int op,
+			       unsigned long start_time)
 {
-	struct hd_struct *part = &disk->part0;
 	const int sgrp = op_stat_group(op);
 	unsigned long now = READ_ONCE(jiffies);
 	unsigned long duration = now - start_time;
@@ -1492,6 +1505,20 @@ void disk_end_io_acct(struct gendisk *disk, unsigned int op,
 	part_stat_local_dec(part, in_flight[op_is_write(op)]);
 	part_stat_unlock();
 }
+
+void part_end_io_acct(struct hd_struct *part, struct bio *bio,
+		      unsigned long start_time)
+{
+	__part_end_io_acct(part, bio_op(bio), start_time);
+	hd_struct_put(part);
+}
+EXPORT_SYMBOL_GPL(part_end_io_acct);
+
+void disk_end_io_acct(struct gendisk *disk, unsigned int op,
+		      unsigned long start_time)
+{
+	__part_end_io_acct(&disk->part0, op, start_time);
+}
 EXPORT_SYMBOL(disk_end_io_acct);
 
 /*
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index bb5636cc17b91..b3f5815a573aa 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1930,6 +1930,11 @@ unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors,
 void disk_end_io_acct(struct gendisk *disk, unsigned int op,
 		unsigned long start_time);
 
+unsigned long part_start_io_acct(struct gendisk *disk, struct hd_struct **part,
+				 struct bio *bio);
+void part_end_io_acct(struct hd_struct *part, struct bio *bio,
+		      unsigned long start_time);
+
 /**
  * bio_start_io_acct - start I/O accounting for bio based drivers
  * @bio:	bio to start account for
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/3] md: use part_[begin|end]_io_acct instead of disk_[begin|end]_io_acct
  2020-08-31 22:27 [PATCH v3 0/3] block: improve iostat for md/bcache partitions Song Liu
  2020-08-31 22:27 ` [PATCH v3 1/3] block: introduce part_[begin|end]_io_acct Song Liu
@ 2020-08-31 22:27 ` Song Liu
  2020-08-31 22:27 ` [PATCH v3 3/3] bcache: " Song Liu
  2020-09-11 21:37 ` [PATCH v3 0/3] block: improve iostat for md/bcache partitions Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Song Liu @ 2020-08-31 22:27 UTC (permalink / raw)
  To: linux-block, linux-raid, linux-bcache
  Cc: colyli, axboe, kernel-team, song, hch, Song Liu, Christoph Hellwig

This enables proper statistics in /proc/diskstats for md partitions.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Song Liu <songliubraving@fb.com>
---
 drivers/md/md.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 6072782070230..8d310d90001c8 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -464,6 +464,7 @@ struct md_io {
 	bio_end_io_t *orig_bi_end_io;
 	void *orig_bi_private;
 	unsigned long start_time;
+	struct hd_struct *part;
 };
 
 static void md_end_io(struct bio *bio)
@@ -471,7 +472,7 @@ static void md_end_io(struct bio *bio)
 	struct md_io *md_io = bio->bi_private;
 	struct mddev *mddev = md_io->mddev;
 
-	disk_end_io_acct(mddev->gendisk, bio_op(bio), md_io->start_time);
+	part_end_io_acct(md_io->part, bio, md_io->start_time);
 
 	bio->bi_end_io = md_io->orig_bi_end_io;
 	bio->bi_private = md_io->orig_bi_private;
@@ -517,9 +518,8 @@ static blk_qc_t md_submit_bio(struct bio *bio)
 		bio->bi_end_io = md_end_io;
 		bio->bi_private = md_io;
 
-		md_io->start_time = disk_start_io_acct(mddev->gendisk,
-						       bio_sectors(bio),
-						       bio_op(bio));
+		md_io->start_time = part_start_io_acct(mddev->gendisk,
+						       &md_io->part, bio);
 	}
 
 	/* bio could be mergeable after passing to underlayer */
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 3/3] bcache: use part_[begin|end]_io_acct instead of disk_[begin|end]_io_acct
  2020-08-31 22:27 [PATCH v3 0/3] block: improve iostat for md/bcache partitions Song Liu
  2020-08-31 22:27 ` [PATCH v3 1/3] block: introduce part_[begin|end]_io_acct Song Liu
  2020-08-31 22:27 ` [PATCH v3 2/3] md: use part_[begin|end]_io_acct instead of disk_[begin|end]_io_acct Song Liu
@ 2020-08-31 22:27 ` Song Liu
  2020-09-11 21:37 ` [PATCH v3 0/3] block: improve iostat for md/bcache partitions Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Song Liu @ 2020-08-31 22:27 UTC (permalink / raw)
  To: linux-block, linux-raid, linux-bcache
  Cc: colyli, axboe, kernel-team, song, hch, Song Liu, Christoph Hellwig

This enables proper statistics in /proc/diskstats for bcache partitions.

Reviewed-by: Coly Li <colyli@suse.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Song Liu <songliubraving@fb.com>
---
 drivers/md/bcache/request.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
index c7cadaafa9475..7f54ae2236441 100644
--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -475,6 +475,7 @@ struct search {
 	unsigned int		read_dirty_data:1;
 	unsigned int		cache_missed:1;
 
+	struct hd_struct	*part;
 	unsigned long		start_time;
 
 	struct btree_op		op;
@@ -669,7 +670,7 @@ static void bio_complete(struct search *s)
 {
 	if (s->orig_bio) {
 		/* Count on bcache device */
-		disk_end_io_acct(s->d->disk, bio_op(s->orig_bio), s->start_time);
+		part_end_io_acct(s->part, s->orig_bio, s->start_time);
 
 		trace_bcache_request_end(s->d, s->orig_bio);
 		s->orig_bio->bi_status = s->iop.status;
@@ -731,7 +732,7 @@ static inline struct search *search_alloc(struct bio *bio,
 	s->write		= op_is_write(bio_op(bio));
 	s->read_dirty_data	= 0;
 	/* Count on the bcache device */
-	s->start_time		= disk_start_io_acct(d->disk, bio_sectors(bio), bio_op(bio));
+	s->start_time		= part_start_io_acct(d->disk, &s->part, bio);
 	s->iop.c		= d->c;
 	s->iop.bio		= NULL;
 	s->iop.inode		= d->id;
@@ -1072,6 +1073,7 @@ struct detached_dev_io_private {
 	unsigned long		start_time;
 	bio_end_io_t		*bi_end_io;
 	void			*bi_private;
+	struct hd_struct	*part;
 };
 
 static void detached_dev_end_io(struct bio *bio)
@@ -1083,7 +1085,7 @@ static void detached_dev_end_io(struct bio *bio)
 	bio->bi_private = ddip->bi_private;
 
 	/* Count on the bcache device */
-	disk_end_io_acct(ddip->d->disk, bio_op(bio), ddip->start_time);
+	part_end_io_acct(ddip->part, bio, ddip->start_time);
 
 	if (bio->bi_status) {
 		struct cached_dev *dc = container_of(ddip->d,
@@ -1109,7 +1111,7 @@ static void detached_dev_do_request(struct bcache_device *d, struct bio *bio)
 	ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO);
 	ddip->d = d;
 	/* Count on the bcache device */
-	ddip->start_time = disk_start_io_acct(d->disk, bio_sectors(bio), bio_op(bio));
+	ddip->start_time = part_start_io_acct(d->disk, &ddip->part, bio);
 	ddip->bi_end_io = bio->bi_end_io;
 	ddip->bi_private = bio->bi_private;
 	bio->bi_end_io = detached_dev_end_io;
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 0/3] block: improve iostat for md/bcache partitions
  2020-08-31 22:27 [PATCH v3 0/3] block: improve iostat for md/bcache partitions Song Liu
                   ` (2 preceding siblings ...)
  2020-08-31 22:27 ` [PATCH v3 3/3] bcache: " Song Liu
@ 2020-09-11 21:37 ` Jens Axboe
  3 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2020-09-11 21:37 UTC (permalink / raw)
  To: Song Liu, linux-block, linux-raid, linux-bcache
  Cc: colyli, kernel-team, song, hch

On 8/31/20 4:27 PM, Song Liu wrote:
> Currently, devices like md, bcache uses disk_[start|end]_io_acct to report
> iostat. These functions couldn't get proper iostat for partitions on these
> devices.
> 
> This set resolves this issue by introducing part_[begin|end]_io_acct, and
> using them in md and bcache code.

Applied, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-09-11 21:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-31 22:27 [PATCH v3 0/3] block: improve iostat for md/bcache partitions Song Liu
2020-08-31 22:27 ` [PATCH v3 1/3] block: introduce part_[begin|end]_io_acct Song Liu
2020-08-31 22:27 ` [PATCH v3 2/3] md: use part_[begin|end]_io_acct instead of disk_[begin|end]_io_acct Song Liu
2020-08-31 22:27 ` [PATCH v3 3/3] bcache: " Song Liu
2020-09-11 21:37 ` [PATCH v3 0/3] block: improve iostat for md/bcache partitions Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.