Linux Container Development
 help / color / mirror / Atom feed
From: Vivek Goyal <vgoyal-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org,
	ctalbott-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
	rni-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
	containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 19/24] blkcg: implement blkg_[rw]stat_recursive_sum() and blkg_[rw]stat_merge()
Date: Tue, 8 Jan 2013 13:03:01 -0500	[thread overview]
Message-ID: <20130108180301.GA29933@redhat.com> (raw)
In-Reply-To: <1356726946-26037-20-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>

On Fri, Dec 28, 2012 at 12:35:41PM -0800, Tejun Heo wrote:
> Implement blkg_[rw]stat_recursive_sum() and blkg_[rw]stat_merge().
> The former two collect the [rw]stats designated by the target policy
> data and offset from the pd's subtree.  The latter two add one
> [rw]stat to another.
> 
> Note that the recursive sum functions require the queue lock to be
> held on entry to make blkg online test reliable.  This is necessary to
> properly handle stats of a dying blkg.
> 
> These will be used to implement hierarchical stats.
> 
> Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>

Acked-by: Vivek Goyal <vgoyal-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

Vivek

> ---
>  block/blk-cgroup.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  block/blk-cgroup.h |  35 ++++++++++++++++++
>  2 files changed, 142 insertions(+)
> 
> diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
> index 4d625d2..a1a4b97 100644
> --- a/block/blk-cgroup.c
> +++ b/block/blk-cgroup.c
> @@ -32,6 +32,26 @@ EXPORT_SYMBOL_GPL(blkcg_root);
>  
>  static struct blkcg_policy *blkcg_policy[BLKCG_MAX_POLS];
>  
> +static struct blkcg_gq *__blkg_lookup(struct blkcg *blkcg,
> +				      struct request_queue *q, bool update_hint);
> +
> +/**
> + * blkg_for_each_descendant_pre - pre-order walk of a blkg's descendants
> + * @d_blkg: loop cursor pointing to the current descendant
> + * @pos_cgrp: used for iteration
> + * @p_blkg: target blkg to walk descendants of
> + *
> + * Walk @c_blkg through the descendants of @p_blkg.  Must be used with RCU
> + * read locked.  If called under either blkcg or queue lock, the iteration
> + * is guaranteed to include all and only online blkgs.  The caller may
> + * update @pos_cgrp by calling cgroup_rightmost_descendant() to skip
> + * subtree.
> + */
> +#define blkg_for_each_descendant_pre(d_blkg, pos_cgrp, p_blkg)		\
> +	cgroup_for_each_descendant_pre((pos_cgrp), (p_blkg)->blkcg->css.cgroup) \
> +		if (((d_blkg) = __blkg_lookup(cgroup_to_blkcg(pos_cgrp), \
> +					      (p_blkg)->q, false)))
> +
>  static bool blkcg_policy_enabled(struct request_queue *q,
>  				 const struct blkcg_policy *pol)
>  {
> @@ -127,6 +147,17 @@ err_free:
>  	return NULL;
>  }
>  
> +/**
> + * __blkg_lookup - internal version of blkg_lookup()
> + * @blkcg: blkcg of interest
> + * @q: request_queue of interest
> + * @update_hint: whether to update lookup hint with the result or not
> + *
> + * This is internal version and shouldn't be used by policy
> + * implementations.  Looks up blkgs for the @blkcg - @q pair regardless of
> + * @q's bypass state.  If @update_hint is %true, the caller should be
> + * holding @q->queue_lock and lookup hint is updated on success.
> + */
>  static struct blkcg_gq *__blkg_lookup(struct blkcg *blkcg,
>  				      struct request_queue *q, bool update_hint)
>  {
> @@ -585,6 +616,82 @@ u64 blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
>  EXPORT_SYMBOL_GPL(blkg_prfill_rwstat);
>  
>  /**
> + * blkg_stat_recursive_sum - collect hierarchical blkg_stat
> + * @pd: policy private data of interest
> + * @off: offset to the blkg_stat in @pd
> + *
> + * Collect the blkg_stat specified by @off from @pd and all its online
> + * descendants and return the sum.  The caller must be holding the queue
> + * lock for online tests.
> + */
> +u64 blkg_stat_recursive_sum(struct blkg_policy_data *pd, int off)
> +{
> +	struct blkcg_policy *pol = blkcg_policy[pd->plid];
> +	struct blkcg_gq *pos_blkg;
> +	struct cgroup *pos_cgrp;
> +	u64 sum;
> +
> +	lockdep_assert_held(pd->blkg->q->queue_lock);
> +
> +	sum = blkg_stat_read((void *)pd + off);
> +
> +	rcu_read_lock();
> +	blkg_for_each_descendant_pre(pos_blkg, pos_cgrp, pd_to_blkg(pd)) {
> +		struct blkg_policy_data *pos_pd = blkg_to_pd(pos_blkg, pol);
> +		struct blkg_stat *stat = (void *)pos_pd + off;
> +
> +		if (pos_blkg->online)
> +			sum += blkg_stat_read(stat);
> +	}
> +	rcu_read_unlock();
> +
> +	return sum;
> +}
> +EXPORT_SYMBOL_GPL(blkg_stat_recursive_sum);
> +
> +/**
> + * blkg_rwstat_recursive_sum - collect hierarchical blkg_rwstat
> + * @pd: policy private data of interest
> + * @off: offset to the blkg_stat in @pd
> + *
> + * Collect the blkg_rwstat specified by @off from @pd and all its online
> + * descendants and return the sum.  The caller must be holding the queue
> + * lock for online tests.
> + */
> +struct blkg_rwstat blkg_rwstat_recursive_sum(struct blkg_policy_data *pd,
> +					     int off)
> +{
> +	struct blkcg_policy *pol = blkcg_policy[pd->plid];
> +	struct blkcg_gq *pos_blkg;
> +	struct cgroup *pos_cgrp;
> +	struct blkg_rwstat sum;
> +	int i;
> +
> +	lockdep_assert_held(pd->blkg->q->queue_lock);
> +
> +	sum = blkg_rwstat_read((void *)pd + off);
> +
> +	rcu_read_lock();
> +	blkg_for_each_descendant_pre(pos_blkg, pos_cgrp, pd_to_blkg(pd)) {
> +		struct blkg_policy_data *pos_pd = blkg_to_pd(pos_blkg, pol);
> +		struct blkg_rwstat *rwstat = (void *)pos_pd + off;
> +		struct blkg_rwstat tmp;
> +
> +		if (!pos_blkg->online)
> +			continue;
> +
> +		tmp = blkg_rwstat_read(rwstat);
> +
> +		for (i = 0; i < BLKG_RWSTAT_NR; i++)
> +			sum.cnt[i] += tmp.cnt[i];
> +	}
> +	rcu_read_unlock();
> +
> +	return sum;
> +}
> +EXPORT_SYMBOL_GPL(blkg_rwstat_recursive_sum);
> +
> +/**
>   * blkg_conf_prep - parse and prepare for per-blkg config update
>   * @blkcg: target block cgroup
>   * @pol: target policy
> diff --git a/block/blk-cgroup.h b/block/blk-cgroup.h
> index 586c0ac..f2b2929 100644
> --- a/block/blk-cgroup.h
> +++ b/block/blk-cgroup.h
> @@ -164,6 +164,10 @@ u64 blkg_prfill_stat(struct seq_file *sf, struct blkg_policy_data *pd, int off);
>  u64 blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
>  		       int off);
>  
> +u64 blkg_stat_recursive_sum(struct blkg_policy_data *pd, int off);
> +struct blkg_rwstat blkg_rwstat_recursive_sum(struct blkg_policy_data *pd,
> +					     int off);
> +
>  struct blkg_conf_ctx {
>  	struct gendisk			*disk;
>  	struct blkcg_gq			*blkg;
> @@ -414,6 +418,18 @@ static inline void blkg_stat_reset(struct blkg_stat *stat)
>  }
>  
>  /**
> + * blkg_stat_merge - merge a blkg_stat into another
> + * @to: the destination blkg_stat
> + * @from: the source
> + *
> + * Add @from's count to @to.
> + */
> +static inline void blkg_stat_merge(struct blkg_stat *to, struct blkg_stat *from)
> +{
> +	blkg_stat_add(to, blkg_stat_read(from));
> +}
> +
> +/**
>   * blkg_rwstat_add - add a value to a blkg_rwstat
>   * @rwstat: target blkg_rwstat
>   * @rw: mask of REQ_{WRITE|SYNC}
> @@ -484,6 +500,25 @@ static inline void blkg_rwstat_reset(struct blkg_rwstat *rwstat)
>  	memset(rwstat->cnt, 0, sizeof(rwstat->cnt));
>  }
>  
> +/**
> + * blkg_rwstat_merge - merge a blkg_rwstat into another
> + * @to: the destination blkg_rwstat
> + * @from: the source
> + *
> + * Add @from's counts to @to.
> + */
> +static inline void blkg_rwstat_merge(struct blkg_rwstat *to,
> +				     struct blkg_rwstat *from)
> +{
> +	struct blkg_rwstat v = blkg_rwstat_read(from);
> +	int i;
> +
> +	u64_stats_update_begin(&to->syncp);
> +	for (i = 0; i < BLKG_RWSTAT_NR; i++)
> +		to->cnt[i] += v.cnt[i];
> +	u64_stats_update_end(&to->syncp);
> +}
> +
>  #else	/* CONFIG_BLK_CGROUP */
>  
>  struct cgroup;
> -- 
> 1.8.0.2

  parent reply	other threads:[~2013-01-08 18:03 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1356726946-26037-1-git-send-email-tj@kernel.org>
     [not found] ` <1356726946-26037-1-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2012-12-28 20:35   ` [PATCH 01/24] cfq-iosched: Properly name all references to IO class Tejun Heo
2012-12-28 20:35   ` [PATCH 02/24] cfq-iosched: More renaming to better represent wl_class and wl_type Tejun Heo
2012-12-28 20:35   ` [PATCH 03/24] cfq-iosched: Rename "service_tree" to "st" at some places Tejun Heo
2012-12-28 20:35   ` [PATCH 04/24] cfq-iosched: Rename few functions related to selecting workload Tejun Heo
2012-12-28 20:35   ` [PATCH 05/24] cfq-iosched: Get rid of unnecessary local variable Tejun Heo
2012-12-28 20:35   ` [PATCH 06/24] cfq-iosched: Print sync-noidle information in blktrace messages Tejun Heo
2012-12-28 20:35   ` [PATCH 07/24] blkcg: fix minor bug in blkg_alloc() Tejun Heo
2012-12-28 20:35   ` [PATCH 08/24] blkcg: reorganize blkg_lookup_create() and friends Tejun Heo
2012-12-28 20:35   ` [PATCH 09/24] blkcg: cosmetic updates to blkg_create() Tejun Heo
2012-12-28 20:35   ` [PATCH 10/24] blkcg: make blkcg_gq's hierarchical Tejun Heo
2012-12-28 20:35   ` [PATCH 11/24] cfq-iosched: add leaf_weight Tejun Heo
2012-12-28 20:35   ` [PATCH 12/24] cfq-iosched: implement cfq_group->nr_active and ->children_weight Tejun Heo
2012-12-28 20:35   ` [PATCH 13/24] cfq-iosched: implement hierarchy-ready cfq_group charge scaling Tejun Heo
     [not found]     ` <1356726946-26037-14-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-01-08 16:16       ` Vivek Goyal
2012-12-28 20:35   ` [PATCH 14/24] cfq-iosched: convert cfq_group_slice() to use cfqg->vfraction Tejun Heo
2012-12-28 20:35   ` [PATCH 15/24] cfq-iosched: enable full blkcg hierarchy support Tejun Heo
2012-12-28 20:35   ` [PATCH 16/24] blkcg: add blkg_policy_data->plid Tejun Heo
2012-12-28 20:35   ` [PATCH 17/24] blkcg: implement blkcg_policy->on/offline_pd_fn() and blkcg_gq->online Tejun Heo
     [not found]     ` <1356726946-26037-18-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-01-02 19:38       ` Vivek Goyal
2013-01-08 16:58       ` Vivek Goyal
     [not found]     ` <20130102193828.GE4306@redhat.com>
     [not found]       ` <20130102193828.GE4306-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-01-02 20:37         ` Tejun Heo
2012-12-28 20:35   ` [PATCH 18/24] blkcg: s/blkg_rwstat_sum()/blkg_rwstat_total()/ Tejun Heo
     [not found]     ` <1356726946-26037-19-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-01-08 16:59       ` Vivek Goyal
2012-12-28 20:35   ` [PATCH 19/24] blkcg: implement blkg_[rw]stat_recursive_sum() and blkg_[rw]stat_merge() Tejun Heo
2012-12-28 20:35   ` [PATCH 20/24] block: RCU free request_queue Tejun Heo
2012-12-28 20:35   ` [PATCH 21/24] blkcg: make blkcg_print_blkgs() grab q locks instead of blkcg lock Tejun Heo
     [not found]     ` <1356726946-26037-22-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-01-02 19:27       ` Vivek Goyal
2013-01-08 18:08       ` Vivek Goyal
     [not found]     ` <20130102192700.GA9552@redhat.com>
     [not found]       ` <20130102192700.GA9552-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-01-02 20:45         ` Tejun Heo
2012-12-28 20:35   ` [PATCH 22/24] cfq-iosched: separate out cfqg_stats_reset() from cfq_pd_reset_stats() Tejun Heo
2012-12-28 20:35   ` [PATCH 23/24] cfq-iosched: collect stats from dead cfqgs Tejun Heo
2012-12-28 20:35   ` [PATCH 24/24] cfq-iosched: add hierarchical cfq_group statistics Tejun Heo
2012-12-28 23:18   ` [PATCH 18.5/24] blkcg: export __blkg_prfill_rwstat() take#2 Tejun Heo
2013-01-02 18:20   ` [PATCHSET] block: implement blkcg hierarchy support in cfq, take#2 Vivek Goyal
     [not found] ` <1356726946-26037-21-git-send-email-tj@kernel.org>
     [not found]   ` <1356726946-26037-21-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-01-02 18:48     ` [PATCH 20/24] block: RCU free request_queue Vivek Goyal
     [not found]       ` <20130102184814.GD4306-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-01-02 20:43         ` Tejun Heo
2013-01-08 18:05     ` Vivek Goyal
     [not found] ` <1356726946-26037-16-git-send-email-tj@kernel.org>
     [not found]   ` <1356726946-26037-16-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-01-07 16:34     ` [PATCH UPDATED 15/24] cfq-iosched: enable full blkcg hierarchy support Tejun Heo
     [not found]       ` <20130107163405.GE3926-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-01-08 14:42         ` Vivek Goyal
     [not found]           ` <20130108144240.GA29635-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-01-08 17:19             ` Tejun Heo
     [not found] ` <20130102182037.GC4306@redhat.com>
     [not found]   ` <20130102182037.GC4306-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-01-07 16:34     ` [PATCHSET] block: implement blkcg hierarchy support in cfq, take#2 Tejun Heo
     [not found]   ` <20130107163437.GF3926@htj.dyndns.org>
     [not found]     ` <20130107163437.GF3926-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2013-01-08 18:28       ` Vivek Goyal
     [not found] ` <1356726946-26037-12-git-send-email-tj@kernel.org>
     [not found]   ` <1356726946-26037-12-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-01-08 15:34     ` [PATCH 11/24] cfq-iosched: add leaf_weight Vivek Goyal
     [not found]       ` <20130108153448.GB29635-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-01-08 17:24         ` Tejun Heo
     [not found] ` <1356726946-26037-13-git-send-email-tj@kernel.org>
     [not found]   ` <1356726946-26037-13-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-01-08 15:51     ` [PATCH 12/24] cfq-iosched: implement cfq_group->nr_active and ->children_weight Vivek Goyal
     [not found] ` <1356726946-26037-15-git-send-email-tj@kernel.org>
     [not found]   ` <1356726946-26037-15-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-01-08 16:42     ` [PATCH 14/24] cfq-iosched: convert cfq_group_slice() to use cfqg->vfraction Vivek Goyal
     [not found] ` <1356726946-26037-17-git-send-email-tj@kernel.org>
     [not found]   ` <1356726946-26037-17-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-01-08 16:51     ` [PATCH 16/24] blkcg: add blkg_policy_data->plid Vivek Goyal
     [not found] ` <1356726946-26037-20-git-send-email-tj@kernel.org>
     [not found]   ` <1356726946-26037-20-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-01-08 18:03     ` Vivek Goyal [this message]
     [not found] ` <1356726946-26037-23-git-send-email-tj@kernel.org>
     [not found]   ` <1356726946-26037-23-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-01-08 18:09     ` [PATCH 22/24] cfq-iosched: separate out cfqg_stats_reset() from cfq_pd_reset_stats() Vivek Goyal
     [not found] ` <1356726946-26037-24-git-send-email-tj@kernel.org>
     [not found]   ` <20130102162415.GA4306@redhat.com>
     [not found]     ` <20130102162415.GA4306-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-01-02 16:30       ` [PATCH 23/24] cfq-iosched: collect stats from dead cfqgs Tejun Heo
     [not found]     ` <20130102163010.GC11220@mtj.dyndns.org>
     [not found]       ` <20130102163010.GC11220-9pTldWuhBndy/B6EtB590w@public.gmane.org>
2013-01-02 16:44         ` Vivek Goyal
     [not found]           ` <20130102164415.GB4306-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-01-02 16:52             ` Tejun Heo
     [not found]   ` <1356726946-26037-24-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-01-02 16:24     ` Vivek Goyal
2013-01-08 18:12     ` Vivek Goyal
     [not found] ` <1356726946-26037-25-git-send-email-tj@kernel.org>
     [not found]   ` <1356726946-26037-25-git-send-email-tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2013-01-08 18:27     ` [PATCH 24/24] cfq-iosched: add hierarchical cfq_group statistics Vivek Goyal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130108180301.GA29933@redhat.com \
    --to=vgoyal-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org \
    --cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=ctalbott-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=rni-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox