[Devel] [PATCH RHEL7 COMMIT] ub: ressurrect iostat and ioprio reporting

Konstantin Khorenko khorenko at virtuozzo.com
Tue Jun 16 05:28:52 PDT 2015


The commit is pushed to "branch-rh7-3.10.0-123.1.2-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-123.1.2.vz7.5.13
------>
commit 2a160eaabf65a85402dbf277a653961240e13604
Author: Vladimir Davydov <vdavydov at parallels.com>
Date:   Tue Jun 16 16:28:52 2015 +0400

    ub: ressurrect iostat and ioprio reporting
    
    Patchset description:
    
    https://jira.sw.ru/browse/PSBM-34007
    
    Vladimir Davydov (7):
      ioprio: move IOPRIO_WHO_UBC handling out of rcu section
      ub: zap ub_{init,fini}_ioprio
      ub: export ub_get_{mem,blkio}_css
      ub: ressurrect ioprio_set IOPRIO_WHO_UBC
      ub: ressurrect iostat and ioprio reporting
      ub: account writeback io
      ub: do not include block/blk-cgroup.h from io_prio.c
    
    This patch description:
    
    This patch resurrects hunks from diff-bc-io-combined-rh358.2.1-8
    procuring iostat/ioprio from the blkio cgroup and reporting them in
    /proc/bc.
    
    diff-bc-io-added-numbers-of-read-and-write-completed-requests-in-iostat
    is folded in.
    
    Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
    Acked-by: Dmitry Monakhov <dmonakhov at openvz.org>
---
 block/cfq-iosched.c | 55 +++++++++++++++++++++++++++++++++++
 kernel/bc/io_prio.c | 82 +++++++++++++----------------------------------------
 2 files changed, 75 insertions(+), 62 deletions(-)

diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index b4a9ff7..faf5cdd 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -1740,6 +1740,11 @@ static int cfq_set_leaf_weight(struct cgroup *cgrp, struct cftype *cft, u64 val)
 }
 
 #ifdef CONFIG_BC_IO_PRIORITY
