From: Vivek Goyal <vgoyal@redhat.com>
To: Tejun Heo <tj@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Jens Axboe <axboe@kernel.dk>
Subject: Re: [PATCH percpu/for-3.17 2/2] blk-throttle: replace custom async percpu alloc mechanism with percpu_pool
Date: Mon, 21 Jul 2014 13:27:34 -0400 [thread overview]
Message-ID: <20140721172734.GA13577@redhat.com> (raw)
In-Reply-To: <20140718200834.GH13012@htj.dyndns.org>
On Fri, Jul 18, 2014 at 04:08:34PM -0400, Tejun Heo wrote:
> >From 0a4bd997ba9725565883c688d7dcee8264abf71c Mon Sep 17 00:00:00 2001
> From: Tejun Heo <tj@kernel.org>
> Date: Fri, 18 Jul 2014 16:07:14 -0400
>
> throtl_pd_init() is called under the queue lock but needs to allocate
> the percpu stats area. This is currently handled by queueing it on a
> list and scheduling a work item to allocate and fill the percpu stats
> area. Now that perpcu_pool is available, this custom mechanism can be
> replaced.
>
> Add tg_stats_cpu_pool and implement tg_ensure_stats_cpu() which tries
> to make sure that tg->stats_cpu is populated to replace the custom
> async alloc mechanism. As percpu_pool allocation can fail,
> tg_ensure_stats_cpu() is invoked whenever ->stats_cpu is about to be
> accessed. This is similar to the way code was structured before as
> the custom async alloc could take arbitrary amount of time and each
> access should verify that ->stats_cpu is populated.
>
> This simplifies the code. There shouldn't be noticeable functional
> difference.
Hi Tejun,
This is a very good cleanup.
I have a query inline below.
Otherwise patch looks good to me from blk-throttle perspective.
Acked-by: Vivek Goyal <vgoyal@redhat.com>
[..]
> +static bool tg_ensure_stats_cpu(struct throtl_grp *tg)
> +{
> + struct tg_stats_cpu __percpu *stats_cpu;
> + int cpu;
> +
> + if (likely(tg->stats_cpu))
> + return true;
> +
> + stats_cpu = percpu_pool_alloc(&tg_stats_cpu_pool);
> + if (!stats_cpu)
> + return false;
> +
> + for_each_possible_cpu(cpu) {
> + struct tg_stats_cpu *tg_stats = per_cpu_ptr(stats_cpu, cpu);
> +
> + blkg_rwstat_init(&tg_stats->service_bytes);
> + blkg_rwstat_init(&tg_stats->serviced);
> + }
> +
> + /*
> + * Try to install @stats_cpu. There may be multiple competing
> + * instances of this function. Use cmpxchg() so that only the
> + * first one gets installed.
> + */
> + if (cmpxchg(&tg->stats_cpu, (struct tg_stats_cpu __percpu *)NULL,
> + stats_cpu))
> + free_percpu(stats_cpu);
> +
So we are using atomic cmpxchg() so that we don't ask callers to hold queue
lock during this call? One of the callers is throtl_update_dispatch_stats()
and we don't want to grab queue lock while updating per cpu stat. In fact
stats were made per cpu so that we don't have to grab the lock.
Thanks
Vivek
next prev parent reply other threads:[~2014-07-21 17:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-18 20:08 [PATCH percpu/for-3.17 1/2] percpu: implement percpu_pool Tejun Heo
2014-07-18 20:08 ` [PATCH percpu/for-3.17 2/2] blk-throttle: replace custom async percpu alloc mechanism with percpu_pool Tejun Heo
2014-07-21 17:27 ` Vivek Goyal [this message]
2014-07-22 0:50 ` Tejun Heo
2014-07-22 0:51 ` Tejun Heo
2014-07-31 19:00 ` [PATCH percpu/for-3.17 1/2] percpu: implement percpu_pool Tejun Heo
2014-07-31 22:03 ` Andrew Morton
2014-08-01 0:44 ` Tejun Heo
2014-08-01 1:16 ` Andrew Morton
2014-08-01 1:23 ` Tejun Heo
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=20140721172734.GA13577@redhat.com \
--to=vgoyal@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.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;
as well as URLs for NNTP newsgroup(s).