Skip to content

Commit 903d23f

Browse files
Josef Bacikaxboe
authored andcommitted
blk-cgroup: allow controllers to output their own stats
blk-iolatency has a few stats that it would like to print out, and instead of adding a bunch of crap to the generic code just provide a helper so that controllers can add stuff to the stat line if they want to. Hide it behind a boot option since it changes the output of io.stat from normal, and these stats are only interesting to developers. Signed-off-by: Josef Bacik <jbacik@fb.com> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c7c98fd commit 903d23f

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

block/blk-cgroup.c

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ static struct blkcg_policy *blkcg_policy[BLKCG_MAX_POLS];
5050

5151
static LIST_HEAD(all_blkcgs); /* protected by blkcg_pol_mutex */
5252

53+
static bool blkcg_debug_stats = false;
54+
5355
static bool blkcg_policy_enabled(struct request_queue *q,
5456
const struct blkcg_policy *pol)
5557
{
@@ -954,13 +956,25 @@ static int blkcg_print_stat(struct seq_file *sf, void *v)
954956

955957
hlist_for_each_entry_rcu(blkg, &blkcg->blkg_list, blkcg_node) {
956958
const char *dname;
959+
char *buf;
957960
struct blkg_rwstat rwstat;
958961
u64 rbytes, wbytes, rios, wios;
962+
size_t size = seq_get_buf(sf, &buf), off = 0;
963+
int i;
964+
bool has_stats = false;
959965

960966
dname = blkg_dev_name(blkg);
961967
if (!dname)
962968
continue;
963969

970+
/*
971+
* Hooray string manipulation, count is the size written NOT
972+
* INCLUDING THE \0, so size is now count+1 less than what we
973+
* had before, but we want to start writing the next bit from
974+
* the \0 so we only add count to buf.
975+
*/
976+
off += scnprintf(buf+off, size-off, "%s ", dname);
977+
964978
spin_lock_irq(blkg->q->queue_lock);
965979

966980
rwstat = blkg_rwstat_recursive_sum(blkg, NULL,
@@ -975,9 +989,33 @@ static int blkcg_print_stat(struct seq_file *sf, void *v)
975989

976990
spin_unlock_irq(blkg->q->queue_lock);
977991

978-
if (rbytes || wbytes || rios || wios)
979-
seq_printf(sf, "%s rbytes=%llu wbytes=%llu rios=%llu wios=%llu\n",
980-
dname, rbytes, wbytes, rios, wios);
992+
if (rbytes || wbytes || rios || wios) {
993+
has_stats = true;
994+
off += scnprintf(buf+off, size-off,
995+
"rbytes=%llu wbytes=%llu rios=%llu wios=%llu",
996+
rbytes, wbytes, rios, wios);
997+
}
998+
999+
if (!blkcg_debug_stats)
1000+
goto next;
1001+
1002+
for (i = 0; i < BLKCG_MAX_POLS; i++) {
1003+
struct blkcg_policy *pol = blkcg_policy[i];
1004+
size_t written;
1005+
1006+
if (!blkg->pd[i] || !pol->pd_stat_fn)
1007+
continue;
1008+
1009+
written = pol->pd_stat_fn(blkg->pd[i], buf+off, size-off);
1010+
if (written)
1011+
has_stats = true;
1012+
off += written;
1013+
}
1014+
next:
1015+
if (has_stats) {
1016+
off += scnprintf(buf+off, size-off, "\n");
1017+
seq_commit(sf, off);
1018+
}
9811019
}
9821020

9831021
rcu_read_unlock();
@@ -1547,3 +1585,6 @@ void blkcg_policy_unregister(struct blkcg_policy *pol)
15471585
mutex_unlock(&blkcg_pol_register_mutex);
15481586
}
15491587
EXPORT_SYMBOL_GPL(blkcg_policy_unregister);
1588+
1589+
module_param(blkcg_debug_stats, bool, 0644);
1590+
MODULE_PARM_DESC(blkcg_debug_stats, "True if you want debug stats, false if not");

include/linux/blk-cgroup.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ typedef void (blkcg_pol_online_pd_fn)(struct blkg_policy_data *pd);
148148
typedef void (blkcg_pol_offline_pd_fn)(struct blkg_policy_data *pd);
149149
typedef void (blkcg_pol_free_pd_fn)(struct blkg_policy_data *pd);
150150
typedef void (blkcg_pol_reset_pd_stats_fn)(struct blkg_policy_data *pd);
151+
typedef size_t (blkcg_pol_stat_pd_fn)(struct blkg_policy_data *pd, char *buf,
152+
size_t size);
151153

152154
struct blkcg_policy {
153155
int plid;
@@ -167,6 +169,7 @@ struct blkcg_policy {
167169
blkcg_pol_offline_pd_fn *pd_offline_fn;
168170
blkcg_pol_free_pd_fn *pd_free_fn;
169171
blkcg_pol_reset_pd_stats_fn *pd_reset_stats_fn;
172+
blkcg_pol_stat_pd_fn *pd_stat_fn;
170173
};
171174

172175
extern struct blkcg blkcg_root;

0 commit comments

Comments
 (0)