+unsigned int blkcg_get_weight(struct cgroup *cgrp)
+{
+	return cgroup_to_blkcg(cgrp)->cfq_weight;
+}
+
 int blkcg_set_weight(struct cgroup *cgrp, unsigned int weight)
 {
 	return cfq_set_weight(cgrp, NULL, weight);
@@ -1802,6 +1807,56 @@ static int cfqg_print_rwstat_recursive(struct cgroup *cgrp, struct cftype *cft,
 	return 0;
 }
 
+#ifdef CONFIG_BC_IO_PRIORITY
+static u64 cfqg_prfill_ub_iostat(struct seq_file *sf,
+				 struct blkg_policy_data *pd, int unused)
+{
+	struct user_beancounter *ub = sf->private;
+	struct blkg_rwstat queued, serviced, wait_time;
+	u64 sectors, time;
+	const char *dev_name;
+
+	if (pd->blkg->q->kobj.parent)
+		dev_name = kobject_name(pd->blkg->q->kobj.parent);
+	else
+		dev_name = "none";
+
+	queued = cfqg_rwstat_pd_recursive_sum(pd,
+			offsetof(struct cfq_group, stats.queued));
+	serviced = cfqg_rwstat_pd_recursive_sum(pd,
+			offsetof(struct cfq_group, stats.serviced));
+	wait_time = cfqg_rwstat_pd_recursive_sum(pd,
+			offsetof(struct cfq_group, stats.wait_time));
+	sectors = cfqg_stat_pd_recursive_sum(pd,
+			offsetof(struct cfq_group, stats.sectors));
+	time = cfqg_stat_pd_recursive_sum(pd,
+			offsetof(struct cfq_group, stats.time));
+
+	seq_printf(sf, "%s %s . %llu 0 0 %llu %llu %llu %llu %llu %llu\n",
+		   dev_name, ub->ub_name,
+		   (unsigned long long)(queued.cnt[BLKG_RWSTAT_READ] +
+					queued.cnt[BLKG_RWSTAT_WRITE]),
+		   (unsigned long long)div_u64(wait_time.cnt[BLKG_RWSTAT_READ] +
+					       wait_time.cnt[BLKG_RWSTAT_WRITE],
+					       NSEC_PER_MSEC),
+		   (unsigned long long)time,
+		   (unsigned long long)(serviced.cnt[BLKG_RWSTAT_READ] +
+					serviced.cnt[BLKG_RWSTAT_WRITE]),
+		   (unsigned long long)sectors,
+		   (unsigned long long)serviced.cnt[BLKG_RWSTAT_READ],
+		   (unsigned long long)serviced.cnt[BLKG_RWSTAT_WRITE]);
+	return 0;
+}
+
+void blkcg_show_ub_iostat(struct cgroup *cgrp, struct seq_file *sf)
+{
+	struct blkcg *blkcg = cgroup_to_blkcg(cgrp);
+
+	blkcg_print_blkgs(sf, blkcg, cfqg_prfill_ub_iostat,
+			  &blkcg_policy_cfq, 0, false);
+}
+#endif
+
 #ifdef CONFIG_DEBUG_BLK_CGROUP
 static u64 cfqg_prfill_avg_queue_size(struct seq_file *sf,
 				      struct blkg_policy_data *pd, int off)
diff --git a/kernel/bc/io_prio.c b/kernel/bc/io_prio.c
index 6d31ce9..69f2f79 100644
--- a/kernel/bc/io_prio.c
+++ b/kernel/bc/io_prio.c
@@ -18,7 +18,9 @@ static unsigned int ioprio_weight[UB_IOPRIO_MAX] = {
 	320, 365, 410, 460, 500, 550, 600, 640,
 };
 
+extern unsigned int blkcg_get_weight(struct cgroup *cgrp);
 extern int blkcg_set_weight(struct cgroup *cgrp, unsigned int weight);
+extern void blkcg_show_ub_iostat(struct cgroup *cgrp, struct seq_file *sf);
 
 int ub_set_ioprio(int id, int ioprio)
 {
@@ -43,67 +45,25 @@ out:
 	return ret;
 }
 
-#if 0
+#ifdef CONFIG_PROC_FS
 
 static int bc_iostat(struct seq_file *f, struct user_beancounter *bc)
 {
-	struct blkio_group_stats *stats;
-	struct blkio_cgroup *blkcg;
-	struct blkio_group *blkg;
-	struct hlist_node *n;
-
-	seq_printf(f, "%s %s %c %lu %lu %lu %u %u %lu %lu\n",
-			"flush" ,
-			bc->ub_name, '.',
-			0ul, 0ul, 0ul, 0, 0,
+	struct cgroup_subsys_state *css;
+
+	seq_printf(f, "flush %s . 0 0 0 0 0 %ld %ld 0 0\n",
+			bc->ub_name,
 			ub_stat_get_exact(bc, wb_requests),
 			ub_stat_get_exact(bc, wb_sectors));
 
-	seq_printf(f, "%s %s %c %lu %lu %lu %u %u %lu %lu\n",
-			"fuse" ,
-			bc->ub_name, '.',
-			0ul, 0ul, 0ul, 0, 0,
+	seq_printf(f, "fuse %s . 0 0 0 0 0 %lu %lu 0 0\n",
+			bc->ub_name,
 			__ub_percpu_sum(bc, fuse_requests),
 			__ub_percpu_sum(bc, fuse_bytes) >> 9);
 
-	if (!bc->blkio_cgroup)
-		return 0;
-
-	blkcg = cgroup_to_blkio_cgroup(bc->blkio_cgroup);
-
-	rcu_read_lock();
-	hlist_for_each_entry_rcu(blkg, n, &blkcg->blkg_list, blkcg_node) {
-		unsigned long queued, serviced, sectors;
-		unsigned int used_time, wait_time;
-		uint64_t tmp;
-
-		if (!blkg->dev || blkg->plid != BLKIO_POLICY_PROP)
-			continue;
-
-		spin_lock_irq(&blkg->stats_lock);
-		stats = &blkg->stats;
-		queued    = stats->stat_arr[BLKIO_STAT_QUEUED][BLKIO_STAT_READ] +
-			    stats->stat_arr[BLKIO_STAT_QUEUED][BLKIO_STAT_WRITE];
-		serviced  = blkio_read_stat_cpu(blkg, BLKIO_STAT_CPU_SERVICED, BLKIO_STAT_READ);
-		serviced += blkio_read_stat_cpu(blkg, BLKIO_STAT_CPU_SERVICED, BLKIO_STAT_WRITE);
-		tmp	  = stats->stat_arr[BLKIO_STAT_WAIT_TIME][BLKIO_STAT_READ] +
-			    stats->stat_arr[BLKIO_STAT_WAIT_TIME][BLKIO_STAT_WRITE];
-		do_div(tmp, NSEC_PER_MSEC);
-		wait_time = tmp;
-
-		used_time = jiffies_to_msecs(stats->time);
-		sectors   = blkio_read_stat_cpu(blkg, BLKIO_STAT_CPU_SECTORS, 0);
-		spin_unlock_irq(&blkg->stats_lock);
-
-		seq_printf(f, "%s %s %c %lu %lu %lu %u %u %lu %lu\n",
-				blkg->dev_name ?: "none" ,
-				bc->ub_name, '.',
-				queued, 0ul, 0ul,
-				wait_time, used_time,
-				serviced, sectors);
-	}
-	rcu_read_unlock();
-
+	css = ub_get_blkio_css(bc);
+	blkcg_show_ub_iostat(css->cgroup, f);
+	css_put(css);
 	return 0;
 }
 
@@ -133,11 +93,8 @@ static void *bc_iostat_start(struct seq_file *f, loff_t *ppos)
 static void *bc_iostat_next(struct seq_file *f, void *v, loff_t *ppos)
 {
 	struct user_beancounter *ub = v;
-	struct list_head *entry;
 
-	entry = &ub->ub_list;
-	list_for_each_continue_rcu(entry, &ub_list_head) {
-		ub = list_entry(entry, struct user_beancounter, ub_list);
+	list_for_each_entry_continue_rcu(ub, &ub_list_head, ub_list) {
 		(*ppos)++;
 		return ub;
 	}
@@ -146,6 +103,7 @@ static void *bc_iostat_next(struct seq_file *f, void *v, loff_t *ppos)
 
 static int bc_iostat_show(struct seq_file *f, void *v)
 {
+	f->private = v;
 	return bc_iostat(f, v);
 }
 
@@ -184,18 +142,18 @@ static struct bc_proc_entry bc_root_iostat_entry = {
 static int bc_ioprio_show(struct seq_file *f, void *v)
 {
 	struct user_beancounter *bc;
-	struct blkio_cgroup *blkcg;
+	struct cgroup_subsys_state *css;
+	unsigned int weight;
 	int ioprio;
 
 	bc = seq_beancounter(f);
 
-	if (!bc->blkio_cgroup)
-		return 0;
-
-	blkcg = cgroup_to_blkio_cgroup(bc->blkio_cgroup);
+	css = ub_get_blkio_css(bc);
+	weight = blkcg_get_weight(css->cgroup);
+	css_put(css);
 
 	ioprio = UB_IOPRIO_MAX - 1;
-	while (ioprio && blkcg->weight < ioprio_weight[ioprio])
+	while (ioprio && weight < ioprio_weight[ioprio])
 		ioprio--;
 
 	seq_printf(f, "prio: %d\n", ioprio);



More information about the Devel mailing list