Re: [PATCHSET] mempool, percpu, blkcg: fix percpu stat allocationand remove stats_lock

From: Tejun Heo
Date: Wed Mar 07 2012 - 14:22:38 EST


Hello, Vivek.

On Wed, Mar 07, 2012 at 02:13:34PM -0500, Vivek Goyal wrote:
> +static void blkio_stat_alloc_fn(struct work_struct *work)
> +{
> +
> + struct delayed_work *dwork = to_delayed_work(work);
> + struct blkio_group *blkg;
> + int i;
> + bool alloc_more = 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)) {
> + alloc_more = false;
> + goto unlock;
> + }
> +
> + 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);
> +
> + if (list_empty(&alloc_list))
> + alloc_more = false;
> + else
> + alloc_more = true;

Sorry about being a pain in the ass for small stuff but how about the
following?

lock_stuff()

if (!list_empty()) {
struct blkio_group *blkg = list_first_entry();

for (i = 0; ..) {
set stuff;
}
list_del_init();
}
empty = list_empty();

unlock_stuff();

if (!empty)
goto repeat;

Thanks.

--
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/