Skip to contentSkip to conversation

block: modularize blkcg config and stat file handling

PATCH In review Tejun Heo 9 participants 79 messages Mar 28, 2012 – Apr 4, 2012 19 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Tejun Heo

author maintainer
#0 lore raw

PATCH 1/1 block: modularize blkcg config and stat file handling

Hello,

The way configuration and statistics are handled in block cgroup is rather depressing. Every configuration and stat counter are defined in blkcg core and specific policy implementations should go through some blkcg interface to access and manipulate them and be notified of the changes.

By doing things this way, it achieves both complexity and inflexibility - the code paths are unnecessarily complex while not achieving any layering or modularity. A configuration or statistics counter cannot be added to policies without modifying multiple places in blkcg core code. Wanna implement a new policy? Good luck. The implementation details are sad too. Stuff goes through needless layers of functions with hard coded cases on specific counters and configurations and fields specific to policies are thrown into common area with some shared and others unused.

This patchset is an attempt at bringing some sanity to blkcg config and stat file handling. It makes use of the pending dynamic cgroup file type addition / removal support [1], which will be merged into cgroup/for-3.5 once 3.4-rc1 is released.

All conf and stat file handling is moved into the policy implementaiton the files belong to and blkcg supplies helpers to ease file handling in policy implementations without requiring full knowledge of all configurations and statistic counters.

This patchset sheds >500 lines of code while maintaining the same features and with more comments and much more modular design. Yeah, it was just wrong.

This patchset contains the following 21 patches

0001-blkcg-remove-unused-pol-and-plid-parameters.patch 0002-blkcg-BLKIO_STAT_CPU_SECTORS-doesn-t-have-subcounter.patch 0003-blkcg-introduce-blkg_stat-and-blkg_rwstat.patch 0004-blkcg-restructure-statistics-printing.patch 0005-blkcg-drop-blkiocg_file_write_u64.patch 0006-blkcg-restructure-configuration-printing.patch 0007-blkcg-restructure-blkio_group-configruation-setting.patch 0008-blkcg-blkg_conf_prep.patch 0009-blkcg-export-conf-stat-helpers-to-prepare-for-reorga.patch 0010-blkcg-implement-blkio_policy_type-cftypes.patch 0011-blkcg-move-conf-stat-file-handling-code-to-policies.patch 0012-cfq-collapse-cfq.h-into-cfq-iosched.c.patch 0013-blkcg-move-statistics-update-code-to-policies.patch 0014-blkcg-cfq-doesn-t-need-per-cpu-dispatch-stats.patch 0015-blkcg-add-blkio_policy_ops-operations-for-exit-and-s.patch 0016-blkcg-move-blkio_group_stats-to-cfq-iosched.c.patch 0017-blkcg-move-blkio_group_stats_cpu-and-friends-to-blk-.patch 0018-blkcg-move-blkio_group_conf-weight-to-cfq.patch 0019-blkcg-move-blkio_group_conf-iops-and-bps-to-blk-thro.patch 0020-blkcg-pass-around-pd-pdata-instead-of-pd-itself-in-p.patch 0021-blkcg-drop-BLKCG_STAT_-PRIV-POL-OFF-macros.patch

and is on top of

block/for-3.5/core eb7d8c07f9 "cfq: fix cfqg ref handling..."
+ [1] cgroup-cftypes d954ca6469 "cgroup: implement cgroup_rm_cftypes()"

Note that the cgroup branch is temporary and the merge between the two branches aren't trivial. I'll prepare a proper merged branch once the cgroup/for-3.5 branch is settled.

This patchset is also available in the following git branch.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git blkcg-files

diffstat follows.

 block/blk-cgroup.c   | 1343 ++++++---------------------------------------------
 block/blk-cgroup.h   |  414 ++++++---------
 block/blk-throttle.c |  318 ++++++++++--
 block/cfq-iosched.c  |  567 +++++++++++++++++++--
 block/cfq.h          |  118 ----
 5 files changed, 1102 insertions(+), 1658 deletions(-)

--
tejun

[1] http://thread.gmane.org/gmane.linux.kernel.containers/22623

author maintainer
#1 lore raw

PATCH 1/21 blkcg: remove unused @pol and @plid parameters

@pol to blkg_to_pdata() and @plid to blkg_lookup_create() are no longer necessary. Drop them.

---
 block/blk-cgroup.c   |    3 +--
 block/blk-cgroup.h   |    8 ++------
 block/blk-throttle.c |    7 +++----
 block/cfq-iosched.c  |    7 +++----
 4 files changed, 9 insertions(+), 16 deletions(-)
