Skip to contentSkip to conversation

block/throttle: remove redundant type transition

PATCH In review Robin Dong 3 participants 5 messages Nov 2, 2012

Subsystems (2)
lore
Share & tools
lore

Robin Dong

author
#0 lore raw

PATCH v5 1/2 block/throttle: remove redundant type transition

From: Robin Dong <[email protected]>

We don't need to convert tg to blkg and then convert it back in throtl_update_dispatch_stats().

---
 block/blk-throttle.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
block/blk-throttle.c +3 -4
index a9664fa..46ddeff 100644
@@ -674,10 +674,9 @@ static bool tg_may_dispatch(struct throtl_data *td, struct throtl_grp *tg,
 	return 0;
 }
 
-static void throtl_update_dispatch_stats(struct blkcg_gq *blkg, u64 bytes,
+static void throtl_update_dispatch_stats(struct throtl_grp *tg, u64 bytes,
 					 int rw)
 {
-	struct throtl_grp *tg = blkg_to_tg(blkg);
 	struct tg_stats_cpu *stats_cpu;
 	unsigned long flags;
 
@@ -708,7 +707,7 @@ static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio)
 	tg->bytes_disp[rw] += bio->bi_size;
 	tg->io_disp[rw]++;
 
-	throtl_update_dispatch_stats(tg_to_blkg(tg), bio->bi_size, bio->bi_rw);
+	throtl_update_dispatch_stats(tg, bio->bi_size, bio->bi_rw);
 }
 
 static void throtl_add_bio_tg(struct throtl_data *td, struct throtl_grp *tg,
@@ -1127,7 +1126,7 @@ bool blk_throtl_bio(struct request_queue *q, struct bio *bio)
 	tg = throtl_lookup_tg(td, blkcg);
 	if (tg) {
 		if (tg_no_rule_group(tg, rw)) {
-			throtl_update_dispatch_stats(tg_to_blkg(tg),
+			throtl_update_dispatch_stats(tg,
 						     bio->bi_size, bio->bi_rw);
 			goto out_unlock_rcu;
 		}
Signature · 1 line
1.7.1
author
#1 lore raw

PATCH v5 2/2 block/throttle: Add IO submitted information in blkio.throttle

From: Robin Dong <[email protected]>

Currently, if the IO is throttled by io-throttle, the system admin has no idea of the situation and can't report it to the real application user about that he/she has to do something.

So this patch adds a new interface named blkio.throttle.io_submitted which exposes the number of bios that have been sent into blk-throttle therefore the user could calculate the difference from throttle.io_serviced to see how many IOs are currently throttled.

Cc Tejun Heo <[email protected]>
Cc Vivek Goyal <[email protected]>
Cc Jens Axboe <[email protected]>

---
v3 <-- v2:
- Use nr-queued[] of struct throtl_grp for stats instaed of adding new blkg_rwstat.

v4 <-- v3:
- Add two new blkg_rwstat arguments to count total bios be sent into blk_throttle.

v5 <-- v4:
- Change name "io_submit_bytes" to "io_submitted_bytes".

 block/blk-throttle.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)
block/blk-throttle.c +43 -0
index 46ddeff..c6391b5 100644
@@ -46,6 +46,10 @@ struct tg_stats_cpu {
 	struct blkg_rwstat		service_bytes;
 	/* total IOs serviced, post merge */
 	struct blkg_rwstat		serviced;
+	/* total bytes submitted into blk-throttle */
+	struct blkg_rwstat		submit_bytes;
+	/* total IOs submitted into blk-throttle */
+	struct blkg_rwstat		submitted;
 };
 
 struct throtl_grp {
@@ -266,6 +270,8 @@ static void throtl_pd_reset_stats(struct blkcg_gq *blkg)
 
 		blkg_rwstat_reset(&sc->service_bytes);
 		blkg_rwstat_reset(&sc->serviced);
+		blkg_rwstat_reset(&sc->submit_bytes);
+		blkg_rwstat_reset(&sc->submitted);
 	}
 }
 
@@ -699,6 +705,30 @@ static void throtl_update_dispatch_stats(struct throtl_grp *tg, u64 bytes,
 	local_irq_restore(flags);
 }
 
+static void throtl_update_submit_stats(struct throtl_grp *tg, u64 bytes, int rw)
+{
+	struct tg_stats_cpu *stats_cpu;
+	unsigned long flags;
+
+	/* If per cpu stats are not allocated yet, don't do any accounting. */
+	if (tg->stats_cpu == NULL)
+		return;
+
+	/*
+	 * Disabling interrupts to provide mutual exclusion between two
+	 * writes on same cpu. It probably is not needed for 64bit. Not
+	 * optimizing that case yet.
+	 */
+	local_irq_save(flags);
+
+	stats_cpu = this_cpu_ptr(tg->stats_cpu);
+
+	blkg_rwstat_add(&stats_cpu->submitted, rw, 1);
+	blkg_rwstat_add(&stats_cpu->submit_bytes, rw, bytes);
+
+	local_irq_restore(flags);
+}
+
 static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio)
 {
 	bool rw = bio_data_dir(bio);
@@ -1084,6 +1114,16 @@ static struct cftype throtl_files[] = {
 		.private = offsetof(struct tg_stats_cpu, serviced),
 		.read_seq_string = tg_print_cpu_rwstat,
 	},
+	{
+		.name = "throttle.io_submitted_bytes",
+		.private = offsetof(struct tg_stats_cpu, submit_bytes),
+		.read_seq_string = tg_print_cpu_rwstat,
+	},
+	{
+		.name = "throttle.io_submitted",
+		.private = offsetof(struct tg_stats_cpu, submitted),
+		.read_seq_string = tg_print_cpu_rwstat,
+	},
 	{ }	/* terminate */
 };
 
@@ -1128,6 +1168,8 @@ bool blk_throtl_bio(struct request_queue *q, struct bio *bio)
 		if (tg_no_rule_group(tg, rw)) {
 			throtl_update_dispatch_stats(tg,
 						     bio->bi_size, bio->bi_rw);
+			throtl_update_submit_stats(tg,
+					bio->bi_size, bio->bi_rw);
 			goto out_unlock_rcu;
 		}
 	}
@@ -1141,6 +1183,7 @@ bool blk_throtl_bio(struct request_queue *q, struct bio *bio)
 	if (unlikely(!tg))
 		goto out_unlock;
 
+	throtl_update_submit_stats(tg, bio->bi_size, bio->bi_rw);
 	if (tg->nr_queued[rw]) {
 		/*
 		 * There is already another bio queued in same dir. No
Signature · 1 line
1.7.1
Acked-by on v5 2/2
#2 lore raw

Re: [PATCH 2/2 v5] block/throttle: Add IO submitted information in blkio.throttle

Quoted 11 lines · Robin Dong

From: Robin Dong <[email protected]>

Currently, if the IO is throttled by io-throttle, the system admin has no idea of the situation and can't report it to the real application user about that he/she has to do something.

So this patch adds a new interface named blkio.throttle.io_submitted which exposes the number of bios that have been sent into blk-throttle therefore the user could calculate the difference from throttle.io_serviced to see how many IOs are currently throttled.

Quoted 6 lines
Cc Tejun Heo <[email protected]>
Cc Vivek Goyal <[email protected]>
Cc Jens Axboe <[email protected]>

---

Looks good to me.

Vivek

Quoted 103 lines

v3 <-- v2:
- Use nr-queued[] of struct throtl_grp for stats instaed of adding new blkg_rwstat.

v4 <-- v3:
- Add two new blkg_rwstat arguments to count total bios be sent into blk_throttle.

v5 <-- v4:
- Change name "io_submit_bytes" to "io_submitted_bytes".

 block/blk-throttle.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)
block/blk-throttle.c +43 -0
index 46ddeff..c6391b5 100644
@@ -46,6 +46,10 @@ struct tg_stats_cpu {
 	struct blkg_rwstat		service_bytes;
 	/* total IOs serviced, post merge */
 	struct blkg_rwstat		serviced;
+	/* total bytes submitted into blk-throttle */
+	struct blkg_rwstat		submit_bytes;
+	/* total IOs submitted into blk-throttle */
+	struct blkg_rwstat		submitted;
 };
 
 struct throtl_grp {
@@ -266,6 +270,8 @@ static void throtl_pd_reset_stats(struct blkcg_gq *blkg)
 
 		blkg_rwstat_reset(&sc->service_bytes);
 		blkg_rwstat_reset(&sc->serviced);
+		blkg_rwstat_reset(&sc->submit_bytes);
+		blkg_rwstat_reset(&sc->submitted);
 	}
 }
 
@@ -699,6 +705,30 @@ static void throtl_update_dispatch_stats(struct throtl_grp *tg, u64 bytes,
 	local_irq_restore(flags);
 }
 