block/blk-cgroup.c +1 -2
index 7947e17..d4cf77d 100644
@@ -568,7 +568,6 @@ static struct blkio_group *blkg_alloc(struct blkio_cgroup *blkcg,
 
 struct blkio_group *blkg_lookup_create(struct blkio_cgroup *blkcg,
 				       struct request_queue *q,
-				       enum blkio_policy_id plid,
 				       bool for_root)
 	__releases(q->queue_lock) __acquires(q->queue_lock)
 {
@@ -1027,7 +1026,7 @@ static int blkio_policy_parse_and_set(char *buf, enum blkio_policy_id plid,
 	rcu_read_lock();
 
 	spin_lock_irq(disk->queue->queue_lock);
-	blkg = blkg_lookup_create(blkcg, disk->queue, plid, false);
+	blkg = blkg_lookup_create(blkcg, disk->queue, false);
 	spin_unlock_irq(disk->queue->queue_lock);
 
 	if (IS_ERR(blkg)) {
block/blk-cgroup.h +2 -6
index 1cb8f76..1add3dc 100644
@@ -266,13 +266,10 @@ static inline void *blkg_to_pdata(struct blkio_group *blkg,
 /**
  * pdata_to_blkg - get blkg associated with policy private data
  * @pdata: policy private data of interest
- * @pol: policy @pdata is for
  *
- * @pdata is policy private data for @pol.  Determine the blkg it's
- * associated with.
+ * @pdata is policy private data.  Determine the blkg it's associated with.
  */
-static inline struct blkio_group *pdata_to_blkg(void *pdata,
-						struct blkio_policy_type *pol)
+static inline struct blkio_group *pdata_to_blkg(void *pdata)
 {
 	if (pdata) {
 		struct blkg_policy_data *pd =
@@ -402,7 +399,6 @@ extern struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg,
 				       struct request_queue *q);
 struct blkio_group *blkg_lookup_create(struct blkio_cgroup *blkcg,
 				       struct request_queue *q,
-				       enum blkio_policy_id plid,
 				       bool for_root);
 void blkiocg_update_timeslice_used(struct blkio_group *blkg,
 				   struct blkio_policy_type *pol,
block/blk-throttle.c +3 -4
index 4ba1418..1cc6c23d 100644
@@ -107,7 +107,7 @@ static inline struct throtl_grp *blkg_to_tg(struct blkio_group *blkg)
 
 static inline struct blkio_group *tg_to_blkg(struct throtl_grp *tg)
 {
-	return pdata_to_blkg(tg, &blkio_policy_throtl);
+	return pdata_to_blkg(tg);
 }
 
 enum tg_state_flags {
@@ -185,7 +185,7 @@ static struct throtl_grp *throtl_lookup_create_tg(struct throtl_data *td,
 	} else {
 		struct blkio_group *blkg;
 
-		blkg = blkg_lookup_create(blkcg, q, BLKIO_POLICY_THROTL, false);
+		blkg = blkg_lookup_create(blkcg, q, false);
 
 		/* if %NULL and @q is alive, fall back to root_tg */
 		if (!IS_ERR(blkg))
@@ -1033,8 +1033,7 @@ int blk_throtl_init(struct request_queue *q)
 	rcu_read_lock();
 	spin_lock_irq(q->queue_lock);
 
-	blkg = blkg_lookup_create(&blkio_root_cgroup, q, BLKIO_POLICY_THROTL,
-				  true);
+	blkg = blkg_lookup_create(&blkio_root_cgroup, q, true);
 	if (!IS_ERR(blkg))
 		td->root_tg = blkg_to_tg(blkg);
 
block/cfq-iosched.c +3 -4
index 39c4330..8cca6161 100644
@@ -374,7 +374,7 @@ static inline struct cfq_group *blkg_to_cfqg(struct blkio_group *blkg)
 
 static inline struct blkio_group *cfqg_to_blkg(struct cfq_group *cfqg)
 {
-	return pdata_to_blkg(cfqg, &blkio_policy_cfq);
+	return pdata_to_blkg(cfqg);
 }
 
 static inline void cfqg_get(struct cfq_group *cfqg)
@@ -1092,7 +1092,7 @@ static struct cfq_group *cfq_lookup_create_cfqg(struct cfq_data *cfqd,
 	} else {
 		struct blkio_group *blkg;
 
-		blkg = blkg_lookup_create(blkcg, q, BLKIO_POLICY_PROP, false);
+		blkg = blkg_lookup_create(blkcg, q, false);
 		if (!IS_ERR(blkg))
 			cfqg = blkg_to_cfqg(blkg);
 	}
@@ -3523,8 +3523,7 @@ static int cfq_init_queue(struct request_queue *q)
 	rcu_read_lock();
 	spin_lock_irq(q->queue_lock);
 
-	blkg = blkg_lookup_create(&blkio_root_cgroup, q, BLKIO_POLICY_PROP,
-				  true);
+	blkg = blkg_lookup_create(&blkio_root_cgroup, q, true);
 	if (!IS_ERR(blkg))
 		cfqd->root_group = blkg_to_cfqg(blkg);
 
Signature · 1 line
1.7.7.3
#3 lore raw

PATCH 1/21 blkcg: remove unused @pol and @plid parameters

In reply to a message not in the archive

@pol to blkg_to_pdata() and @plid to blkg_lookup_create() are no longer necessary. Drop them.

---
 block/blk-cgroup.c   |    3 +--
 block/blk-cgroup.h   |    8 ++------
 block/blk-throttle.c |    7 +++----
 block/cfq-iosched.c  |    7 +++----
 4 files changed, 9 insertions(+), 16 deletions(-)
block/blk-cgroup.c +1 -2
index 7947e17..d4cf77d 100644
@@ -568,7 +568,6 @@ static struct blkio_group *blkg_alloc(struct blkio_cgroup *blkcg,
 
 struct blkio_group *blkg_lookup_create(struct blkio_cgroup *blkcg,
 				       struct request_queue *q,
-				       enum blkio_policy_id plid,
 				       bool for_root)
 	__releases(q->queue_lock) __acquires(q->queue_lock)
 {
@@ -1027,7 +1026,7 @@ static int blkio_policy_parse_and_set(char *buf, enum blkio_policy_id plid,
 	rcu_read_lock();
 
 	spin_lock_irq(disk->queue->queue_lock);
-	blkg = blkg_lookup_create(blkcg, disk->queue, plid, false);
+	blkg = blkg_lookup_create(blkcg, disk->queue, false);
 	spin_unlock_irq(disk->queue->queue_lock);
 
 	if (IS_ERR(blkg)) {
block/blk-cgroup.h +2 -6
index 1cb8f76..1add3dc 100644
@@ -266,13 +266,10 @@ static inline void *blkg_to_pdata(struct blkio_group *blkg,
 /**
  * pdata_to_blkg - get blkg associated with policy private data
  * @pdata: policy private data of interest
- * @pol: policy @pdata is for
  *
- * @pdata is policy private data for @pol.  Determine the blkg it's
- * associated with.
+ * @pdata is policy private data.  Determine the blkg it's associated with.
  */
-static inline struct blkio_group *pdata_to_blkg(void *pdata,
-						struct blkio_policy_type *pol)
+static inline struct blkio_group *pdata_to_blkg(void *pdata)
 {
 	if (pdata) {
 		struct blkg_policy_data *pd =
@@ -402,7 +399,6 @@ extern struct blkio_group *blkg_lookup(struct blkio_cgroup *blkcg,
 				       struct request_queue *q);
 struct blkio_group *blkg_lookup_create(struct blkio_cgroup *blkcg,
 				       struct request_queue *q,
-				       enum blkio_policy_id plid,
 				       bool for_root);
 void blkiocg_update_timeslice_used(struct blkio_group *blkg,
 				   struct blkio_policy_type *pol,
block/blk-throttle.c +3 -4
index 4ba1418..1cc6c23d 100644
@@ -107,7 +107,7 @@ static inline struct throtl_grp *blkg_to_tg(struct blkio_group *blkg)
 
 static inline struct blkio_group *tg_to_blkg(struct throtl_grp *tg)
 {
-	return pdata_to_blkg(tg, &blkio_policy_throtl);
+	return pdata_to_blkg(tg);
 }
 
 enum tg_state_flags {
@@ -185,7 +185,7 @@ static struct throtl_grp *throtl_lookup_create_tg(struct throtl_data *td,
 	} else {
 		struct blkio_group *blkg;
 
-		blkg = blkg_lookup_create(blkcg, q, BLKIO_POLICY_THROTL, false);
+		blkg = blkg_lookup_create(blkcg, q, false);
 
 		/* if %NULL and @q is alive, fall back to root_tg */
 		if (!IS_ERR(blkg))
@@ -1033,8 +1033,7 @@ int blk_throtl_init(struct request_queue *q)
 	rcu_read_lock();
 	spin_lock_irq(q->queue_lock);
 
-	blkg = blkg_lookup_create(&blkio_root_cgroup, q, BLKIO_POLICY_THROTL,
-				  true);
+	blkg = blkg_lookup_create(&blkio_root_cgroup, q, true);
 	if (!IS_ERR(blkg))
 		td->root_tg = blkg_to_tg(blkg);
 
block/cfq-iosched.c +3 -4
index 39c4330..8cca6161 100644
@@ -374,7 +374,7 @@ static inline struct cfq_group *blkg_to_cfqg(struct blkio_group *blkg)
 
 static inline struct blkio_group *cfqg_to_blkg(struct cfq_group *cfqg)
 {
-	return pdata_to_blkg(cfqg, &blkio_policy_cfq);
+	return pdata_to_blkg(cfqg);
 }
 
 static inline void cfqg_get(struct cfq_group *cfqg)
@@ -1092,7 +1092,7 @@ static struct cfq_group *cfq_lookup_create_cfqg(struct cfq_data *cfqd,
 	} else {
 		struct blkio_group *blkg;
 
-		blkg = blkg_lookup_create(blkcg, q, BLKIO_POLICY_PROP, false);
+		blkg = blkg_lookup_create(blkcg, q, false);
 		if (!IS_ERR(blkg))
 			cfqg = blkg_to_cfqg(blkg);
 	}
@@ -3523,8 +3523,7 @@ static int cfq_init_queue(struct request_queue *q)
 	rcu_read_lock();
 	spin_lock_irq(q->queue_lock);
 
-	blkg = blkg_lookup_create(&blkio_root_cgroup, q, BLKIO_POLICY_PROP,
-				  true);
+	blkg = blkg_lookup_create(&blkio_root_cgroup, q, true);
 	if (!IS_ERR(blkg))
 		cfqd->root_group = blkg_to_cfqg(blkg);
 
Signature · 1 line
1.7.7.3
author maintainer
#6 lore raw

PATCH 2/21 blkcg: BLKIO_STAT_CPU_SECTORS doesn't have subcounters

In reply to Tejun Heo

BLKIO_STAT_CPU_SECTORS doesn't need read/write/sync/async subcounters and is counted by blkio_group_stats_cpu->sectors; however, it still holds a member in blkio_group_stats_cpu->stat_arr_cpu.

Rearrange stat_type_cpu and define BLKIO_STAT_CPU_ARR_NR and use it for stat_arr_cpu[] size so that only SERVICE_BYTES and SERVICED have subcounters.

---
 block/blk-cgroup.h |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
block/blk-cgroup.h +6 -3
index 1add3dc..2060d81 100644
@@ -58,14 +58,17 @@ enum stat_type {
 
 /* Per cpu stats */
 enum stat_type_cpu {
-	BLKIO_STAT_CPU_SECTORS,
 	/* Total bytes transferred */
 	BLKIO_STAT_CPU_SERVICE_BYTES,
 	/* Total IOs serviced, post merge */
 	BLKIO_STAT_CPU_SERVICED,
-	BLKIO_STAT_CPU_NR
+
+	/* All the single valued stats go below this */
+	BLKIO_STAT_CPU_SECTORS,
 };
 
+#define BLKIO_STAT_CPU_ARR_NR	(BLKIO_STAT_CPU_SERVICED + 1)
+
 enum stat_sub_type {
 	BLKIO_STAT_READ = 0,
 	BLKIO_STAT_WRITE,
@@ -167,7 +170,7 @@ struct blkio_group_stats {
 /* Per cpu blkio group stats */
 struct blkio_group_stats_cpu {
 	uint64_t sectors;
-	uint64_t stat_arr_cpu[BLKIO_STAT_CPU_NR][BLKIO_STAT_TOTAL];
+	uint64_t stat_arr_cpu[BLKIO_STAT_CPU_ARR_NR][BLKIO_STAT_TOTAL];
 	struct u64_stats_sync syncp;
 };
 
Signature · 1 line
1.7.7.3
author maintainer
#7 lore raw

PATCH 3/21 blkcg: introduce blkg_stat and blkg_rwstat

In reply to Tejun Heo

blkcg uses u64_stats_sync to avoid reading wrong u64 statistic values on 32bit archs and some stat counters have subtypes to distinguish read/writes and sync/async IOs. The stat code paths are confusing and involve a lot of going back and forth between blkcg core and specific policy implementations, and synchronization and subtype handling are open coded in blkcg core.

This patch introduces struct blkg_stat and blkg_rwstat which, with accompanying operations, encapsulate stat updating and accessing with proper synchronization.

blkg_stat is simple u64 counter with 64bit read-access protection. blkg_rwstat is the one with rw and [a]sync subcounters and takes @rw flags to distinguish IO subtypes (%REQ_WRITE and %REQ_SYNC) and replaces stat_sub_type indexed arrays.

All counters in blkio_group_stats and blkio_group_stats_cpu are replaced with either blkg_stat or blkg_rwstat along with all users.

This does add one u64_stats_sync per counter and increase stats_sync operations but they're empty/noops on 64bit archs and blkcg doesn't have too many counters, especially with DEBUG_BLK_CGROUP off.

While the currently resulting code isn't necessarily simpler at the moment, this will enable further clean up of blkcg stats code.

- BLKIO_STAT_{READ|WRITE|SYNC|ASYNC|TOTAL} renamed to BLKG_RWSTAT_{READ|WRITE|SYNC|ASYNC|TOTAL}.

- blkg_stat_add() replaces blkio_add_stat() and blkio_check_and_dec_stat(). Note that BUG_ON() on underflow in the latter function no longer exists. It's *way* better to have underflowed stat counters than oopsing.

- blkio_group_stats->dequeue is now a proper u64 stat counter instead of ulong.

- reset_stats() updated to clear each stat counters individually and BLKG_STATS_DEBUG_CLEAR_{START|SIZE} are removed.

- Some functions reconstruct rw flags from direction and sync booleans. This will be removed by future patches.

---
 block/blk-cgroup.c |  289 +++++++++++++++++++++++-----------------------------
 block/blk-cgroup.h |  211 ++++++++++++++++++++++++++++++--------
 2 files changed, 293 insertions(+), 207 deletions(-)
block/blk-cgroup.c +127 -162
index d4cf77d..153a2db 100644
@@ -132,46 +132,6 @@ static inline void blkio_update_group_iops(struct blkio_group *blkg,
 	}
 }
 
-/*
- * Add to the appropriate stat variable depending on the request type.
- * This should be called with queue_lock held.
- */
-static void blkio_add_stat(uint64_t *stat, uint64_t add, bool direction,
-				bool sync)
-{
-	if (direction)
-		stat[BLKIO_STAT_WRITE] += add;
-	else
-		stat[BLKIO_STAT_READ] += add;
-	if (sync)
-		stat[BLKIO_STAT_SYNC] += add;
-	else
-		stat[BLKIO_STAT_ASYNC] += add;
-}
-
-/*
- * Decrements the appropriate stat variable if non-zero depending on the
- * request type. Panics on value being zero.
- * This should be called with the queue_lock held.
- */
-static void blkio_check_and_dec_stat(uint64_t *stat, bool direction, bool sync)
-{
-	if (direction) {
-		BUG_ON(stat[BLKIO_STAT_WRITE] == 0);
-		stat[BLKIO_STAT_WRITE]--;
-	} else {
-		BUG_ON(stat[BLKIO_STAT_READ] == 0);
-		stat[BLKIO_STAT_READ]--;
-	}
-	if (sync) {
-		BUG_ON(stat[BLKIO_STAT_SYNC] == 0);
-		stat[BLKIO_STAT_SYNC]--;
-	} else {
-		BUG_ON(stat[BLKIO_STAT_ASYNC] == 0);
-		stat[BLKIO_STAT_ASYNC]--;
-	}
-}
-
 #ifdef CONFIG_DEBUG_BLK_CGROUP
 /* This should be called with the queue_lock held. */
 static void blkio_set_start_group_wait_time(struct blkio_group *blkg,
@@ -198,7 +158,8 @@ static void blkio_update_group_wait_time(struct blkio_group_stats *stats)
 
 	now = sched_clock();
 	if (time_after64(now, stats->start_group_wait_time))
-		stats->group_wait_time += now - stats->start_group_wait_time;
+		blkg_stat_add(&stats->group_wait_time,
+			      now - stats->start_group_wait_time);
 	blkio_clear_blkg_waiting(stats);
 }
 
@@ -212,7 +173,8 @@ static void blkio_end_empty_time(struct blkio_group_stats *stats)
 
 	now = sched_clock();
 	if (time_after64(now, stats->start_empty_time))
-		stats->empty_time += now - stats->start_empty_time;
+		blkg_stat_add(&stats->empty_time,
+			      now - stats->start_empty_time);
 	blkio_clear_blkg_empty(stats);
 }
 
@@ -239,11 +201,9 @@ void blkiocg_update_idle_time_stats(struct blkio_group *blkg,
 	if (blkio_blkg_idling(stats)) {
 		unsigned long long now = sched_clock();
 
-		if (time_after64(now, stats->start_idle_time)) {
-			u64_stats_update_begin(&stats->syncp);
-			stats->idle_time += now - stats->start_idle_time;
-			u64_stats_update_end(&stats->syncp);
-		}
+		if (time_after64(now, stats->start_idle_time))
+			blkg_stat_add(&stats->idle_time,
+				      now - stats->start_idle_time);
 		blkio_clear_blkg_idling(stats);
 	}
 }
@@ -256,13 +216,10 @@ void blkiocg_update_avg_queue_size_stats(struct blkio_group *blkg,
 
 	lockdep_assert_held(blkg->q->queue_lock);
 
-	u64_stats_update_begin(&stats->syncp);
-	stats->avg_queue_size_sum +=
-			stats->stat_arr[BLKIO_STAT_QUEUED][BLKIO_STAT_READ] +
-			stats->stat_arr[BLKIO_STAT_QUEUED][BLKIO_STAT_WRITE];
-	stats->avg_queue_size_samples++;
+	blkg_stat_add(&stats->avg_queue_size_sum,
+		      blkg_rwstat_sum(&stats->queued));
+	blkg_stat_add(&stats->avg_queue_size_samples, 1);
 	blkio_update_group_wait_time(stats);
-	u64_stats_update_end(&stats->syncp);
 }
 EXPORT_SYMBOL_GPL(blkiocg_update_avg_queue_size_stats);
 
@@ -273,8 +230,7 @@ void blkiocg_set_start_empty_time(struct blkio_group *blkg,
 
 	lockdep_assert_held(blkg->q->queue_lock);
 
-	if (stats->stat_arr[BLKIO_STAT_QUEUED][BLKIO_STAT_READ] ||
-			stats->stat_arr[BLKIO_STAT_QUEUED][BLKIO_STAT_WRITE])
+	if (blkg_rwstat_sum(&stats->queued))
 		return;
 
 	/*
@@ -298,7 +254,7 @@ void blkiocg_update_dequeue_stats(struct blkio_group *blkg,
 
 	lockdep_assert_held(blkg->q->queue_lock);
 
-	pd->stats.dequeue += dequeue;
+	blkg_stat_add(&pd->stats.dequeue, dequeue);
 }
 EXPORT_SYMBOL_GPL(blkiocg_update_dequeue_stats);
 #else
@@ -314,14 +270,12 @@ void blkiocg_update_io_add_stats(struct blkio_group *blkg,
 				 bool sync)
 {
 	struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
+	int rw = (direction ? REQ_WRITE : 0) | (sync ? REQ_SYNC : 0);
 
 	lockdep_assert_held(blkg->q->queue_lock);
 
-	u64_stats_update_begin(&stats->syncp);
-	blkio_add_stat(stats->stat_arr[BLKIO_STAT_QUEUED], 1, direction, sync);
+	blkg_rwstat_add(&stats->queued, rw, 1);
 	blkio_end_empty_time(stats);
-	u64_stats_update_end(&stats->syncp);
-
 	blkio_set_start_group_wait_time(blkg, pol, curr_blkg);
 }
 EXPORT_SYMBOL_GPL(blkiocg_update_io_add_stats);
@@ -331,13 +285,11 @@ void blkiocg_update_io_remove_stats(struct blkio_group *blkg,
 				    bool direction, bool sync)
 {
 	struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
+	int rw = (direction ? REQ_WRITE : 0) | (sync ? REQ_SYNC : 0);
 
 	lockdep_assert_held(blkg->q->queue_lock);
 
-	u64_stats_update_begin(&stats->syncp);
-	blkio_check_and_dec_stat(stats->stat_arr[BLKIO_STAT_QUEUED], direction,
-				 sync);
-	u64_stats_update_end(&stats->syncp);
+	blkg_rwstat_add(&stats->queued, rw, -1);
 }
 EXPORT_SYMBOL_GPL(blkiocg_update_io_remove_stats);
 
@@ -350,12 +302,10 @@ void blkiocg_update_timeslice_used(struct blkio_group *blkg,
 
 	lockdep_assert_held(blkg->q->queue_lock);
 
-	u64_stats_update_begin(&stats->syncp);
-	stats->time += time;
+	blkg_stat_add(&stats->time, time);
 #ifdef CONFIG_DEBUG_BLK_CGROUP
-	stats->unaccounted_time += unaccounted_time;
+	blkg_stat_add(&stats->unaccounted_time, unaccounted_time);
 #endif
-	u64_stats_update_end(&stats->syncp);
 }
 EXPORT_SYMBOL_GPL(blkiocg_update_timeslice_used);
 
@@ -367,6 +317,7 @@ void blkiocg_update_dispatch_stats(struct blkio_group *blkg,
 				   struct blkio_policy_type *pol,
 				   uint64_t bytes, bool direction, bool sync)
 {
+	int rw = (direction ? REQ_WRITE : 0) | (sync ? REQ_SYNC : 0);
 	struct blkg_policy_data *pd = blkg->pd[pol->plid];
 	struct blkio_group_stats_cpu *stats_cpu;
 	unsigned long flags;
@@ -384,13 +335,10 @@ void blkiocg_update_dispatch_stats(struct blkio_group *blkg,
 
 	stats_cpu = this_cpu_ptr(pd->stats_cpu);
 
-	u64_stats_update_begin(&stats_cpu->syncp);
-	stats_cpu->sectors += bytes >> 9;
-	blkio_add_stat(stats_cpu->stat_arr_cpu[BLKIO_STAT_CPU_SERVICED],
-			1, direction, sync);
-	blkio_add_stat(stats_cpu->stat_arr_cpu[BLKIO_STAT_CPU_SERVICE_BYTES],
-			bytes, direction, sync);
-	u64_stats_update_end(&stats_cpu->syncp);
+	blkg_stat_add(&stats_cpu->sectors, bytes >> 9);
+	blkg_rwstat_add(&stats_cpu->serviced, rw, 1);
+	blkg_rwstat_add(&stats_cpu->service_bytes, rw, bytes);
+
 	local_irq_restore(flags);
 }
 EXPORT_SYMBOL_GPL(blkiocg_update_dispatch_stats);
@@ -403,17 +351,15 @@ void blkiocg_update_completion_stats(struct blkio_group *blkg,
 {
 	struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
 	unsigned long long now = sched_clock();
+	int rw = (direction ? REQ_WRITE : 0) | (sync ? REQ_SYNC : 0);
 
 	lockdep_assert_held(blkg->q->queue_lock);
 
-	u64_stats_update_begin(&stats->syncp);
 	if (time_after64(now, io_start_time))
-		blkio_add_stat(stats->stat_arr[BLKIO_STAT_SERVICE_TIME],
-				now - io_start_time, direction, sync);
+		blkg_rwstat_add(&stats->service_time, rw, now - io_start_time);
 	if (time_after64(io_start_time, start_time))
-		blkio_add_stat(stats->stat_arr[BLKIO_STAT_WAIT_TIME],
-				io_start_time - start_time, direction, sync);
-	u64_stats_update_end(&stats->syncp);
+		blkg_rwstat_add(&stats->wait_time, rw,
+				io_start_time - start_time);
 }
 EXPORT_SYMBOL_GPL(blkiocg_update_completion_stats);
 
@@ -423,12 +369,11 @@ void blkiocg_update_io_merged_stats(struct blkio_group *blkg,
 				    bool direction, bool sync)
 {
 	struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
+	int rw = (direction ? REQ_WRITE : 0) | (sync ? REQ_SYNC : 0);
 
 	lockdep_assert_held(blkg->q->queue_lock);
 
-	u64_stats_update_begin(&stats->syncp);
-	blkio_add_stat(stats->stat_arr[BLKIO_STAT_MERGED], 1, direction, sync);
-	u64_stats_update_end(&stats->syncp);
+	blkg_rwstat_add(&stats->merged, rw, 1);
 }
 EXPORT_SYMBOL_GPL(blkiocg_update_io_merged_stats);
 
@@ -757,8 +702,9 @@ static void blkio_reset_stats_cpu(struct blkio_group *blkg, int plid)
 		struct blkio_group_stats_cpu *sc =
 			per_cpu_ptr(pd->stats_cpu, cpu);
 
-		sc->sectors = 0;
-		memset(sc->stat_arr_cpu, 0, sizeof(sc->stat_arr_cpu));
+		blkg_rwstat_reset(&sc->service_bytes);
+		blkg_rwstat_reset(&sc->serviced);
+		blkg_stat_reset(&sc->sectors);
 	}
 }
 
@@ -768,7 +714,6 @@ blkiocg_reset_stats(struct cgroup *cgroup, struct cftype *cftype, u64 val)
 	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgroup);
 	struct blkio_group *blkg;
 	struct hlist_node *n;
-	int i;
 
 	spin_lock(&blkio_list_lock);
 	spin_lock_irq(&blkcg->lock);
@@ -786,14 +731,18 @@ blkiocg_reset_stats(struct cgroup *cgroup, struct cftype *cftype, u64 val)
 			struct blkio_group_stats *stats = &pd->stats;
 
 			/* queued stats shouldn't be cleared */
-			for (i = 0; i < ARRAY_SIZE(stats->stat_arr); i++)
-				if (i != BLKIO_STAT_QUEUED)
-					memset(stats->stat_arr[i], 0,
-					       sizeof(stats->stat_arr[i]));
-			stats->time = 0;
+			blkg_rwstat_reset(&stats->merged);
+			blkg_rwstat_reset(&stats->service_time);
+			blkg_rwstat_reset(&stats->wait_time);
+			blkg_stat_reset(&stats->time);
 #ifdef CONFIG_DEBUG_BLK_CGROUP
-			memset((void *)stats + BLKG_STATS_DEBUG_CLEAR_START, 0,
-			       BLKG_STATS_DEBUG_CLEAR_SIZE);
+			blkg_stat_reset(&stats->unaccounted_time);
+			blkg_stat_reset(&stats->avg_queue_size_sum);
+			blkg_stat_reset(&stats->avg_queue_size_samples);
+			blkg_stat_reset(&stats->dequeue);
+			blkg_stat_reset(&stats->group_wait_time);
+			blkg_stat_reset(&stats->idle_time);
+			blkg_stat_reset(&stats->empty_time);
 #endif
 			blkio_reset_stats_cpu(blkg, pol->plid);
 		}
@@ -804,7 +753,7 @@ blkiocg_reset_stats(struct cgroup *cgroup, struct cftype *cftype, u64 val)
 	return 0;
 }
 
-static void blkio_get_key_name(enum stat_sub_type type, const char *dname,
+static void blkio_get_key_name(enum blkg_rwstat_type type, const char *dname,
 			       char *str, int chars_left, bool diskname_only)
 {
 	snprintf(str, chars_left, "%s", dname);
@@ -817,19 +766,19 @@ static void blkio_get_key_name(enum stat_sub_type type, const char *dname,
 	if (diskname_only)
 		return;
 	switch (type) {
-	case BLKIO_STAT_READ:
+	case BLKG_RWSTAT_READ:
 		strlcat(str, " Read", chars_left);
 		break;
-	case BLKIO_STAT_WRITE:
+	case BLKG_RWSTAT_WRITE:
 		strlcat(str, " Write", chars_left);
 		break;
-	case BLKIO_STAT_SYNC:
+	case BLKG_RWSTAT_SYNC:
 		strlcat(str, " Sync", chars_left);
 		break;
-	case BLKIO_STAT_ASYNC:
+	case BLKG_RWSTAT_ASYNC:
 		strlcat(str, " Async", chars_left);
 		break;
-	case BLKIO_STAT_TOTAL:
+	case BLKG_RWSTAT_TOTAL:
 		strlcat(str, " Total", chars_left);
 		break;
 	default:
@@ -838,29 +787,34 @@ static void blkio_get_key_name(enum stat_sub_type type, const char *dname,
 }
 
 static uint64_t blkio_read_stat_cpu(struct blkio_group *blkg, int plid,
-			enum stat_type_cpu type, enum stat_sub_type sub_type)
+				    enum stat_type_cpu type,
+				    enum blkg_rwstat_type sub_type)
 {
 	struct blkg_policy_data *pd = blkg->pd[plid];
+	u64 val = 0;
 	int cpu;
-	struct blkio_group_stats_cpu *stats_cpu;
-	u64 val = 0, tval;
 
 	if (pd->stats_cpu == NULL)
 		return val;
 
 	for_each_possible_cpu(cpu) {
-		unsigned int start;
-		stats_cpu = per_cpu_ptr(pd->stats_cpu, cpu);
-
-		do {
-			start = u64_stats_fetch_begin(&stats_cpu->syncp);
-			if (type == BLKIO_STAT_CPU_SECTORS)
-				tval = stats_cpu->sectors;
-			else
-				tval = stats_cpu->stat_arr_cpu[type][sub_type];
-		} while(u64_stats_fetch_retry(&stats_cpu->syncp, start));
-
-		val += tval;
+		struct blkio_group_stats_cpu *stats_cpu =
+			per_cpu_ptr(pd->stats_cpu, cpu);
+		struct blkg_rwstat rws;
+
+		switch (type) {
+		case BLKIO_STAT_CPU_SECTORS:
+			val += blkg_stat_read(&stats_cpu->sectors);
+			break;
+		case BLKIO_STAT_CPU_SERVICE_BYTES:
+			rws = blkg_rwstat_read(&stats_cpu->service_bytes);
+			val += rws.cnt[sub_type];
+			break;
+		case BLKIO_STAT_CPU_SERVICED:
+			rws = blkg_rwstat_read(&stats_cpu->serviced);
+			val += rws.cnt[sub_type];
+			break;
+		}
 	}
 
 	return val;
@@ -872,7 +826,7 @@ static uint64_t blkio_get_stat_cpu(struct blkio_group *blkg, int plid,
 {
 	uint64_t disk_total, val;
 	char key_str[MAX_KEY_LEN];
-	enum stat_sub_type sub_type;
+	enum blkg_rwstat_type sub_type;
 
 	if (type == BLKIO_STAT_CPU_SECTORS) {
 		val = blkio_read_stat_cpu(blkg, plid, type, 0);
@@ -881,7 +835,7 @@ static uint64_t blkio_get_stat_cpu(struct blkio_group *blkg, int plid,
 		return val;
 	}
 
-	for (sub_type = BLKIO_STAT_READ; sub_type < BLKIO_STAT_TOTAL;
+	for (sub_type = BLKG_RWSTAT_READ; sub_type < BLKG_RWSTAT_NR;
 			sub_type++) {
 		blkio_get_key_name(sub_type, dname, key_str, MAX_KEY_LEN,
 				   false);
@@ -889,10 +843,10 @@ static uint64_t blkio_get_stat_cpu(struct blkio_group *blkg, int plid,
 		cb->fill(cb, key_str, val);
 	}
 
-	disk_total = blkio_read_stat_cpu(blkg, plid, type, BLKIO_STAT_READ) +
-		blkio_read_stat_cpu(blkg, plid, type, BLKIO_STAT_WRITE);
+	disk_total = blkio_read_stat_cpu(blkg, plid, type, BLKG_RWSTAT_READ) +
+		blkio_read_stat_cpu(blkg, plid, type, BLKG_RWSTAT_WRITE);
 
-	blkio_get_key_name(BLKIO_STAT_TOTAL, dname, key_str, MAX_KEY_LEN,
+	blkio_get_key_name(BLKG_RWSTAT_TOTAL, dname, key_str, MAX_KEY_LEN,
 			   false);
 	cb->fill(cb, key_str, disk_total);
 	return disk_total;
@@ -905,65 +859,76 @@ static uint64_t blkio_get_stat(struct blkio_group *blkg, int plid,
 	struct blkio_group_stats *stats = &blkg->pd[plid]->stats;
 	uint64_t v = 0, disk_total = 0;
 	char key_str[MAX_KEY_LEN];
-	unsigned int sync_start;
+	struct blkg_rwstat rws = { };
 	int st;
 
 	if (type >= BLKIO_STAT_ARR_NR) {
-		do {
-			sync_start = u64_stats_fetch_begin(&stats->syncp);
-			switch (type) {
-			case BLKIO_STAT_TIME:
-				v = stats->time;
-				break;
+		switch (type) {
+		case BLKIO_STAT_TIME:
+			v = blkg_stat_read(&stats->time);
+			break;
 #ifdef CONFIG_DEBUG_BLK_CGROUP
-			case BLKIO_STAT_UNACCOUNTED_TIME:
-				v = stats->unaccounted_time;
-				break;
-			case BLKIO_STAT_AVG_QUEUE_SIZE: {
-				uint64_t samples = stats->avg_queue_size_samples;
+		case BLKIO_STAT_UNACCOUNTED_TIME:
+			v = blkg_stat_read(&stats->unaccounted_time);
+			break;
+		case BLKIO_STAT_AVG_QUEUE_SIZE: {
+			uint64_t samples;
 
-				if (samples) {
-					v = stats->avg_queue_size_sum;
-					do_div(v, samples);
-				}
-				break;
+			samples = blkg_stat_read(&stats->avg_queue_size_samples);
+			if (samples) {
+				v = blkg_stat_read(&stats->avg_queue_size_sum);
+				do_div(v, samples);
 			}
-			case BLKIO_STAT_IDLE_TIME:
-				v = stats->idle_time;
-				break;
-			case BLKIO_STAT_EMPTY_TIME:
-				v = stats->empty_time;
-				break;
-			case BLKIO_STAT_DEQUEUE:
-				v = stats->dequeue;
-				break;
-			case BLKIO_STAT_GROUP_WAIT_TIME:
-				v = stats->group_wait_time;
-				break;
+			break;
+		}
+		case BLKIO_STAT_IDLE_TIME:
+			v = blkg_stat_read(&stats->idle_time);
+			break;
+		case BLKIO_STAT_EMPTY_TIME:
+			v = blkg_stat_read(&stats->empty_time);
+			break;
+		case BLKIO_STAT_DEQUEUE:
+			v = blkg_stat_read(&stats->dequeue);
+			break;
+		case BLKIO_STAT_GROUP_WAIT_TIME:
+			v = blkg_stat_read(&stats->group_wait_time);
+			break;
 #endif
-			default:
-				WARN_ON_ONCE(1);
-			}
-		} while (u64_stats_fetch_retry(&stats->syncp, sync_start));
+		default:
+			WARN_ON_ONCE(1);
+		}
 
 		blkio_get_key_name(0, dname, key_str, MAX_KEY_LEN, true);
 		cb->fill(cb, key_str, v);
 		return v;
 	}
 
-	for (st = BLKIO_STAT_READ; st < BLKIO_STAT_TOTAL; st++) {
-		do {
-			sync_start = u64_stats_fetch_begin(&stats->syncp);
-			v = stats->stat_arr[type][st];
-		} while (u64_stats_fetch_retry(&stats->syncp, sync_start));
+	switch (type) {
+	case BLKIO_STAT_MERGED:
+		rws = blkg_rwstat_read(&stats->merged);
+		break;
+	case BLKIO_STAT_SERVICE_TIME:
+		rws = blkg_rwstat_read(&stats->service_time);
+		break;
+	case BLKIO_STAT_WAIT_TIME:
+		rws = blkg_rwstat_read(&stats->wait_time);
+		break;
+	case BLKIO_STAT_QUEUED:
+		rws = blkg_rwstat_read(&stats->queued);
+		break;
+	default:
+		WARN_ON_ONCE(true);
+		break;
+	}
 
+	for (st = BLKG_RWSTAT_READ; st < BLKG_RWSTAT_NR; st++) {
 		blkio_get_key_name(st, dname, key_str, MAX_KEY_LEN, false);
-		cb->fill(cb, key_str, v);
-		if (st == BLKIO_STAT_READ || st == BLKIO_STAT_WRITE)
-			disk_total += v;
+		cb->fill(cb, key_str, rws.cnt[st]);
+		if (st == BLKG_RWSTAT_READ || st == BLKG_RWSTAT_WRITE)
+			disk_total += rws.cnt[st];
 	}
 
-	blkio_get_key_name(BLKIO_STAT_TOTAL, dname, key_str, MAX_KEY_LEN,
+	blkio_get_key_name(BLKG_RWSTAT_TOTAL, dname, key_str, MAX_KEY_LEN,
 			   false);
 	cb->fill(cb, key_str, disk_total);
 	return disk_total;
block/blk-cgroup.h +166 -45

238 lines not on this page · raw message

Signature · 1 line
1.7.7.3
author maintainer
#8 lore raw

PATCH 4/21 blkcg: restructure statistics printing

In reply to Tejun Heo

blkcg stats handling is a mess. None of the stats has much to do with blkcg core but they are all implemented in blkcg core. Code sharing is achieved by mixing common code with hard-coded cases for each stat counter.

This patch restructures statistics printing such that

* Common logic exists as helper functions and specific print functions use the helpers to implement specific cases.

* Printing functions serving multiple counters don't require hardcoded switching on specific counters.

* Printing uses read_seq_string callback (other methods will be phased out).

This change enables further cleanups and relocating stats code to the policy implementation it belongs to.

---
 block/blk-cgroup.c |  557 ++++++++++++++++++++++------------------------------
 block/blk-cgroup.h |   60 +------
 2 files changed, 243 insertions(+), 374 deletions(-)
block/blk-cgroup.c +239 -318
index 153a2db..f670217 100644
@@ -753,186 +753,227 @@ blkiocg_reset_stats(struct cgroup *cgroup, struct cftype *cftype, u64 val)
 	return 0;
 }
 
-static void blkio_get_key_name(enum blkg_rwstat_type type, const char *dname,
-			       char *str, int chars_left, bool diskname_only)
-{
-	snprintf(str, chars_left, "%s", dname);
-	chars_left -= strlen(str);
-	if (chars_left <= 0) {
-		printk(KERN_WARNING
-			"Possibly incorrect cgroup stat display format");
-		return;
-	}
-	if (diskname_only)
-		return;
-	switch (type) {
-	case BLKG_RWSTAT_READ:
-		strlcat(str, " Read", chars_left);
-		break;
-	case BLKG_RWSTAT_WRITE:
-		strlcat(str, " Write", chars_left);
-		break;
-	case BLKG_RWSTAT_SYNC:
-		strlcat(str, " Sync", chars_left);
-		break;
-	case BLKG_RWSTAT_ASYNC:
-		strlcat(str, " Async", chars_left);
-		break;
-	case BLKG_RWSTAT_TOTAL:
-		strlcat(str, " Total", chars_left);
-		break;
-	default:
-		strlcat(str, " Invalid", chars_left);
-	}
+static const char *blkg_dev_name(struct blkio_group *blkg)
+{
+	/* some drivers (floppy) instantiate a queue w/o disk registered */
+	if (blkg->q->backing_dev_info.dev)
+		return dev_name(blkg->q->backing_dev_info.dev);
+	return NULL;
 }
 
-static uint64_t blkio_read_stat_cpu(struct blkio_group *blkg, int plid,
-				    enum stat_type_cpu type,
-				    enum blkg_rwstat_type sub_type)
+/**
+ * blkcg_print_blkgs - helper for printing per-blkg data
+ * @sf: seq_file to print to
+ * @blkcg: blkcg of interest
+ * @prfill: fill function to print out a blkg
+ * @pol: policy in question
+ * @data: data to be passed to @prfill
+ * @show_total: to print out sum of prfill return values or not
+ *
+ * This function invokes @prfill on each blkg of @blkcg if pd for the
+ * policy specified by @pol exists.  @prfill is invoked with @sf, the
+ * policy data and @data.  If @show_total is %true, the sum of the return
+ * values from @prfill is printed with "Total" label at the end.
+ *
+ * This is to be used to construct print functions for
+ * cftype->read_seq_string method.
+ */
+static void blkcg_print_blkgs(struct seq_file *sf, struct blkio_cgroup *blkcg,
+			      u64 (*prfill)(struct seq_file *,
+					    struct blkg_policy_data *, int),
+			      int pol, int data, bool show_total)
 {
-	struct blkg_policy_data *pd = blkg->pd[plid];
-	u64 val = 0;
-	int cpu;
+	struct blkio_group *blkg;
+	struct hlist_node *n;
+	u64 total = 0;
 
-	if (pd->stats_cpu == NULL)
-		return val;
+	spin_lock_irq(&blkcg->lock);
+	hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node)
+		if (blkg->pd[pol])
+			total += prfill(sf, blkg->pd[pol], data);
+	spin_unlock_irq(&blkcg->lock);
+
+	if (show_total)
+		seq_printf(sf, "Total %llu\n", (unsigned long long)total);
+}
+
+/**
+ * __blkg_prfill_u64 - prfill helper for a single u64 value
+ * @sf: seq_file to print to
+ * @pd: policy data of interest
+ * @v: value to print
+ *
+ * Print @v to @sf for the device assocaited with @pd.
+ */
+static u64 __blkg_prfill_u64(struct seq_file *sf, struct blkg_policy_data *pd,
+			     u64 v)
+{
+	const char *dname = blkg_dev_name(pd->blkg);
+
+	if (!dname)
+		return 0;
+
+	seq_printf(sf, "%s %llu\n", dname, (unsigned long long)v);
+	return v;
+}
+
+/**
+ * __blkg_prfill_rwstat - prfill helper for a blkg_rwstat
+ * @sf: seq_file to print to
+ * @pd: policy data of interest
+ * @rwstat: rwstat to print
+ *
+ * Print @rwstat to @sf for the device assocaited with @pd.
+ */
+static u64 __blkg_prfill_rwstat(struct seq_file *sf,
+				struct blkg_policy_data *pd,
+				const struct blkg_rwstat *rwstat)
+{
+	static const char *rwstr[] = {
+		[BLKG_RWSTAT_READ]	= "Read",
+		[BLKG_RWSTAT_WRITE]	= "Write",
+		[BLKG_RWSTAT_SYNC]	= "Sync",
+		[BLKG_RWSTAT_ASYNC]	= "Async",
+	};
+	const char *dname = blkg_dev_name(pd->blkg);
+	u64 v;
+	int i;
+
+	if (!dname)
+		return 0;
+
+	for (i = 0; i < BLKG_RWSTAT_NR; i++)
+		seq_printf(sf, "%s %s %llu\n", dname, rwstr[i],
+			   (unsigned long long)rwstat->cnt[i]);
+
+	v = rwstat->cnt[BLKG_RWSTAT_READ] + rwstat->cnt[BLKG_RWSTAT_WRITE];
+	seq_printf(sf, "%s Total %llu\n", dname, (unsigned long long)v);
+	return v;
+}
+
+static u64 blkg_prfill_stat(struct seq_file *sf, struct blkg_policy_data *pd,
+			    int off)
+{
+	return __blkg_prfill_u64(sf, pd,
+				 blkg_stat_read((void *)&pd->stats + off));
+}
+
+static u64 blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
+			      int off)
+{
+	struct blkg_rwstat rwstat = blkg_rwstat_read((void *)&pd->stats + off);
+
+	return __blkg_prfill_rwstat(sf, pd, &rwstat);
+}
+
+/* print blkg_stat specified by BLKCG_STAT_PRIV() */
+static int blkcg_print_stat(struct cgroup *cgrp, struct cftype *cft,
+			    struct seq_file *sf)
+{
+	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
+
+	blkcg_print_blkgs(sf, blkcg, blkg_prfill_stat,
+			  BLKCG_STAT_POL(cft->private),
+			  BLKCG_STAT_OFF(cft->private), false);
+	return 0;
+}
+
+/* print blkg_rwstat specified by BLKCG_STAT_PRIV() */
+static int blkcg_print_rwstat(struct cgroup *cgrp, struct cftype *cft,
+			      struct seq_file *sf)
+{
+	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
+
+	blkcg_print_blkgs(sf, blkcg, blkg_prfill_rwstat,
+			  BLKCG_STAT_POL(cft->private),
+			  BLKCG_STAT_OFF(cft->private), true);
+	return 0;
+}
+
+static u64 blkg_prfill_cpu_stat(struct seq_file *sf,
+				struct blkg_policy_data *pd, int off)
+{
+	u64 v = 0;
+	int cpu;
 
 	for_each_possible_cpu(cpu) {
-		struct blkio_group_stats_cpu *stats_cpu =
+		struct blkio_group_stats_cpu *sc =
 			per_cpu_ptr(pd->stats_cpu, cpu);
-		struct blkg_rwstat rws;
 
-		switch (type) {
-		case BLKIO_STAT_CPU_SECTORS:
-			val += blkg_stat_read(&stats_cpu->sectors);
-			break;
-		case BLKIO_STAT_CPU_SERVICE_BYTES:
-			rws = blkg_rwstat_read(&stats_cpu->service_bytes);
-			val += rws.cnt[sub_type];
-			break;
-		case BLKIO_STAT_CPU_SERVICED:
-			rws = blkg_rwstat_read(&stats_cpu->serviced);
-			val += rws.cnt[sub_type];
-			break;
-		}
+		v += blkg_stat_read((void *)sc + off);
 	}
 
-	return val;
+	return __blkg_prfill_u64(sf, pd, v);
 }
 
-static uint64_t blkio_get_stat_cpu(struct blkio_group *blkg, int plid,
-				   struct cgroup_map_cb *cb, const char *dname,
-				   enum stat_type_cpu type)
+static u64 blkg_prfill_cpu_rwstat(struct seq_file *sf,
+				  struct blkg_policy_data *pd, int off)
 {
-	uint64_t disk_total, val;
-	char key_str[MAX_KEY_LEN];
-	enum blkg_rwstat_type sub_type;
+	struct blkg_rwstat rwstat = { }, tmp;
+	int i, cpu;
 
-	if (type == BLKIO_STAT_CPU_SECTORS) {
-		val = blkio_read_stat_cpu(blkg, plid, type, 0);
-		blkio_get_key_name(0, dname, key_str, MAX_KEY_LEN, true);
-		cb->fill(cb, key_str, val);
-		return val;
-	}
+	for_each_possible_cpu(cpu) {
+		struct blkio_group_stats_cpu *sc =
+			per_cpu_ptr(pd->stats_cpu, cpu);
 
-	for (sub_type = BLKG_RWSTAT_READ; sub_type < BLKG_RWSTAT_NR;
-			sub_type++) {
-		blkio_get_key_name(sub_type, dname, key_str, MAX_KEY_LEN,
-				   false);
-		val = blkio_read_stat_cpu(blkg, plid, type, sub_type);
-		cb->fill(cb, key_str, val);
+		tmp = blkg_rwstat_read((void *)sc + off);
+		for (i = 0; i < BLKG_RWSTAT_NR; i++)
+			rwstat.cnt[i] += tmp.cnt[i];
 	}
 
-	disk_total = blkio_read_stat_cpu(blkg, plid, type, BLKG_RWSTAT_READ) +
-		blkio_read_stat_cpu(blkg, plid, type, BLKG_RWSTAT_WRITE);
-
-	blkio_get_key_name(BLKG_RWSTAT_TOTAL, dname, key_str, MAX_KEY_LEN,
-			   false);
-	cb->fill(cb, key_str, disk_total);
-	return disk_total;
+	return __blkg_prfill_rwstat(sf, pd, &rwstat);
 }
 
-static uint64_t blkio_get_stat(struct blkio_group *blkg, int plid,
-			       struct cgroup_map_cb *cb, const char *dname,
-			       enum stat_type type)
+/* print per-cpu blkg_stat specified by BLKCG_STAT_PRIV() */
+static int blkcg_print_cpu_stat(struct cgroup *cgrp, struct cftype *cft,
+				struct seq_file *sf)
 {
-	struct blkio_group_stats *stats = &blkg->pd[plid]->stats;
-	uint64_t v = 0, disk_total = 0;
-	char key_str[MAX_KEY_LEN];
-	struct blkg_rwstat rws = { };
-	int st;
+	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
 
-	if (type >= BLKIO_STAT_ARR_NR) {
-		switch (type) {
-		case BLKIO_STAT_TIME:
-			v = blkg_stat_read(&stats->time);
-			break;
-#ifdef CONFIG_DEBUG_BLK_CGROUP
-		case BLKIO_STAT_UNACCOUNTED_TIME:
-			v = blkg_stat_read(&stats->unaccounted_time);
-			break;
-		case BLKIO_STAT_AVG_QUEUE_SIZE: {
-			uint64_t samples;
+	blkcg_print_blkgs(sf, blkcg, blkg_prfill_cpu_stat,
+			  BLKCG_STAT_POL(cft->private),
+			  BLKCG_STAT_OFF(cft->private), false);
+	return 0;
+}
 
-			samples = blkg_stat_read(&stats->avg_queue_size_samples);
-			if (samples) {
-				v = blkg_stat_read(&stats->avg_queue_size_sum);
-				do_div(v, samples);
-			}
-			break;
-		}
-		case BLKIO_STAT_IDLE_TIME:
-			v = blkg_stat_read(&stats->idle_time);
-			break;
-		case BLKIO_STAT_EMPTY_TIME:
-			v = blkg_stat_read(&stats->empty_time);
-			break;
-		case BLKIO_STAT_DEQUEUE:
-			v = blkg_stat_read(&stats->dequeue);
-			break;
-		case BLKIO_STAT_GROUP_WAIT_TIME:
-			v = blkg_stat_read(&stats->group_wait_time);
-			break;
-#endif
-		default:
-			WARN_ON_ONCE(1);
-		}
+/* print per-cpu blkg_rwstat specified by BLKCG_STAT_PRIV() */
+static int blkcg_print_cpu_rwstat(struct cgroup *cgrp, struct cftype *cft,
+				  struct seq_file *sf)
+{
+	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
 
-		blkio_get_key_name(0, dname, key_str, MAX_KEY_LEN, true);
-		cb->fill(cb, key_str, v);
-		return v;
-	}
+	blkcg_print_blkgs(sf, blkcg, blkg_prfill_cpu_rwstat,
+			  BLKCG_STAT_POL(cft->private),
+			  BLKCG_STAT_OFF(cft->private), true);
+	return 0;
+}
 
-	switch (type) {
-	case BLKIO_STAT_MERGED:
-		rws = blkg_rwstat_read(&stats->merged);
-		break;
-	case BLKIO_STAT_SERVICE_TIME:
-		rws = blkg_rwstat_read(&stats->service_time);
-		break;
-	case BLKIO_STAT_WAIT_TIME:
-		rws = blkg_rwstat_read(&stats->wait_time);
-		break;
-	case BLKIO_STAT_QUEUED:
-		rws = blkg_rwstat_read(&stats->queued);
-		break;
-	default:
-		WARN_ON_ONCE(true);
-		break;
-	}
+#ifdef CONFIG_DEBUG_BLK_CGROUP
+static u64 blkg_prfill_avg_queue_size(struct seq_file *sf,
+				      struct blkg_policy_data *pd, int off)
+{
+	u64 samples = blkg_stat_read(&pd->stats.avg_queue_size_samples);
+	u64 v = 0;
 
-	for (st = BLKG_RWSTAT_READ; st < BLKG_RWSTAT_NR; st++) {
-		blkio_get_key_name(st, dname, key_str, MAX_KEY_LEN, false);
-		cb->fill(cb, key_str, rws.cnt[st]);
-		if (st == BLKG_RWSTAT_READ || st == BLKG_RWSTAT_WRITE)
-			disk_total += rws.cnt[st];
+	if (samples) {
+		v = blkg_stat_read(&pd->stats.avg_queue_size_sum);
+		do_div(v, samples);
 	}
+	__blkg_prfill_u64(sf, pd, v);
+	return 0;
+}
+
+/* print avg_queue_size */
+static int blkcg_print_avg_queue_size(struct cgroup *cgrp, struct cftype *cft,
+				      struct seq_file *sf)
+{
+	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
 
-	blkio_get_key_name(BLKG_RWSTAT_TOTAL, dname, key_str, MAX_KEY_LEN,
-			   false);
-	cb->fill(cb, key_str, disk_total);
-	return disk_total;
+	blkcg_print_blkgs(sf, blkcg, blkg_prfill_avg_queue_size,
+			  BLKIO_POLICY_PROP, 0, false);
+	return 0;
 }
+#endif	/* CONFIG_DEBUG_BLK_CGROUP */
 
 static int blkio_policy_parse_and_set(char *buf, enum blkio_policy_id plid,
 				      int fileid, struct blkio_cgroup *blkcg)
@@ -1074,14 +1115,6 @@ static int blkiocg_file_write(struct cgroup *cgrp, struct cftype *cft,
 	return ret;
 }
 
-static const char *blkg_dev_name(struct blkio_group *blkg)
-{
-	/* some drivers (floppy) instantiate a queue w/o disk registered */
-	if (blkg->q->backing_dev_info.dev)
-		return dev_name(blkg->q->backing_dev_info.dev);
-	return NULL;
-}
-
 static void blkio_print_group_conf(struct cftype *cft, struct blkio_group *blkg,
 				   struct seq_file *m)
 {
@@ -1174,116 +1207,6 @@ static int blkiocg_file_read(struct cgroup *cgrp, struct cftype *cft,
 	return 0;
 }
 
-static int blkio_read_blkg_stats(struct blkio_cgroup *blkcg,
-		struct cftype *cft, struct cgroup_map_cb *cb,
-		enum stat_type type, bool show_total, bool pcpu)
-{
-	struct blkio_group *blkg;
-	struct hlist_node *n;
-	uint64_t cgroup_total = 0;
-
-	spin_lock_irq(&blkcg->lock);
-
-	hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node) {
-		const char *dname = blkg_dev_name(blkg);
-		int plid = BLKIOFILE_POLICY(cft->private);
-
-		if (!dname)
-			continue;
-		if (pcpu)
-			cgroup_total += blkio_get_stat_cpu(blkg, plid,
-							   cb, dname, type);
-		else
-			cgroup_total += blkio_get_stat(blkg, plid,
-						       cb, dname, type);
-	}
-	if (show_total)
-		cb->fill(cb, "Total", cgroup_total);
-
-	spin_unlock_irq(&blkcg->lock);
-	return 0;
-}
-
-/* All map kind of cgroup file get serviced by this function */
-static int blkiocg_file_read_map(struct cgroup *cgrp, struct cftype *cft,
-				struct cgroup_map_cb *cb)
-{
-	struct blkio_cgroup *blkcg;
-	enum blkio_policy_id plid = BLKIOFILE_POLICY(cft->private);
-	int name = BLKIOFILE_ATTR(cft->private);
-
-	blkcg = cgroup_to_blkio_cgroup(cgrp);
-
-	switch(plid) {
-	case BLKIO_POLICY_PROP:
-		switch(name) {
-		case BLKIO_PROP_time:
-			return blkio_read_blkg_stats(blkcg, cft, cb,
-						BLKIO_STAT_TIME, 0, 0);
-		case BLKIO_PROP_sectors:
-			return blkio_read_blkg_stats(blkcg, cft, cb,
-						BLKIO_STAT_CPU_SECTORS, 0, 1);
-		case BLKIO_PROP_io_service_bytes:
-			return blkio_read_blkg_stats(blkcg, cft, cb,
-					BLKIO_STAT_CPU_SERVICE_BYTES, 1, 1);
-		case BLKIO_PROP_io_serviced:
-			return blkio_read_blkg_stats(blkcg, cft, cb,
-						BLKIO_STAT_CPU_SERVICED, 1, 1);
-		case BLKIO_PROP_io_service_time:
-			return blkio_read_blkg_stats(blkcg, cft, cb,
-						BLKIO_STAT_SERVICE_TIME, 1, 0);
-		case BLKIO_PROP_io_wait_time:
-			return blkio_read_blkg_stats(blkcg, cft, cb,
-						BLKIO_STAT_WAIT_TIME, 1, 0);
-		case BLKIO_PROP_io_merged:
-			return blkio_read_blkg_stats(blkcg, cft, cb,
-						BLKIO_STAT_MERGED, 1, 0);
-		case BLKIO_PROP_io_queued:
-			return blkio_read_blkg_stats(blkcg, cft, cb,
-						BLKIO_STAT_QUEUED, 1, 0);
-#ifdef CONFIG_DEBUG_BLK_CGROUP
-		case BLKIO_PROP_unaccounted_time:
-			return blkio_read_blkg_stats(blkcg, cft, cb,
-					BLKIO_STAT_UNACCOUNTED_TIME, 0, 0);
-		case BLKIO_PROP_dequeue:
-			return blkio_read_blkg_stats(blkcg, cft, cb,
-						BLKIO_STAT_DEQUEUE, 0, 0);
-		case BLKIO_PROP_avg_queue_size:
-			return blkio_read_blkg_stats(blkcg, cft, cb,
-					BLKIO_STAT_AVG_QUEUE_SIZE, 0, 0);
-		case BLKIO_PROP_group_wait_time:
-			return blkio_read_blkg_stats(blkcg, cft, cb,
-					BLKIO_STAT_GROUP_WAIT_TIME, 0, 0);
-		case BLKIO_PROP_idle_time:
-			return blkio_read_blkg_stats(blkcg, cft, cb,
-						BLKIO_STAT_IDLE_TIME, 0, 0);
-		case BLKIO_PROP_empty_time:
-			return blkio_read_blkg_stats(blkcg, cft, cb,
-						BLKIO_STAT_EMPTY_TIME, 0, 0);
-#endif
-		default:
-			BUG();
-		}
-		break;
-	case BLKIO_POLICY_THROTL:
-		switch(name){
-		case BLKIO_THROTL_io_service_bytes:
-			return blkio_read_blkg_stats(blkcg, cft, cb,
-						BLKIO_STAT_CPU_SERVICE_BYTES, 1, 1);
-		case BLKIO_THROTL_io_serviced:
-			return blkio_read_blkg_stats(blkcg, cft, cb,
-						BLKIO_STAT_CPU_SERVICED, 1, 1);
-		default:
-			BUG();
-		}
-		break;
-	default:
-		BUG();
-	}
-
-	return 0;
-}
-
 static int blkio_weight_write(struct blkio_cgroup *blkcg, int plid, u64 val)
 {
 	struct blkio_group *blkg;
@@ -1369,51 +1292,51 @@ struct cftype blkio_files[] = {
 	},
 	{
 		.name = "time",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
-				BLKIO_PROP_time),
-		.read_map = blkiocg_file_read_map,
+		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
+				offsetof(struct blkio_group_stats, time)),
+		.read_seq_string = blkcg_print_stat,
 	},
 	{
 		.name = "sectors",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
-				BLKIO_PROP_sectors),
-		.read_map = blkiocg_file_read_map,
+		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
+				offsetof(struct blkio_group_stats_cpu, sectors)),
+		.read_seq_string = blkcg_print_cpu_stat,
 	},
 	{
 		.name = "io_service_bytes",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
-				BLKIO_PROP_io_service_bytes),
-		.read_map = blkiocg_file_read_map,
+		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
+				offsetof(struct blkio_group_stats_cpu, service_bytes)),
+		.read_seq_string = blkcg_print_cpu_rwstat,
 	},
 	{
 		.name = "io_serviced",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
-				BLKIO_PROP_io_serviced),
-		.read_map = blkiocg_file_read_map,
+		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
+				offsetof(struct blkio_group_stats_cpu, serviced)),
+		.read_seq_string = blkcg_print_cpu_rwstat,
 	},
 	{
 		.name = "io_service_time",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
-				BLKIO_PROP_io_service_time),
-		.read_map = blkiocg_file_read_map,
+		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
+				offsetof(struct blkio_group_stats, service_time)),
+		.read_seq_string = blkcg_print_rwstat,
 	},
 	{
 		.name = "io_wait_time",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
-				BLKIO_PROP_io_wait_time),
-		.read_map = blkiocg_file_read_map,
+		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
+				offsetof(struct blkio_group_stats, wait_time)),
+		.read_seq_string = blkcg_print_rwstat,
 	},
 	{
 		.name = "io_merged",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
-				BLKIO_PROP_io_merged),
-		.read_map = blkiocg_file_read_map,
+		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
+				offsetof(struct blkio_group_stats, merged)),
+		.read_seq_string = blkcg_print_rwstat,
 	},
 	{
 		.name = "io_queued",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
-				BLKIO_PROP_io_queued),
-		.read_map = blkiocg_file_read_map,
+		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
+				offsetof(struct blkio_group_stats, queued)),
+		.read_seq_string = blkcg_print_rwstat,
 	},
 	{
 		.name = "reset_stats",
@@ -1457,54 +1380,52 @@ struct cftype blkio_files[] = {
 	},
 	{
 		.name = "throttle.io_service_bytes",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
-				BLKIO_THROTL_io_service_bytes),
-		.read_map = blkiocg_file_read_map,
+		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_THROTL,
+				offsetof(struct blkio_group_stats_cpu, service_bytes)),
+		.read_seq_string = blkcg_print_cpu_rwstat,
 	},
 	{
 		.name = "throttle.io_serviced",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
-				BLKIO_THROTL_io_serviced),
-		.read_map = blkiocg_file_read_map,
+		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_THROTL,
+				offsetof(struct blkio_group_stats_cpu, serviced)),
+		.read_seq_string = blkcg_print_cpu_rwstat,
 	},
 #endif /* CONFIG_BLK_DEV_THROTTLING */
 
 #ifdef CONFIG_DEBUG_BLK_CGROUP
 	{
 		.name = "avg_queue_size",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
-				BLKIO_PROP_avg_queue_size),
-		.read_map = blkiocg_file_read_map,
+		.read_seq_string = blkcg_print_avg_queue_size,
 	},
 	{
 		.name = "group_wait_time",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
-				BLKIO_PROP_group_wait_time),
-		.read_map = blkiocg_file_read_map,
+		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
+				offsetof(struct blkio_group_stats, group_wait_time)),
+		.read_seq_string = blkcg_print_stat,
 	},
 	{
 		.name = "idle_time",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
-				BLKIO_PROP_idle_time),
-		.read_map = blkiocg_file_read_map,
+		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
+				offsetof(struct blkio_group_stats, idle_time)),
+		.read_seq_string = blkcg_print_stat,
 	},
 	{
 		.name = "empty_time",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
-				BLKIO_PROP_empty_time),
-		.read_map = blkiocg_file_read_map,
+		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
+				offsetof(struct blkio_group_stats, empty_time)),
+		.read_seq_string = blkcg_print_stat,
 	},
 	{
 		.name = "dequeue",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
-				BLKIO_PROP_dequeue),
-		.read_map = blkiocg_file_read_map,
+		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
+				offsetof(struct blkio_group_stats, dequeue)),
+		.read_seq_string = blkcg_print_stat,
 	},
 	{
 		.name = "unaccounted_time",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
-				BLKIO_PROP_unaccounted_time),
-		.read_map = blkiocg_file_read_map,
+		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
+				offsetof(struct blkio_group_stats, unaccounted_time)),
+		.read_seq_string = blkcg_print_stat,
 	},
 #endif
 	{ }	/* terminate */
block/blk-cgroup.h +4 -56

78 lines not on this page · raw message

Signature · 1 line
1.7.7.3
author maintainer
#9 lore raw

PATCH 5/21 blkcg: drop blkiocg_file_write_u64()

In reply to Tejun Heo

blkiocg_file_write_u64() has single switch case. Drop blkiocg_file_write_u64(), rename blkio_weight_write() to blkcg_set_weight() and use it directly for .write_u64 callback.

---
 block/blk-cgroup.c |   35 +++++++----------------------------
 1 files changed, 7 insertions(+), 28 deletions(-)
block/blk-cgroup.c +7 -28
index f670217..ae539d3 100644
@@ -1207,8 +1207,9 @@ static int blkiocg_file_read(struct cgroup *cgrp, struct cftype *cft,
 	return 0;
 }
 
-static int blkio_weight_write(struct blkio_cgroup *blkcg, int plid, u64 val)
+static int blkcg_set_weight(struct cgroup *cgrp, struct cftype *cft, u64 val)
 {
+	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
 	struct blkio_group *blkg;
 	struct hlist_node *n;
 
@@ -1220,10 +1221,11 @@ static int blkio_weight_write(struct blkio_cgroup *blkcg, int plid, u64 val)
 	blkcg->weight = (unsigned int)val;
 
 	hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node) {
-		struct blkg_policy_data *pd = blkg->pd[plid];
+		struct blkg_policy_data *pd = blkg->pd[BLKIO_POLICY_PROP];
 
-		if (!pd->conf.weight)
-			blkio_update_group_weight(blkg, plid, blkcg->weight);
+		if (pd && !pd->conf.weight)
+			blkio_update_group_weight(blkg, BLKIO_POLICY_PROP,
+						  blkcg->weight);
 	}
 
 	spin_unlock_irq(&blkcg->lock);
@@ -1251,29 +1253,6 @@ static u64 blkiocg_file_read_u64 (struct cgroup *cgrp, struct cftype *cft) {
 	return 0;
 }
 
-static int
-blkiocg_file_write_u64(struct cgroup *cgrp, struct cftype *cft, u64 val)
-{
-	struct blkio_cgroup *blkcg;
-	enum blkio_policy_id plid = BLKIOFILE_POLICY(cft->private);
-	int name = BLKIOFILE_ATTR(cft->private);
-
-	blkcg = cgroup_to_blkio_cgroup(cgrp);
-
-	switch(plid) {
-	case BLKIO_POLICY_PROP:
-		switch(name) {
-		case BLKIO_PROP_weight:
-			return blkio_weight_write(blkcg, plid, val);
-		}
-		break;
-	default:
-		BUG();
-	}
-
-	return 0;
-}
-
 struct cftype blkio_files[] = {
 	{
 		.name = "weight_device",
@@ -1288,7 +1267,7 @@ struct cftype blkio_files[] = {
 		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
 				BLKIO_PROP_weight),
 		.read_u64 = blkiocg_file_read_u64,
-		.write_u64 = blkiocg_file_write_u64,
+		.write_u64 = blkcg_set_weight,
 	},
 	{
 		.name = "time",
Signature · 1 line
1.7.7.3
author maintainer
#10 lore raw

PATCH 6/21 blkcg: restructure configuration printing

In reply to Tejun Heo

Similarly to the previous stat restructuring, this patch restructures conf printing code such that,

* Conf printing uses the same helpers as stat.

* Printing function doesn't require hardcoded switching on the config being printed. Note that this isn't complete yet for throttle confs. The next patch will convert setting for these confs and will complete the transition.

* Printing uses read_seq_string callback (other methods will be phased out).

Note that blkio_group_conf.iops[2] is changed to u64 so that they can be manipulated with the same functions. This is transitional and will go away later.

After this patch, per-device configurations - weight, bps and iops - use __blkg_prfill_u64() for printing which uses white space as delimiter instead of tab.

---
 block/blk-cgroup.c |  156 ++++++++++++++++++----------------------------------
 block/blk-cgroup.h |    3 +-
 2 files changed, 55 insertions(+), 104 deletions(-)
block/blk-cgroup.c +54 -102
index ae539d3..5e8a818 100644
@@ -1115,95 +1115,28 @@ static int blkiocg_file_write(struct cgroup *cgrp, struct cftype *cft,
 	return ret;
 }
 
-static void blkio_print_group_conf(struct cftype *cft, struct blkio_group *blkg,
-				   struct seq_file *m)
+/* for propio conf */
+static u64 blkg_prfill_weight_device(struct seq_file *sf,
+				     struct blkg_policy_data *pd, int off)
 {
-	int plid = BLKIOFILE_POLICY(cft->private);
-	int fileid = BLKIOFILE_ATTR(cft->private);
-	struct blkg_policy_data *pd = blkg->pd[plid];
-	const char *dname = blkg_dev_name(blkg);
-	int rw = WRITE;
-
-	if (!dname)
-		return;
-
-	switch (plid) {
-		case BLKIO_POLICY_PROP:
-			if (pd->conf.weight)
-				seq_printf(m, "%s\t%u\n",
-					   dname, pd->conf.weight);
-			break;
-		case BLKIO_POLICY_THROTL:
-			switch (fileid) {
-			case BLKIO_THROTL_read_bps_device:
-				rw = READ;
-			case BLKIO_THROTL_write_bps_device:
-				if (pd->conf.bps[rw])
-					seq_printf(m, "%s\t%llu\n",
-						   dname, pd->conf.bps[rw]);
-				break;
-			case BLKIO_THROTL_read_iops_device:
-				rw = READ;
-			case BLKIO_THROTL_write_iops_device:
-				if (pd->conf.iops[rw])
-					seq_printf(m, "%s\t%u\n",
-						   dname, pd->conf.iops[rw]);
-				break;
-			}
-			break;
-		default:
-			BUG();
-	}
+	if (!pd->conf.weight)
+		return 0;
+	return __blkg_prfill_u64(sf, pd, pd->conf.weight);
 }
 
-/* cgroup files which read their data from policy nodes end up here */
-static void blkio_read_conf(struct cftype *cft, struct blkio_cgroup *blkcg,
-			    struct seq_file *m)
+static int blkcg_print_weight_device(struct cgroup *cgrp, struct cftype *cft,
+				     struct seq_file *sf)
 {
-	struct blkio_group *blkg;
-	struct hlist_node *n;
-
-	spin_lock_irq(&blkcg->lock);
-	hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node)
-		blkio_print_group_conf(cft, blkg, m);
-	spin_unlock_irq(&blkcg->lock);
+	blkcg_print_blkgs(sf, cgroup_to_blkio_cgroup(cgrp),
+			  blkg_prfill_weight_device, BLKIO_POLICY_PROP, 0,
+			  false);
+	return 0;
 }
 
-static int blkiocg_file_read(struct cgroup *cgrp, struct cftype *cft,
-				struct seq_file *m)
+static int blkcg_print_weight(struct cgroup *cgrp, struct cftype *cft,
+			      struct seq_file *sf)
 {
-	struct blkio_cgroup *blkcg;
-	enum blkio_policy_id plid = BLKIOFILE_POLICY(cft->private);
-	int name = BLKIOFILE_ATTR(cft->private);
-
-	blkcg = cgroup_to_blkio_cgroup(cgrp);
-
-	switch(plid) {
-	case BLKIO_POLICY_PROP:
-		switch(name) {
-		case BLKIO_PROP_weight_device:
-			blkio_read_conf(cft, blkcg, m);
-			return 0;
-		default:
-			BUG();
-		}
-		break;
-	case BLKIO_POLICY_THROTL:
-		switch(name){
-		case BLKIO_THROTL_read_bps_device:
-		case BLKIO_THROTL_write_bps_device:
-		case BLKIO_THROTL_read_iops_device:
-		case BLKIO_THROTL_write_iops_device:
-			blkio_read_conf(cft, blkcg, m);
-			return 0;
-		default:
-			BUG();
-		}
-		break;
-	default:
-		BUG();
-	}
-
+	seq_printf(sf, "%u\n", cgroup_to_blkio_cgroup(cgrp)->weight);
 	return 0;
 }
 
@@ -1233,40 +1166,59 @@ static int blkcg_set_weight(struct cgroup *cgrp, struct cftype *cft, u64 val)
 	return 0;
 }
 
-static u64 blkiocg_file_read_u64 (struct cgroup *cgrp, struct cftype *cft) {
-	struct blkio_cgroup *blkcg;
-	enum blkio_policy_id plid = BLKIOFILE_POLICY(cft->private);
-	int name = BLKIOFILE_ATTR(cft->private);
+/* for blk-throttle conf */
+#ifdef CONFIG_BLK_DEV_THROTTLING
+static u64 blkg_prfill_conf_u64(struct seq_file *sf,
+				struct blkg_policy_data *pd, int off)
+{
+	u64 v = *(u64 *)((void *)&pd->conf + off);
 
-	blkcg = cgroup_to_blkio_cgroup(cgrp);
+	if (!v)
+		return 0;
+	return __blkg_prfill_u64(sf, pd, v);
+}
 
-	switch(plid) {
-	case BLKIO_POLICY_PROP:
-		switch(name) {
-		case BLKIO_PROP_weight:
-			return (u64)blkcg->weight;
-		}
+static int blkcg_print_conf_u64(struct cgroup *cgrp, struct cftype *cft,
+				struct seq_file *sf)
+{
+	int off;
+
+	switch (BLKIOFILE_ATTR(cft->private)) {
+	case BLKIO_THROTL_read_bps_device:
+		off = offsetof(struct blkio_group_conf, bps[READ]);
+		break;
+	case BLKIO_THROTL_write_bps_device:
+		off = offsetof(struct blkio_group_conf, bps[WRITE]);
+		break;
+	case BLKIO_THROTL_read_iops_device:
+		off = offsetof(struct blkio_group_conf, iops[READ]);
+		break;
+	case BLKIO_THROTL_write_iops_device:
+		off = offsetof(struct blkio_group_conf, iops[WRITE]);
 		break;
 	default:
-		BUG();
+		return -EINVAL;
 	}
+
+	blkcg_print_blkgs(sf, cgroup_to_blkio_cgroup(cgrp),
+			  blkg_prfill_conf_u64, BLKIO_POLICY_THROTL,
+			  off, false);
 	return 0;
 }
+#endif
 
 struct cftype blkio_files[] = {
 	{
 		.name = "weight_device",
 		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
 				BLKIO_PROP_weight_device),
-		.read_seq_string = blkiocg_file_read,
+		.read_seq_string = blkcg_print_weight_device,
 		.write_string = blkiocg_file_write,
 		.max_write_len = 256,
 	},
 	{
 		.name = "weight",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
-				BLKIO_PROP_weight),
-		.read_u64 = blkiocg_file_read_u64,
+		.read_seq_string = blkcg_print_weight,
 		.write_u64 = blkcg_set_weight,
 	},
 	{
@@ -1326,7 +1278,7 @@ struct cftype blkio_files[] = {
 		.name = "throttle.read_bps_device",
 		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
 				BLKIO_THROTL_read_bps_device),
-		.read_seq_string = blkiocg_file_read,
+		.read_seq_string = blkcg_print_conf_u64,
 		.write_string = blkiocg_file_write,
 		.max_write_len = 256,
 	},
@@ -1335,7 +1287,7 @@ struct cftype blkio_files[] = {
 		.name = "throttle.write_bps_device",
 		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
 				BLKIO_THROTL_write_bps_device),
-		.read_seq_string = blkiocg_file_read,
+		.read_seq_string = blkcg_print_conf_u64,
 		.write_string = blkiocg_file_write,
 		.max_write_len = 256,
 	},
@@ -1344,7 +1296,7 @@ struct cftype blkio_files[] = {
 		.name = "throttle.read_iops_device",
 		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
 				BLKIO_THROTL_read_iops_device),
-		.read_seq_string = blkiocg_file_read,
+		.read_seq_string = blkcg_print_conf_u64,
 		.write_string = blkiocg_file_write,
 		.max_write_len = 256,
 	},
@@ -1353,7 +1305,7 @@ struct cftype blkio_files[] = {
 		.name = "throttle.write_iops_device",
 		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
 				BLKIO_THROTL_write_iops_device),
-		.read_seq_string = blkiocg_file_read,
+		.read_seq_string = blkcg_print_conf_u64,
 		.write_string = blkiocg_file_write,
 		.max_write_len = 256,
 	},
block/blk-cgroup.h +1 -2
index 7331d79..b67eefa 100644
@@ -52,7 +52,6 @@ enum blkg_state_flags {
 
 /* cgroup files owned by proportional weight policy */
 enum blkcg_file_name_prop {
-	BLKIO_PROP_weight = 1,
 	BLKIO_PROP_weight_device,
 };
 
@@ -130,7 +129,7 @@ struct blkio_group_stats_cpu {
 
 struct blkio_group_conf {
 	unsigned int weight;
-	unsigned int iops[2];
+	u64 iops[2];
 	u64 bps[2];
 };
 
Signature · 1 line
1.7.7.3
author maintainer
#11 lore raw

PATCH 7/21 blkcg: restructure blkio_group configruation setting

In reply to Tejun Heo

As part of userland interface restructuring, this patch updates per-blkio_group configuration setting. Instead of funneling everything through a master function which has hard-coded cases for each config file it may handle, the common part is factored into blkg_conf_prep() and blkg_conf_finish() and different configuration setters are implemented using the helpers.

While this doesn't result in immediate LOC reduction, this enables further cleanups and more modular implementation.

---
 block/blk-cgroup.c |  274 ++++++++++++++++++++++++++++------------------------
 block/blk-cgroup.h |   13 ---
 2 files changed, 147 insertions(+), 140 deletions(-)
block/blk-cgroup.c +147 -127
index 5e8a818..0d4f21e 100644
@@ -43,12 +43,6 @@ EXPORT_SYMBOL_GPL(blkio_root_cgroup);
 
 static struct blkio_policy_type *blkio_policy[BLKIO_NR_POLICIES];
 
-/* for encoding cft->private value on file */
-#define BLKIOFILE_PRIVATE(x, val)	(((x) << 16) | (val))
-/* What policy owns the file, proportional or throttle */
-#define BLKIOFILE_POLICY(val)		(((val) >> 16) & 0xffff)
-#define BLKIOFILE_ATTR(val)		((val) & 0xffff)
-
 struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup)
 {
 	return container_of(cgroup_subsys_state(cgroup, blkio_subsys_id),
@@ -86,7 +80,7 @@ static inline void blkio_update_group_weight(struct blkio_group *blkg,
 }
 
 static inline void blkio_update_group_bps(struct blkio_group *blkg, int plid,
-					  u64 bps, int fileid)
+					  u64 bps, int rw)
 {
 	struct blkio_policy_type *blkiop;
 
@@ -96,21 +90,18 @@ static inline void blkio_update_group_bps(struct blkio_group *blkg, int plid,
 		if (blkiop->plid != plid)
 			continue;
 
-		if (fileid == BLKIO_THROTL_read_bps_device
-		    && blkiop->ops.blkio_update_group_read_bps_fn)
+		if (rw == READ && blkiop->ops.blkio_update_group_read_bps_fn)
 			blkiop->ops.blkio_update_group_read_bps_fn(blkg->q,
 								blkg, bps);
 
-		if (fileid == BLKIO_THROTL_write_bps_device
-		    && blkiop->ops.blkio_update_group_write_bps_fn)
+		if (rw == WRITE && blkiop->ops.blkio_update_group_write_bps_fn)
 			blkiop->ops.blkio_update_group_write_bps_fn(blkg->q,
 								blkg, bps);
 	}
 }
 
-static inline void blkio_update_group_iops(struct blkio_group *blkg,
-					   int plid, unsigned int iops,
-					   int fileid)
+static inline void blkio_update_group_iops(struct blkio_group *blkg, int plid,
+					   u64 iops, int rw)
 {
 	struct blkio_policy_type *blkiop;
 
@@ -120,13 +111,11 @@ static inline void blkio_update_group_iops(struct blkio_group *blkg,
 		if (blkiop->plid != plid)
 			continue;
 
-		if (fileid == BLKIO_THROTL_read_iops_device
-		    && blkiop->ops.blkio_update_group_read_iops_fn)
+		if (rw == READ && blkiop->ops.blkio_update_group_read_iops_fn)
 			blkiop->ops.blkio_update_group_read_iops_fn(blkg->q,
 								blkg, iops);
 
-		if (fileid == BLKIO_THROTL_write_iops_device
-		    && blkiop->ops.blkio_update_group_write_iops_fn)
+		if (rw == WRITE && blkiop->ops.blkio_update_group_write_iops_fn)
 			blkiop->ops.blkio_update_group_write_iops_fn(blkg->q,
 								blkg,iops);
 	}
@@ -975,19 +964,40 @@ static int blkcg_print_avg_queue_size(struct cgroup *cgrp, struct cftype *cft,
 }
 #endif	/* CONFIG_DEBUG_BLK_CGROUP */
 
-static int blkio_policy_parse_and_set(char *buf, enum blkio_policy_id plid,
-				      int fileid, struct blkio_cgroup *blkcg)
+struct blkg_conf_ctx {
+	struct gendisk		*disk;
+	struct blkio_group	*blkg;
+	u64			v;
+};
+
+/**
+ * blkg_conf_prep - parse and prepare for per-blkg config update
+ * @blkcg: target block cgroup
+ * @input: input string
+ * @ctx: blkg_conf_ctx to be filled
+ *
+ * Parse per-blkg config update from @input and initialize @ctx with the
+ * result.  @ctx->blkg points to the blkg to be updated and @ctx->v the new
+ * value.  This function returns with RCU read locked and must be paired
+ * with blkg_conf_finish().
+ */
+static int blkg_conf_prep(struct blkio_cgroup *blkcg, const char *input,
+			  struct blkg_conf_ctx *ctx)
+	__acquires(rcu)
 {
-	struct gendisk *disk = NULL;
-	struct blkio_group *blkg = NULL;
-	struct blkg_policy_data *pd;
-	char *s[4], *p, *major_s = NULL, *minor_s = NULL;
+	struct gendisk *disk;
+	struct blkio_group *blkg;
+	char *buf, *s[4], *p, *major_s, *minor_s;
 	unsigned long major, minor;
 	int i = 0, ret = -EINVAL;
 	int part;
 	dev_t dev;
 	u64 temp;
 
+	buf = kstrdup(input, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
 	memset(s, 0, sizeof(s));
 
 	while ((p = strsep(&buf, " ")) != NULL) {
@@ -1037,82 +1047,42 @@ static int blkio_policy_parse_and_set(char *buf, enum blkio_policy_id plid,
 
 	if (IS_ERR(blkg)) {
 		ret = PTR_ERR(blkg);
-		goto out_unlock;
-	}
-
-	pd = blkg->pd[plid];
-
-	switch (plid) {
-	case BLKIO_POLICY_PROP:
-		if ((temp < BLKIO_WEIGHT_MIN && temp > 0) ||
-		     temp > BLKIO_WEIGHT_MAX)
-			goto out_unlock;
-
-		pd->conf.weight = temp;
-		blkio_update_group_weight(blkg, plid, temp ?: blkcg->weight);
-		break;
-	case BLKIO_POLICY_THROTL:
-		switch(fileid) {
-		case BLKIO_THROTL_read_bps_device:
-			pd->conf.bps[READ] = temp;
-			blkio_update_group_bps(blkg, plid, temp ?: -1, fileid);
-			break;
-		case BLKIO_THROTL_write_bps_device:
-			pd->conf.bps[WRITE] = temp;
-			blkio_update_group_bps(blkg, plid, temp ?: -1, fileid);
-			break;
-		case BLKIO_THROTL_read_iops_device:
-			if (temp > THROTL_IOPS_MAX)
-				goto out_unlock;
-			pd->conf.iops[READ] = temp;
-			blkio_update_group_iops(blkg, plid, temp ?: -1, fileid);
-			break;
-		case BLKIO_THROTL_write_iops_device:
-			if (temp > THROTL_IOPS_MAX)
-				goto out_unlock;
-			pd->conf.iops[WRITE] = temp;
-			blkio_update_group_iops(blkg, plid, temp ?: -1, fileid);
-			break;
+		rcu_read_unlock();
+		put_disk(disk);
+		/*
+		 * If queue was bypassing, we should retry.  Do so after a
+		 * short msleep().  It isn't strictly necessary but queue
+		 * can be bypassing for some time and it's always nice to
+		 * avoid busy looping.
+		 */
+		if (ret == -EBUSY) {
+			msleep(10);
+			ret = restart_syscall();
 		}
-		break;
-	default:
-		BUG();
+		goto out;
 	}
+
+	ctx->disk = disk;
+	ctx->blkg = blkg;
+	ctx->v = temp;
 	ret = 0;
-out_unlock:
-	rcu_read_unlock();
 out:
-	put_disk(disk);
-
-	/*
-	 * If queue was bypassing, we should retry.  Do so after a short
-	 * msleep().  It isn't strictly necessary but queue can be
-	 * bypassing for some time and it's always nice to avoid busy
-	 * looping.
-	 */
-	if (ret == -EBUSY) {
-		msleep(10);
-		return restart_syscall();
-	}
+	kfree(buf);
 	return ret;
 }
 
-static int blkiocg_file_write(struct cgroup *cgrp, struct cftype *cft,
- 				       const char *buffer)
+/**
+ * blkg_conf_finish - finish up per-blkg config update
+ * @ctx: blkg_conf_ctx intiailized by blkg_conf_prep()
+ *
+ * Finish up after per-blkg config update.  This function must be paired
+ * with blkg_conf_prep().
+ */
+static void blkg_conf_finish(struct blkg_conf_ctx *ctx)
+	__releases(rcu)
 {
-	int ret = 0;
-	char *buf;
-	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
-	enum blkio_policy_id plid = BLKIOFILE_POLICY(cft->private);
-	int fileid = BLKIOFILE_ATTR(cft->private);
-
-	buf = kstrdup(buffer, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
-
-	ret = blkio_policy_parse_and_set(buf, plid, fileid, blkcg);
-	kfree(buf);
-	return ret;
+	rcu_read_unlock();
+	put_disk(ctx->disk);
 }
 
 /* for propio conf */
@@ -1140,6 +1110,32 @@ static int blkcg_print_weight(struct cgroup *cgrp, struct cftype *cft,
 	return 0;
 }
 
+static int blkcg_set_weight_device(struct cgroup *cgrp, struct cftype *cft,
+				   const char *buf)
+{
+	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
+	struct blkg_policy_data *pd;
+	struct blkg_conf_ctx ctx;
+	int ret;
+
+	ret = blkg_conf_prep(blkcg, buf, &ctx);
+	if (ret)
+		return ret;
+
+	ret = -EINVAL;
+	pd = ctx.blkg->pd[BLKIO_POLICY_PROP];
+	if (pd && (!ctx.v || (ctx.v >= BLKIO_WEIGHT_MIN &&
+			      ctx.v <= BLKIO_WEIGHT_MAX))) {
+		pd->conf.weight = ctx.v;
+		blkio_update_group_weight(ctx.blkg, BLKIO_POLICY_PROP,
+					  ctx.v ?: blkcg->weight);
+		ret = 0;
+	}
+
+	blkg_conf_finish(&ctx);
+	return ret;
+}
+
 static int blkcg_set_weight(struct cgroup *cgrp, struct cftype *cft, u64 val)
 {
 	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
@@ -1181,39 +1177,67 @@ static u64 blkg_prfill_conf_u64(struct seq_file *sf,
 static int blkcg_print_conf_u64(struct cgroup *cgrp, struct cftype *cft,
 				struct seq_file *sf)
 {
-	int off;
-
-	switch (BLKIOFILE_ATTR(cft->private)) {
-	case BLKIO_THROTL_read_bps_device:
-		off = offsetof(struct blkio_group_conf, bps[READ]);
-		break;
-	case BLKIO_THROTL_write_bps_device:
-		off = offsetof(struct blkio_group_conf, bps[WRITE]);
-		break;
-	case BLKIO_THROTL_read_iops_device:
-		off = offsetof(struct blkio_group_conf, iops[READ]);
-		break;
-	case BLKIO_THROTL_write_iops_device:
-		off = offsetof(struct blkio_group_conf, iops[WRITE]);
-		break;
-	default:
-		return -EINVAL;
-	}
-
 	blkcg_print_blkgs(sf, cgroup_to_blkio_cgroup(cgrp),
 			  blkg_prfill_conf_u64, BLKIO_POLICY_THROTL,
-			  off, false);
+			  cft->private, false);
 	return 0;
 }
+
+static int blkcg_set_conf_u64(struct cgroup *cgrp, struct cftype *cft,
+			      const char *buf, int rw,
+			      void (*update)(struct blkio_group *, int, u64, int))
+{
+	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
+	struct blkg_policy_data *pd;
+	struct blkg_conf_ctx ctx;
+	int ret;
+
+	ret = blkg_conf_prep(blkcg, buf, &ctx);
+	if (ret)
+		return ret;
+
+	ret = -EINVAL;
+	pd = ctx.blkg->pd[BLKIO_POLICY_THROTL];
+	if (pd) {
+		*(u64 *)((void *)&pd->conf + cft->private) = ctx.v;
+		update(ctx.blkg, BLKIO_POLICY_THROTL, ctx.v ?: -1, rw);
+		ret = 0;
+	}
+
+	blkg_conf_finish(&ctx);
+	return ret;
+}
+
+static int blkcg_set_conf_bps_r(struct cgroup *cgrp, struct cftype *cft,
+				const char *buf)
+{
+	return blkcg_set_conf_u64(cgrp, cft, buf, READ, blkio_update_group_bps);
+}
+
+static int blkcg_set_conf_bps_w(struct cgroup *cgrp, struct cftype *cft,
+				const char *buf)
+{
+	return blkcg_set_conf_u64(cgrp, cft, buf, WRITE, blkio_update_group_bps);
+}
+
+static int blkcg_set_conf_iops_r(struct cgroup *cgrp, struct cftype *cft,
+				 const char *buf)
+{
+	return blkcg_set_conf_u64(cgrp, cft, buf, READ, blkio_update_group_iops);
+}
+
+static int blkcg_set_conf_iops_w(struct cgroup *cgrp, struct cftype *cft,
+				 const char *buf)
+{
+	return blkcg_set_conf_u64(cgrp, cft, buf, WRITE, blkio_update_group_iops);
+}
 #endif
 
 struct cftype blkio_files[] = {
 	{
 		.name = "weight_device",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_PROP,
-				BLKIO_PROP_weight_device),
 		.read_seq_string = blkcg_print_weight_device,
-		.write_string = blkiocg_file_write,
+		.write_string = blkcg_set_weight_device,
 		.max_write_len = 256,
 	},
 	{
@@ -1276,37 +1300,33 @@ struct cftype blkio_files[] = {
 #ifdef CONFIG_BLK_DEV_THROTTLING
 	{
 		.name = "throttle.read_bps_device",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
-				BLKIO_THROTL_read_bps_device),
+		.private = offsetof(struct blkio_group_conf, bps[READ]),
 		.read_seq_string = blkcg_print_conf_u64,
-		.write_string = blkiocg_file_write,
+		.write_string = blkcg_set_conf_bps_r,
 		.max_write_len = 256,
 	},
 
 	{
 		.name = "throttle.write_bps_device",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
-				BLKIO_THROTL_write_bps_device),
+		.private = offsetof(struct blkio_group_conf, bps[WRITE]),
 		.read_seq_string = blkcg_print_conf_u64,
-		.write_string = blkiocg_file_write,
+		.write_string = blkcg_set_conf_bps_w,
 		.max_write_len = 256,
 	},
 
 	{
 		.name = "throttle.read_iops_device",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
-				BLKIO_THROTL_read_iops_device),
+		.private = offsetof(struct blkio_group_conf, iops[READ]),
 		.read_seq_string = blkcg_print_conf_u64,
-		.write_string = blkiocg_file_write,
+		.write_string = blkcg_set_conf_iops_r,
 		.max_write_len = 256,
 	},
 
 	{
 		.name = "throttle.write_iops_device",
-		.private = BLKIOFILE_PRIVATE(BLKIO_POLICY_THROTL,
-				BLKIO_THROTL_write_iops_device),
+		.private = offsetof(struct blkio_group_conf, iops[WRITE]),
 		.read_seq_string = blkcg_print_conf_u64,
-		.write_string = blkiocg_file_write,
+		.write_string = blkcg_set_conf_iops_w,
 		.max_write_len = 256,
 	},
 	{
block/blk-cgroup.h +0 -13
index b67eefa..108ffbf 100644
@@ -50,19 +50,6 @@ enum blkg_state_flags {
 	BLKG_empty,
 };
 
-/* cgroup files owned by proportional weight policy */
-enum blkcg_file_name_prop {
-	BLKIO_PROP_weight_device,
-};
-
-/* cgroup files owned by throttle policy */
-enum blkcg_file_name_throtl {
-	BLKIO_THROTL_read_bps_device,
-	BLKIO_THROTL_write_bps_device,
-	BLKIO_THROTL_read_iops_device,
-	BLKIO_THROTL_write_iops_device,
-};
-
 struct blkio_cgroup {
 	struct cgroup_subsys_state css;
 	unsigned int weight;
Signature · 1 line
1.7.7.3
author maintainer
#12 lore raw

PATCH 8/21 blkcg: blkg_conf_prep()

In reply to Tejun Heo

blkg_conf_prep() implements "MAJ:MIN VAL" parsing manually, which is unnecessary. Just use sscanf("%u:%u %llu"). This might not reject some malformed input (extra input at the end) but we don't care.

---
 block/blk-cgroup.c |   64 ++++++++-------------------------------------------
 1 files changed, 10 insertions(+), 54 deletions(-)
block/blk-cgroup.c +10 -54
index 0d4f21e..3d933b0 100644
@@ -987,57 +987,16 @@ static int blkg_conf_prep(struct blkio_cgroup *blkcg, const char *input,
 {
 	struct gendisk *disk;
 	struct blkio_group *blkg;
-	char *buf, *s[4], *p, *major_s, *minor_s;
-	unsigned long major, minor;
-	int i = 0, ret = -EINVAL;
-	int part;
-	dev_t dev;
-	u64 temp;
+	unsigned int major, minor;
+	unsigned long long v;
+	int part, ret;
 
-	buf = kstrdup(input, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
-
-	memset(s, 0, sizeof(s));
-
-	while ((p = strsep(&buf, " ")) != NULL) {
-		if (!*p)
-			continue;
-
-		s[i++] = p;
-
-		/* Prevent from inputing too many things */
-		if (i == 3)
-			break;
-	}
-
-	if (i != 2)
-		goto out;
-
-	p = strsep(&s[0], ":");
-	if (p != NULL)
-		major_s = p;
-	else
-		goto out;
-
-	minor_s = s[0];
-	if (!minor_s)
-		goto out;
-
-	if (strict_strtoul(major_s, 10, &major))
-		goto out;
-
-	if (strict_strtoul(minor_s, 10, &minor))
-		goto out;
-
-	dev = MKDEV(major, minor);
-
-	if (strict_strtoull(s[1], 10, &temp))
-		goto out;
+	if (sscanf(input, "%u:%u %llu", &major, &minor, &v) != 3)
+		return -EINVAL;
 
-	disk = get_gendisk(dev, &part);
+	disk = get_gendisk(MKDEV(major, minor), &part);
 	if (!disk || part)
-		goto out;
+		return -EINVAL;
 
 	rcu_read_lock();
 
@@ -1059,16 +1018,13 @@ static int blkg_conf_prep(struct blkio_cgroup *blkcg, const char *input,
 			msleep(10);
 			ret = restart_syscall();
 		}
-		goto out;
+		return ret;
 	}
 
 	ctx->disk = disk;
 	ctx->blkg = blkg;
-	ctx->v = temp;
-	ret = 0;
-out:
-	kfree(buf);
-	return ret;
+	ctx->v = v;
+	return 0;
 }
 
 /**
Signature · 1 line
1.7.7.3
author maintainer
#14 lore raw

PATCH 9/21 blkcg: export conf/stat helpers to prepare for reorganization

In reply to Tejun Heo

conf/stat handling is about to be moved to policy implementation from blkcg core. Export conf/stat helpers from blkcg core so that blk-throttle and cfq-iosched can use them.

---
 block/blk-cgroup.c |   52 +++++++++++++++++++++++++---------------------------
 block/blk-cgroup.h |   27 +++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 27 deletions(-)
block/blk-cgroup.c +25 -27
index 3d933b0..df1e197 100644
@@ -11,7 +11,6 @@
  * 	              Nauman Rafique <[email protected]>
  */
 #include <linux/ioprio.h>
-#include <linux/seq_file.h>
 #include <linux/kdev_t.h>
 #include <linux/module.h>
 #include <linux/err.h>
@@ -767,10 +766,9 @@ static const char *blkg_dev_name(struct blkio_group *blkg)
  * This is to be used to construct print functions for
  * cftype->read_seq_string method.
  */
-static void blkcg_print_blkgs(struct seq_file *sf, struct blkio_cgroup *blkcg,
-			      u64 (*prfill)(struct seq_file *,
-					    struct blkg_policy_data *, int),
-			      int pol, int data, bool show_total)
+void blkcg_print_blkgs(struct seq_file *sf, struct blkio_cgroup *blkcg,
+		       u64 (*prfill)(struct seq_file *, struct blkg_policy_data *, int),
+		       int pol, int data, bool show_total)
 {
 	struct blkio_group *blkg;
 	struct hlist_node *n;
@@ -785,6 +783,7 @@ static void blkcg_print_blkgs(struct seq_file *sf, struct blkio_cgroup *blkcg,
 	if (show_total)
 		seq_printf(sf, "Total %llu\n", (unsigned long long)total);
 }
+EXPORT_SYMBOL_GPL(blkcg_print_blkgs);
 
 /**
  * __blkg_prfill_u64 - prfill helper for a single u64 value
@@ -794,8 +793,7 @@ static void blkcg_print_blkgs(struct seq_file *sf, struct blkio_cgroup *blkcg,
  *
  * Print @v to @sf for the device assocaited with @pd.
  */
-static u64 __blkg_prfill_u64(struct seq_file *sf, struct blkg_policy_data *pd,
-			     u64 v)
+u64 __blkg_prfill_u64(struct seq_file *sf, struct blkg_policy_data *pd, u64 v)
 {
 	const char *dname = blkg_dev_name(pd->blkg);
 
@@ -805,6 +803,7 @@ static u64 __blkg_prfill_u64(struct seq_file *sf, struct blkg_policy_data *pd,
 	seq_printf(sf, "%s %llu\n", dname, (unsigned long long)v);
 	return v;
 }
+EXPORT_SYMBOL_GPL(__blkg_prfill_u64);
 
 /**
  * __blkg_prfill_rwstat - prfill helper for a blkg_rwstat
@@ -814,9 +813,8 @@ static u64 __blkg_prfill_u64(struct seq_file *sf, struct blkg_policy_data *pd,
  *
  * Print @rwstat to @sf for the device assocaited with @pd.
  */
-static u64 __blkg_prfill_rwstat(struct seq_file *sf,
-				struct blkg_policy_data *pd,
-				const struct blkg_rwstat *rwstat)
+u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
+			 const struct blkg_rwstat *rwstat)
 {
 	static const char *rwstr[] = {
 		[BLKG_RWSTAT_READ]	= "Read",
@@ -856,8 +854,8 @@ static u64 blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
 }
 
 /* print blkg_stat specified by BLKCG_STAT_PRIV() */
-static int blkcg_print_stat(struct cgroup *cgrp, struct cftype *cft,
-			    struct seq_file *sf)
+int blkcg_print_stat(struct cgroup *cgrp, struct cftype *cft,
+		     struct seq_file *sf)
 {
 	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
 
@@ -866,10 +864,11 @@ static int blkcg_print_stat(struct cgroup *cgrp, struct cftype *cft,
 			  BLKCG_STAT_OFF(cft->private), false);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(blkcg_print_stat);
 
 /* print blkg_rwstat specified by BLKCG_STAT_PRIV() */
-static int blkcg_print_rwstat(struct cgroup *cgrp, struct cftype *cft,
-			      struct seq_file *sf)
+int blkcg_print_rwstat(struct cgroup *cgrp, struct cftype *cft,
+		       struct seq_file *sf)
 {
 	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
 
@@ -878,6 +877,7 @@ static int blkcg_print_rwstat(struct cgroup *cgrp, struct cftype *cft,
 			  BLKCG_STAT_OFF(cft->private), true);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(blkcg_print_rwstat);
 
 static u64 blkg_prfill_cpu_stat(struct seq_file *sf,
 				struct blkg_policy_data *pd, int off)
@@ -914,8 +914,8 @@ static u64 blkg_prfill_cpu_rwstat(struct seq_file *sf,
 }
 
 /* print per-cpu blkg_stat specified by BLKCG_STAT_PRIV() */
-static int blkcg_print_cpu_stat(struct cgroup *cgrp, struct cftype *cft,
-				struct seq_file *sf)
+int blkcg_print_cpu_stat(struct cgroup *cgrp, struct cftype *cft,
+			 struct seq_file *sf)
 {
 	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
 
@@ -924,10 +924,11 @@ static int blkcg_print_cpu_stat(struct cgroup *cgrp, struct cftype *cft,
 			  BLKCG_STAT_OFF(cft->private), false);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(blkcg_print_cpu_stat);
 
 /* print per-cpu blkg_rwstat specified by BLKCG_STAT_PRIV() */
-static int blkcg_print_cpu_rwstat(struct cgroup *cgrp, struct cftype *cft,
-				  struct seq_file *sf)
+int blkcg_print_cpu_rwstat(struct cgroup *cgrp, struct cftype *cft,
+			   struct seq_file *sf)
 {
 	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
 
@@ -936,6 +937,7 @@ static int blkcg_print_cpu_rwstat(struct cgroup *cgrp, struct cftype *cft,
 			  BLKCG_STAT_OFF(cft->private), true);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(blkcg_print_cpu_rwstat);
 
 #ifdef CONFIG_DEBUG_BLK_CGROUP
 static u64 blkg_prfill_avg_queue_size(struct seq_file *sf,
@@ -964,12 +966,6 @@ static int blkcg_print_avg_queue_size(struct cgroup *cgrp, struct cftype *cft,
 }
 #endif	/* CONFIG_DEBUG_BLK_CGROUP */
 
-struct blkg_conf_ctx {
-	struct gendisk		*disk;
-	struct blkio_group	*blkg;
-	u64			v;
-};
-
 /**
  * blkg_conf_prep - parse and prepare for per-blkg config update
  * @blkcg: target block cgroup
@@ -981,8 +977,8 @@ struct blkg_conf_ctx {
  * value.  This function returns with RCU read locked and must be paired
  * with blkg_conf_finish().
  */
-static int blkg_conf_prep(struct blkio_cgroup *blkcg, const char *input,
-			  struct blkg_conf_ctx *ctx)
+int blkg_conf_prep(struct blkio_cgroup *blkcg, const char *input,
+		   struct blkg_conf_ctx *ctx)
 	__acquires(rcu)
 {
 	struct gendisk *disk;
@@ -1026,6 +1022,7 @@ static int blkg_conf_prep(struct blkio_cgroup *blkcg, const char *input,
 	ctx->v = v;
 	return 0;
 }
+EXPORT_SYMBOL_GPL(blkg_conf_prep);
 
 /**
  * blkg_conf_finish - finish up per-blkg config update
@@ -1034,12 +1031,13 @@ static int blkg_conf_prep(struct blkio_cgroup *blkcg, const char *input,
  * Finish up after per-blkg config update.  This function must be paired
  * with blkg_conf_prep().
  */
-static void blkg_conf_finish(struct blkg_conf_ctx *ctx)
+void blkg_conf_finish(struct blkg_conf_ctx *ctx)
 	__releases(rcu)
 {
 	rcu_read_unlock();
 	put_disk(ctx->disk);
 }
+EXPORT_SYMBOL_GPL(blkg_conf_finish);
 
 /* for propio conf */
 static u64 blkg_prfill_weight_device(struct seq_file *sf,
block/blk-cgroup.h +27 -0
index 108ffbf..361ecfa 100644
@@ -15,6 +15,7 @@
 
 #include <linux/cgroup.h>
 #include <linux/u64_stats_sync.h>
+#include <linux/seq_file.h>
 
 enum blkio_policy_id {
 	BLKIO_POLICY_PROP = 0,		/* Proportional Bandwidth division */
@@ -193,6 +194,32 @@ extern void blkg_destroy_all(struct request_queue *q, bool destroy_root);
 extern void update_root_blkg_pd(struct request_queue *q,
 				enum blkio_policy_id plid);
 
+void blkcg_print_blkgs(struct seq_file *sf, struct blkio_cgroup *blkcg,
+		       u64 (*prfill)(struct seq_file *, struct blkg_policy_data *, int),
+		       int pol, int data, bool show_total);
+u64 __blkg_prfill_u64(struct seq_file *sf, struct blkg_policy_data *pd, u64 v);
+u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
+			 const struct blkg_rwstat *rwstat);
+int blkcg_print_stat(struct cgroup *cgrp, struct cftype *cft,
+		     struct seq_file *sf);
+int blkcg_print_rwstat(struct cgroup *cgrp, struct cftype *cft,
+		       struct seq_file *sf);
+int blkcg_print_cpu_stat(struct cgroup *cgrp, struct cftype *cft,
+			 struct seq_file *sf);
+int blkcg_print_cpu_rwstat(struct cgroup *cgrp, struct cftype *cft,
+			   struct seq_file *sf);
+
+struct blkg_conf_ctx {
+	struct gendisk		*disk;
+	struct blkio_group	*blkg;
+	u64			v;
+};
+
+int blkg_conf_prep(struct blkio_cgroup *blkcg, const char *input,
+		   struct blkg_conf_ctx *ctx);
+void blkg_conf_finish(struct blkg_conf_ctx *ctx);
+
+
 /**
  * blkg_to_pdata - get policy private data
  * @blkg: blkg of interest
Signature · 1 line
1.7.7.3
author maintainer
#15 lore raw

PATCH 10/21 blkcg: implement blkio_policy_type->cftypes

In reply to Tejun Heo

Add blkiop->cftypes which is added and removed together with the policy. This will be used to move conf/stat handling to the policies.

---
 block/blk-cgroup.c |    6 ++++++
 block/blk-cgroup.h |    1 +
 2 files changed, 7 insertions(+), 0 deletions(-)
block/blk-cgroup.c +6 -0
index df1e197..2f05056 100644
@@ -1538,6 +1538,9 @@ void blkio_policy_register(struct blkio_policy_type *blkiop)
 	list_for_each_entry(q, &all_q_list, all_q_node)
 		update_root_blkg_pd(q, blkiop->plid);
 	blkcg_bypass_end();
+
+	if (blkiop->cftypes)
+		WARN_ON(cgroup_add_cftypes(&blkio_subsys, blkiop->cftypes));
 }
 EXPORT_SYMBOL_GPL(blkio_policy_register);
 
@@ -1545,6 +1548,9 @@ void blkio_policy_unregister(struct blkio_policy_type *blkiop)
 {
 	struct request_queue *q;
 
+	if (blkiop->cftypes)
+		cgroup_rm_cftypes(&blkio_subsys, blkiop->cftypes);
+
 	blkcg_bypass_start();
 	spin_lock(&blkio_list_lock);
 
block/blk-cgroup.h +1 -0
index 361ecfa..fa744d5 100644
@@ -181,6 +181,7 @@ struct blkio_policy_type {
 	struct blkio_policy_ops ops;
 	enum blkio_policy_id plid;
 	size_t pdata_size;		/* policy specific private data size */
+	struct cftype *cftypes;		/* cgroup files for the policy */
 };
 
 extern int blkcg_init_queue(struct request_queue *q);
Signature · 1 line
1.7.7.3
author maintainer
#16 lore raw

PATCH 11/21 blkcg: move conf/stat file handling code to policies

In reply to Tejun Heo

blkcg conf/stat handling is convoluted in that details which belong to specific policy implementations are all out in blkcg core and then policies hook into core layer to access and manipulate confs and stats. This sadly achieves both inflexibility (confs/stats can't be modified without messing with blkcg core) and complexity (all the call-ins and call-backs).

The previous patches restructured conf and stat handling code such that they can be separated out. This patch relocates the file handling part. All conf/stat file handling code which belongs to BLKIO_POLICY_PROP is moved to cfq-iosched.c and all BKLIO_POLICY_THROTL code to blk-throtl.c.

The move is verbatim except for blkio_update_group_{weight|bps|iops}() callbacks which relays conf changes to policies. The configuration settings are handled in policies themselves so the relaying isn't necessary. Conf setting functions are modified to directly call per-policy update functions and the relaying mechanism is dropped.

---
 block/blk-cgroup.c   |  373 --------------------------------------------------
 block/blk-cgroup.h   |   15 --
 block/blk-throttle.c |  163 ++++++++++++++++++----
 block/cfq-iosched.c  |  202 +++++++++++++++++++++++++++-
 4 files changed, 333 insertions(+), 420 deletions(-)
block/blk-cgroup.c +0 -373
index 2f05056..96b6b5a 100644
@@ -63,63 +63,6 @@ struct blkio_cgroup *bio_blkio_cgroup(struct bio *bio)
 }
 EXPORT_SYMBOL_GPL(bio_blkio_cgroup);
 
-static inline void blkio_update_group_weight(struct blkio_group *blkg,
-					     int plid, unsigned int weight)
-{
-	struct blkio_policy_type *blkiop;
-
-	list_for_each_entry(blkiop, &blkio_list, list) {
-		/* If this policy does not own the blkg, do not send updates */
-		if (blkiop->plid != plid)
-			continue;
-		if (blkiop->ops.blkio_update_group_weight_fn)
-			blkiop->ops.blkio_update_group_weight_fn(blkg->q,
-							blkg, weight);
-	}
-}
-
-static inline void blkio_update_group_bps(struct blkio_group *blkg, int plid,
-					  u64 bps, int rw)
-{
-	struct blkio_policy_type *blkiop;
-
-	list_for_each_entry(blkiop, &blkio_list, list) {
-
-		/* If this policy does not own the blkg, do not send updates */
-		if (blkiop->plid != plid)
-			continue;
-
-		if (rw == READ && blkiop->ops.blkio_update_group_read_bps_fn)
-			blkiop->ops.blkio_update_group_read_bps_fn(blkg->q,
-								blkg, bps);
-
-		if (rw == WRITE && blkiop->ops.blkio_update_group_write_bps_fn)
-			blkiop->ops.blkio_update_group_write_bps_fn(blkg->q,
-								blkg, bps);
-	}
-}
-
-static inline void blkio_update_group_iops(struct blkio_group *blkg, int plid,
-					   u64 iops, int rw)
-{
-	struct blkio_policy_type *blkiop;
-
-	list_for_each_entry(blkiop, &blkio_list, list) {
-
-		/* If this policy does not own the blkg, do not send updates */
-		if (blkiop->plid != plid)
-			continue;
-
-		if (rw == READ && blkiop->ops.blkio_update_group_read_iops_fn)
-			blkiop->ops.blkio_update_group_read_iops_fn(blkg->q,
-								blkg, iops);
-
-		if (rw == WRITE && blkiop->ops.blkio_update_group_write_iops_fn)
-			blkiop->ops.blkio_update_group_write_iops_fn(blkg->q,
-								blkg,iops);
-	}
-}
-
 #ifdef CONFIG_DEBUG_BLK_CGROUP
 /* This should be called with the queue_lock held. */
 static void blkio_set_start_group_wait_time(struct blkio_group *blkg,
@@ -939,33 +882,6 @@ int blkcg_print_cpu_rwstat(struct cgroup *cgrp, struct cftype *cft,
 }
 EXPORT_SYMBOL_GPL(blkcg_print_cpu_rwstat);
 
-#ifdef CONFIG_DEBUG_BLK_CGROUP
-static u64 blkg_prfill_avg_queue_size(struct seq_file *sf,
-				      struct blkg_policy_data *pd, int off)
-{
-	u64 samples = blkg_stat_read(&pd->stats.avg_queue_size_samples);
-	u64 v = 0;
-
-	if (samples) {
-		v = blkg_stat_read(&pd->stats.avg_queue_size_sum);
-		do_div(v, samples);
-	}
-	__blkg_prfill_u64(sf, pd, v);
-	return 0;
-}
-
-/* print avg_queue_size */
-static int blkcg_print_avg_queue_size(struct cgroup *cgrp, struct cftype *cft,
-				      struct seq_file *sf)
-{
-	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
-
-	blkcg_print_blkgs(sf, blkcg, blkg_prfill_avg_queue_size,
-			  BLKIO_POLICY_PROP, 0, false);
-	return 0;
-}
-#endif	/* CONFIG_DEBUG_BLK_CGROUP */
-
 /**
  * blkg_conf_prep - parse and prepare for per-blkg config update
  * @blkcg: target block cgroup
@@ -1039,300 +955,11 @@ void blkg_conf_finish(struct blkg_conf_ctx *ctx)
 }
 EXPORT_SYMBOL_GPL(blkg_conf_finish);
 
-/* for propio conf */
-static u64 blkg_prfill_weight_device(struct seq_file *sf,
-				     struct blkg_policy_data *pd, int off)
-{
-	if (!pd->conf.weight)
-		return 0;
-	return __blkg_prfill_u64(sf, pd, pd->conf.weight);
-}
-
-static int blkcg_print_weight_device(struct cgroup *cgrp, struct cftype *cft,
-				     struct seq_file *sf)
-{
-	blkcg_print_blkgs(sf, cgroup_to_blkio_cgroup(cgrp),
-			  blkg_prfill_weight_device, BLKIO_POLICY_PROP, 0,
-			  false);
-	return 0;
-}
-
-static int blkcg_print_weight(struct cgroup *cgrp, struct cftype *cft,
-			      struct seq_file *sf)
-{
-	seq_printf(sf, "%u\n", cgroup_to_blkio_cgroup(cgrp)->weight);
-	return 0;
-}
-
-static int blkcg_set_weight_device(struct cgroup *cgrp, struct cftype *cft,
-				   const char *buf)
-{
-	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
-	struct blkg_policy_data *pd;
-	struct blkg_conf_ctx ctx;
-	int ret;
-
-	ret = blkg_conf_prep(blkcg, buf, &ctx);
-	if (ret)
-		return ret;
-
-	ret = -EINVAL;
-	pd = ctx.blkg->pd[BLKIO_POLICY_PROP];
-	if (pd && (!ctx.v || (ctx.v >= BLKIO_WEIGHT_MIN &&
-			      ctx.v <= BLKIO_WEIGHT_MAX))) {
-		pd->conf.weight = ctx.v;
-		blkio_update_group_weight(ctx.blkg, BLKIO_POLICY_PROP,
-					  ctx.v ?: blkcg->weight);
-		ret = 0;
-	}
-
-	blkg_conf_finish(&ctx);
-	return ret;
-}
-
-static int blkcg_set_weight(struct cgroup *cgrp, struct cftype *cft, u64 val)
-{
-	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
-	struct blkio_group *blkg;
-	struct hlist_node *n;
-
-	if (val < BLKIO_WEIGHT_MIN || val > BLKIO_WEIGHT_MAX)
-		return -EINVAL;
-
-	spin_lock(&blkio_list_lock);
-	spin_lock_irq(&blkcg->lock);
-	blkcg->weight = (unsigned int)val;
-
-	hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node) {
-		struct blkg_policy_data *pd = blkg->pd[BLKIO_POLICY_PROP];
-
-		if (pd && !pd->conf.weight)
-			blkio_update_group_weight(blkg, BLKIO_POLICY_PROP,
-						  blkcg->weight);
-	}
-
-	spin_unlock_irq(&blkcg->lock);
-	spin_unlock(&blkio_list_lock);
-	return 0;
-}
-
-/* for blk-throttle conf */
-#ifdef CONFIG_BLK_DEV_THROTTLING
-static u64 blkg_prfill_conf_u64(struct seq_file *sf,
-				struct blkg_policy_data *pd, int off)
-{
-	u64 v = *(u64 *)((void *)&pd->conf + off);
-
-	if (!v)
-		return 0;
-	return __blkg_prfill_u64(sf, pd, v);
-}
-
-static int blkcg_print_conf_u64(struct cgroup *cgrp, struct cftype *cft,
-				struct seq_file *sf)
-{
-	blkcg_print_blkgs(sf, cgroup_to_blkio_cgroup(cgrp),
-			  blkg_prfill_conf_u64, BLKIO_POLICY_THROTL,
-			  cft->private, false);
-	return 0;
-}
-
-static int blkcg_set_conf_u64(struct cgroup *cgrp, struct cftype *cft,
-			      const char *buf, int rw,
-			      void (*update)(struct blkio_group *, int, u64, int))
-{
-	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
-	struct blkg_policy_data *pd;
-	struct blkg_conf_ctx ctx;
-	int ret;
-
-	ret = blkg_conf_prep(blkcg, buf, &ctx);
-	if (ret)
-		return ret;
-
-	ret = -EINVAL;
-	pd = ctx.blkg->pd[BLKIO_POLICY_THROTL];
-	if (pd) {
-		*(u64 *)((void *)&pd->conf + cft->private) = ctx.v;
-		update(ctx.blkg, BLKIO_POLICY_THROTL, ctx.v ?: -1, rw);
-		ret = 0;
-	}
-
-	blkg_conf_finish(&ctx);
-	return ret;
-}
-
-static int blkcg_set_conf_bps_r(struct cgroup *cgrp, struct cftype *cft,
-				const char *buf)
-{
-	return blkcg_set_conf_u64(cgrp, cft, buf, READ, blkio_update_group_bps);
-}
-
-static int blkcg_set_conf_bps_w(struct cgroup *cgrp, struct cftype *cft,
-				const char *buf)
-{
-	return blkcg_set_conf_u64(cgrp, cft, buf, WRITE, blkio_update_group_bps);
-}
-
-static int blkcg_set_conf_iops_r(struct cgroup *cgrp, struct cftype *cft,
-				 const char *buf)
-{
-	return blkcg_set_conf_u64(cgrp, cft, buf, READ, blkio_update_group_iops);
-}
-
-static int blkcg_set_conf_iops_w(struct cgroup *cgrp, struct cftype *cft,
-				 const char *buf)
-{
-	return blkcg_set_conf_u64(cgrp, cft, buf, WRITE, blkio_update_group_iops);
-}
-#endif
-
 struct cftype blkio_files[] = {
 	{
-		.name = "weight_device",
-		.read_seq_string = blkcg_print_weight_device,
-		.write_string = blkcg_set_weight_device,
-		.max_write_len = 256,
-	},
-	{
-		.name = "weight",
-		.read_seq_string = blkcg_print_weight,
-		.write_u64 = blkcg_set_weight,
-	},
-	{
-		.name = "time",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
-				offsetof(struct blkio_group_stats, time)),
-		.read_seq_string = blkcg_print_stat,
-	},
-	{
-		.name = "sectors",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
-				offsetof(struct blkio_group_stats_cpu, sectors)),
-		.read_seq_string = blkcg_print_cpu_stat,
-	},
-	{
-		.name = "io_service_bytes",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
-				offsetof(struct blkio_group_stats_cpu, service_bytes)),
-		.read_seq_string = blkcg_print_cpu_rwstat,
-	},
-	{
-		.name = "io_serviced",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
-				offsetof(struct blkio_group_stats_cpu, serviced)),
-		.read_seq_string = blkcg_print_cpu_rwstat,
-	},
-	{
-		.name = "io_service_time",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
-				offsetof(struct blkio_group_stats, service_time)),
-		.read_seq_string = blkcg_print_rwstat,
-	},
-	{
-		.name = "io_wait_time",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
-				offsetof(struct blkio_group_stats, wait_time)),
-		.read_seq_string = blkcg_print_rwstat,
-	},
-	{
-		.name = "io_merged",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
-				offsetof(struct blkio_group_stats, merged)),
-		.read_seq_string = blkcg_print_rwstat,
-	},
-	{
-		.name = "io_queued",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
-				offsetof(struct blkio_group_stats, queued)),
-		.read_seq_string = blkcg_print_rwstat,
-	},
-	{
 		.name = "reset_stats",
 		.write_u64 = blkiocg_reset_stats,
 	},
-#ifdef CONFIG_BLK_DEV_THROTTLING
-	{
-		.name = "throttle.read_bps_device",
-		.private = offsetof(struct blkio_group_conf, bps[READ]),
-		.read_seq_string = blkcg_print_conf_u64,
-		.write_string = blkcg_set_conf_bps_r,
-		.max_write_len = 256,
-	},
-
-	{
-		.name = "throttle.write_bps_device",
-		.private = offsetof(struct blkio_group_conf, bps[WRITE]),
-		.read_seq_string = blkcg_print_conf_u64,
-		.write_string = blkcg_set_conf_bps_w,
-		.max_write_len = 256,
-	},
-
-	{
-		.name = "throttle.read_iops_device",
-		.private = offsetof(struct blkio_group_conf, iops[READ]),
-		.read_seq_string = blkcg_print_conf_u64,
-		.write_string = blkcg_set_conf_iops_r,
-		.max_write_len = 256,
-	},
-
-	{
-		.name = "throttle.write_iops_device",
-		.private = offsetof(struct blkio_group_conf, iops[WRITE]),
-		.read_seq_string = blkcg_print_conf_u64,
-		.write_string = blkcg_set_conf_iops_w,
-		.max_write_len = 256,
-	},
-	{
-		.name = "throttle.io_service_bytes",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_THROTL,
-				offsetof(struct blkio_group_stats_cpu, service_bytes)),
-		.read_seq_string = blkcg_print_cpu_rwstat,
-	},
-	{
-		.name = "throttle.io_serviced",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_THROTL,
-				offsetof(struct blkio_group_stats_cpu, serviced)),
-		.read_seq_string = blkcg_print_cpu_rwstat,
-	},
-#endif /* CONFIG_BLK_DEV_THROTTLING */
-
-#ifdef CONFIG_DEBUG_BLK_CGROUP
-	{
-		.name = "avg_queue_size",
-		.read_seq_string = blkcg_print_avg_queue_size,
-	},
-	{
-		.name = "group_wait_time",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
-				offsetof(struct blkio_group_stats, group_wait_time)),
-		.read_seq_string = blkcg_print_stat,
-	},
-	{
-		.name = "idle_time",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
-				offsetof(struct blkio_group_stats, idle_time)),
-		.read_seq_string = blkcg_print_stat,
-	},
-	{
-		.name = "empty_time",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
-				offsetof(struct blkio_group_stats, empty_time)),
-		.read_seq_string = blkcg_print_stat,
-	},
-	{
-		.name = "dequeue",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
-				offsetof(struct blkio_group_stats, dequeue)),
-		.read_seq_string = blkcg_print_stat,
-	},
-	{
-		.name = "unaccounted_time",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
-				offsetof(struct blkio_group_stats, unaccounted_time)),
-		.read_seq_string = blkcg_print_stat,
-	},
-#endif
 	{ }	/* terminate */
 };
 
block/blk-cgroup.h +0 -15
index fa744d5..ba64b28 100644
@@ -156,24 +156,9 @@ struct blkio_group {
 };
 
 typedef void (blkio_init_group_fn)(struct blkio_group *blkg);
-typedef void (blkio_update_group_weight_fn)(struct request_queue *q,
-			struct blkio_group *blkg, unsigned int weight);
-typedef void (blkio_update_group_read_bps_fn)(struct request_queue *q,
-			struct blkio_group *blkg, u64 read_bps);
-typedef void (blkio_update_group_write_bps_fn)(struct request_queue *q,
-			struct blkio_group *blkg, u64 write_bps);
-typedef void (blkio_update_group_read_iops_fn)(struct request_queue *q,
-			struct blkio_group *blkg, unsigned int read_iops);
-typedef void (blkio_update_group_write_iops_fn)(struct request_queue *q,
-			struct blkio_group *blkg, unsigned int write_iops);
 
 struct blkio_policy_ops {
 	blkio_init_group_fn *blkio_init_group_fn;
-	blkio_update_group_weight_fn *blkio_update_group_weight_fn;
-	blkio_update_group_read_bps_fn *blkio_update_group_read_bps_fn;
-	blkio_update_group_write_bps_fn *blkio_update_group_write_bps_fn;
-	blkio_update_group_read_iops_fn *blkio_update_group_read_iops_fn;
-	blkio_update_group_write_iops_fn *blkio_update_group_write_iops_fn;
 };
 
 struct blkio_policy_type {
block/blk-throttle.c +134 -29

208 lines not on this page · raw message

block/cfq-iosched.c +199 -3

223 lines not on this page · raw message

Signature · 1 line
1.7.7.3
author maintainer
#17 lore raw

PATCH 12/21 cfq: collapse cfq.h into cfq-iosched.c

In reply to Tejun Heo

block/cfq.h contains some functions which interact with blkcg; however, this is only part of it and cfq-iosched.c already has quite some #ifdef CONFIG_CFQ_GROUP_IOSCHED. With conf/stat handling being moved to specific policies, having these relay functions isolated in cfq.h doesn't make much sense. Collapse cfq.h into cfq-iosched.c for now. Let's split blkcg support properly later if necessary.

---
 block/cfq-iosched.c |  114 ++++++++++++++++++++++++++++++++++++++++++++++++-
 block/cfq.h         |  118 ---------------------------------------------------
 2 files changed, 113 insertions(+), 119 deletions(-)
 delete mode 100644 block/cfq.h
block/cfq-iosched.c +113 -1
index 119e061..2e13e9e 100644
@@ -15,7 +15,6 @@
 #include <linux/ioprio.h>
 #include <linux/blktrace_api.h>
 #include "blk.h"
-#include "cfq.h"
 
 static struct blkio_policy_type blkio_policy_cfq;
 
@@ -367,6 +366,9 @@ CFQ_CFQQ_FNS(wait_busy);
 #undef CFQ_CFQQ_FNS
 
 #ifdef CONFIG_CFQ_GROUP_IOSCHED
+
+#include "blk-cgroup.h"
+
 static inline struct cfq_group *blkg_to_cfqg(struct blkio_group *blkg)
 {
 	return blkg_to_pdata(blkg, &blkio_policy_cfq);
@@ -396,6 +398,82 @@ static inline void cfqg_put(struct cfq_group *cfqg)
 	blk_add_trace_msg((cfqd)->queue, "%s " fmt,			\
 			blkg_path(cfqg_to_blkg((cfqg))), ##args)	\
 
+static inline void cfq_blkiocg_update_io_add_stats(struct blkio_group *blkg,
+			struct blkio_policy_type *pol,
+			struct blkio_group *curr_blkg,
+			bool direction, bool sync)
+{
+	blkiocg_update_io_add_stats(blkg, pol, curr_blkg, direction, sync);
+}
+
+static inline void cfq_blkiocg_update_dequeue_stats(struct blkio_group *blkg,
+			struct blkio_policy_type *pol, unsigned long dequeue)
+{
+	blkiocg_update_dequeue_stats(blkg, pol, dequeue);
+}
+
+static inline void cfq_blkiocg_update_timeslice_used(struct blkio_group *blkg,
+			struct blkio_policy_type *pol, unsigned long time,
+			unsigned long unaccounted_time)
+{
+	blkiocg_update_timeslice_used(blkg, pol, time, unaccounted_time);
+}
+
+static inline void cfq_blkiocg_set_start_empty_time(struct blkio_group *blkg,
+			struct blkio_policy_type *pol)
+{
+	blkiocg_set_start_empty_time(blkg, pol);
+}
+
+static inline void cfq_blkiocg_update_io_remove_stats(struct blkio_group *blkg,
+			struct blkio_policy_type *pol, bool direction,
+			bool sync)
+{
+	blkiocg_update_io_remove_stats(blkg, pol, direction, sync);
+}
+
+static inline void cfq_blkiocg_update_io_merged_stats(struct blkio_group *blkg,
+			struct blkio_policy_type *pol, bool direction,
+			bool sync)
+{
+	blkiocg_update_io_merged_stats(blkg, pol, direction, sync);
+}
+
+static inline void cfq_blkiocg_update_idle_time_stats(struct blkio_group *blkg,
+			struct blkio_policy_type *pol)
+{
+	blkiocg_update_idle_time_stats(blkg, pol);
+}
+
+static inline void
+cfq_blkiocg_update_avg_queue_size_stats(struct blkio_group *blkg,
+			struct blkio_policy_type *pol)
+{
+	blkiocg_update_avg_queue_size_stats(blkg, pol);
+}
+
+static inline void
+cfq_blkiocg_update_set_idle_time_stats(struct blkio_group *blkg,
+			struct blkio_policy_type *pol)
+{
+	blkiocg_update_set_idle_time_stats(blkg, pol);
+}
+
+static inline void cfq_blkiocg_update_dispatch_stats(struct blkio_group *blkg,
+			struct blkio_policy_type *pol, uint64_t bytes,
+			bool direction, bool sync)
+{
+	blkiocg_update_dispatch_stats(blkg, pol, bytes, direction, sync);
+}
+
+static inline void cfq_blkiocg_update_completion_stats(struct blkio_group *blkg,
+			struct blkio_policy_type *pol, uint64_t start_time,
+			uint64_t io_start_time, bool direction, bool sync)
+{
+	blkiocg_update_completion_stats(blkg, pol, start_time, io_start_time,
+					direction, sync);
+}
+
 #else	/* CONFIG_CFQ_GROUP_IOSCHED */
 
 static inline struct cfq_group *blkg_to_cfqg(struct blkio_group *blkg) { return NULL; }
@@ -407,6 +485,40 @@ static inline void cfqg_put(struct cfq_group *cfqg) { }
 	blk_add_trace_msg((cfqd)->queue, "cfq%d " fmt, (cfqq)->pid, ##args)
 #define cfq_log_cfqg(cfqd, cfqg, fmt, args...)		do {} while (0)
 
+static inline void cfq_blkiocg_update_io_add_stats(struct blkio_group *blkg,
+			struct blkio_policy_type *pol,
+			struct blkio_group *curr_blkg, bool direction,
+			bool sync) { }
+static inline void cfq_blkiocg_update_dequeue_stats(struct blkio_group *blkg,
+			struct blkio_policy_type *pol, unsigned long dequeue) { }
+static inline void cfq_blkiocg_update_timeslice_used(struct blkio_group *blkg,
+			struct blkio_policy_type *pol, unsigned long time,
+			unsigned long unaccounted_time) { }
+static inline void cfq_blkiocg_set_start_empty_time(struct blkio_group *blkg,
+			struct blkio_policy_type *pol) { }
+static inline void cfq_blkiocg_update_io_remove_stats(struct blkio_group *blkg,
+			struct blkio_policy_type *pol, bool direction,
+			bool sync) { }
+static inline void cfq_blkiocg_update_io_merged_stats(struct blkio_group *blkg,
+			struct blkio_policy_type *pol, bool direction,
+			bool sync) { }
+static inline void cfq_blkiocg_update_idle_time_stats(struct blkio_group *blkg,
+			struct blkio_policy_type *pol) { }
+static inline void
+cfq_blkiocg_update_avg_queue_size_stats(struct blkio_group *blkg,
+					struct blkio_policy_type *pol) { }
+
+static inline void
+cfq_blkiocg_update_set_idle_time_stats(struct blkio_group *blkg,
+				       struct blkio_policy_type *pol) { }
+
+static inline void cfq_blkiocg_update_dispatch_stats(struct blkio_group *blkg,
+			struct blkio_policy_type *pol, uint64_t bytes,
+			bool direction, bool sync) { }
+static inline void cfq_blkiocg_update_completion_stats(struct blkio_group *blkg,
+			struct blkio_policy_type *pol, uint64_t start_time,
+			uint64_t io_start_time, bool direction, bool sync) { }
+
 #endif	/* CONFIG_CFQ_GROUP_IOSCHED */
 
 #define cfq_log(cfqd, fmt, args...)	\
block/cfq.h deleted +0 -118

118 lines not on this page · raw message

Signature · 1 line
1.7.7.3
author maintainer
#18 lore raw

PATCH 13/21 blkcg: move statistics update code to policies

In reply to Tejun Heo

As with conf/stats file handling code, there's no reason for stat update code to live in blkcg core with policies calling into update them. The current organization is both inflexible and complex.

This patch moves stat update code to specific policies. All blkiocg_update_*_stats() functions which deal with BLKIO_POLICY_PROP stats are collapsed into their cfq_blkiocg_update_*_stats() counterparts. blkiocg_update_dispatch_stats() is used by both policies and duplicated as throtl_update_dispatch_stats() and cfq_blkiocg_update_dispatch_stats(). This will be cleaned up later.

---
 block/blk-cgroup.c   |  245 -------------------------------------------
 block/blk-cgroup.h   |   94 -----------------
 block/blk-throttle.c |   37 ++++++--
 block/cfq-iosched.c  |  280 +++++++++++++++++++++++++++++++++++++++++---------
 4 files changed, 259 insertions(+), 397 deletions(-)
block/blk-cgroup.c +0 -245
index 96b6b5a..dfa5f2c 100644
@@ -63,251 +63,6 @@ struct blkio_cgroup *bio_blkio_cgroup(struct bio *bio)
 }
 EXPORT_SYMBOL_GPL(bio_blkio_cgroup);
 
-#ifdef CONFIG_DEBUG_BLK_CGROUP
-/* This should be called with the queue_lock held. */
-static void blkio_set_start_group_wait_time(struct blkio_group *blkg,
-					    struct blkio_policy_type *pol,
-					    struct blkio_group *curr_blkg)
-{
-	struct blkg_policy_data *pd = blkg->pd[pol->plid];
-
-	if (blkio_blkg_waiting(&pd->stats))
-		return;
-	if (blkg == curr_blkg)
-		return;
-	pd->stats.start_group_wait_time = sched_clock();
-	blkio_mark_blkg_waiting(&pd->stats);
-}
-
-/* This should be called with the queue_lock held. */
-static void blkio_update_group_wait_time(struct blkio_group_stats *stats)
-{
-	unsigned long long now;
-
-	if (!blkio_blkg_waiting(stats))
-		return;
-
-	now = sched_clock();
-	if (time_after64(now, stats->start_group_wait_time))
-		blkg_stat_add(&stats->group_wait_time,
-			      now - stats->start_group_wait_time);
-	blkio_clear_blkg_waiting(stats);
-}
-
-/* This should be called with the queue_lock held. */
-static void blkio_end_empty_time(struct blkio_group_stats *stats)
-{
-	unsigned long long now;
-
-	if (!blkio_blkg_empty(stats))
-		return;
-
-	now = sched_clock();
-	if (time_after64(now, stats->start_empty_time))
-		blkg_stat_add(&stats->empty_time,
-			      now - stats->start_empty_time);
-	blkio_clear_blkg_empty(stats);
-}
-
-void blkiocg_update_set_idle_time_stats(struct blkio_group *blkg,
-					struct blkio_policy_type *pol)
-{
-	struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
-
-	lockdep_assert_held(blkg->q->queue_lock);
-	BUG_ON(blkio_blkg_idling(stats));
-
-	stats->start_idle_time = sched_clock();
-	blkio_mark_blkg_idling(stats);
-}
-EXPORT_SYMBOL_GPL(blkiocg_update_set_idle_time_stats);
-
-void blkiocg_update_idle_time_stats(struct blkio_group *blkg,
-				    struct blkio_policy_type *pol)
-{
-	struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
-
-	lockdep_assert_held(blkg->q->queue_lock);
-
-	if (blkio_blkg_idling(stats)) {
-		unsigned long long now = sched_clock();
-
-		if (time_after64(now, stats->start_idle_time))
-			blkg_stat_add(&stats->idle_time,
-				      now - stats->start_idle_time);
-		blkio_clear_blkg_idling(stats);
-	}
-}
-EXPORT_SYMBOL_GPL(blkiocg_update_idle_time_stats);
-
-void blkiocg_update_avg_queue_size_stats(struct blkio_group *blkg,
-					 struct blkio_policy_type *pol)
-{
-	struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
-
-	lockdep_assert_held(blkg->q->queue_lock);
-
-	blkg_stat_add(&stats->avg_queue_size_sum,
-		      blkg_rwstat_sum(&stats->queued));
-	blkg_stat_add(&stats->avg_queue_size_samples, 1);
-	blkio_update_group_wait_time(stats);
-}
-EXPORT_SYMBOL_GPL(blkiocg_update_avg_queue_size_stats);
-
-void blkiocg_set_start_empty_time(struct blkio_group *blkg,
-				  struct blkio_policy_type *pol)
-{
-	struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
-
-	lockdep_assert_held(blkg->q->queue_lock);
-
-	if (blkg_rwstat_sum(&stats->queued))
-		return;
-
-	/*
-	 * group is already marked empty. This can happen if cfqq got new
-	 * request in parent group and moved to this group while being added
-	 * to service tree. Just ignore the event and move on.
-	 */
-	if (blkio_blkg_empty(stats))
-		return;
-
-	stats->start_empty_time = sched_clock();
-	blkio_mark_blkg_empty(stats);
-}
-EXPORT_SYMBOL_GPL(blkiocg_set_start_empty_time);
-
-void blkiocg_update_dequeue_stats(struct blkio_group *blkg,
-				  struct blkio_policy_type *pol,
-				  unsigned long dequeue)
-{
-	struct blkg_policy_data *pd = blkg->pd[pol->plid];
-
-	lockdep_assert_held(blkg->q->queue_lock);
-
-	blkg_stat_add(&pd->stats.dequeue, dequeue);
-}
-EXPORT_SYMBOL_GPL(blkiocg_update_dequeue_stats);
-#else
-static inline void blkio_set_start_group_wait_time(struct blkio_group *blkg,
-					struct blkio_policy_type *pol,
-					struct blkio_group *curr_blkg) { }
-static inline void blkio_end_empty_time(struct blkio_group_stats *stats) { }
-#endif
-
-void blkiocg_update_io_add_stats(struct blkio_group *blkg,
-				 struct blkio_policy_type *pol,
-				 struct blkio_group *curr_blkg, bool direction,
-				 bool sync)
-{
-	struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
-	int rw = (direction ? REQ_WRITE : 0) | (sync ? REQ_SYNC : 0);
-
-	lockdep_assert_held(blkg->q->queue_lock);
-
-	blkg_rwstat_add(&stats->queued, rw, 1);
-	blkio_end_empty_time(stats);
-	blkio_set_start_group_wait_time(blkg, pol, curr_blkg);
-}
-EXPORT_SYMBOL_GPL(blkiocg_update_io_add_stats);
-
-void blkiocg_update_io_remove_stats(struct blkio_group *blkg,
-				    struct blkio_policy_type *pol,
-				    bool direction, bool sync)
-{
-	struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
-	int rw = (direction ? REQ_WRITE : 0) | (sync ? REQ_SYNC : 0);
-
-	lockdep_assert_held(blkg->q->queue_lock);
-
-	blkg_rwstat_add(&stats->queued, rw, -1);
-}
-EXPORT_SYMBOL_GPL(blkiocg_update_io_remove_stats);
-
-void blkiocg_update_timeslice_used(struct blkio_group *blkg,
-				   struct blkio_policy_type *pol,
-				   unsigned long time,
-				   unsigned long unaccounted_time)
-{
-	struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
-
-	lockdep_assert_held(blkg->q->queue_lock);
-
-	blkg_stat_add(&stats->time, time);
-#ifdef CONFIG_DEBUG_BLK_CGROUP
-	blkg_stat_add(&stats->unaccounted_time, unaccounted_time);
-#endif
-}
-EXPORT_SYMBOL_GPL(blkiocg_update_timeslice_used);
-
-/*
- * should be called under rcu read lock or queue lock to make sure blkg pointer
- * is valid.
- */
-void blkiocg_update_dispatch_stats(struct blkio_group *blkg,
-				   struct blkio_policy_type *pol,
-				   uint64_t bytes, bool direction, bool sync)
-{
-	int rw = (direction ? REQ_WRITE : 0) | (sync ? REQ_SYNC : 0);
-	struct blkg_policy_data *pd = blkg->pd[pol->plid];
-	struct blkio_group_stats_cpu *stats_cpu;
-	unsigned long flags;
-
-	/* If per cpu stats are not allocated yet, don't do any accounting. */
-	if (pd->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(pd->stats_cpu);
-
-	blkg_stat_add(&stats_cpu->sectors, bytes >> 9);
-	blkg_rwstat_add(&stats_cpu->serviced, rw, 1);
-	blkg_rwstat_add(&stats_cpu->service_bytes, rw, bytes);
-
-	local_irq_restore(flags);
-}
-EXPORT_SYMBOL_GPL(blkiocg_update_dispatch_stats);
-
-void blkiocg_update_completion_stats(struct blkio_group *blkg,
-				     struct blkio_policy_type *pol,
-				     uint64_t start_time,
-				     uint64_t io_start_time, bool direction,
-				     bool sync)
-{
-	struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
-	unsigned long long now = sched_clock();
-	int rw = (direction ? REQ_WRITE : 0) | (sync ? REQ_SYNC : 0);
-
-	lockdep_assert_held(blkg->q->queue_lock);
-
-	if (time_after64(now, io_start_time))
-		blkg_rwstat_add(&stats->service_time, rw, now - io_start_time);
-	if (time_after64(io_start_time, start_time))
-		blkg_rwstat_add(&stats->wait_time, rw,
-				io_start_time - start_time);
-}
-EXPORT_SYMBOL_GPL(blkiocg_update_completion_stats);
-
-/*  Merged stats are per cpu.  */
-void blkiocg_update_io_merged_stats(struct blkio_group *blkg,
-				    struct blkio_policy_type *pol,
-				    bool direction, bool sync)
-{
-	struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
-	int rw = (direction ? REQ_WRITE : 0) | (sync ? REQ_SYNC : 0);
-
-	lockdep_assert_held(blkg->q->queue_lock);
-
-	blkg_rwstat_add(&stats->merged, rw, 1);
-}
-EXPORT_SYMBOL_GPL(blkiocg_update_io_merged_stats);
-
 /*
  * Worker for allocating per cpu stat for blk groups. This is scheduled on
  * the system_nrt_wq once there are some groups on the alloc_list waiting
block/blk-cgroup.h +0 -94

117 lines not on this page · raw message

block/blk-throttle.c +30 -7
index fb6f257..5d647ed 100644
@@ -562,17 +562,42 @@ static bool tg_may_dispatch(struct throtl_data *td, struct throtl_grp *tg,
 	return 0;
 }
 
+static void throtl_update_dispatch_stats(struct blkio_group *blkg, u64 bytes,
+					 int rw)
+{
+	struct blkg_policy_data *pd = blkg->pd[BLKIO_POLICY_THROTL];
+	struct blkio_group_stats_cpu *stats_cpu;
+	unsigned long flags;
+
+	/* If per cpu stats are not allocated yet, don't do any accounting. */
+	if (pd->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(pd->stats_cpu);
+
+	blkg_stat_add(&stats_cpu->sectors, bytes >> 9);
+	blkg_rwstat_add(&stats_cpu->serviced, rw, 1);
+	blkg_rwstat_add(&stats_cpu->service_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);
-	bool sync = rw_is_sync(bio->bi_rw);
 
 	/* Charge the bio to the group */
 	tg->bytes_disp[rw] += bio->bi_size;
 	tg->io_disp[rw]++;
 
-	blkiocg_update_dispatch_stats(tg_to_blkg(tg), &blkio_policy_throtl,
-				      bio->bi_size, rw, sync);
+	throtl_update_dispatch_stats(tg_to_blkg(tg), bio->bi_size, bio->bi_rw);
 }
 
 static void throtl_add_bio_tg(struct throtl_data *td, struct throtl_grp *tg,
@@ -1012,10 +1037,8 @@ 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)) {
-			blkiocg_update_dispatch_stats(tg_to_blkg(tg),
-						      &blkio_policy_throtl,
-						      bio->bi_size, rw,
-						      rw_is_sync(bio->bi_rw));
+			throtl_update_dispatch_stats(tg_to_blkg(tg),
+						     bio->bi_size, bio->bi_rw);
 			goto out_unlock_rcu;
 		}
 	}
block/cfq-iosched.c +229 -51

348 lines not on this page · raw message

Signature · 1 line
1.7.7.3
author maintainer
#19 lore raw

PATCH 14/21 blkcg: cfq doesn't need per-cpu dispatch stats

In reply to Tejun Heo

blkio_group_stats_cpu is used to count dispatch stats using per-cpu counters. This is used by both blk-throtl and cfq-iosched but the sharing is rather silly.

* cfq-iosched doesn't need per-cpu dispatch stats. cfq always updates those stats while holding queue_lock.

* blk-throtl needs per-cpu dispatch stats but only service_bytes and serviced. It doesn't make use of sectors.

This patch makes cfq add and use global stats for service_bytes, serviced and sectors, removes per-cpu sectors counter and moves per-cpu stat printing code to blk-throttle.c.

---
 block/blk-cgroup.c   |   63 +------------------------------------------------
 block/blk-cgroup.h   |   12 ++++----
 block/blk-throttle.c |   31 +++++++++++++++++++++++-
 block/cfq-iosched.c  |   37 ++++++++---------------------
 4 files changed, 48 insertions(+), 95 deletions(-)
block/blk-cgroup.c +2 -61
index dfa5f2c..16158e5 100644
@@ -390,7 +390,6 @@ static void blkio_reset_stats_cpu(struct blkio_group *blkg, int plid)
 
 		blkg_rwstat_reset(&sc->service_bytes);
 		blkg_rwstat_reset(&sc->serviced);
-		blkg_stat_reset(&sc->sectors);
 	}
 }
 
@@ -417,6 +416,8 @@ blkiocg_reset_stats(struct cgroup *cgroup, struct cftype *cftype, u64 val)
 			struct blkio_group_stats *stats = &pd->stats;
 
 			/* queued stats shouldn't be cleared */
+			blkg_rwstat_reset(&stats->service_bytes);
+			blkg_rwstat_reset(&stats->serviced);
 			blkg_rwstat_reset(&stats->merged);
 			blkg_rwstat_reset(&stats->service_time);
 			blkg_rwstat_reset(&stats->wait_time);
@@ -577,66 +578,6 @@ int blkcg_print_rwstat(struct cgroup *cgrp, struct cftype *cft,
 }
 EXPORT_SYMBOL_GPL(blkcg_print_rwstat);
 
-static u64 blkg_prfill_cpu_stat(struct seq_file *sf,
-				struct blkg_policy_data *pd, int off)
-{
-	u64 v = 0;
-	int cpu;
-
-	for_each_possible_cpu(cpu) {
-		struct blkio_group_stats_cpu *sc =
-			per_cpu_ptr(pd->stats_cpu, cpu);
-
-		v += blkg_stat_read((void *)sc + off);
-	}
-
-	return __blkg_prfill_u64(sf, pd, v);
-}
-
-static u64 blkg_prfill_cpu_rwstat(struct seq_file *sf,
-				  struct blkg_policy_data *pd, int off)
-{
-	struct blkg_rwstat rwstat = { }, tmp;
-	int i, cpu;
-
-	for_each_possible_cpu(cpu) {
-		struct blkio_group_stats_cpu *sc =
-			per_cpu_ptr(pd->stats_cpu, cpu);
-
-		tmp = blkg_rwstat_read((void *)sc + off);
-		for (i = 0; i < BLKG_RWSTAT_NR; i++)
-			rwstat.cnt[i] += tmp.cnt[i];
-	}
-
-	return __blkg_prfill_rwstat(sf, pd, &rwstat);
-}
-
-/* print per-cpu blkg_stat specified by BLKCG_STAT_PRIV() */
-int blkcg_print_cpu_stat(struct cgroup *cgrp, struct cftype *cft,
-			 struct seq_file *sf)
-{
-	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
-
-	blkcg_print_blkgs(sf, blkcg, blkg_prfill_cpu_stat,
-			  BLKCG_STAT_POL(cft->private),
-			  BLKCG_STAT_OFF(cft->private), false);
-	return 0;
-}
-EXPORT_SYMBOL_GPL(blkcg_print_cpu_stat);
-
-/* print per-cpu blkg_rwstat specified by BLKCG_STAT_PRIV() */
-int blkcg_print_cpu_rwstat(struct cgroup *cgrp, struct cftype *cft,
-			   struct seq_file *sf)
-{
-	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
-
-	blkcg_print_blkgs(sf, blkcg, blkg_prfill_cpu_rwstat,
-			  BLKCG_STAT_POL(cft->private),
-			  BLKCG_STAT_OFF(cft->private), true);
-	return 0;
-}
-EXPORT_SYMBOL_GPL(blkcg_print_cpu_rwstat);
-
 /**
  * blkg_conf_prep - parse and prepare for per-blkg config update
  * @blkcg: target block cgroup
block/blk-cgroup.h +6 -6
index 0b0a176..c82de47 100644
@@ -65,6 +65,10 @@ struct blkg_rwstat {
 };
 
 struct blkio_group_stats {
+	/* total bytes transferred */
+	struct blkg_rwstat		service_bytes;
+	/* total IOs serviced, post merge */
+	struct blkg_rwstat		serviced;
 	/* number of ios merged */
 	struct blkg_rwstat		merged;
 	/* total time spent on device in ns, may not be accurate w/ queueing */
@@ -73,6 +77,8 @@ struct blkio_group_stats {
 	struct blkg_rwstat		wait_time;
 	/* number of IOs queued up */
 	struct blkg_rwstat		queued;
+	/* total sectors transferred */
+	struct blkg_stat		sectors;
 	/* total disk time and nr sectors dispatched by this group */
 	struct blkg_stat		time;
 #ifdef CONFIG_DEBUG_BLK_CGROUP
@@ -104,8 +110,6 @@ struct blkio_group_stats_cpu {
 	struct blkg_rwstat		service_bytes;
 	/* total IOs serviced, post merge */
 	struct blkg_rwstat		serviced;
-	/* total sectors transferred */
-	struct blkg_stat		sectors;
 };
 
 struct blkio_group_conf {
@@ -183,10 +187,6 @@ int blkcg_print_stat(struct cgroup *cgrp, struct cftype *cft,
 		     struct seq_file *sf);
 int blkcg_print_rwstat(struct cgroup *cgrp, struct cftype *cft,
 		       struct seq_file *sf);
-int blkcg_print_cpu_stat(struct cgroup *cgrp, struct cftype *cft,
-			 struct seq_file *sf);
-int blkcg_print_cpu_rwstat(struct cgroup *cgrp, struct cftype *cft,
-			   struct seq_file *sf);
 
 struct blkg_conf_ctx {
 	struct gendisk		*disk;
block/blk-throttle.c +30 -1
index 5d647ed..cb259bc 100644
@@ -582,7 +582,6 @@ static void throtl_update_dispatch_stats(struct blkio_group *blkg, u64 bytes,
 
 	stats_cpu = this_cpu_ptr(pd->stats_cpu);
 
-	blkg_stat_add(&stats_cpu->sectors, bytes >> 9);
 	blkg_rwstat_add(&stats_cpu->serviced, rw, 1);
 	blkg_rwstat_add(&stats_cpu->service_bytes, rw, bytes);
 
@@ -843,6 +842,36 @@ static void throtl_update_blkio_group_common(struct throtl_data *td,
 	throtl_schedule_delayed_work(td, 0);
 }
 
+static u64 blkg_prfill_cpu_rwstat(struct seq_file *sf,
+				  struct blkg_policy_data *pd, int off)
+{
+	struct blkg_rwstat rwstat = { }, tmp;
+	int i, cpu;
+
+	for_each_possible_cpu(cpu) {
+		struct blkio_group_stats_cpu *sc =
+			per_cpu_ptr(pd->stats_cpu, cpu);
+
+		tmp = blkg_rwstat_read((void *)sc + off);
+		for (i = 0; i < BLKG_RWSTAT_NR; i++)
+			rwstat.cnt[i] += tmp.cnt[i];
+	}
+
+	return __blkg_prfill_rwstat(sf, pd, &rwstat);
+}
+
+/* print per-cpu blkg_rwstat specified by BLKCG_STAT_PRIV() */
+static int blkcg_print_cpu_rwstat(struct cgroup *cgrp, struct cftype *cft,
+				  struct seq_file *sf)
+{
+	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
+
+	blkcg_print_blkgs(sf, blkcg, blkg_prfill_cpu_rwstat,
+			  BLKCG_STAT_POL(cft->private),
+			  BLKCG_STAT_OFF(cft->private), true);
+	return 0;
+}
+
 static u64 blkg_prfill_conf_u64(struct seq_file *sf,
 				struct blkg_policy_data *pd, int off)
 {
block/cfq-iosched.c +10 -27
index 4991380..effd894 100644
@@ -624,29 +624,12 @@ static inline void cfq_blkiocg_update_dispatch_stats(struct blkio_group *blkg,
 			struct blkio_policy_type *pol, uint64_t bytes,
 			bool direction, bool sync)
 {
+	struct blkio_group_stats *stats = &blkg->pd[pol->plid]->stats;
 	int rw = (direction ? REQ_WRITE : 0) | (sync ? REQ_SYNC : 0);
-	struct blkg_policy_data *pd = blkg->pd[pol->plid];
-	struct blkio_group_stats_cpu *stats_cpu;
-	unsigned long flags;
 
-	/* If per cpu stats are not allocated yet, don't do any accounting. */
-	if (pd->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(pd->stats_cpu);
-
-	blkg_stat_add(&stats_cpu->sectors, bytes >> 9);
-	blkg_rwstat_add(&stats_cpu->serviced, rw, 1);
-	blkg_rwstat_add(&stats_cpu->service_bytes, rw, bytes);
-
-	local_irq_restore(flags);
+	blkg_stat_add(&stats->sectors, bytes >> 9);
+	blkg_rwstat_add(&stats->serviced, rw, 1);
+	blkg_rwstat_add(&stats->service_bytes, rw, bytes);
 }
 
 static inline void cfq_blkiocg_update_completion_stats(struct blkio_group *blkg,
@@ -1520,20 +1503,20 @@ static struct cftype cfq_blkcg_files[] = {
 	{
 		.name = "sectors",
 		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
-				offsetof(struct blkio_group_stats_cpu, sectors)),
-		.read_seq_string = blkcg_print_cpu_stat,
+				offsetof(struct blkio_group_stats, sectors)),
+		.read_seq_string = blkcg_print_stat,
 	},
 	{
 		.name = "io_service_bytes",
 		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
-				offsetof(struct blkio_group_stats_cpu, service_bytes)),
-		.read_seq_string = blkcg_print_cpu_rwstat,
+				offsetof(struct blkio_group_stats, service_bytes)),
+		.read_seq_string = blkcg_print_rwstat,
 	},
 	{
 		.name = "io_serviced",
 		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_PROP,
-				offsetof(struct blkio_group_stats_cpu, serviced)),
-		.read_seq_string = blkcg_print_cpu_rwstat,
+				offsetof(struct blkio_group_stats, serviced)),
+		.read_seq_string = blkcg_print_rwstat,
 	},
 	{
 		.name = "io_service_time",
Signature · 1 line
1.7.7.3
author maintainer
#20 lore raw

PATCH 15/21 blkcg: add blkio_policy_ops operations for exit and stat reset

In reply to Tejun Heo

Add blkio_policy_ops->blkio_exit_group_fn() and ->blkio_reset_group_stats_fn(). These will be used to further modularize blkcg policy implementation.

---
 block/blk-cgroup.c |   16 ++++++++++++----
 block/blk-cgroup.h |    4 ++++
 2 files changed, 16 insertions(+), 4 deletions(-)
block/blk-cgroup.c +12 -4
index 16158e5..e4848ee 100644
@@ -131,12 +131,17 @@ static void blkg_free(struct blkio_group *blkg)
 		return;
 
 	for (i = 0; i < BLKIO_NR_POLICIES; i++) {
+		struct blkio_policy_type *pol = blkio_policy[i];
 		struct blkg_policy_data *pd = blkg->pd[i];
 
-		if (pd) {
-			free_percpu(pd->stats_cpu);
-			kfree(pd);
-		}
+		if (!pd)
+			continue;
+
+		if (pol && pol->ops.blkio_exit_group_fn)
+			pol->ops.blkio_exit_group_fn(blkg);
+
+		free_percpu(pd->stats_cpu);
+		kfree(pd);
 	}
 
 	kfree(blkg);
@@ -432,6 +437,9 @@ blkiocg_reset_stats(struct cgroup *cgroup, struct cftype *cftype, u64 val)
 			blkg_stat_reset(&stats->empty_time);
 #endif
 			blkio_reset_stats_cpu(blkg, pol->plid);
+
+			if (pol->ops.blkio_reset_group_stats_fn)
+				pol->ops.blkio_reset_group_stats_fn(blkg);
 		}
 	}
 
block/blk-cgroup.h +4 -0
index c82de47..d0ee649 100644
@@ -153,9 +153,13 @@ struct blkio_group {
 };
 
 typedef void (blkio_init_group_fn)(struct blkio_group *blkg);
+typedef void (blkio_exit_group_fn)(struct blkio_group *blkg);
+typedef void (blkio_reset_group_stats_fn)(struct blkio_group *blkg);
 
 struct blkio_policy_ops {
 	blkio_init_group_fn *blkio_init_group_fn;
+	blkio_exit_group_fn *blkio_exit_group_fn;
+	blkio_reset_group_stats_fn *blkio_reset_group_stats_fn;
 };
 
 struct blkio_policy_type {
Signature · 1 line
1.7.7.3
author maintainer
#21 lore raw

PATCH 16/21 blkcg: move blkio_group_stats to cfq-iosched.c

In reply to Tejun Heo

blkio_group_stats contains only fields used by cfq and has no reason to be defined in blkcg core.

* Move blkio_group_stats to cfq-iosched.c and rename it to cfqg_stats.

* blkg_policy_data->stats is replaced with cfq_group->stats. blkg_prfill_[rw]stat() are updated to use offset against pd->pdata instead.

* All related macros / functions are renamed so that they have cfqg_ prefix and the unnecessary @pol arguments are dropped.

* All stat functions now take cfq_group * instead of blkio_group *.

* lockdep assertion on queue lock dropped. Elevator runs under queue lock by default. There isn't much to be gained by adding lockdep assertions at stat function level.

* cfqg_stats_reset() implemented for blkio_reset_group_stats_fn method so that cfqg->stats can be reset.

---
 block/blk-cgroup.c  |   23 +---
 block/blk-cgroup.h  |   41 -----
 block/cfq-iosched.c |  407 ++++++++++++++++++++++++---------------------------
 3 files changed, 193 insertions(+), 278 deletions(-)
block/blk-cgroup.c +2 -21
index e4848ee..d7c7f17 100644
@@ -417,25 +417,6 @@ blkiocg_reset_stats(struct cgroup *cgroup, struct cftype *cftype, u64 val)
 		struct blkio_policy_type *pol;
 
 		list_for_each_entry(pol, &blkio_list, list) {
-			struct blkg_policy_data *pd = blkg->pd[pol->plid];
-			struct blkio_group_stats *stats = &pd->stats;
-
-			/* queued stats shouldn't be cleared */
-			blkg_rwstat_reset(&stats->service_bytes);
-			blkg_rwstat_reset(&stats->serviced);
-			blkg_rwstat_reset(&stats->merged);
-			blkg_rwstat_reset(&stats->service_time);
-			blkg_rwstat_reset(&stats->wait_time);
-			blkg_stat_reset(&stats->time);
-#ifdef CONFIG_DEBUG_BLK_CGROUP
-			blkg_stat_reset(&stats->unaccounted_time);
-			blkg_stat_reset(&stats->avg_queue_size_sum);
-			blkg_stat_reset(&stats->avg_queue_size_samples);
-			blkg_stat_reset(&stats->dequeue);
-			blkg_stat_reset(&stats->group_wait_time);
-			blkg_stat_reset(&stats->idle_time);
-			blkg_stat_reset(&stats->empty_time);
-#endif
 			blkio_reset_stats_cpu(blkg, pol->plid);
 
 			if (pol->ops.blkio_reset_group_stats_fn)
@@ -549,13 +530,13 @@ static u64 blkg_prfill_stat(struct seq_file *sf, struct blkg_policy_data *pd,
 			    int off)
 {
 	return __blkg_prfill_u64(sf, pd,
-				 blkg_stat_read((void *)&pd->stats + off));
+				 blkg_stat_read((void *)pd->pdata + off));
 }
 
 static u64 blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
 			      int off)
 {
-	struct blkg_rwstat rwstat = blkg_rwstat_read((void *)&pd->stats + off);
+	struct blkg_rwstat rwstat = blkg_rwstat_read((void *)pd->pdata + off);
 
 	return __blkg_prfill_rwstat(sf, pd, &rwstat);
 }
block/blk-cgroup.h +0 -41

53 lines not on this page · raw message

block/cfq-iosched.c +191 -216

718 lines not on this page · raw message

Signature · 1 line
1.7.7.3
author maintainer
#22 lore raw

PATCH 17/21 blkcg: move blkio_group_stats_cpu and friends to blk-throttle.c

In reply to Tejun Heo

blkio_group_stats_cpu is used only by blk-throtl and has no reason to be defined in blkcg core.

* Move blkio_group_stats_cpu to blk-throttle.c and rename it to tg_stats_cpu.

* blkg_policy_data->stats_cpu is replaced with throtl_grp->stats_cpu. prfill functions updated accordingly.

* All related macros / functions are renamed so that they have tg_ prefix and the unnecessary @pol arguments are dropped.

* Per-cpu stats allocation code is also moved from blk-cgroup.c to blk-throttle.c and gets simplified to only deal with BLKIO_POLICY_THROTL. percpu stat free is performed by the exit method throtl_exit_blkio_group().

* throtl_reset_group_stats() implemented for blkio_reset_group_stats_fn method so that tg->stats_cpu can be reset.

---
 block/blk-cgroup.c   |   98 +--------------------------------------
 block/blk-cgroup.h   |   13 -----
 block/blk-throttle.c |  128 ++++++++++++++++++++++++++++++++++++++++++++------
 3 files changed, 114 insertions(+), 125 deletions(-)
block/blk-cgroup.c +1 -97
index d7c7f17..0b4b765 100644
@@ -30,13 +30,6 @@ static LIST_HEAD(blkio_list);
 static DEFINE_MUTEX(all_q_mutex);
 static LIST_HEAD(all_q_list);
 
-/* List of groups pending per cpu stats allocation */
-static DEFINE_SPINLOCK(alloc_list_lock);
-static LIST_HEAD(alloc_list);
-
-static void blkio_stat_alloc_fn(struct work_struct *);
-static DECLARE_DELAYED_WORK(blkio_stat_alloc_work, blkio_stat_alloc_fn);
-
 struct blkio_cgroup blkio_root_cgroup = { .weight = 2*BLKIO_WEIGHT_DEFAULT };
 EXPORT_SYMBOL_GPL(blkio_root_cgroup);
 
@@ -63,60 +56,6 @@ struct blkio_cgroup *bio_blkio_cgroup(struct bio *bio)
 }
 EXPORT_SYMBOL_GPL(bio_blkio_cgroup);
 
-/*
- * Worker for allocating per cpu stat for blk groups. This is scheduled on
- * the system_nrt_wq once there are some groups on the alloc_list waiting
- * for allocation.
- */
-static void blkio_stat_alloc_fn(struct work_struct *work)
-{
-	static void *pcpu_stats[BLKIO_NR_POLICIES];
-	struct delayed_work *dwork = to_delayed_work(work);
-	struct blkio_group *blkg;
-	int i;
-	bool empty = false;
-
-alloc_stats:
-	for (i = 0; i < BLKIO_NR_POLICIES; i++) {
-		if (pcpu_stats[i] != NULL)
-			continue;
-
-		pcpu_stats[i] = alloc_percpu(struct blkio_group_stats_cpu);
-
-		/* Allocation failed. Try again after some time. */
-		if (pcpu_stats[i] == NULL) {
-			queue_delayed_work(system_nrt_wq, dwork,
-						msecs_to_jiffies(10));
-			return;
-		}
-	}
-
-	spin_lock_irq(&blkio_list_lock);
-	spin_lock(&alloc_list_lock);
-
-	/* cgroup got deleted or queue exited. */
-	if (!list_empty(&alloc_list)) {
-		blkg = list_first_entry(&alloc_list, struct blkio_group,
-						alloc_node);
-		for (i = 0; i < BLKIO_NR_POLICIES; i++) {
-			struct blkg_policy_data *pd = blkg->pd[i];
-
-			if (blkio_policy[i] && pd && !pd->stats_cpu)
-				swap(pd->stats_cpu, pcpu_stats[i]);
-		}
-
-		list_del_init(&blkg->alloc_node);
-	}
-
-	empty = list_empty(&alloc_list);
-
-	spin_unlock(&alloc_list_lock);
-	spin_unlock_irq(&blkio_list_lock);
-
-	if (!empty)
-		goto alloc_stats;
-}
-
 /**
  * blkg_free - free a blkg
  * @blkg: blkg to free
@@ -140,7 +79,6 @@ static void blkg_free(struct blkio_group *blkg)
 		if (pol && pol->ops.blkio_exit_group_fn)
 			pol->ops.blkio_exit_group_fn(blkg);
 
-		free_percpu(pd->stats_cpu);
 		kfree(pd);
 	}
 
@@ -167,7 +105,6 @@ static struct blkio_group *blkg_alloc(struct blkio_cgroup *blkcg,
 
 	blkg->q = q;
 	INIT_LIST_HEAD(&blkg->q_node);
-	INIT_LIST_HEAD(&blkg->alloc_node);
 	blkg->blkcg = blkcg;
 	blkg->refcnt = 1;
 	cgroup_path(blkcg->css.cgroup, blkg->path, sizeof(blkg->path));
@@ -245,12 +182,6 @@ struct blkio_group *blkg_lookup_create(struct blkio_cgroup *blkcg,
 	hlist_add_head_rcu(&blkg->blkcg_node, &blkcg->blkg_list);
 	list_add(&blkg->q_node, &q->blkg_list);
 	spin_unlock(&blkcg->lock);
-
-	spin_lock(&alloc_list_lock);
-	list_add(&blkg->alloc_node, &alloc_list);
-	/* Queue per cpu stat allocation from worker thread. */
-	queue_delayed_work(system_nrt_wq, &blkio_stat_alloc_work, 0);
-	spin_unlock(&alloc_list_lock);
 out:
 	return blkg;
 }
@@ -284,10 +215,6 @@ static void blkg_destroy(struct blkio_group *blkg)
 	list_del_init(&blkg->q_node);
 	hlist_del_init_rcu(&blkg->blkcg_node);
 
-	spin_lock(&alloc_list_lock);
-	list_del_init(&blkg->alloc_node);
-	spin_unlock(&alloc_list_lock);
-
 	/*
 	 * Put the reference taken at the time of creation so that when all
 	 * queues are gone, group can be destroyed.
@@ -319,9 +246,6 @@ void update_root_blkg_pd(struct request_queue *q, enum blkio_policy_id plid)
 	pd = kzalloc(sizeof(*pd) + pol->pdata_size, GFP_KERNEL);
 	WARN_ON_ONCE(!pd);
 
-	pd->stats_cpu = alloc_percpu(struct blkio_group_stats_cpu);
-	WARN_ON_ONCE(!pd->stats_cpu);
-
 	blkg->pd[plid] = pd;
 	pd->blkg = blkg;
 	pol->ops.blkio_init_group_fn(blkg);
@@ -381,23 +305,6 @@ void __blkg_release(struct blkio_group *blkg)
 }
 EXPORT_SYMBOL_GPL(__blkg_release);
 
-static void blkio_reset_stats_cpu(struct blkio_group *blkg, int plid)
-{
-	struct blkg_policy_data *pd = blkg->pd[plid];
-	int cpu;
-
-	if (pd->stats_cpu == NULL)
-		return;
-
-	for_each_possible_cpu(cpu) {
-		struct blkio_group_stats_cpu *sc =
-			per_cpu_ptr(pd->stats_cpu, cpu);
-
-		blkg_rwstat_reset(&sc->service_bytes);
-		blkg_rwstat_reset(&sc->serviced);
-	}
-}
-
 static int
 blkiocg_reset_stats(struct cgroup *cgroup, struct cftype *cftype, u64 val)
 {
@@ -416,12 +323,9 @@ blkiocg_reset_stats(struct cgroup *cgroup, struct cftype *cftype, u64 val)
 	hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node) {
 		struct blkio_policy_type *pol;
 
-		list_for_each_entry(pol, &blkio_list, list) {
-			blkio_reset_stats_cpu(blkg, pol->plid);
-
+		list_for_each_entry(pol, &blkio_list, list)
 			if (pol->ops.blkio_reset_group_stats_fn)
 				pol->ops.blkio_reset_group_stats_fn(blkg);
-		}
 	}
 
 	spin_unlock_irq(&blkcg->lock);
block/blk-cgroup.h +0 -13
index 791570394..e368dd00 100644
@@ -64,14 +64,6 @@ struct blkg_rwstat {
 	uint64_t			cnt[BLKG_RWSTAT_NR];
 };
 
-/* Per cpu blkio group stats */
-struct blkio_group_stats_cpu {
-	/* total bytes transferred */
-	struct blkg_rwstat		service_bytes;
-	/* total IOs serviced, post merge */
-	struct blkg_rwstat		serviced;
-};
-
 struct blkio_group_conf {
 	unsigned int weight;
 	u64 iops[2];
@@ -86,9 +78,6 @@ struct blkg_policy_data {
 	/* Configuration */
 	struct blkio_group_conf conf;
 
-	/* Per cpu stats pointer */
-	struct blkio_group_stats_cpu __percpu *stats_cpu;
-
 	/* pol->pdata_size bytes of private data used by policy impl */
 	char pdata[] __aligned(__alignof__(unsigned long long));
 };
@@ -106,8 +95,6 @@ struct blkio_group {
 
 	struct blkg_policy_data *pd[BLKIO_NR_POLICIES];
 
-	/* List of blkg waiting for per cpu stats memory to be allocated */
-	struct list_head alloc_node;
 	struct rcu_head rcu_head;
 };
 
block/blk-throttle.c +113 -15

209 lines not on this page · raw message

Signature · 1 line
1.7.7.3
author maintainer
#23 lore raw

PATCH 18/21 blkcg: move blkio_group_conf->weight to cfq

In reply to Tejun Heo

blkio_group_conf->weight is owned by cfq and has no reason to be defined in blkcg core. Replace it with cfq_group->dev_weight and let conf setting functions directly set it. If dev_weight is zero, the cfqg doesn't have device specific weight configured.

Also, rename BLKIO_WEIGHT_* constants to CFQ_WEIGHT_* and rename blkio_cgroup->weight to blkio_cgroup->cfq_weight. We eventually want per-policy storage in blkio_cgroup but just mark the ownership of the field for now.

---
 block/blk-cgroup.c  |    4 +-
 block/blk-cgroup.h  |   14 +++++----
 block/cfq-iosched.c |   77 +++++++++++++++++++++++---------------------------
 3 files changed, 45 insertions(+), 50 deletions(-)
block/blk-cgroup.c +2 -2
index 0b4b765..7688aef 100644
@@ -30,7 +30,7 @@ static LIST_HEAD(blkio_list);
 static DEFINE_MUTEX(all_q_mutex);
 static LIST_HEAD(all_q_list);
 
-struct blkio_cgroup blkio_root_cgroup = { .weight = 2*BLKIO_WEIGHT_DEFAULT };
+struct blkio_cgroup blkio_root_cgroup = { .cfq_weight = 2 * CFQ_WEIGHT_DEFAULT };
 EXPORT_SYMBOL_GPL(blkio_root_cgroup);
 
 static struct blkio_policy_type *blkio_policy[BLKIO_NR_POLICIES];
@@ -611,7 +611,7 @@ static struct cgroup_subsys_state *blkiocg_create(struct cgroup *cgroup)
 	if (!blkcg)
 		return ERR_PTR(-ENOMEM);
 
-	blkcg->weight = BLKIO_WEIGHT_DEFAULT;
+	blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
 	blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
 done:
 	spin_lock_init(&blkcg->lock);
block/blk-cgroup.h +8 -6
index e368dd00..386db29 100644
@@ -29,6 +29,11 @@ enum blkio_policy_id {
 
 #ifdef CONFIG_BLK_CGROUP
 
+/* CFQ specific, out here for blkcg->cfq_weight */
+#define CFQ_WEIGHT_MIN		10
+#define CFQ_WEIGHT_MAX		1000
+#define CFQ_WEIGHT_DEFAULT	500
+
 /* cft->private [un]packing for stat printing */
 #define BLKCG_STAT_PRIV(pol, off)	(((unsigned)(pol) << 16) | (off))
 #define BLKCG_STAT_POL(prv)		((unsigned)(prv) >> 16)
@@ -46,12 +51,14 @@ enum blkg_rwstat_type {
 
 struct blkio_cgroup {
 	struct cgroup_subsys_state css;
-	unsigned int weight;
 	spinlock_t lock;
 	struct hlist_head blkg_list;
 
 	/* for policies to test whether associated blkcg has changed */
 	uint64_t id;
+
+	/* TODO: per-policy storage in blkio_cgroup */
+	unsigned int cfq_weight;	/* belongs to cfq */
 };
 
 struct blkg_stat {
@@ -65,7 +72,6 @@ struct blkg_rwstat {
 };
 
 struct blkio_group_conf {
-	unsigned int weight;
 	u64 iops[2];
 	u64 bps[2];
 };
@@ -355,10 +361,6 @@ static inline void blkg_put(struct blkio_group *blkg) { }
 
 #endif
 
-#define BLKIO_WEIGHT_MIN	10
-#define BLKIO_WEIGHT_MAX	1000
-#define BLKIO_WEIGHT_DEFAULT	500
-
 #ifdef CONFIG_BLK_CGROUP
 extern struct blkio_cgroup blkio_root_cgroup;
 extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
block/cfq-iosched.c +35 -42

170 lines not on this page · raw message

Signature · 1 line
1.7.7.3
author maintainer
#85 lore raw

PATCH 19/21 blkcg: move blkio_group_conf->iops and ->bps to blk-throttle

In reply to Tejun Heo

blkio_cgroup_conf->iops and ->bps are owned by blk-throttle and has no reason to be defined in blkcg core. Drop them and let conf setting functions directly manipulate throtl_grp->bps[] and ->iops[].

This makes blkio_group_conf empty. Drop it.

---
 block/blk-cgroup.h   |    8 ---
 block/blk-throttle.c |  153 +++++++++++++++++++-------------------------------
 2 files changed, 58 insertions(+), 103 deletions(-)
block/blk-cgroup.h +0 -8
index 386db29..a77ab1a 100644
@@ -71,19 +71,11 @@ struct blkg_rwstat {
 	uint64_t			cnt[BLKG_RWSTAT_NR];
 };
 
-struct blkio_group_conf {
-	u64 iops[2];
-	u64 bps[2];
-};
-
 /* per-blkg per-policy data */
 struct blkg_policy_data {
 	/* the blkg this per-policy data belongs to */
 	struct blkio_group *blkg;
 
-	/* Configuration */
-	struct blkio_group_conf conf;
-
 	/* pol->pdata_size bytes of private data used by policy impl */
 	char pdata[] __aligned(__alignof__(unsigned long long));
 };
block/blk-throttle.c +58 -95

217 lines not on this page · raw message

Signature · 1 line
1.7.7.3
author maintainer
#86 lore raw

PATCH 20/21 blkcg: pass around pd->pdata instead of pd itself in prfill functions

In reply to Tejun Heo

Now that all conf and stat fields are moved into policy specific blkio_policy_data->pdata areas, there's no reason to use blkio_policy_data itself in prfill functions. Pass around @pd->pdata instead of @pd.

---
 block/blk-cgroup.c   |   33 +++++++++++++++------------------
 block/blk-cgroup.h   |    6 +++---
 block/blk-throttle.c |   21 +++++++++------------
 block/cfq-iosched.c  |   14 ++++++--------
 4 files changed, 33 insertions(+), 41 deletions(-)
block/blk-cgroup.c +15 -18
index 7688aef..8f678d7 100644
@@ -359,7 +359,7 @@ static const char *blkg_dev_name(struct blkio_group *blkg)
  * cftype->read_seq_string method.
  */
 void blkcg_print_blkgs(struct seq_file *sf, struct blkio_cgroup *blkcg,
-		       u64 (*prfill)(struct seq_file *, struct blkg_policy_data *, int),
+		       u64 (*prfill)(struct seq_file *, void *, int),
 		       int pol, int data, bool show_total)
 {
 	struct blkio_group *blkg;
@@ -369,7 +369,7 @@ void blkcg_print_blkgs(struct seq_file *sf, struct blkio_cgroup *blkcg,
 	spin_lock_irq(&blkcg->lock);
 	hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node)
 		if (blkg->pd[pol])
-			total += prfill(sf, blkg->pd[pol], data);
+			total += prfill(sf, blkg->pd[pol]->pdata, data);
 	spin_unlock_irq(&blkcg->lock);
 
 	if (show_total)
@@ -380,14 +380,14 @@ EXPORT_SYMBOL_GPL(blkcg_print_blkgs);
 /**
  * __blkg_prfill_u64 - prfill helper for a single u64 value
  * @sf: seq_file to print to
- * @pd: policy data of interest
+ * @pdata: policy private data of interest
  * @v: value to print
  *
- * Print @v to @sf for the device assocaited with @pd.
+ * Print @v to @sf for the device assocaited with @pdata.
  */
-u64 __blkg_prfill_u64(struct seq_file *sf, struct blkg_policy_data *pd, u64 v)
+u64 __blkg_prfill_u64(struct seq_file *sf, void *pdata, u64 v)
 {
-	const char *dname = blkg_dev_name(pd->blkg);
+	const char *dname = blkg_dev_name(pdata_to_blkg(pdata));
 
 	if (!dname)
 		return 0;
@@ -400,12 +400,12 @@ EXPORT_SYMBOL_GPL(__blkg_prfill_u64);
 /**
  * __blkg_prfill_rwstat - prfill helper for a blkg_rwstat
  * @sf: seq_file to print to
- * @pd: policy data of interest
+ * @pdata: policy private data of interest
  * @rwstat: rwstat to print
  *
- * Print @rwstat to @sf for the device assocaited with @pd.
+ * Print @rwstat to @sf for the device assocaited with @pdata.
  */
-u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
+u64 __blkg_prfill_rwstat(struct seq_file *sf, void *pdata,
 			 const struct blkg_rwstat *rwstat)
 {
 	static const char *rwstr[] = {
@@ -414,7 +414,7 @@ u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
 		[BLKG_RWSTAT_SYNC]	= "Sync",
 		[BLKG_RWSTAT_ASYNC]	= "Async",
 	};
-	const char *dname = blkg_dev_name(pd->blkg);
+	const char *dname = blkg_dev_name(pdata_to_blkg(pdata));
 	u64 v;
 	int i;
 
@@ -430,19 +430,16 @@ u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
 	return v;
 }
 
-static u64 blkg_prfill_stat(struct seq_file *sf, struct blkg_policy_data *pd,
-			    int off)
+static u64 blkg_prfill_stat(struct seq_file *sf, void *pdata, int off)
 {
-	return __blkg_prfill_u64(sf, pd,
-				 blkg_stat_read((void *)pd->pdata + off));
+	return __blkg_prfill_u64(sf, pdata, blkg_stat_read(pdata + off));
 }
 
-static u64 blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
-			      int off)
+static u64 blkg_prfill_rwstat(struct seq_file *sf, void *pdata, int off)
 {
-	struct blkg_rwstat rwstat = blkg_rwstat_read((void *)pd->pdata + off);
+	struct blkg_rwstat rwstat = blkg_rwstat_read(pdata + off);
 
-	return __blkg_prfill_rwstat(sf, pd, &rwstat);
+	return __blkg_prfill_rwstat(sf, pdata, &rwstat);
 }
 
 /* print blkg_stat specified by BLKCG_STAT_PRIV() */
block/blk-cgroup.h +3 -3
index a77ab1a..c930895 100644
@@ -126,10 +126,10 @@ extern void update_root_blkg_pd(struct request_queue *q,
 				enum blkio_policy_id plid);
 
 void blkcg_print_blkgs(struct seq_file *sf, struct blkio_cgroup *blkcg,
-		       u64 (*prfill)(struct seq_file *, struct blkg_policy_data *, int),
+		       u64 (*prfill)(struct seq_file *, void *, int),
 		       int pol, int data, bool show_total);
-u64 __blkg_prfill_u64(struct seq_file *sf, struct blkg_policy_data *pd, u64 v);
-u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
+u64 __blkg_prfill_u64(struct seq_file *sf, void *pdata, u64 v);
+u64 __blkg_prfill_rwstat(struct seq_file *sf, void *pdata,
 			 const struct blkg_rwstat *rwstat);
 int blkcg_print_stat(struct cgroup *cgrp, struct cftype *cft,
 		     struct seq_file *sf);
block/blk-throttle.c +9 -12
index 004964b..bd6dbfe 100644
@@ -924,10 +924,9 @@ throtl_schedule_delayed_work(struct throtl_data *td, unsigned long delay)
 	}
 }
 
-static u64 tg_prfill_cpu_rwstat(struct seq_file *sf,
-				struct blkg_policy_data *pd, int off)
+static u64 tg_prfill_cpu_rwstat(struct seq_file *sf, void *pdata, int off)
 {
-	struct throtl_grp *tg = (void *)pd->pdata;
+	struct throtl_grp *tg = pdata;
 	struct blkg_rwstat rwstat = { }, tmp;
 	int i, cpu;
 
@@ -939,7 +938,7 @@ static u64 tg_prfill_cpu_rwstat(struct seq_file *sf,
 			rwstat.cnt[i] += tmp.cnt[i];
 	}
 
-	return __blkg_prfill_rwstat(sf, pd, &rwstat);
+	return __blkg_prfill_rwstat(sf, pdata, &rwstat);
 }
 
 /* print per-cpu blkg_rwstat specified by BLKCG_STAT_PRIV() */
@@ -954,24 +953,22 @@ static int tg_print_cpu_rwstat(struct cgroup *cgrp, struct cftype *cft,
 	return 0;
 }
 
-static u64 tg_prfill_conf_u64(struct seq_file *sf, struct blkg_policy_data *pd,
-			      int off)
+static u64 tg_prfill_conf_u64(struct seq_file *sf, void *pdata, int off)
 {
-	u64 v = *(u64 *)((void *)pd->pdata + off);
+	u64 v = *(u64 *)(pdata + off);
 
 	if (v == -1)
 		return 0;
-	return __blkg_prfill_u64(sf, pd, v);
+	return __blkg_prfill_u64(sf, pdata, v);
 }
 
-static u64 tg_prfill_conf_uint(struct seq_file *sf, struct blkg_policy_data *pd,
-			       int off)
+static u64 tg_prfill_conf_uint(struct seq_file *sf, void *pdata, int off)
 {
-	unsigned int v = *(unsigned int *)((void *)pd->pdata + off);
+	unsigned int v = *(unsigned int *)(pdata + off);
 
 	if (v == -1)
 		return 0;
-	return __blkg_prfill_u64(sf, pd, v);
+	return __blkg_prfill_u64(sf, pdata, v);
 }
 
 static int tg_print_conf_u64(struct cgroup *cgrp, struct cftype *cft,
block/cfq-iosched.c +6 -8
index adab10d..fd505f7 100644
@@ -1368,14 +1368,13 @@ static void cfq_link_cfqq_cfqg(struct cfq_queue *cfqq, struct cfq_group *cfqg)
 	cfqg_get(cfqg);
 }
 
-static u64 cfqg_prfill_weight_device(struct seq_file *sf,
-				     struct blkg_policy_data *pd, int off)
+static u64 cfqg_prfill_weight_device(struct seq_file *sf, void *pdata, int off)
 {
-	struct cfq_group *cfqg = (void *)pd->pdata;
+	struct cfq_group *cfqg = pdata;
 
 	if (!cfqg->dev_weight)
 		return 0;
-	return __blkg_prfill_u64(sf, pd, cfqg->dev_weight);
+	return __blkg_prfill_u64(sf, pdata, cfqg->dev_weight);
 }
 
 static int cfqg_print_weight_device(struct cgroup *cgrp, struct cftype *cft,
@@ -1443,10 +1442,9 @@ static int cfq_set_weight(struct cgroup *cgrp, struct cftype *cft, u64 val)
 }
 
 #ifdef CONFIG_DEBUG_BLK_CGROUP
-static u64 cfqg_prfill_avg_queue_size(struct seq_file *sf,
-				      struct blkg_policy_data *pd, int off)
+static u64 cfqg_prfill_avg_queue_size(struct seq_file *sf, void *pdata, int off)
 {
-	struct cfq_group *cfqg = (void *)pd->pdata;
+	struct cfq_group *cfqg = pdata;
 	u64 samples = blkg_stat_read(&cfqg->stats.avg_queue_size_samples);
 	u64 v = 0;
 
@@ -1454,7 +1452,7 @@ static u64 cfqg_prfill_avg_queue_size(struct seq_file *sf,
 		v = blkg_stat_read(&cfqg->stats.avg_queue_size_sum);
 		do_div(v, samples);
 	}
-	__blkg_prfill_u64(sf, pd, v);
+	__blkg_prfill_u64(sf, pdata, v);
 	return 0;
 }
 
Signature · 1 line
1.7.7.3
author maintainer
#87 lore raw

PATCH 21/21 blkcg: drop BLKCG_STAT_{PRIV|POL|OFF} macros

In reply to Tejun Heo

Now that all stat handling code lives in policy implementations, there's no need to encode policy ID in cft->private.

* Export blkcg_prfill_[rw]stat() from blkcg, remove blkcg_print_[rw]stat(), and implement cfqg_print_[rw]stat() which use hard-code BLKIO_POLICY_PROP.

* Use cft->private for offset of the target field directly and drop BLKCG_STAT_{PRIV|POL|OFF}().

---
 block/blk-cgroup.c   |   48 ++++++++++++----------------
 block/blk-cgroup.h   |   11 +-----
 block/blk-throttle.c |   12 ++-----
 block/cfq-iosched.c  |   85 +++++++++++++++++++++++++++-----------------------
 4 files changed, 72 insertions(+), 84 deletions(-)
block/blk-cgroup.c +20 -28
index 8f678d7..f762333 100644
@@ -430,43 +430,35 @@ u64 __blkg_prfill_rwstat(struct seq_file *sf, void *pdata,
 	return v;
 }
 
-static u64 blkg_prfill_stat(struct seq_file *sf, void *pdata, int off)
+/**
+ * blkg_prfill_stat - prfill callback for blkg_stat
+ * @sf: seq_file to print to
+ * @pdata: policy private data of interest
+ * @off: offset to the blkg_stat in @pdata
+ *
+ * prfill callback for printing a blkg_stat.
+ */
+u64 blkg_prfill_stat(struct seq_file *sf, void *pdata, int off)
 {
 	return __blkg_prfill_u64(sf, pdata, blkg_stat_read(pdata + off));
 }
+EXPORT_SYMBOL_GPL(blkg_prfill_stat);
 
-static u64 blkg_prfill_rwstat(struct seq_file *sf, void *pdata, int off)
+/**
+ * blkg_prfill_rwstat - prfill callback for blkg_rwstat
+ * @sf: seq_file to print to
+ * @pdata: policy private data of interest
+ * @off: offset to the blkg_rwstat in @pdata
+ *
+ * prfill callback for printing a blkg_rwstat.
+ */
+u64 blkg_prfill_rwstat(struct seq_file *sf, void *pdata, int off)
 {
 	struct blkg_rwstat rwstat = blkg_rwstat_read(pdata + off);
 
 	return __blkg_prfill_rwstat(sf, pdata, &rwstat);
 }
-
-/* print blkg_stat specified by BLKCG_STAT_PRIV() */
-int blkcg_print_stat(struct cgroup *cgrp, struct cftype *cft,
-		     struct seq_file *sf)
-{
-	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
-
-	blkcg_print_blkgs(sf, blkcg, blkg_prfill_stat,
-			  BLKCG_STAT_POL(cft->private),
-			  BLKCG_STAT_OFF(cft->private), false);
-	return 0;
-}
-EXPORT_SYMBOL_GPL(blkcg_print_stat);
-
-/* print blkg_rwstat specified by BLKCG_STAT_PRIV() */
-int blkcg_print_rwstat(struct cgroup *cgrp, struct cftype *cft,
-		       struct seq_file *sf)
-{
-	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
-
-	blkcg_print_blkgs(sf, blkcg, blkg_prfill_rwstat,
-			  BLKCG_STAT_POL(cft->private),
-			  BLKCG_STAT_OFF(cft->private), true);
-	return 0;
-}
-EXPORT_SYMBOL_GPL(blkcg_print_rwstat);
+EXPORT_SYMBOL_GPL(blkg_prfill_rwstat);
 
 /**
  * blkg_conf_prep - parse and prepare for per-blkg config update
block/blk-cgroup.h +2 -9
index c930895..ca0ff7c 100644
@@ -34,11 +34,6 @@ enum blkio_policy_id {
 #define CFQ_WEIGHT_MAX		1000
 #define CFQ_WEIGHT_DEFAULT	500
 
-/* cft->private [un]packing for stat printing */
-#define BLKCG_STAT_PRIV(pol, off)	(((unsigned)(pol) << 16) | (off))
-#define BLKCG_STAT_POL(prv)		((unsigned)(prv) >> 16)
-#define BLKCG_STAT_OFF(prv)		((unsigned)(prv) & 0xffff)
-
 enum blkg_rwstat_type {
 	BLKG_RWSTAT_READ,
 	BLKG_RWSTAT_WRITE,
@@ -131,10 +126,8 @@ void blkcg_print_blkgs(struct seq_file *sf, struct blkio_cgroup *blkcg,
 u64 __blkg_prfill_u64(struct seq_file *sf, void *pdata, u64 v);
 u64 __blkg_prfill_rwstat(struct seq_file *sf, void *pdata,
 			 const struct blkg_rwstat *rwstat);
-int blkcg_print_stat(struct cgroup *cgrp, struct cftype *cft,
-		     struct seq_file *sf);
-int blkcg_print_rwstat(struct cgroup *cgrp, struct cftype *cft,
-		       struct seq_file *sf);
+u64 blkg_prfill_stat(struct seq_file *sf, void *pdata, int off);
+u64 blkg_prfill_rwstat(struct seq_file *sf, void *pdata, int off);
 
 struct blkg_conf_ctx {
 	struct gendisk		*disk;
block/blk-throttle.c +4 -8
index bd6dbfe..6024014 100644
@@ -941,15 +941,13 @@ static u64 tg_prfill_cpu_rwstat(struct seq_file *sf, void *pdata, int off)
 	return __blkg_prfill_rwstat(sf, pdata, &rwstat);
 }
 
-/* print per-cpu blkg_rwstat specified by BLKCG_STAT_PRIV() */
 static int tg_print_cpu_rwstat(struct cgroup *cgrp, struct cftype *cft,
 			       struct seq_file *sf)
 {
 	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
 
-	blkcg_print_blkgs(sf, blkcg, tg_prfill_cpu_rwstat,
-			  BLKCG_STAT_POL(cft->private),
-			  BLKCG_STAT_OFF(cft->private), true);
+	blkcg_print_blkgs(sf, blkcg, tg_prfill_cpu_rwstat, BLKIO_POLICY_THROTL,
+			  cft->private, true);
 	return 0;
 }
 
@@ -1067,14 +1065,12 @@ static struct cftype throtl_files[] = {
 	},
 	{
 		.name = "throttle.io_service_bytes",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_THROTL,
-				offsetof(struct tg_stats_cpu, service_bytes)),
+		.private = offsetof(struct tg_stats_cpu, service_bytes),
 		.read_seq_string = tg_print_cpu_rwstat,
 	},
 	{
 		.name = "throttle.io_serviced",
-		.private = BLKCG_STAT_PRIV(BLKIO_POLICY_THROTL,
-				offsetof(struct tg_stats_cpu, serviced)),
+		.private = offsetof(struct tg_stats_cpu, serviced),
 		.read_seq_string = tg_print_cpu_rwstat,
 	},
 	{ }	/* terminate */
block/cfq-iosched.c +46 -39

136 lines not on this page · raw message

Signature · 1 line
1.7.7.3
author maintainer
#13 lore raw

Re: [PATCH 08/21] blkcg: blkg_conf_prep()

In reply to Tejun Heo

Oops, $SUBJ should have been "simplify blkg_conf_prep()".

Signature · 1 line
tejun
maintainer
#88 lore raw
In reply to Tejun Heo
Quoted 8 lines · Tejun Heo

and is on top of

block/for-3.5/core eb7d8c07f9 "cfq: fix cfqg ref handling..."
+ [1] cgroup-cftypes d954ca6469 "cgroup: implement cgroup_rm_cftypes()"

Note that the cgroup branch is temporary and the merge between the two branches aren't trivial. I'll prepare a proper merged branch once the cgroup/for-3.5 branch is settled.

The diffstat is very tasty... I'll leave this on out until the cgroup merge mess is settled, though.

Signature · 1 line
Jens Axboe
#4 lore raw
In reply to a message not in the archive

On Wed, Mar 28, 2012 at 03:51:10PM -0700, Tejun Heo wrote:

[..]

Quoted 4 lines

This patchset is an attempt at bringing some sanity to blkcg config and stat file handling. It makes use of the pending dynamic cgroup file type addition / removal support [1], which will be merged into cgroup/for-3.5 once 3.4-rc1 is released.

Thanks Tejun. This looks like a nice cleanup. Especially the stat part. It was very messy in blkcg core code. Now atleast it is clear who owns what file and who needs per cpu stats etc. And new policies should be easily able to define their own cgroup files.

Thanks
Vivek

#96 lore raw
In reply to Tejun Heo

On Wed, Mar 28, 2012 at 03:51:10PM -0700, Tejun Heo wrote:

[..]

Quoted 4 lines

This patchset is an attempt at bringing some sanity to blkcg config and stat file handling. It makes use of the pending dynamic cgroup file type addition / removal support [1], which will be merged into cgroup/for-3.5 once 3.4-rc1 is released.

Thanks Tejun. This looks like a nice cleanup. Especially the stat part. It was very messy in blkcg core code. Now atleast it is clear who owns what file and who needs per cpu stats etc. And new policies should be easily able to define their own cgroup files.

Thanks
Vivek

#24 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

In reply to Tejun Heo
Quoted 9 lines · Tejun Heo

blkio_group_conf->weight is owned by cfq and has no reason to be defined in blkcg core. Replace it with cfq_group->dev_weight and let conf setting functions directly set it. If dev_weight is zero, the cfqg doesn't have device specific weight configured.

Also, rename BLKIO_WEIGHT_* constants to CFQ_WEIGHT_* and rename blkio_cgroup->weight to blkio_cgroup->cfq_weight. We eventually want per-policy storage in blkio_cgroup but just mark the ownership of the field for now.

Hi Tejun,

blkio_cgroup->weight can be thought of in a more generic manner and that is sytem wide cgroup weight. And more than one policy should be allowed to make use of it. That's a differnt thing that currently only CFQ makes use of it.

For example, Fengguang posted RFC patches to try to make use of blkcg->weight and differentiate between buffered write bandwidth.

https://lkml.org/lkml/2012/3/28/275

Thanks
Vivek

author maintainer
#25 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

Hello, Vivek.

Quoted 9 lines · Vivek Goyal

blkio_cgroup->weight can be thought of in a more generic manner and that is sytem wide cgroup weight. And more than one policy should be allowed to make use of it. That's a differnt thing that currently only CFQ makes use of it.

For example, Fengguang posted RFC patches to try to make use of blkcg->weight and differentiate between buffered write bandwidth.

https://lkml.org/lkml/2012/3/28/275

I don't think that's a good idea. It makes it fuzzy which knob controls what. If we're gonna have single set of controls followed by all controllers, fine, but I really don't think we should be mixing different layers of configurations. I mean, what about blkcg.read_bps then? Let's just give this one to cfq. If someone else wants weight, let it use its own weight config.

Thanks.

Signature · 1 line
tejun
#27 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

In reply to a message not in the archive

Hello, Vivek.

Quoted 9 lines · Vivek Goyal

blkio_cgroup->weight can be thought of in a more generic manner and that is sytem wide cgroup weight. And more than one policy should be allowed to make use of it. That's a differnt thing that currently only CFQ makes use of it.

For example, Fengguang posted RFC patches to try to make use of blkcg->weight and differentiate between buffered write bandwidth.

https://lkml.org/lkml/2012/3/28/275

I don't think that's a good idea. It makes it fuzzy which knob controls what. If we're gonna have single set of controls followed by all controllers, fine, but I really don't think we should be mixing different layers of configurations. I mean, what about blkcg.read_bps then? Let's just give this one to cfq. If someone else wants weight, let it use its own weight config.

Thanks.

Signature · 1 line
tejun
#5 lore raw
In reply to a message not in the archive
Quoted 5 lines · Tejun Heo

and is on top of

block/for-3.5/core eb7d8c07f9 "cfq: fix cfqg ref handling..."
+ [1] cgroup-cftypes d954ca6469 "cgroup: implement cgroup_rm_cftypes()"

Quoted 7 lines

Note that the cgroup branch is temporary and the merge between the two branches aren't trivial. I'll prepare a proper merged branch once the cgroup/for-3.5 branch is settled.

This patchset is also available in the following git branch.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git blkcg-files

The above branch has been updated on top of block/for-3.5/core + cgroup/for-3.5. Ready to be pulled.

Thanks.

Signature · 1 line
tejun
author maintainer
#97 lore raw
In reply to Tejun Heo
Quoted 5 lines · Tejun Heo

and is on top of

block/for-3.5/core eb7d8c07f9 "cfq: fix cfqg ref handling..."
+ [1] cgroup-cftypes d954ca6469 "cgroup: implement cgroup_rm_cftypes()"

Quoted 7 lines

Note that the cgroup branch is temporary and the merge between the two branches aren't trivial. I'll prepare a proper merged branch once the cgroup/for-3.5 branch is settled.

This patchset is also available in the following git branch.

git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git blkcg-files

The above branch has been updated on top of block/for-3.5/core + cgroup/for-3.5. Ready to be pulled.

Thanks.

Signature · 1 line
tejun
author maintainer
#89 lore raw
In reply to Jens Axboe

Hey, Jens.

Quoted 2 lines · Jens Axboe

The diffstat is very tasty... I'll leave this on out until the cgroup merge mess is settled, though.

The following branch contains this patchset on top of the current block/for-3.5/core 959d851caa "Merge branch 'for-3.5' of ../cgroup into block/for-3.5/core-merged".

git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git blkcg-files

Other than $SUBJ update on the eigth patch from "blkcg:
blkg_conf_prep()" to "blkcg: simplify blkg_conf_prep()", the patchset can be applied as-is on top of the current block/for-3.5/core.

Thanks.

Signature · 1 line
tejun
#95 lore raw
In reply to a message not in the archive

Hey, Jens.

Quoted 2 lines · Jens Axboe

The diffstat is very tasty... I'll leave this on out until the cgroup merge mess is settled, though.

The following branch contains this patchset on top of the current block/for-3.5/core 959d851caa "Merge branch 'for-3.5' of ../cgroup into block/for-3.5/core-merged".

git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git blkcg-files

Other than $SUBJ update on the eigth patch from "blkcg:
blkg_conf_prep()" to "blkcg: simplify blkg_conf_prep()", the patchset can be applied as-is on top of the current block/for-3.5/core.

Thanks.

Signature · 1 line
tejun
#28 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

In reply to Tejun Heo

Hi Tejun,

Quoted 9 lines · Tejun Heo

blkio_group_conf->weight is owned by cfq and has no reason to be defined in blkcg core. Replace it with cfq_group->dev_weight and let conf setting functions directly set it. If dev_weight is zero, the cfqg doesn't have device specific weight configured.

Also, rename BLKIO_WEIGHT_* constants to CFQ_WEIGHT_* and rename blkio_cgroup->weight to blkio_cgroup->cfq_weight. We eventually want per-policy storage in blkio_cgroup but just mark the ownership of the field for now.

I guess blkio->weight is a generic way of abstracting the weight between different block cgroups. Yes, currently, only cfq uses it, but I am trying to improve Shaohua's original fiops scheduler and add cgroup support to it. So please leave it there so that future scheduler(if other than the fiops scheduler) can use the framework.

Thanks
Tao

Quoted 264 lines
---
 block/blk-cgroup.c  |    4 +-
 block/blk-cgroup.h  |   14 +++++----
 block/cfq-iosched.c |   77 +++++++++++++++++++++++---------------------------
 3 files changed, 45 insertions(+), 50 deletions(-)
block/blk-cgroup.c +2 -2
index 0b4b765..7688aef 100644
@@ -30,7 +30,7 @@ static LIST_HEAD(blkio_list);
 static DEFINE_MUTEX(all_q_mutex);
 static LIST_HEAD(all_q_list);
 
-struct blkio_cgroup blkio_root_cgroup = { .weight = 2*BLKIO_WEIGHT_DEFAULT };
+struct blkio_cgroup blkio_root_cgroup = { .cfq_weight = 2 * CFQ_WEIGHT_DEFAULT };
 EXPORT_SYMBOL_GPL(blkio_root_cgroup);
 
 static struct blkio_policy_type *blkio_policy[BLKIO_NR_POLICIES];
@@ -611,7 +611,7 @@ static struct cgroup_subsys_state *blkiocg_create(struct cgroup *cgroup)
 	if (!blkcg)
 		return ERR_PTR(-ENOMEM);
 
-	blkcg->weight = BLKIO_WEIGHT_DEFAULT;
+	blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
 	blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
 done:
 	spin_lock_init(&blkcg->lock);
block/blk-cgroup.h +8 -6
index e368dd00..386db29 100644
@@ -29,6 +29,11 @@ enum blkio_policy_id {
 
 #ifdef CONFIG_BLK_CGROUP
 
+/* CFQ specific, out here for blkcg->cfq_weight */
+#define CFQ_WEIGHT_MIN		10
+#define CFQ_WEIGHT_MAX		1000
+#define CFQ_WEIGHT_DEFAULT	500
+
 /* cft->private [un]packing for stat printing */
 #define BLKCG_STAT_PRIV(pol, off)	(((unsigned)(pol) << 16) | (off))
 #define BLKCG_STAT_POL(prv)		((unsigned)(prv) >> 16)
@@ -46,12 +51,14 @@ enum blkg_rwstat_type {
 
 struct blkio_cgroup {
 	struct cgroup_subsys_state css;
-	unsigned int weight;
 	spinlock_t lock;
 	struct hlist_head blkg_list;
 
 	/* for policies to test whether associated blkcg has changed */
 	uint64_t id;
+
+	/* TODO: per-policy storage in blkio_cgroup */
+	unsigned int cfq_weight;	/* belongs to cfq */
 };
 
 struct blkg_stat {
@@ -65,7 +72,6 @@ struct blkg_rwstat {
 };
 
 struct blkio_group_conf {
-	unsigned int weight;
 	u64 iops[2];
 	u64 bps[2];
 };
@@ -355,10 +361,6 @@ static inline void blkg_put(struct blkio_group *blkg) { }
 
 #endif
 
-#define BLKIO_WEIGHT_MIN	10
-#define BLKIO_WEIGHT_MAX	1000
-#define BLKIO_WEIGHT_DEFAULT	500
-
 #ifdef CONFIG_BLK_CGROUP
 extern struct blkio_cgroup blkio_root_cgroup;
 extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
block/cfq-iosched.c +35 -42
index a1f37df..adab10d 100644
@@ -224,7 +224,7 @@ struct cfq_group {
 	u64 vdisktime;
 	unsigned int weight;
 	unsigned int new_weight;
-	bool needs_update;
+	unsigned int dev_weight;
 
 	/* number of cfqq currently on this group */
 	int nr_cfqq;
@@ -838,7 +838,7 @@ static inline u64 cfq_scale_slice(unsigned long delta, struct cfq_group *cfqg)
 {
 	u64 d = delta << CFQ_SERVICE_SHIFT;
 
-	d = d * BLKIO_WEIGHT_DEFAULT;
+	d = d * CFQ_WEIGHT_DEFAULT;
 	do_div(d, cfqg->weight);
 	return d;
 }
@@ -1165,9 +1165,9 @@ static void
 cfq_update_group_weight(struct cfq_group *cfqg)
 {
 	BUG_ON(!RB_EMPTY_NODE(&cfqg->rb_node));
-	if (cfqg->needs_update) {
+	if (cfqg->new_weight) {
 		cfqg->weight = cfqg->new_weight;
-		cfqg->needs_update = false;
+		cfqg->new_weight = 0;
 	}
 }
 
@@ -1325,21 +1325,12 @@ static void cfq_init_cfqg_base(struct cfq_group *cfqg)
 }
 
 #ifdef CONFIG_CFQ_GROUP_IOSCHED
-static void cfq_update_blkio_group_weight(struct blkio_group *blkg,
-					  unsigned int weight)
-{
-	struct cfq_group *cfqg = blkg_to_cfqg(blkg);
-
-	cfqg->new_weight = weight;
-	cfqg->needs_update = true;
-}
-
 static void cfq_init_blkio_group(struct blkio_group *blkg)
 {
 	struct cfq_group *cfqg = blkg_to_cfqg(blkg);
 
 	cfq_init_cfqg_base(cfqg);
-	cfqg->weight = blkg->blkcg->weight;
+	cfqg->weight = blkg->blkcg->cfq_weight;
 }
 
 /*
@@ -1377,36 +1368,38 @@ static void cfq_link_cfqq_cfqg(struct cfq_queue *cfqq, struct cfq_group *cfqg)
 	cfqg_get(cfqg);
 }
 
-static u64 blkg_prfill_weight_device(struct seq_file *sf,
+static u64 cfqg_prfill_weight_device(struct seq_file *sf,
 				     struct blkg_policy_data *pd, int off)
 {
-	if (!pd->conf.weight)
+	struct cfq_group *cfqg = (void *)pd->pdata;
+
+	if (!cfqg->dev_weight)
 		return 0;
-	return __blkg_prfill_u64(sf, pd, pd->conf.weight);
+	return __blkg_prfill_u64(sf, pd, cfqg->dev_weight);
 }
 
-static int blkcg_print_weight_device(struct cgroup *cgrp, struct cftype *cft,
-				     struct seq_file *sf)
+static int cfqg_print_weight_device(struct cgroup *cgrp, struct cftype *cft,
+				    struct seq_file *sf)
 {
 	blkcg_print_blkgs(sf, cgroup_to_blkio_cgroup(cgrp),
-			  blkg_prfill_weight_device, BLKIO_POLICY_PROP, 0,
+			  cfqg_prfill_weight_device, BLKIO_POLICY_PROP, 0,
 			  false);
 	return 0;
 }
 
-static int blkcg_print_weight(struct cgroup *cgrp, struct cftype *cft,
-			      struct seq_file *sf)
+static int cfq_print_weight(struct cgroup *cgrp, struct cftype *cft,
+			    struct seq_file *sf)
 {
-	seq_printf(sf, "%u\n", cgroup_to_blkio_cgroup(cgrp)->weight);
+	seq_printf(sf, "%u\n", cgroup_to_blkio_cgroup(cgrp)->cfq_weight);
 	return 0;
 }
 
-static int blkcg_set_weight_device(struct cgroup *cgrp, struct cftype *cft,
-				   const char *buf)
+static int cfqg_set_weight_device(struct cgroup *cgrp, struct cftype *cft,
+				  const char *buf)
 {
 	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
-	struct blkg_policy_data *pd;
 	struct blkg_conf_ctx ctx;
+	struct cfq_group *cfqg;
 	int ret;
 
 	ret = blkg_conf_prep(blkcg, buf, &ctx);
@@ -1414,11 +1407,11 @@ static int blkcg_set_weight_device(struct cgroup *cgrp, struct cftype *cft,
 		return ret;
 
 	ret = -EINVAL;
-	pd = ctx.blkg->pd[BLKIO_POLICY_PROP];
-	if (pd && (!ctx.v || (ctx.v >= BLKIO_WEIGHT_MIN &&
-			      ctx.v <= BLKIO_WEIGHT_MAX))) {
-		pd->conf.weight = ctx.v;
-		cfq_update_blkio_group_weight(ctx.blkg, ctx.v ?: blkcg->weight);
+	cfqg = blkg_to_cfqg(ctx.blkg);
+	if (cfqg && (!ctx.v || (ctx.v >= CFQ_WEIGHT_MIN &&
+				ctx.v <= CFQ_WEIGHT_MAX))) {
+		cfqg->dev_weight = ctx.v;
+		cfqg->new_weight = cfqg->dev_weight ?: blkcg->cfq_weight;
 		ret = 0;
 	}
 
@@ -1426,23 +1419,23 @@ static int blkcg_set_weight_device(struct cgroup *cgrp, struct cftype *cft,
 	return ret;
 }
 
-static int blkcg_set_weight(struct cgroup *cgrp, struct cftype *cft, u64 val)
+static int cfq_set_weight(struct cgroup *cgrp, struct cftype *cft, u64 val)
 {
 	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
 	struct blkio_group *blkg;
 	struct hlist_node *n;
 
-	if (val < BLKIO_WEIGHT_MIN || val > BLKIO_WEIGHT_MAX)
+	if (val < CFQ_WEIGHT_MIN || val > CFQ_WEIGHT_MAX)
 		return -EINVAL;
 
 	spin_lock_irq(&blkcg->lock);
-	blkcg->weight = (unsigned int)val;
+	blkcg->cfq_weight = (unsigned int)val;
 
 	hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node) {
-		struct blkg_policy_data *pd = blkg->pd[BLKIO_POLICY_PROP];
+		struct cfq_group *cfqg = blkg_to_cfqg(blkg);
 
-		if (pd && !pd->conf.weight)
-			cfq_update_blkio_group_weight(blkg, blkcg->weight);
+		if (cfqg && !cfqg->dev_weight)
+			cfqg->new_weight = blkcg->cfq_weight;
 	}
 
 	spin_unlock_irq(&blkcg->lock);
@@ -1480,14 +1473,14 @@ static int cfqg_print_avg_queue_size(struct cgroup *cgrp, struct cftype *cft,
 static struct cftype cfq_blkcg_files[] = {
 	{
 		.name = "weight_device",
-		.read_seq_string = blkcg_print_weight_device,
-		.write_string = blkcg_set_weight_device,
+		.read_seq_string = cfqg_print_weight_device,
+		.write_string = cfqg_set_weight_device,
 		.max_write_len = 256,
 	},
 	{
 		.name = "weight",
-		.read_seq_string = blkcg_print_weight,
-		.write_u64 = blkcg_set_weight,
+		.read_seq_string = cfq_print_weight,
+		.write_u64 = cfq_set_weight,
 	},
 	{
 		.name = "time",
@@ -3983,7 +3976,7 @@ static int cfq_init_queue(struct request_queue *q)
 		return -ENOMEM;
 	}
 
-	cfqd->root_group->weight = 2*BLKIO_WEIGHT_DEFAULT;
+	cfqd->root_group->weight = 2 * CFQ_WEIGHT_DEFAULT;
 
 	/*
 	 * Not strictly needed (since RB_ROOT just clears the node and we
#84 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

In reply to a message not in the archive

Hi Tejun,

Quoted 9 lines · Tejun Heo

blkio_group_conf->weight is owned by cfq and has no reason to be defined in blkcg core. Replace it with cfq_group->dev_weight and let conf setting functions directly set it. If dev_weight is zero, the cfqg doesn't have device specific weight configured.

Also, rename BLKIO_WEIGHT_* constants to CFQ_WEIGHT_* and rename blkio_cgroup->weight to blkio_cgroup->cfq_weight. We eventually want per-policy storage in blkio_cgroup but just mark the ownership of the field for now.

I guess blkio->weight is a generic way of abstracting the weight between different block cgroups. Yes, currently, only cfq uses it, but I am trying to improve Shaohua's original fiops scheduler and add cgroup support to it. So please leave it there so that future scheduler(if other than the fiops scheduler) can use the framework.

Thanks
Tao

Quoted 264 lines
---
 block/blk-cgroup.c  |    4 +-
 block/blk-cgroup.h  |   14 +++++----
 block/cfq-iosched.c |   77 +++++++++++++++++++++++---------------------------
 3 files changed, 45 insertions(+), 50 deletions(-)
block/blk-cgroup.c +2 -2
index 0b4b765..7688aef 100644
@@ -30,7 +30,7 @@ static LIST_HEAD(blkio_list);
 static DEFINE_MUTEX(all_q_mutex);
 static LIST_HEAD(all_q_list);
 
-struct blkio_cgroup blkio_root_cgroup = { .weight = 2*BLKIO_WEIGHT_DEFAULT };
+struct blkio_cgroup blkio_root_cgroup = { .cfq_weight = 2 * CFQ_WEIGHT_DEFAULT };
 EXPORT_SYMBOL_GPL(blkio_root_cgroup);
 
 static struct blkio_policy_type *blkio_policy[BLKIO_NR_POLICIES];
@@ -611,7 +611,7 @@ static struct cgroup_subsys_state *blkiocg_create(struct cgroup *cgroup)
 	if (!blkcg)
 		return ERR_PTR(-ENOMEM);
 
-	blkcg->weight = BLKIO_WEIGHT_DEFAULT;
+	blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
 	blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
 done:
 	spin_lock_init(&blkcg->lock);
block/blk-cgroup.h +8 -6
index e368dd00..386db29 100644
@@ -29,6 +29,11 @@ enum blkio_policy_id {
 
 #ifdef CONFIG_BLK_CGROUP
 
+/* CFQ specific, out here for blkcg->cfq_weight */
+#define CFQ_WEIGHT_MIN		10
+#define CFQ_WEIGHT_MAX		1000
+#define CFQ_WEIGHT_DEFAULT	500
+
 /* cft->private [un]packing for stat printing */
 #define BLKCG_STAT_PRIV(pol, off)	(((unsigned)(pol) << 16) | (off))
 #define BLKCG_STAT_POL(prv)		((unsigned)(prv) >> 16)
@@ -46,12 +51,14 @@ enum blkg_rwstat_type {
 
 struct blkio_cgroup {
 	struct cgroup_subsys_state css;
-	unsigned int weight;
 	spinlock_t lock;
 	struct hlist_head blkg_list;
 
 	/* for policies to test whether associated blkcg has changed */
 	uint64_t id;
+
+	/* TODO: per-policy storage in blkio_cgroup */
+	unsigned int cfq_weight;	/* belongs to cfq */
 };
 
 struct blkg_stat {
@@ -65,7 +72,6 @@ struct blkg_rwstat {
 };
 
 struct blkio_group_conf {
-	unsigned int weight;
 	u64 iops[2];
 	u64 bps[2];
 };
@@ -355,10 +361,6 @@ static inline void blkg_put(struct blkio_group *blkg) { }
 
 #endif
 
-#define BLKIO_WEIGHT_MIN	10
-#define BLKIO_WEIGHT_MAX	1000
-#define BLKIO_WEIGHT_DEFAULT	500
-
 #ifdef CONFIG_BLK_CGROUP
 extern struct blkio_cgroup blkio_root_cgroup;
 extern struct blkio_cgroup *cgroup_to_blkio_cgroup(struct cgroup *cgroup);
block/cfq-iosched.c +35 -42
index a1f37df..adab10d 100644
@@ -224,7 +224,7 @@ struct cfq_group {
 	u64 vdisktime;
 	unsigned int weight;
 	unsigned int new_weight;
-	bool needs_update;
+	unsigned int dev_weight;
 
 	/* number of cfqq currently on this group */
 	int nr_cfqq;
@@ -838,7 +838,7 @@ static inline u64 cfq_scale_slice(unsigned long delta, struct cfq_group *cfqg)
 {
 	u64 d = delta << CFQ_SERVICE_SHIFT;
 
-	d = d * BLKIO_WEIGHT_DEFAULT;
+	d = d * CFQ_WEIGHT_DEFAULT;
 	do_div(d, cfqg->weight);
 	return d;
 }
@@ -1165,9 +1165,9 @@ static void
 cfq_update_group_weight(struct cfq_group *cfqg)
 {
 	BUG_ON(!RB_EMPTY_NODE(&cfqg->rb_node));
-	if (cfqg->needs_update) {
+	if (cfqg->new_weight) {
 		cfqg->weight = cfqg->new_weight;
-		cfqg->needs_update = false;
+		cfqg->new_weight = 0;
 	}
 }
 
@@ -1325,21 +1325,12 @@ static void cfq_init_cfqg_base(struct cfq_group *cfqg)
 }
 
 #ifdef CONFIG_CFQ_GROUP_IOSCHED
-static void cfq_update_blkio_group_weight(struct blkio_group *blkg,
-					  unsigned int weight)
-{
-	struct cfq_group *cfqg = blkg_to_cfqg(blkg);
-
-	cfqg->new_weight = weight;
-	cfqg->needs_update = true;
-}
-
 static void cfq_init_blkio_group(struct blkio_group *blkg)
 {
 	struct cfq_group *cfqg = blkg_to_cfqg(blkg);
 
 	cfq_init_cfqg_base(cfqg);
-	cfqg->weight = blkg->blkcg->weight;
+	cfqg->weight = blkg->blkcg->cfq_weight;
 }
 
 /*
@@ -1377,36 +1368,38 @@ static void cfq_link_cfqq_cfqg(struct cfq_queue *cfqq, struct cfq_group *cfqg)
 	cfqg_get(cfqg);
 }
 
-static u64 blkg_prfill_weight_device(struct seq_file *sf,
+static u64 cfqg_prfill_weight_device(struct seq_file *sf,
 				     struct blkg_policy_data *pd, int off)
 {
-	if (!pd->conf.weight)
+	struct cfq_group *cfqg = (void *)pd->pdata;
+
+	if (!cfqg->dev_weight)
 		return 0;
-	return __blkg_prfill_u64(sf, pd, pd->conf.weight);
+	return __blkg_prfill_u64(sf, pd, cfqg->dev_weight);
 }
 
-static int blkcg_print_weight_device(struct cgroup *cgrp, struct cftype *cft,
-				     struct seq_file *sf)
+static int cfqg_print_weight_device(struct cgroup *cgrp, struct cftype *cft,
+				    struct seq_file *sf)
 {
 	blkcg_print_blkgs(sf, cgroup_to_blkio_cgroup(cgrp),
-			  blkg_prfill_weight_device, BLKIO_POLICY_PROP, 0,
+			  cfqg_prfill_weight_device, BLKIO_POLICY_PROP, 0,
 			  false);
 	return 0;
 }
 
-static int blkcg_print_weight(struct cgroup *cgrp, struct cftype *cft,
-			      struct seq_file *sf)
+static int cfq_print_weight(struct cgroup *cgrp, struct cftype *cft,
+			    struct seq_file *sf)
 {
-	seq_printf(sf, "%u\n", cgroup_to_blkio_cgroup(cgrp)->weight);
+	seq_printf(sf, "%u\n", cgroup_to_blkio_cgroup(cgrp)->cfq_weight);
 	return 0;
 }
 
-static int blkcg_set_weight_device(struct cgroup *cgrp, struct cftype *cft,
-				   const char *buf)
+static int cfqg_set_weight_device(struct cgroup *cgrp, struct cftype *cft,
+				  const char *buf)
 {
 	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
-	struct blkg_policy_data *pd;
 	struct blkg_conf_ctx ctx;
+	struct cfq_group *cfqg;
 	int ret;
 
 	ret = blkg_conf_prep(blkcg, buf, &ctx);
@@ -1414,11 +1407,11 @@ static int blkcg_set_weight_device(struct cgroup *cgrp, struct cftype *cft,
 		return ret;
 
 	ret = -EINVAL;
-	pd = ctx.blkg->pd[BLKIO_POLICY_PROP];
-	if (pd && (!ctx.v || (ctx.v >= BLKIO_WEIGHT_MIN &&
-			      ctx.v <= BLKIO_WEIGHT_MAX))) {
-		pd->conf.weight = ctx.v;
-		cfq_update_blkio_group_weight(ctx.blkg, ctx.v ?: blkcg->weight);
+	cfqg = blkg_to_cfqg(ctx.blkg);
+	if (cfqg && (!ctx.v || (ctx.v >= CFQ_WEIGHT_MIN &&
+				ctx.v <= CFQ_WEIGHT_MAX))) {
+		cfqg->dev_weight = ctx.v;
+		cfqg->new_weight = cfqg->dev_weight ?: blkcg->cfq_weight;
 		ret = 0;
 	}
 
@@ -1426,23 +1419,23 @@ static int blkcg_set_weight_device(struct cgroup *cgrp, struct cftype *cft,
 	return ret;
 }
 
-static int blkcg_set_weight(struct cgroup *cgrp, struct cftype *cft, u64 val)
+static int cfq_set_weight(struct cgroup *cgrp, struct cftype *cft, u64 val)
 {
 	struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
 	struct blkio_group *blkg;
 	struct hlist_node *n;
 
-	if (val < BLKIO_WEIGHT_MIN || val > BLKIO_WEIGHT_MAX)
+	if (val < CFQ_WEIGHT_MIN || val > CFQ_WEIGHT_MAX)
 		return -EINVAL;
 
 	spin_lock_irq(&blkcg->lock);
-	blkcg->weight = (unsigned int)val;
+	blkcg->cfq_weight = (unsigned int)val;
 
 	hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node) {
-		struct blkg_policy_data *pd = blkg->pd[BLKIO_POLICY_PROP];
+		struct cfq_group *cfqg = blkg_to_cfqg(blkg);
 
-		if (pd && !pd->conf.weight)
-			cfq_update_blkio_group_weight(blkg, blkcg->weight);
+		if (cfqg && !cfqg->dev_weight)
+			cfqg->new_weight = blkcg->cfq_weight;
 	}
 
 	spin_unlock_irq(&blkcg->lock);
@@ -1480,14 +1473,14 @@ static int cfqg_print_avg_queue_size(struct cgroup *cgrp, struct cftype *cft,
 static struct cftype cfq_blkcg_files[] = {
 	{
 		.name = "weight_device",
-		.read_seq_string = blkcg_print_weight_device,
-		.write_string = blkcg_set_weight_device,
+		.read_seq_string = cfqg_print_weight_device,
+		.write_string = cfqg_set_weight_device,
 		.max_write_len = 256,
 	},
 	{
 		.name = "weight",
-		.read_seq_string = blkcg_print_weight,
-		.write_u64 = blkcg_set_weight,
+		.read_seq_string = cfq_print_weight,
+		.write_u64 = cfq_set_weight,
 	},
 	{
 		.name = "time",
@@ -3983,7 +3976,7 @@ static int cfq_init_queue(struct request_queue *q)
 		return -ENOMEM;
 	}
 
-	cfqd->root_group->weight = 2*BLKIO_WEIGHT_DEFAULT;
+	cfqd->root_group->weight = 2 * CFQ_WEIGHT_DEFAULT;
 
 	/*
 	 * Not strictly needed (since RB_ROOT just clears the node and we
author maintainer
#29 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

In reply to Tao Ma

Hello,

Quoted 2 lines · Tao Ma

I guess blkio->weight is a generic way of abstracting the weight between different block cgroups.

It isn't and can't be. There's nothing generic about it across different policies and it's not even clear what that means. If the user chooses combine, iops limit with cfq weights, what the hell is "generic" about that weight?

Quoted 4 lines

Yes, currently, only cfq uses it, but I am
trying to improve Shaohua's original fiops scheduler and add cgroup support to it. So please leave it there so that future scheduler(if other than the fiops scheduler) can use the framework.

So, if you want to implement a new blkcg policy, add the config parameters and export the stats the policy wants *yourself*. Not having clear separation between policies and generic stuff was what led us to this yucky mess and there's no way we're going back there. So, NO.

Thanks.

Signature · 1 line
tejun
#82 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

In reply to a message not in the archive

Hello,

Quoted 2 lines · Tao Ma

I guess blkio->weight is a generic way of abstracting the weight between different block cgroups.

It isn't and can't be. There's nothing generic about it across different policies and it's not even clear what that means. If the user chooses combine, iops limit with cfq weights, what the hell is "generic" about that weight?

Quoted 4 lines

Yes, currently, only cfq uses it, but I am
trying to improve Shaohua's original fiops scheduler and add cgroup support to it. So please leave it there so that future scheduler(if other than the fiops scheduler) can use the framework.

So, if you want to implement a new blkcg policy, add the config parameters and export the stats the policy wants *yourself*. Not having clear separation between policies and generic stuff was what led us to this yucky mess and there's no way we're going back there. So, NO.

Thanks.

Signature · 1 line
tejun
maintainer
#90 lore raw
In reply to Tejun Heo
Quoted 10 lines · Tejun Heo

Hey, Jens.

Quoted 2 lines · Jens Axboe

The diffstat is very tasty... I'll leave this on out until the cgroup merge mess is settled, though.

The following branch contains this patchset on top of the current block/for-3.5/core 959d851caa "Merge branch 'for-3.5' of ../cgroup into block/for-3.5/core-merged".

Quoted 5 lines

git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git blkcg-files

Other than $SUBJ update on the eigth patch from "blkcg:
blkg_conf_prep()" to "blkcg: simplify blkg_conf_prep()", the patchset can be applied as-is on top of the current block/for-3.5/core.

Alright, pulled in as well. I'm glad we pushed this to 3.5 :-)

Signature · 1 line
Jens Axboe
#30 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

In reply to Tejun Heo
Quoted 16 lines · Tejun Heo

Hello,

Quoted 2 lines · Tao Ma

I guess blkio->weight is a generic way of abstracting the weight between different block cgroups.

It isn't and can't be. There's nothing generic about it across different policies and it's not even clear what that means. If the user chooses combine, iops limit with cfq weights, what the hell is "generic" about that weight?

Quoted 4 lines

Yes, currently, only cfq uses it, but I am
trying to improve Shaohua's original fiops scheduler and add cgroup support to it. So please leave it there so that future scheduler(if other than the fiops scheduler) can use the framework.

Quoted 5 lines

So, if you want to implement a new blkcg policy, add the config parameters and export the stats the policy wants *yourself*. Not having clear separation between policies and generic stuff was what led us to this yucky mess and there's no way we're going back there. So, NO.

Currently weight is just used to calculate the time slice of different cfq group, right? So why can't it be used to indicate other weight? So say, if we are just want to use iops to indicate the difference between different cgroups(100 weight vs 200 weight), so one process will send 100 ios while the other will send 200 ios just for example. We will need a new iops_weight in your option to be exported?

Thanks
Tao

#80 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

In reply to a message not in the archive
Quoted 16 lines · Tejun Heo

Hello,

Quoted 2 lines · Tao Ma

I guess blkio->weight is a generic way of abstracting the weight between different block cgroups.

It isn't and can't be. There's nothing generic about it across different policies and it's not even clear what that means. If the user chooses combine, iops limit with cfq weights, what the hell is "generic" about that weight?

Quoted 4 lines

Yes, currently, only cfq uses it, but I am
trying to improve Shaohua's original fiops scheduler and add cgroup support to it. So please leave it there so that future scheduler(if other than the fiops scheduler) can use the framework.

Quoted 5 lines

So, if you want to implement a new blkcg policy, add the config parameters and export the stats the policy wants *yourself*. Not having clear separation between policies and generic stuff was what led us to this yucky mess and there's no way we're going back there. So, NO.

Currently weight is just used to calculate the time slice of different cfq group, right? So why can't it be used to indicate other weight? So say, if we are just want to use iops to indicate the difference between different cgroups(100 weight vs 200 weight), so one process will send 100 ios while the other will send 200 ios just for example. We will need a new iops_weight in your option to be exported?

Thanks
Tao

author maintainer
#31 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

In reply to Tao Ma
Quoted 5 lines · Tao Ma

Currently weight is just used to calculate the time slice of different cfq group, right? So why can't it be used to indicate other weight? So say, if we are just want to use iops to indicate the difference between different cgroups(100 weight vs 200 weight), so one process will send 100 ios while the other will send 200 ios just for example.

Because it's configuring stuff which is completely unrelated. Let's say you added a new elevator w/ iops based proportional IO which shares blkio.weight configuration with cfq but nothing else and in turn your new thing would probably need some other config parameters which don't make much sense for cfq, right?

Now, let's say there's a system which has two hard drives and sda is using cfq and sdb is using your new elevator and you're trying to configure cgroup blkio limits. Now, you have blkio.weight which applies to both elevators and other configurations which aren't and from the looks of it there's no way to tell which configuration controls what.

It also makes the configuration implementation hairier. We'll need callbacks from blkcg core layer to all policies to notify changes to per-cgroup configuration and from there policies would have to decide whether it has overriding per-cgroup-device configuration. It's not even clear we even want per-cgroup configuration. blk-throttle only has per-cgroup-device configuration after all.

So, again, no. blkcg.weight isn't and won't be generic.

Quoted 1 line

We will need a new iops_weight in your option to be exported?

Yeah, just add config and stat files prefixed with the name of the new blkcg policy.

Thanks.

Signature · 1 line
tejun
#32 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

Quoted 20 lines · Tejun Heo
Quoted 5 lines · Tao Ma

Currently weight is just used to calculate the time slice of different cfq group, right? So why can't it be used to indicate other weight? So say, if we are just want to use iops to indicate the difference between different cgroups(100 weight vs 200 weight), so one process will send 100 ios while the other will send 200 ios just for example.

Because it's configuring stuff which is completely unrelated. Let's say you added a new elevator w/ iops based proportional IO which shares blkio.weight configuration with cfq but nothing else and in turn your new thing would probably need some other config parameters which don't make much sense for cfq, right?

Now, let's say there's a system which has two hard drives and sda is using cfq and sdb is using your new elevator and you're trying to configure cgroup blkio limits. Now, you have blkio.weight which applies to both elevators and other configurations which aren't and from the looks of it there's no way to tell which configuration controls what.

Quoted 6 lines

It also makes the configuration implementation hairier. We'll need callbacks from blkcg core layer to all policies to notify changes to per-cgroup configuration and from there policies would have to decide whether it has overriding per-cgroup-device configuration. It's not even clear we even want per-cgroup configuration. blk-throttle only has per-cgroup-device configuration after all.

Fair enough.

Quoted 7 lines

So, again, no. blkcg.weight isn't and won't be generic.

Quoted 1 line

We will need a new iops_weight in your option to be exported?

Yeah, just add config and stat files prefixed with the name of the new blkcg policy.

OK, I will add a new config file for it.

Thanks
Tao

#78 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

In reply to a message not in the archive
Quoted 20 lines · Tejun Heo
Quoted 5 lines · Tao Ma

Currently weight is just used to calculate the time slice of different cfq group, right? So why can't it be used to indicate other weight? So say, if we are just want to use iops to indicate the difference between different cgroups(100 weight vs 200 weight), so one process will send 100 ios while the other will send 200 ios just for example.

Because it's configuring stuff which is completely unrelated. Let's say you added a new elevator w/ iops based proportional IO which shares blkio.weight configuration with cfq but nothing else and in turn your new thing would probably need some other config parameters which don't make much sense for cfq, right?

Now, let's say there's a system which has two hard drives and sda is using cfq and sdb is using your new elevator and you're trying to configure cgroup blkio limits. Now, you have blkio.weight which applies to both elevators and other configurations which aren't and from the looks of it there's no way to tell which configuration controls what.

Quoted 6 lines

It also makes the configuration implementation hairier. We'll need callbacks from blkcg core layer to all policies to notify changes to per-cgroup configuration and from there policies would have to decide whether it has overriding per-cgroup-device configuration. It's not even clear we even want per-cgroup configuration. blk-throttle only has per-cgroup-device configuration after all.

Fair enough.

Quoted 7 lines

So, again, no. blkcg.weight isn't and won't be generic.

Quoted 1 line

We will need a new iops_weight in your option to be exported?

Yeah, just add config and stat files prefixed with the name of the new blkcg policy.

OK, I will add a new config file for it.

Thanks
Tao

#33 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

In reply to Tao Ma

On Tue, Apr 03, 2012 at 06:20:10AM +0800, Tao Ma wrote:

[..]

Quoted 3 lines
Quoted 2 lines

Yeah, just add config and stat files prefixed with the name of the new blkcg policy.

OK, I will add a new config file for it.

Only if CFQ could be modified to add one iops mode, flippable through a sysfs tunable, things will be much simpler. You will not have to add a new IO scheduler, no new configuration/stat files in blkcg (which is already crowded now).

I don't think anybody has shown the code that why CFQ can't be modified to support iops mode.

Thanks
Vivek

author maintainer
#34 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

Quoted 7 lines · Vivek Goyal

On Tue, Apr 03, 2012 at 06:20:10AM +0800, Tao Ma wrote:

[..]

Quoted 3 lines
Quoted 2 lines

Yeah, just add config and stat files prefixed with the name of the new blkcg policy.

OK, I will add a new config file for it.

Quoted 7 lines

Only if CFQ could be modified to add one iops mode, flippable through a sysfs tunable, things will be much simpler. You will not have to add a new IO scheduler, no new configuration/stat files in blkcg (which is already crowded now).

I don't think anybody has shown the code that why CFQ can't be modified to support iops mode.

I haven't looked at the code so it's just an imporession but if we're talking about completely different scheduling policy - cfq is about slicing disk service time and IIUC the new thing being talked about is using iops as scheduling unit probably for devices where seeking isn't extremely expensive, and it might not make much sense to mix them together.

Thanks.

Signature · 1 line
tejun
#36 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

In reply to a message not in the archive
Quoted 7 lines · Vivek Goyal

On Tue, Apr 03, 2012 at 06:20:10AM +0800, Tao Ma wrote:

[..]

Quoted 3 lines
Quoted 2 lines

Yeah, just add config and stat files prefixed with the name of the new blkcg policy.

OK, I will add a new config file for it.

Quoted 7 lines

Only if CFQ could be modified to add one iops mode, flippable through a sysfs tunable, things will be much simpler. You will not have to add a new IO scheduler, no new configuration/stat files in blkcg (which is already crowded now).

I don't think anybody has shown the code that why CFQ can't be modified to support iops mode.

I haven't looked at the code so it's just an imporession but if we're talking about completely different scheduling policy - cfq is about slicing disk service time and IIUC the new thing being talked about is using iops as scheduling unit probably for devices where seeking isn't extremely expensive, and it might not make much sense to mix them together.

Thanks.

Signature · 1 line
tejun
author maintainer
#91 lore raw
In reply to Jens Axboe
Quoted 5 lines · Jens Axboe
Quoted 3 lines

Other than $SUBJ update on the eigth patch from "blkcg:
blkg_conf_prep()" to "blkcg: simplify blkg_conf_prep()", the patchset can be applied as-is on top of the current block/for-3.5/core.

Alright, pulled in as well. I'm glad we pushed this to 3.5 :-)

Yeah, I'm fairly sure if we had shoved this through 3.4, we would be having another round of f**k you's from Linus.

I'll probably send one or two more rounds of patches to clean up in-place blkg updates and make active policy selection per request_queue, but I'm glad to finally have the end in sight.

Thanks.

Signature · 1 line
tejun
#93 lore raw
In reply to a message not in the archive
Quoted 5 lines · Jens Axboe
Quoted 3 lines

Other than $SUBJ update on the eigth patch from "blkcg:
blkg_conf_prep()" to "blkcg: simplify blkg_conf_prep()", the patchset can be applied as-is on top of the current block/for-3.5/core.

Alright, pulled in as well. I'm glad we pushed this to 3.5 :-)

Yeah, I'm fairly sure if we had shoved this through 3.4, we would be having another round of f**k you's from Linus.

I'll probably send one or two more rounds of patches to clean up in-place blkg updates and make active policy selection per request_queue, but I'm glad to finally have the end in sight.

Thanks.

Signature · 1 line
tejun
#37 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

In reply to a message not in the archive
Quoted 7 lines · Vivek Goyal

On Tue, Apr 03, 2012 at 06:20:10AM +0800, Tao Ma wrote:

[..]

Quoted 3 lines
Quoted 2 lines

Yeah, just add config and stat files prefixed with the name of the new blkcg policy.

OK, I will add a new config file for it.

Quoted 7 lines

Only if CFQ could be modified to add one iops mode, flippable through a sysfs tunable, things will be much simpler. You will not have to add a new IO scheduler, no new configuration/stat files in blkcg (which is already crowded now).

I don't think anybody has shown the code that why CFQ can't be modified to support iops mode.

Yes, I have thought of it, but it seems to me that time slice is deeply involved within the cfq(even current cfq's iops mode has used time slice to calculate). So I don't think it is feasible for me to change it. And cfq works perfectly well for sas/sata environment and the code is quite stable, more codes and more complicate algorithm does mean more bugs. So I guess a new iops based scheduler is easy and not intrusive for the user(since he can choose whether to use it or not).

Thanks
Tao

#38 lore raw

Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq

In reply to Vivek Goyal
Quoted 7 lines · Vivek Goyal

On Tue, Apr 03, 2012 at 06:20:10AM +0800, Tao Ma wrote:

[..]

Quoted 3 lines
Quoted 2 lines

Yeah, just add config and stat files prefixed with the name of the new blkcg policy.

OK, I will add a new config file for it.

Quoted 7 lines

Only if CFQ could be modified to add one iops mode, flippable through a sysfs tunable, things will be much simpler. You will not have to add a new IO scheduler, no new configuration/stat files in blkcg (which is already crowded now).

I don't think anybody has shown the code that why CFQ can't be modified to support iops mode.

Yes, I have thought of it, but it seems to me that time slice is deeply involved within the cfq(even current cfq's iops mode has used time slice to calculate). So I don't think it is feasible for me to change it. And cfq works perfectly well for sas/sata environment and the code is quite stable, more codes and more complicate algorithm does mean more bugs. So I guess a new iops based scheduler is easy and not intrusive for the user(since he can choose whether to use it or not).

Thanks
Tao

#39 lore raw

IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

Quoted 15 lines · Tao Ma
Quoted 7 lines · Vivek Goyal

On Tue, Apr 03, 2012 at 06:20:10AM +0800, Tao Ma wrote:

[..]

Quoted 3 lines
Quoted 2 lines

Yeah, just add config and stat files prefixed with the name of the new blkcg policy.

OK, I will add a new config file for it.

Quoted 7 lines

Only if CFQ could be modified to add one iops mode, flippable through a sysfs tunable, things will be much simpler. You will not have to add a new IO scheduler, no new configuration/stat files in blkcg (which is already crowded now).

I don't think anybody has shown the code that why CFQ can't be modified to support iops mode.

Quoted 7 lines

Yes, I have thought of it, but it seems to me that time slice is deeply involved within the cfq(even current cfq's iops mode has used time slice to calculate). So I don't think it is feasible for me to change it. And cfq works perfectly well for sas/sata environment and the code is quite stable, more codes and more complicate algorithm does mean more bugs. So I guess a new iops based scheduler is easy and not intrusive for the user(since he can choose whether to use it or not).

Ok, let me take one step back.

- What's the goal of iops based scheduler. In what kind of workload and storage it is going to help.

- Can't we just set the slice_idle=0 and "quantum" to some high value say "64" or "128" and achieve similar results to iops based scheduler?

In theory, above will cut down on idling and try to provide fairness in terms of time. I thought fairness in terms of time is most fair. The most common problem is measurement of time is not attributable to individual queue in an NCQ hardware. I guess that throws time measurement of out the window until and unless we have a better algorithm to measure time in NCQ environment.

I guess then we can just replace time with number of requests dispatched from a process queue. Allow it to dispatch requests for some time and then schedule it out and put it back on service tree and charge it according to its weight.

This all works only if we have right workload. The workloads which are not doing dependent reads and can keep the disk busy continuously. If there is think time involved, and we do not idle, process will lose its share and whole scheme of trying to differentiate between processes will become ineffective.

So if you have come with a better algorith which can keep track of iops without idling and still provide service differentiation for common workloads, it will be interesting.

Thanks
Vivek

#76 lore raw

IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to a message not in the archive
Quoted 15 lines · Tao Ma
Quoted 7 lines · Vivek Goyal

On Tue, Apr 03, 2012 at 06:20:10AM +0800, Tao Ma wrote:

[..]

Quoted 3 lines
Quoted 2 lines

Yeah, just add config and stat files prefixed with the name of the new blkcg policy.

OK, I will add a new config file for it.

Quoted 7 lines

Only if CFQ could be modified to add one iops mode, flippable through a sysfs tunable, things will be much simpler. You will not have to add a new IO scheduler, no new configuration/stat files in blkcg (which is already crowded now).

I don't think anybody has shown the code that why CFQ can't be modified to support iops mode.

Quoted 7 lines

Yes, I have thought of it, but it seems to me that time slice is deeply involved within the cfq(even current cfq's iops mode has used time slice to calculate). So I don't think it is feasible for me to change it. And cfq works perfectly well for sas/sata environment and the code is quite stable, more codes and more complicate algorithm does mean more bugs. So I guess a new iops based scheduler is easy and not intrusive for the user(since he can choose whether to use it or not).

Ok, let me take one step back.

- What's the goal of iops based scheduler. In what kind of workload and storage it is going to help.

- Can't we just set the slice_idle=0 and "quantum" to some high value say "64" or "128" and achieve similar results to iops based scheduler?

In theory, above will cut down on idling and try to provide fairness in terms of time. I thought fairness in terms of time is most fair. The most common problem is measurement of time is not attributable to individual queue in an NCQ hardware. I guess that throws time measurement of out the window until and unless we have a better algorithm to measure time in NCQ environment.

I guess then we can just replace time with number of requests dispatched from a process queue. Allow it to dispatch requests for some time and then schedule it out and put it back on service tree and charge it according to its weight.

This all works only if we have right workload. The workloads which are not doing dependent reads and can keep the disk busy continuously. If there is think time involved, and we do not idle, process will lose its share and whole scheme of trying to differentiate between processes will become ineffective.

So if you have come with a better algorith which can keep track of iops without idling and still provide service differentiation for common workloads, it will be interesting.

Thanks
Vivek

#40 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to Vivek Goyal

add Shaohua to the cc list,

Quoted 24 lines · Vivek Goyal
Quoted 15 lines · Tao Ma
Quoted 7 lines · Vivek Goyal

On Tue, Apr 03, 2012 at 06:20:10AM +0800, Tao Ma wrote:

[..]

Quoted 3 lines
Quoted 2 lines

Yeah, just add config and stat files prefixed with the name of the new blkcg policy.

OK, I will add a new config file for it.

Quoted 7 lines

Only if CFQ could be modified to add one iops mode, flippable through a sysfs tunable, things will be much simpler. You will not have to add a new IO scheduler, no new configuration/stat files in blkcg (which is already crowded now).

I don't think anybody has shown the code that why CFQ can't be modified to support iops mode.

Quoted 7 lines

Yes, I have thought of it, but it seems to me that time slice is deeply involved within the cfq(even current cfq's iops mode has used time slice to calculate). So I don't think it is feasible for me to change it. And cfq works perfectly well for sas/sata environment and the code is quite stable, more codes and more complicate algorithm does mean more bugs. So I guess a new iops based scheduler is easy and not intrusive for the user(since he can choose whether to use it or not).

Quoted 7 lines

Ok, let me take one step back.

- What's the goal of iops based scheduler. In what kind of workload and storage it is going to help.

- Can't we just set the slice_idle=0 and "quantum" to some high value say "64" or "128" and achieve similar results to iops based scheduler?

yes, I should say cfq with slice_idle = 0 works well in most cases. But if it comes to blkcg with ssd, it is really a disaster. You know, cfq has to choose between different cgroups, so even if you choose 1ms as the service time for each cgroup(actually in my test, only >2ms can work reliably). the latency for some requests(which have been sent by the user while not submitting to the driver) is really too much for the application. I don't think there is a way to resolve it in cfq.

Quoted 8 lines

In theory, above will cut down on idling and try to provide fairness in terms of time. I thought fairness in terms of time is most fair. The most common problem is measurement of time is not attributable to individual queue in an NCQ hardware. I guess that throws time measurement of out the window until and unless we have a better algorithm to measure time in NCQ environment.

Quoted 4 lines

I guess then we can just replace time with number of requests dispatched from a process queue. Allow it to dispatch requests for some time and then schedule it out and put it back on service tree and charge it according to its weight.

As I have said, in this case, the minimal time(1ms) multiple the group number is too much for a ssd.

If we can use iops based scheduler, we can use iops_weight for different cgroups and switch cgroup according to this number. So all the applications can have a moderate response time which can be estimated.

btw, I have talked with Shaohua in LSF and we made a consensus that I will continue his work and try to add cgroup support to it.

Thanks
Tao

Quoted 18 lines

This all works only if we have right workload. The workloads which are not doing dependent reads and can keep the disk busy continuously. If there is think time involved, and we do not idle, process will lose its share and whole scheme of trying to differentiate between processes will become ineffective.

So if you have come with a better algorith which can keep track of iops without idling and still provide service differentiation for common workloads, it will be interesting.

Thanks
Vivek
--
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/

#74 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to a message not in the archive

add Shaohua to the cc list,

Quoted 24 lines · Vivek Goyal
Quoted 15 lines · Tao Ma
Quoted 7 lines · Vivek Goyal

On Tue, Apr 03, 2012 at 06:20:10AM +0800, Tao Ma wrote:

[..]

Quoted 3 lines
Quoted 2 lines

Yeah, just add config and stat files prefixed with the name of the new blkcg policy.

OK, I will add a new config file for it.

Quoted 7 lines

Only if CFQ could be modified to add one iops mode, flippable through a sysfs tunable, things will be much simpler. You will not have to add a new IO scheduler, no new configuration/stat files in blkcg (which is already crowded now).

I don't think anybody has shown the code that why CFQ can't be modified to support iops mode.

Quoted 7 lines

Yes, I have thought of it, but it seems to me that time slice is deeply involved within the cfq(even current cfq's iops mode has used time slice to calculate). So I don't think it is feasible for me to change it. And cfq works perfectly well for sas/sata environment and the code is quite stable, more codes and more complicate algorithm does mean more bugs. So I guess a new iops based scheduler is easy and not intrusive for the user(since he can choose whether to use it or not).

Quoted 7 lines

Ok, let me take one step back.

- What's the goal of iops based scheduler. In what kind of workload and storage it is going to help.

- Can't we just set the slice_idle=0 and "quantum" to some high value say "64" or "128" and achieve similar results to iops based scheduler?

yes, I should say cfq with slice_idle = 0 works well in most cases. But if it comes to blkcg with ssd, it is really a disaster. You know, cfq has to choose between different cgroups, so even if you choose 1ms as the service time for each cgroup(actually in my test, only >2ms can work reliably). the latency for some requests(which have been sent by the user while not submitting to the driver) is really too much for the application. I don't think there is a way to resolve it in cfq.

Quoted 8 lines

In theory, above will cut down on idling and try to provide fairness in terms of time. I thought fairness in terms of time is most fair. The most common problem is measurement of time is not attributable to individual queue in an NCQ hardware. I guess that throws time measurement of out the window until and unless we have a better algorithm to measure time in NCQ environment.

Quoted 4 lines

I guess then we can just replace time with number of requests dispatched from a process queue. Allow it to dispatch requests for some time and then schedule it out and put it back on service tree and charge it according to its weight.

As I have said, in this case, the minimal time(1ms) multiple the group number is too much for a ssd.

If we can use iops based scheduler, we can use iops_weight for different cgroups and switch cgroup according to this number. So all the applications can have a moderate response time which can be estimated.

btw, I have talked with Shaohua in LSF and we made a consensus that I will continue his work and try to add cgroup support to it.

Thanks
Tao

Quoted 18 lines

This all works only if we have right workload. The workloads which are not doing dependent reads and can keep the disk busy continuously. If there is think time involved, and we do not idle, process will lose its share and whole scheme of trying to differentiate between processes will become ineffective.

So if you have come with a better algorith which can keep track of iops without idling and still provide service differentiation for common workloads, it will be interesting.

Thanks
Vivek
--
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/

#41 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to Tao Ma

On Wed, Apr 04, 2012 at 12:36:24AM +0800, Tao Ma wrote:

[..]

Quoted 9 lines
Quoted 2 lines

- Can't we just set the slice_idle=0 and "quantum" to some high value say "64" or "128" and achieve similar results to iops based scheduler?

yes, I should say cfq with slice_idle = 0 works well in most cases. But if it comes to blkcg with ssd, it is really a disaster. You know, cfq has to choose between different cgroups, so even if you choose 1ms as the service time for each cgroup(actually in my test, only >2ms can work reliably). the latency for some requests(which have been sent by the user while not submitting to the driver) is really too much for the application. I don't think there is a way to resolve it in cfq.

Ok, so now you are saying that CFQ as such is not a problem but blkcg logic in CFQ is an issue.

What's the issue there? I think the issue there also is group idling. If you set group_idle=0, that idling will be cut down and switching between groups will be fast. That's a different thing that in the process you will most likely lose service differentiation also for most of the workloads.

Quoted 13 lines
Quoted 9 lines

In theory, above will cut down on idling and try to provide fairness in terms of time. I thought fairness in terms of time is most fair. The most common problem is measurement of time is not attributable to individual queue in an NCQ hardware. I guess that throws time measurement of out the window until and unless we have a better algorithm to measure time in NCQ environment.

Quoted 4 lines

I guess then we can just replace time with number of requests dispatched from a process queue. Allow it to dispatch requests for some time and then schedule it out and put it back on service tree and charge it according to its weight.

Quoted 6 lines

As I have said, in this case, the minimal time(1ms) multiple the group number is too much for a ssd.

If we can use iops based scheduler, we can use iops_weight for different cgroups and switch cgroup according to this number. So all the applications can have a moderate response time which can be estimated.

How iops_weight and switching different than CFQ group scheduling logic? I think shaohua was talking of using similar logic. What would you do fundamentally different so that without idling you will get service differentiation?

If you explain your logic in detail, it will help.

BTW, in last mail you mentioned that in iops_mode() we make use of time. That's not the case. in iops_mode() we charge group based on number of requests dispatched. (slice_dispatch records number of requests dispatched from the queue in that slice). So to me counting number of requests instead of time will effectively switch CFQ to iops based scheduler, isn't it?

Quoted 3 lines

btw, I have talked with Shaohua in LSF and we made a consensus that I will continue his work and try to add cgroup support to it.

That's fine. you can continue to work. But first explaining the problem clearly and how you are going to fix it will help. Instead of just saying "CFQ has problem and we will fix it by bringing in a new scheduler".

Thanks
Vivek

#72 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to a message not in the archive

On Wed, Apr 04, 2012 at 12:36:24AM +0800, Tao Ma wrote:

[..]

Quoted 9 lines
Quoted 2 lines

- Can't we just set the slice_idle=0 and "quantum" to some high value say "64" or "128" and achieve similar results to iops based scheduler?

yes, I should say cfq with slice_idle = 0 works well in most cases. But if it comes to blkcg with ssd, it is really a disaster. You know, cfq has to choose between different cgroups, so even if you choose 1ms as the service time for each cgroup(actually in my test, only >2ms can work reliably). the latency for some requests(which have been sent by the user while not submitting to the driver) is really too much for the application. I don't think there is a way to resolve it in cfq.

Ok, so now you are saying that CFQ as such is not a problem but blkcg logic in CFQ is an issue.

What's the issue there? I think the issue there also is group idling. If you set group_idle=0, that idling will be cut down and switching between groups will be fast. That's a different thing that in the process you will most likely lose service differentiation also for most of the workloads.

Quoted 13 lines
Quoted 9 lines

In theory, above will cut down on idling and try to provide fairness in terms of time. I thought fairness in terms of time is most fair. The most common problem is measurement of time is not attributable to individual queue in an NCQ hardware. I guess that throws time measurement of out the window until and unless we have a better algorithm to measure time in NCQ environment.

Quoted 4 lines

I guess then we can just replace time with number of requests dispatched from a process queue. Allow it to dispatch requests for some time and then schedule it out and put it back on service tree and charge it according to its weight.

Quoted 6 lines

As I have said, in this case, the minimal time(1ms) multiple the group number is too much for a ssd.

If we can use iops based scheduler, we can use iops_weight for different cgroups and switch cgroup according to this number. So all the applications can have a moderate response time which can be estimated.

How iops_weight and switching different than CFQ group scheduling logic? I think shaohua was talking of using similar logic. What would you do fundamentally different so that without idling you will get service differentiation?

If you explain your logic in detail, it will help.

BTW, in last mail you mentioned that in iops_mode() we make use of time. That's not the case. in iops_mode() we charge group based on number of requests dispatched. (slice_dispatch records number of requests dispatched from the queue in that slice). So to me counting number of requests instead of time will effectively switch CFQ to iops based scheduler, isn't it?

Quoted 3 lines

btw, I have talked with Shaohua in LSF and we made a consensus that I will continue his work and try to add cgroup support to it.

That's fine. you can continue to work. But first explaining the problem clearly and how you are going to fix it will help. Instead of just saying "CFQ has problem and we will fix it by bringing in a new scheduler".

Thanks
Vivek

#42 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to Vivek Goyal
Quoted 13 lines · Vivek Goyal

On Wed, Apr 04, 2012 at 12:36:24AM +0800, Tao Ma wrote:

[..]

Quoted 9 lines
Quoted 2 lines

- Can't we just set the slice_idle=0 and "quantum" to some high value say "64" or "128" and achieve similar results to iops based scheduler?

yes, I should say cfq with slice_idle = 0 works well in most cases. But if it comes to blkcg with ssd, it is really a disaster. You know, cfq has to choose between different cgroups, so even if you choose 1ms as the service time for each cgroup(actually in my test, only >2ms can work reliably). the latency for some requests(which have been sent by the user while not submitting to the driver) is really too much for the application. I don't think there is a way to resolve it in cfq.

Quoted 8 lines

Ok, so now you are saying that CFQ as such is not a problem but blkcg logic in CFQ is an issue.

What's the issue there? I think the issue there also is group idling. If you set group_idle=0, that idling will be cut down and switching between groups will be fast. That's a different thing that in the process you will most likely lose service differentiation also for most of the workloads.

No, group_idle=0 doesn't help. We don't have problem with idling, the disk is busy for all the tasks, we just want it to be proportional and time endurable.

Quoted 17 lines
Quoted 17 lines
Quoted 10 lines

In theory, above will cut down on idling and try to provide fairness in terms of time. I thought fairness in terms of time is most fair. The most common problem is measurement of time is not attributable to individual queue in an NCQ hardware. I guess that throws time measurement of out the window until and unless we have a better algorithm to measure time in NCQ environment.

Quoted 4 lines

I guess then we can just replace time with number of requests dispatched from a process queue. Allow it to dispatch requests for some time and then schedule it out and put it back on service tree and charge it according to its weight.

As I have said, in this case, the minimal time(1ms) multiple the group number is too much for a ssd.

Quoted 8 lines
Quoted 3 lines

If we can use iops based scheduler, we can use iops_weight for different cgroups and switch cgroup according to this number. So all the applications can have a moderate response time which can be estimated.

How iops_weight and switching different than CFQ group scheduling logic? I think shaohua was talking of using similar logic. What would you do fundamentally different so that without idling you will get service differentiation?

I am thinking of differentiate different groups with iops, so if there are 3 groups(the weight are 100, 200, 300) we can let them submit 1 io, 2 io and 3 io in a round-robin way. With a intel ssd, every io can be finished within 100us. So the maximum latency for one io is about 600us, still less than 1ms. But with cfq, if all the cgroups are busy, we have to switch between these group in ms which means the maximum latency will be 6ms. It is terrible for some applications since they use ssds now.

Quoted 9 lines

If you explain your logic in detail, it will help.

BTW, in last mail you mentioned that in iops_mode() we make use of time. That's not the case. in iops_mode() we charge group based on number of requests dispatched. (slice_dispatch records number of requests dispatched from the queue in that slice). So to me counting number of requests instead of time will effectively switch CFQ to iops based scheduler, isn't it?

yes, iops_mode in cfq is calculated iops, but it is switched according to the time slice, right? So it can't resolve the problem I mentioned above.

Thanks
Tao

Quoted 7 lines

Thanks
Vivek
--
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/

#70 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to a message not in the archive
Quoted 13 lines · Vivek Goyal

On Wed, Apr 04, 2012 at 12:36:24AM +0800, Tao Ma wrote:

[..]

Quoted 9 lines
Quoted 2 lines

- Can't we just set the slice_idle=0 and "quantum" to some high value say "64" or "128" and achieve similar results to iops based scheduler?

yes, I should say cfq with slice_idle = 0 works well in most cases. But if it comes to blkcg with ssd, it is really a disaster. You know, cfq has to choose between different cgroups, so even if you choose 1ms as the service time for each cgroup(actually in my test, only >2ms can work reliably). the latency for some requests(which have been sent by the user while not submitting to the driver) is really too much for the application. I don't think there is a way to resolve it in cfq.

Quoted 8 lines

Ok, so now you are saying that CFQ as such is not a problem but blkcg logic in CFQ is an issue.

What's the issue there? I think the issue there also is group idling. If you set group_idle=0, that idling will be cut down and switching between groups will be fast. That's a different thing that in the process you will most likely lose service differentiation also for most of the workloads.

No, group_idle=0 doesn't help. We don't have problem with idling, the disk is busy for all the tasks, we just want it to be proportional and time endurable.

Quoted 17 lines
Quoted 17 lines
Quoted 10 lines

In theory, above will cut down on idling and try to provide fairness in terms of time. I thought fairness in terms of time is most fair. The most common problem is measurement of time is not attributable to individual queue in an NCQ hardware. I guess that throws time measurement of out the window until and unless we have a better algorithm to measure time in NCQ environment.

Quoted 4 lines

I guess then we can just replace time with number of requests dispatched from a process queue. Allow it to dispatch requests for some time and then schedule it out and put it back on service tree and charge it according to its weight.

As I have said, in this case, the minimal time(1ms) multiple the group number is too much for a ssd.

Quoted 8 lines
Quoted 3 lines

If we can use iops based scheduler, we can use iops_weight for different cgroups and switch cgroup according to this number. So all the applications can have a moderate response time which can be estimated.

How iops_weight and switching different than CFQ group scheduling logic? I think shaohua was talking of using similar logic. What would you do fundamentally different so that without idling you will get service differentiation?

I am thinking of differentiate different groups with iops, so if there are 3 groups(the weight are 100, 200, 300) we can let them submit 1 io, 2 io and 3 io in a round-robin way. With a intel ssd, every io can be finished within 100us. So the maximum latency for one io is about 600us, still less than 1ms. But with cfq, if all the cgroups are busy, we have to switch between these group in ms which means the maximum latency will be 6ms. It is terrible for some applications since they use ssds now.

Quoted 9 lines

If you explain your logic in detail, it will help.

BTW, in last mail you mentioned that in iops_mode() we make use of time. That's not the case. in iops_mode() we charge group based on number of requests dispatched. (slice_dispatch records number of requests dispatched from the queue in that slice). So to me counting number of requests instead of time will effectively switch CFQ to iops based scheduler, isn't it?

yes, iops_mode in cfq is calculated iops, but it is switched according to the time slice, right? So it can't resolve the problem I mentioned above.

Thanks
Tao

Quoted 7 lines

Thanks
Vivek
--
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/

#43 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to Tao Ma

2012/4/3 Tao Ma <[email protected]>:

Quoted 50 lines · Vivek Goyal
Quoted 13 lines · Tao Ma

[..]

Quoted 9 lines
Quoted 2 lines

- Can't we just set the slice_idle=0 and "quantum" to some high value say "64" or "128" and achieve similar results to iops based scheduler?

yes, I should say cfq with slice_idle = 0 works well in most cases. But if it comes to blkcg with ssd, it is really a disaster. You know, cfq has to choose between different cgroups, so even if you choose 1ms as the service time for each cgroup(actually in my test, only >2ms can work reliably). the latency for some requests(which have been sent by the user while not submitting to the driver) is really too much for the application. I don't think there is a way to resolve it in cfq.

Quoted 8 lines

Ok, so now you are saying that CFQ as such is not a problem but blkcg logic in CFQ is an issue.

What's the issue there? I think the issue there also is group idling. If you set group_idle=0, that idling will be cut down and switching between groups will be fast. That's a different thing that in the process you will most likely lose service differentiation also for most of the workloads.

No, group_idle=0 doesn't help. We don't have problem with idling, the disk is busy for all the tasks, we just want it to be proportional and time endurable.

Quoted 17 lines
Quoted 17 lines
Quoted 10 lines

In theory, above will cut down on idling and try to provide fairness in terms of time. I thought fairness in terms of time is most fair. The most common problem is measurement of time is not attributable to individual queue in an NCQ hardware. I guess that throws time measurement of out the window until and unless we have a better algorithm to measure time in NCQ environment.

Quoted 4 lines

I guess then we can just replace time with number of requests dispatched from a process queue. Allow it to dispatch requests for some time and then schedule it out and put it back on service tree and charge it according to its weight.

As I have said, in this case, the minimal time(1ms) multiple the group number is too much for a ssd.

Quoted 8 lines
Quoted 3 lines

If we can use iops based scheduler, we can use iops_weight for different cgroups and switch cgroup according to this number. So all the applications can have a moderate response time which can be estimated.

How iops_weight and switching different than CFQ group scheduling logic? I think shaohua was talking of using similar logic. What would you do fundamentally different so that without idling you will get service differentiation?

Quoted 7 lines

I am thinking of differentiate different groups with iops, so if there are 3 groups(the weight are 100, 200, 300) we can let them submit 1 io, 2 io and 3 io in a round-robin way. With a intel ssd, every io can be finished within 100us. So the maximum latency for one io is about 600us, still less than 1ms. But with cfq, if all the cgroups are busy, we have to switch between these group in ms which means the maximum latency will be 6ms. It is terrible for some applications since they use ssds now.

Yes, with iops based scheduling, we do queue switching for every request. Doing the same thing between groups is quite straightforward. The only issue I found is this will introduce more process context switch, this isn't a big issue
for io bound application, but depends. It cuts latency a lot, which I guess is more
important for web 2.0 application.

#67 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to a message not in the archive

2012/4/3 Tao Ma <[email protected]>:

Quoted 50 lines · Vivek Goyal
Quoted 13 lines · Tao Ma

[..]

Quoted 9 lines
Quoted 2 lines

- Can't we just set the slice_idle=0 and "quantum" to some high value say "64" or "128" and achieve similar results to iops based scheduler?

yes, I should say cfq with slice_idle = 0 works well in most cases. But if it comes to blkcg with ssd, it is really a disaster. You know, cfq has to choose between different cgroups, so even if you choose 1ms as the service time for each cgroup(actually in my test, only >2ms can work reliably). the latency for some requests(which have been sent by the user while not submitting to the driver) is really too much for the application. I don't think there is a way to resolve it in cfq.

Quoted 8 lines

Ok, so now you are saying that CFQ as such is not a problem but blkcg logic in CFQ is an issue.

What's the issue there? I think the issue there also is group idling. If you set group_idle=0, that idling will be cut down and switching between groups will be fast. That's a different thing that in the process you will most likely lose service differentiation also for most of the workloads.

No, group_idle=0 doesn't help. We don't have problem with idling, the disk is busy for all the tasks, we just want it to be proportional and time endurable.

Quoted 17 lines
Quoted 17 lines
Quoted 10 lines

In theory, above will cut down on idling and try to provide fairness in terms of time. I thought fairness in terms of time is most fair. The most common problem is measurement of time is not attributable to individual queue in an NCQ hardware. I guess that throws time measurement of out the window until and unless we have a better algorithm to measure time in NCQ environment.

Quoted 4 lines

I guess then we can just replace time with number of requests dispatched from a process queue. Allow it to dispatch requests for some time and then schedule it out and put it back on service tree and charge it according to its weight.

As I have said, in this case, the minimal time(1ms) multiple the group number is too much for a ssd.

Quoted 8 lines
Quoted 3 lines

If we can use iops based scheduler, we can use iops_weight for different cgroups and switch cgroup according to this number. So all the applications can have a moderate response time which can be estimated.

How iops_weight and switching different than CFQ group scheduling logic? I think shaohua was talking of using similar logic. What would you do fundamentally different so that without idling you will get service differentiation?

Quoted 7 lines

I am thinking of differentiate different groups with iops, so if there are 3 groups(the weight are 100, 200, 300) we can let them submit 1 io, 2 io and 3 io in a round-robin way. With a intel ssd, every io can be finished within 100us. So the maximum latency for one io is about 600us, still less than 1ms. But with cfq, if all the cgroups are busy, we have to switch between these group in ms which means the maximum latency will be 6ms. It is terrible for some applications since they use ssds now.

Yes, with iops based scheduling, we do queue switching for every request. Doing the same thing between groups is quite straightforward. The only issue I found is this will introduce more process context switch, this isn't a big issue
for io bound application, but depends. It cuts latency a lot, which I guess is more
important for web 2.0 application.

#68 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to Tao Ma
Quoted 17 lines · Tao Ma
Quoted 16 lines · Vivek Goyal

On Wed, Apr 04, 2012 at 12:36:24AM +0800, Tao Ma wrote:

[..]

Quoted 9 lines
Quoted 2 lines

- Can't we just set the slice_idle=0 and "quantum" to some high value say "64" or "128" and achieve similar results to iops based scheduler?

yes, I should say cfq with slice_idle = 0 works well in most cases. But if it comes to blkcg with ssd, it is really a disaster. You know, cfq has to choose between different cgroups, so even if you choose 1ms as the service time for each cgroup(actually in my test, only >2ms can work reliably). the latency for some requests(which have been sent by the user while not submitting to the driver) is really too much for the application. I don't think there is a way to resolve it in cfq.

Ok, so now you are saying that CFQ as such is not a problem but blkcg logic in CFQ is an issue.

Quoted 8 lines
Quoted 5 lines

What's the issue there? I think the issue there also is group idling. If you set group_idle=0, that idling will be cut down and switching between groups will be fast. That's a different thing that in the process you will most likely lose service differentiation also for most of the workloads.

No, group_idle=0 doesn't help. We don't have problem with idling, the disk is busy for all the tasks, we just want it to be proportional and time endurable.

I am not sure what does time "endurable" mean here. So if group idling is not a problem, then what is the problem. I am still failing to understand that what's the problem?

[..]

Quoted 11 lines
Quoted 4 lines

How iops_weight and switching different than CFQ group scheduling logic? I think shaohua was talking of using similar logic. What would you do fundamentally different so that without idling you will get service differentiation?

I am thinking of differentiate different groups with iops, so if there are 3 groups(the weight are 100, 200, 300) we can let them submit 1 io, 2 io and 3 io in a round-robin way. With a intel ssd, every io can be finished within 100us. So the maximum latency for one io is about 600us, still less than 1ms. But with cfq, if all the cgroups are busy, we have to switch between these group in ms which means the maximum latency will be 6ms. It is terrible for some applications since they use ssds now.

You can always do faster switching in CFQ. With idling disabled, you can always expire a queue after dispatching few requests. You don't have to wait for 1ms. I am not sure why are you assuming that the minimum time a queue/group has to dispatch is 1ms.

We already have the notion of not dispatching too many IOs from async queues. (cfq_prio_to_maxrq()). Something similar can be quickly written for iops_mode(). Just define a quantum of requests to be dispatched (say 10), and expire a queue after that and charge the queue/group for those 10 requests. Based on its weight, it will automatically go in right position in the tree and you should get iops based scheduling.

Quoted 11 lines
Quoted 9 lines

If you explain your logic in detail, it will help.

BTW, in last mail you mentioned that in iops_mode() we make use of time. That's not the case. in iops_mode() we charge group based on number of requests dispatched. (slice_dispatch records number of requests dispatched from the queue in that slice). So to me counting number of requests instead of time will effectively switch CFQ to iops based scheduler, isn't it?

yes, iops_mode in cfq is calculated iops, but it is switched according to the time slice, right? So it can't resolve the problem I mentioned above.

What do you mean that it is switched according to time slice?

We currently have separate scheduling tree for queue and groups. Currently iops mode works only for groups. We might still allocate a time slice to a queue but with idling disabled we will expire it much early. Because most of the workloads don't keep queue busy long enough. If your workload keeps the queue busy long enough (say for few ms), then we can introduce the logic in queue expiry to expire queue after dispatch of few requests in iops mode so that queue don't get extended time slices.

Thanks
Vivek

#44 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to Shaohua Li

On Wed, Apr 04, 2012 at 05:35:49AM -0700, Shaohua Li wrote:

[..]

Quoted 11 lines
Quoted 11 lines
Quoted 4 lines

How iops_weight and switching different than CFQ group scheduling logic? I think shaohua was talking of using similar logic. What would you do fundamentally different so that without idling you will get service differentiation?

I am thinking of differentiate different groups with iops, so if there are 3 groups(the weight are 100, 200, 300) we can let them submit 1 io, 2 io and 3 io in a round-robin way. With a intel ssd, every io can be finished within 100us. So the maximum latency for one io is about 600us, still less than 1ms. But with cfq, if all the cgroups are busy, we have to switch between these group in ms which means the maximum latency will be 6ms. It is terrible for some applications since they use ssds now.

Quoted 7 lines

Yes, with iops based scheduling, we do queue switching for every request. Doing the same thing between groups is quite straightforward. The only issue I found is this will introduce more process context switch, this isn't a big issue
for io bound application, but depends. It cuts latency a lot, which I guess is more
important for web 2.0 application.

In iops_mode(), expire each cfqq after dispatch of 1 or bunch of requests and you should get the same behavior (with slice_idle=0 and group_idle=0). So why write a new scheduler.

Only thing is that with above, current code will provide iops fairness only for groups. We should be able to tweak queue scheduling to support iops fairness also.

Anyway, we will end up doing that at some point of time. Supporting two scheduling algorihtms for queue and groups is not sustainable. There are already calls to make CFQ hierarchical and in that case both queue and groups need to be on a single service tree and that means need to follow same algorithm for scheduling.

Thanks
Vivek

#45 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

2012/4/4 Vivek Goyal <[email protected]>:

Quoted 22 lines · Shaohua Li

[..]

Quoted 11 lines
Quoted 11 lines
Quoted 4 lines

How iops_weight and switching different than CFQ group scheduling logic? I think shaohua was talking of using similar logic. What would you do fundamentally different so that without idling you will get service differentiation?

I am thinking of differentiate different groups with iops, so if there are 3 groups(the weight are 100, 200, 300) we can let them submit 1 io, 2 io and 3 io in a round-robin way. With a intel ssd, every io can be finished within 100us. So the maximum latency for one io is about 600us, still less than 1ms. But with cfq, if all the cgroups are busy, we have to switch between these group in ms which means the maximum latency will be 6ms. It is terrible for some applications since they use ssds now.

Quoted 7 lines

Yes, with iops based scheduling, we do queue switching for every request. Doing the same thing between groups is quite straightforward. The only issue I found is this will introduce more process context switch, this isn't a big issue
for io bound application, but depends. It cuts latency a lot, which I guess is more
important for web 2.0 application.

Quoted 7 lines

In iops_mode(), expire each cfqq after dispatch of 1 or bunch of requests and you should get the same behavior (with slice_idle=0 and group_idle=0). So why write a new scheduler.

Only thing is that with above, current code will provide iops fairness only for groups. We should be able to tweak queue scheduling to support iops fairness also.

Agreed, we can tweak cfq to make it support iops fairness because the two are conceptually the same. The problem is if this is a mess. CFQ is quite complicated already. In iops mode, a lot of code isn't required, like idle, queue merging, thinktime/seek detection and so on, as the scheduler will be only for ssd. With recent iocontext cleanup, the iops scheduler code is quite short actually.

#46 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

On Wed, Apr 04, 2012 at 07:52:24AM -0700, Shaohua Li wrote:

[..]

Quoted 6 lines

Agreed, we can tweak cfq to make it support iops fairness because the two are conceptually the same. The problem is if this is a mess. CFQ is quite complicated already. In iops mode, a lot of code isn't required, like idle, queue merging, thinktime/seek detection and so on, as the scheduler will be only for ssd. With recent iocontext cleanup, the iops scheduler code is quite short actually.

Ok, this is somewhat a better reason to have a separate scheduler. I guess we need to look that actual iops code and that can help decide whether to keep it as a separate scheduler.

One question is still unanswered though. What real workload benefits from it? If you are not doing idling in iops based scheduler, I doubt you are doing to see much service differentiation on fast SSDs. As for service differentiation IO queues have to be continuously backlogged and total IOPS needed by applications need to be more than what disk can offer. It becomes very hard to produe continuously backlogged queues because real applications tend to read some data, proces data and then generate more IO.

Thanks
Vivek

#51 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to a message not in the archive

On Wed, Apr 04, 2012 at 07:52:24AM -0700, Shaohua Li wrote:

[..]

Quoted 6 lines

Agreed, we can tweak cfq to make it support iops fairness because the two are conceptually the same. The problem is if this is a mess. CFQ is quite complicated already. In iops mode, a lot of code isn't required, like idle, queue merging, thinktime/seek detection and so on, as the scheduler will be only for ssd. With recent iocontext cleanup, the iops scheduler code is quite short actually.

Ok, this is somewhat a better reason to have a separate scheduler. I guess we need to look that actual iops code and that can help decide whether to keep it as a separate scheduler.

One question is still unanswered though. What real workload benefits from it? If you are not doing idling in iops based scheduler, I doubt you are doing to see much service differentiation on fast SSDs. As for service differentiation IO queues have to be continuously backlogged and total IOPS needed by applications need to be more than what disk can offer. It becomes very hard to produe continuously backlogged queues because real applications tend to read some data, proces data and then generate more IO.

Thanks
Vivek

#47 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to Vivek Goyal
Quoted 10 lines · Vivek Goyal

On Wed, Apr 04, 2012 at 07:52:24AM -0700, Shaohua Li wrote:

[..]

Quoted 6 lines

Agreed, we can tweak cfq to make it support iops fairness because the two are conceptually the same. The problem is if this is a mess. CFQ is quite complicated already. In iops mode, a lot of code isn't required, like idle, queue merging, thinktime/seek detection and so on, as the scheduler will be only for ssd. With recent iocontext cleanup, the iops scheduler code is quite short actually.

Quoted 3 lines

Ok, this is somewhat a better reason to have a separate scheduler. I guess we need to look that actual iops code and that can help decide whether to keep it as a separate scheduler.

yes, actually I am afraid of making any *big* changes to cfq since it is stable and complicated. It would be terrible for our customer which uses sata and sas most of their time. So iops based scheduler is only used for ssds.

Quoted 9 lines

One question is still unanswered though. What real workload benefits from it? If you are not doing idling in iops based scheduler, I doubt you are doing to see much service differentiation on fast SSDs. As for service differentiation IO queues have to be continuously backlogged and total IOPS needed by applications need to be more than what disk can offer. It becomes very hard to produe continuously backlogged queues because real applications tend to read some data, proces data and then generate more IO.

OK, I guess I can describe our workload somehow. Yes, for very fast SSDs, it would not help since the io depth is too high and we can't fill in enough requests. But for some not that fast SSDs(say intel's x25m series), it can only have tens of thousands iops, and it would help us if we can have this type of ssd work as proportional. Yes, in most case, the ssd will be idle, but we do have times that the disk is very busy and we need the proportional iops to fit our customer's need.

Thanks
Tao

#49 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to a message not in the archive
Quoted 10 lines · Vivek Goyal

On Wed, Apr 04, 2012 at 07:52:24AM -0700, Shaohua Li wrote:

[..]

Quoted 6 lines

Agreed, we can tweak cfq to make it support iops fairness because the two are conceptually the same. The problem is if this is a mess. CFQ is quite complicated already. In iops mode, a lot of code isn't required, like idle, queue merging, thinktime/seek detection and so on, as the scheduler will be only for ssd. With recent iocontext cleanup, the iops scheduler code is quite short actually.

Quoted 3 lines

Ok, this is somewhat a better reason to have a separate scheduler. I guess we need to look that actual iops code and that can help decide whether to keep it as a separate scheduler.

yes, actually I am afraid of making any *big* changes to cfq since it is stable and complicated. It would be terrible for our customer which uses sata and sas most of their time. So iops based scheduler is only used for ssds.

Quoted 9 lines

One question is still unanswered though. What real workload benefits from it? If you are not doing idling in iops based scheduler, I doubt you are doing to see much service differentiation on fast SSDs. As for service differentiation IO queues have to be continuously backlogged and total IOPS needed by applications need to be more than what disk can offer. It becomes very hard to produe continuously backlogged queues because real applications tend to read some data, proces data and then generate more IO.

OK, I guess I can describe our workload somehow. Yes, for very fast SSDs, it would not help since the io depth is too high and we can't fill in enough requests. But for some not that fast SSDs(say intel's x25m series), it can only have tens of thousands iops, and it would help us if we can have this type of ssd work as proportional. Yes, in most case, the ssd will be idle, but we do have times that the disk is very busy and we need the proportional iops to fit our customer's need.

Thanks
Tao

#52 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to Vivek Goyal
Quoted 22 lines · Vivek Goyal

On Wed, Apr 04, 2012 at 05:35:49AM -0700, Shaohua Li wrote:

[..]

Quoted 11 lines
Quoted 11 lines
Quoted 4 lines

How iops_weight and switching different than CFQ group scheduling logic? I think shaohua was talking of using similar logic. What would you do fundamentally different so that without idling you will get service differentiation?

I am thinking of differentiate different groups with iops, so if there are 3 groups(the weight are 100, 200, 300) we can let them submit 1 io, 2 io and 3 io in a round-robin way. With a intel ssd, every io can be finished within 100us. So the maximum latency for one io is about 600us, still less than 1ms. But with cfq, if all the cgroups are busy, we have to switch between these group in ms which means the maximum latency will be 6ms. It is terrible for some applications since they use ssds now.

Quoted 7 lines

Yes, with iops based scheduling, we do queue switching for every request. Doing the same thing between groups is quite straightforward. The only issue I found is this will introduce more process context switch, this isn't a big issue
for io bound application, but depends. It cuts latency a lot, which I guess is more
important for web 2.0 application.

Quoted 3 lines

In iops_mode(), expire each cfqq after dispatch of 1 or bunch of requests and you should get the same behavior (with slice_idle=0 and group_idle=0). So why write a new scheduler.

really? How could we config cfq to work like this? Or you mean we can change the code for it?

Quoted 4 lines

Only thing is that with above, current code will provide iops fairness only for groups. We should be able to tweak queue scheduling to support iops fairness also.

OK, as I have said in another e-mail another my concern is the complexity. It will make cfq too much complicated. I just checked the source code of shaohua's original patch, fiops scheduler is only ~700 lines, so with cgroup support added it would be ~1000 lines I guess. Currently cfq-iosched.c is around ~4000 lines even after Tejun's cleanup of io context...

Thanks
Tao

Quoted 14 lines

Anyway, we will end up doing that at some point of time. Supporting two scheduling algorihtms for queue and groups is not sustainable. There are already calls to make CFQ hierarchical and in that case both queue and groups need to be on a single service tree and that means need to follow same algorithm for scheduling.

Thanks
Vivek
--
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/

#53 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

On Thu, Apr 05, 2012 at 12:45:05AM +0800, Tao Ma wrote:

[..]

Quoted 5 lines
Quoted 3 lines

In iops_mode(), expire each cfqq after dispatch of 1 or bunch of requests and you should get the same behavior (with slice_idle=0 and group_idle=0). So why write a new scheduler.

really? How could we config cfq to work like this? Or you mean we can change the code for it?

You can just put a few lines of code to expire queue after 1-2 requests dispatched from the queue. Than run your workload with slice_idle=0 and group_idle=0 and see what happens.

I don't even know what your workload is.

Quoted 10 lines
Quoted 4 lines

Only thing is that with above, current code will provide iops fairness only for groups. We should be able to tweak queue scheduling to support iops fairness also.

OK, as I have said in another e-mail another my concern is the complexity. It will make cfq too much complicated. I just checked the source code of shaohua's original patch, fiops scheduler is only ~700 lines, so with cgroup support added it would be ~1000 lines I guess. Currently cfq-iosched.c is around ~4000 lines even after Tejun's cleanup of io context...

I think a large chunk of that iops scheduler code will be borrowed from CFQ code. All the cgroup logic, queue creation logic, group scheduling logic etc. And that's the reason I was still exploring the possibility of having common code base.

Thanks
Vivek

#54 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

Quoted 6 lines · Vivek Goyal

On Thu, Apr 05, 2012 at 12:45:05AM +0800, Tao Ma wrote:

[..]

Quoted 3 lines
Quoted 3 lines

In iops_mode(), expire each cfqq after dispatch of 1 or bunch of requests and you should get the same behavior (with slice_idle=0 and group_idle=0). So why write a new scheduler.

Quoted 6 lines
Quoted 2 lines

really? How could we config cfq to work like this? Or you mean we can change the code for it?

You can just put a few lines of code to expire queue after 1-2 requests dispatched from the queue. Than run your workload with slice_idle=0 and group_idle=0 and see what happens.

Can you apply following patch and test your workload with slice_idle=0, group_idle=0 and quantum=64/128.

I expect that fast queue and group switching will take place. Even if your workload is creating continuously backlogged queues, we will still expire the queue after dispatching 5 requests from the queue and requeue it.

I also expect that you should see service differentation at *group level*. (And not at cfqq level), if your workload is creating continuously backlogged groups. Otherwise it will effectively become round robin scheduling.

If possible, send me small backtrace (5 seconds trace), of your workload and that can help understand little better what is going on.

Thanks
Vivek

---
 block/cfq-iosched.c |    5 +++++
 1 file changed, 5 insertions(+)
block/cfq-iosched.c +5 -0
Index: linux-2.6/block/cfq-iosched.c
===================================================================
@@ -655,8 +655,13 @@ cfq_set_prio_slice(struct cfq_data *cfqd
  */
 static inline bool cfq_slice_used(struct cfq_queue *cfqq)
 {
+	/* In iops mode, we really are not looking for time measurement */
+	if (iops_mode(cfqq->cfqd) && cfqq->slice_dispatch > 5)
+		return true;
+
 	if (cfq_cfqq_slice_new(cfqq))
 		return false;
+
 	if (time_before(jiffies, cfqq->slice_end))
 		return false;
 
#56 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to a message not in the archive
Quoted 6 lines · Vivek Goyal

On Thu, Apr 05, 2012 at 12:45:05AM +0800, Tao Ma wrote:

[..]

Quoted 3 lines
Quoted 3 lines

In iops_mode(), expire each cfqq after dispatch of 1 or bunch of requests and you should get the same behavior (with slice_idle=0 and group_idle=0). So why write a new scheduler.

Quoted 6 lines
Quoted 2 lines

really? How could we config cfq to work like this? Or you mean we can change the code for it?

You can just put a few lines of code to expire queue after 1-2 requests dispatched from the queue. Than run your workload with slice_idle=0 and group_idle=0 and see what happens.

Can you apply following patch and test your workload with slice_idle=0, group_idle=0 and quantum=64/128.

I expect that fast queue and group switching will take place. Even if your workload is creating continuously backlogged queues, we will still expire the queue after dispatching 5 requests from the queue and requeue it.

I also expect that you should see service differentation at *group level*. (And not at cfqq level), if your workload is creating continuously backlogged groups. Otherwise it will effectively become round robin scheduling.

If possible, send me small backtrace (5 seconds trace), of your workload and that can help understand little better what is going on.

Thanks
Vivek

---
 block/cfq-iosched.c |    5 +++++
 1 file changed, 5 insertions(+)
block/cfq-iosched.c +5 -0
Index: linux-2.6/block/cfq-iosched.c
===================================================================
@@ -655,8 +655,13 @@ cfq_set_prio_slice(struct cfq_data *cfqd
  */
 static inline bool cfq_slice_used(struct cfq_queue *cfqq)
 {
+	/* In iops mode, we really are not looking for time measurement */
+	if (iops_mode(cfqq->cfqd) && cfqq->slice_dispatch > 5)
+		return true;
+
 	if (cfq_cfqq_slice_new(cfqq))
 		return false;
+
 	if (time_before(jiffies, cfqq->slice_end))
 		return false;
#57 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to a message not in the archive
Quoted 6 lines · Vivek Goyal

On Thu, Apr 05, 2012 at 12:45:05AM +0800, Tao Ma wrote:

[..]

Quoted 3 lines
Quoted 3 lines

In iops_mode(), expire each cfqq after dispatch of 1 or bunch of requests and you should get the same behavior (with slice_idle=0 and group_idle=0). So why write a new scheduler.

Quoted 6 lines
Quoted 2 lines

really? How could we config cfq to work like this? Or you mean we can change the code for it?

You can just put a few lines of code to expire queue after 1-2 requests dispatched from the queue. Than run your workload with slice_idle=0 and group_idle=0 and see what happens.

oh, yes I can do this to see whether the latency helps, but it is hacking and doesn't work with the cgroup proportion...

Quoted 2 lines

I don't even know what your workload is.

Sorry for not allowing to say more about it.

Quoted 12 lines
Quoted 11 lines
Quoted 5 lines

Only thing is that with above, current code will provide iops fairness only for groups. We should be able to tweak queue scheduling to support iops fairness also.

OK, as I have said in another e-mail another my concern is the complexity. It will make cfq too much complicated. I just checked the source code of shaohua's original patch, fiops scheduler is only ~700 lines, so with cgroup support added it would be ~1000 lines I guess. Currently cfq-iosched.c is around ~4000 lines even after Tejun's cleanup of io context...

Quoted 4 lines

I think a large chunk of that iops scheduler code will be borrowed from CFQ code. All the cgroup logic, queue creation logic, group scheduling logic etc. And that's the reason I was still exploring the possibility of having common code base.

Yeah, actually I was thinking of abstracting a generic logic, but it seems a lot bit hard. Maybe we can try to unify the code later?

Thanks
Tao

#58 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to Vivek Goyal
Quoted 6 lines · Vivek Goyal

On Thu, Apr 05, 2012 at 12:45:05AM +0800, Tao Ma wrote:

[..]

Quoted 3 lines
Quoted 3 lines

In iops_mode(), expire each cfqq after dispatch of 1 or bunch of requests and you should get the same behavior (with slice_idle=0 and group_idle=0). So why write a new scheduler.

Quoted 6 lines
Quoted 2 lines

really? How could we config cfq to work like this? Or you mean we can change the code for it?

You can just put a few lines of code to expire queue after 1-2 requests dispatched from the queue. Than run your workload with slice_idle=0 and group_idle=0 and see what happens.

oh, yes I can do this to see whether the latency helps, but it is hacking and doesn't work with the cgroup proportion...

Quoted 2 lines

I don't even know what your workload is.

Sorry for not allowing to say more about it.

Quoted 12 lines
Quoted 11 lines
Quoted 5 lines

Only thing is that with above, current code will provide iops fairness only for groups. We should be able to tweak queue scheduling to support iops fairness also.

OK, as I have said in another e-mail another my concern is the complexity. It will make cfq too much complicated. I just checked the source code of shaohua's original patch, fiops scheduler is only ~700 lines, so with cgroup support added it would be ~1000 lines I guess. Currently cfq-iosched.c is around ~4000 lines even after Tejun's cleanup of io context...

Quoted 4 lines

I think a large chunk of that iops scheduler code will be borrowed from CFQ code. All the cgroup logic, queue creation logic, group scheduling logic etc. And that's the reason I was still exploring the possibility of having common code base.

Yeah, actually I was thinking of abstracting a generic logic, but it seems a lot bit hard. Maybe we can try to unify the code later?

Thanks
Tao

#59 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

On Thu, Apr 05, 2012 at 01:18:05AM +0800, Tao Ma wrote:

[..]

Quoted 5 lines
Quoted 3 lines

You can just put a few lines of code to expire queue after 1-2 requests dispatched from the queue. Than run your workload with slice_idle=0 and group_idle=0 and see what happens.

oh, yes I can do this to see whether the latency helps, but it is hacking and doesn't work with the cgroup proportion...

"Hacking"?. I think effectively that's what effectively iops scheduler should be doing to achieve faster switching.

Also, if your workload is keeping groups continuously busy, you should get proportional behavior at group level.

Do try the patch I sent you in a separate mail with your workload.

[..]

Quoted 6 lines
Quoted 4 lines

I think a large chunk of that iops scheduler code will be borrowed from CFQ code. All the cgroup logic, queue creation logic, group scheduling logic etc. And that's the reason I was still exploring the possibility of having common code base.

Yeah, actually I was thinking of abstracting a generic logic, but it seems a lot bit hard. Maybe we can try to unify the code later?

Once you write and merge a new scheduler, that code merge is never going to happen. They will happily part ways with lot of code/logic shared.

Once the hierarchical support comes to CFQ, same hierarchical cgroup support needs to be written to this new scheduler also.

Thanks
Vivek

#60 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to Tao Ma

On Thu, Apr 05, 2012 at 01:18:05AM +0800, Tao Ma wrote:

[..]

Quoted 6 lines
Quoted 4 lines

I think a large chunk of that iops scheduler code will be borrowed from CFQ code. All the cgroup logic, queue creation logic, group scheduling logic etc. And that's the reason I was still exploring the possibility of having common code base.

Yeah, actually I was thinking of abstracting a generic logic, but it seems a lot bit hard. Maybe we can try to unify the code later?

I think if we change the cfqq scheduling logic to something similar to group scheduling logic, it will help a lot.

- Current virtual time based logic does not care whether you are operating in time mode or iops mode. Switching cfqq logic to similar logic will help moving to iops mode quickly.

- Keeping track of vtime will help that we will get rid of all the residual time logic. If some queue was preempted, and did not use full slice, we will automaticlally charge it less and give smaller vtime.

- Keeping both the scheduling logic will enable us the smoother integration of both cfqq and group logic once we support hierarchical cgroups.

- It will also enable easier integration of iops related logic.

So I am in favor of cleaning up CFQ code and change it to deal with both time as well iops. Seriously, implmenting time or iops is not hard. It is about rest of the logic like trees, groups which contributes towards bulk of the code and I am really not convinced that iops scheduler is going to be different enough that it needs new io scheduler.

Thanks
Vivek

#65 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to a message not in the archive

On Thu, Apr 05, 2012 at 01:18:05AM +0800, Tao Ma wrote:

[..]

Quoted 6 lines
Quoted 4 lines

I think a large chunk of that iops scheduler code will be borrowed from CFQ code. All the cgroup logic, queue creation logic, group scheduling logic etc. And that's the reason I was still exploring the possibility of having common code base.

Yeah, actually I was thinking of abstracting a generic logic, but it seems a lot bit hard. Maybe we can try to unify the code later?

I think if we change the cfqq scheduling logic to something similar to group scheduling logic, it will help a lot.

- Current virtual time based logic does not care whether you are operating in time mode or iops mode. Switching cfqq logic to similar logic will help moving to iops mode quickly.

- Keeping track of vtime will help that we will get rid of all the residual time logic. If some queue was preempted, and did not use full slice, we will automaticlally charge it less and give smaller vtime.

- Keeping both the scheduling logic will enable us the smoother integration of both cfqq and group logic once we support hierarchical cgroups.

- It will also enable easier integration of iops related logic.

So I am in favor of cleaning up CFQ code and change it to deal with both time as well iops. Seriously, implmenting time or iops is not hard. It is about rest of the logic like trees, groups which contributes towards bulk of the code and I am really not convinced that iops scheduler is going to be different enough that it needs new io scheduler.

Thanks
Vivek

#61 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to Vivek Goyal
Quoted 21 lines · Vivek Goyal

On Thu, Apr 05, 2012 at 01:18:05AM +0800, Tao Ma wrote:

[..]

Quoted 6 lines
Quoted 4 lines

I think a large chunk of that iops scheduler code will be borrowed from CFQ code. All the cgroup logic, queue creation logic, group scheduling logic etc. And that's the reason I was still exploring the possibility of having common code base.

Yeah, actually I was thinking of abstracting a generic logic, but it seems a lot bit hard. Maybe we can try to unify the code later?

I think if we change the cfqq scheduling logic to something similar to group scheduling logic, it will help a lot.

- Current virtual time based logic does not care whether you are operating in time mode or iops mode. Switching cfqq logic to similar logic will help moving to iops mode quickly.

- Keeping track of vtime will help that we will get rid of all the residual time logic. If some queue was preempted, and did not use full slice, we will automaticlally charge it less and give smaller vtime.

Quoted 5 lines

- Keeping both the scheduling logic will enable us the smoother integration of both cfqq and group logic once we support hierarchical cgroups.

- It will also enable easier integration of iops related logic.

Maybe, I will check all of these after my travel. Also I will try your patch at that time.

Quoted 6 lines

So I am in favor of cleaning up CFQ code and change it to deal with both time as well iops. Seriously, implmenting time or iops is not hard. It is about rest of the logic like trees, groups which contributes towards bulk of the code and I am really not convinced that iops scheduler is going to be different enough that it needs new io scheduler.

Sure, I also want to make my problem perfect resolved while maitaining things simple.

Thanks
Tao

#63 lore raw

Re: IOPS based scheduler (Was: Re: [PATCH 18/21] blkcg: move blkio_group_conf->weight to cfq)

In reply to a message not in the archive
Quoted 21 lines · Vivek Goyal

On Thu, Apr 05, 2012 at 01:18:05AM +0800, Tao Ma wrote:

[..]

Quoted 6 lines
Quoted 4 lines

I think a large chunk of that iops scheduler code will be borrowed from CFQ code. All the cgroup logic, queue creation logic, group scheduling logic etc. And that's the reason I was still exploring the possibility of having common code base.

Yeah, actually I was thinking of abstracting a generic logic, but it seems a lot bit hard. Maybe we can try to unify the code later?

I think if we change the cfqq scheduling logic to something similar to group scheduling logic, it will help a lot.

- Current virtual time based logic does not care whether you are operating in time mode or iops mode. Switching cfqq logic to similar logic will help moving to iops mode quickly.

- Keeping track of vtime will help that we will get rid of all the residual time logic. If some queue was preempted, and did not use full slice, we will automaticlally charge it less and give smaller vtime.

Quoted 5 lines

- Keeping both the scheduling logic will enable us the smoother integration of both cfqq and group logic once we support hierarchical cgroups.

- It will also enable easier integration of iops related logic.

Maybe, I will check all of these after my travel. Also I will try your patch at that time.

Quoted 6 lines

So I am in favor of cleaning up CFQ code and change it to deal with both time as well iops. Seriously, implmenting time or iops is not hard. It is about rest of the logic like trees, groups which contributes towards bulk of the code and I am really not convinced that iops scheduler is going to be different enough that it needs new io scheduler.

Sure, I also want to make my problem perfect resolved while maitaining things simple.

Thanks
Tao