+static void throtl_update_submit_stats(struct throtl_grp *tg, u64 bytes, int rw)
+{
+	struct tg_stats_cpu *stats_cpu;
+	unsigned long flags;
+
+	/* If per cpu stats are not allocated yet, don't do any accounting. */
+	if (tg->stats_cpu == NULL)
+		return;
+
+	/*
+	 * Disabling interrupts to provide mutual exclusion between two
+	 * writes on same cpu. It probably is not needed for 64bit. Not
+	 * optimizing that case yet.
+	 */
+	local_irq_save(flags);
+
+	stats_cpu = this_cpu_ptr(tg->stats_cpu);
+
+	blkg_rwstat_add(&stats_cpu->submitted, rw, 1);
+	blkg_rwstat_add(&stats_cpu->submit_bytes, rw, bytes);
+
+	local_irq_restore(flags);
+}
+
 static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio)
 {
 	bool rw = bio_data_dir(bio);
@@ -1084,6 +1114,16 @@ static struct cftype throtl_files[] = {
 		.private = offsetof(struct tg_stats_cpu, serviced),
 		.read_seq_string = tg_print_cpu_rwstat,
 	},
+	{
+		.name = "throttle.io_submitted_bytes",
+		.private = offsetof(struct tg_stats_cpu, submit_bytes),
+		.read_seq_string = tg_print_cpu_rwstat,
+	},
+	{
+		.name = "throttle.io_submitted",
+		.private = offsetof(struct tg_stats_cpu, submitted),
+		.read_seq_string = tg_print_cpu_rwstat,
+	},
 	{ }	/* terminate */
 };
 
@@ -1128,6 +1168,8 @@ bool blk_throtl_bio(struct request_queue *q, struct bio *bio)
 		if (tg_no_rule_group(tg, rw)) {
 			throtl_update_dispatch_stats(tg,
 						     bio->bi_size, bio->bi_rw);
+			throtl_update_submit_stats(tg,
+					bio->bi_size, bio->bi_rw);
 			goto out_unlock_rcu;
 		}
 	}
@@ -1141,6 +1183,7 @@ bool blk_throtl_bio(struct request_queue *q, struct bio *bio)
 	if (unlikely(!tg))
 		goto out_unlock;
 
+	throtl_update_submit_stats(tg, bio->bi_size, bio->bi_rw);
 	if (tg->nr_queued[rw]) {
 		/*
 		 * There is already another bio queued in same dir. No
Signature · 1 line
1.7.1
maintainer Acked-by on v5 2/2
#3 lore raw

Re: [PATCH 2/2 v5] block/throttle: Add IO submitted information in blkio.throttle

In reply to Robin Dong
Quoted 11 lines · Robin Dong

From: Robin Dong <[email protected]>

Currently, if the IO is throttled by io-throttle, the system admin has no idea of the situation and can't report it to the real application user about that he/she has to do something.

So this patch adds a new interface named blkio.throttle.io_submitted which exposes the number of bios that have been sent into blk-throttle therefore the user could calculate the difference from throttle.io_serviced to see how many IOs are currently throttled.

Quoted 5 lines
Cc Tejun Heo <[email protected]>
Cc Vivek Goyal <[email protected]>
Cc Jens Axboe <[email protected]>

Thanks.

Signature · 1 line
tejun
Acked-by on v5 1/2
#4 lore raw
In reply to Robin Dong
Quoted 7 lines · Robin Dong

From: Robin Dong <[email protected]>

We don't need to convert tg to blkg and then convert it back in throtl_update_dispatch_stats().

---

Looks good to me.

Vivek

Quoted 45 lines
 block/blk-throttle.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
block/blk-throttle.c +3 -4
index a9664fa..46ddeff 100644
@@ -674,10 +674,9 @@ static bool tg_may_dispatch(struct throtl_data *td, struct throtl_grp *tg,
 	return 0;
 }
 
-static void throtl_update_dispatch_stats(struct blkcg_gq *blkg, u64 bytes,
+static void throtl_update_dispatch_stats(struct throtl_grp *tg, u64 bytes,
 					 int rw)
 {
-	struct throtl_grp *tg = blkg_to_tg(blkg);
 	struct tg_stats_cpu *stats_cpu;
 	unsigned long flags;
 
@@ -708,7 +707,7 @@ static void throtl_charge_bio(struct throtl_grp *tg, struct bio *bio)
 	tg->bytes_disp[rw] += bio->bi_size;
 	tg->io_disp[rw]++;
 
-	throtl_update_dispatch_stats(tg_to_blkg(tg), bio->bi_size, bio->bi_rw);
+	throtl_update_dispatch_stats(tg, bio->bi_size, bio->bi_rw);
 }
 
 static void throtl_add_bio_tg(struct throtl_data *td, struct throtl_grp *tg,
@@ -1127,7 +1126,7 @@ bool blk_throtl_bio(struct request_queue *q, struct bio *bio)
 	tg = throtl_lookup_tg(td, blkcg);
 	if (tg) {
 		if (tg_no_rule_group(tg, rw)) {
-			throtl_update_dispatch_stats(tg_to_blkg(tg),
+			throtl_update_dispatch_stats(tg,
 						     bio->bi_size, bio->bi_rw);
 			goto out_unlock_rcu;
 		}
Signature · 7 lines
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/