From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756831Ab3LTBNR (ORCPT ); Thu, 19 Dec 2013 20:13:17 -0500 Received: from v094114.home.net.pl ([79.96.170.134]:57650 "HELO v094114.home.net.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1756516Ab3LTBNQ (ORCPT ); Thu, 19 Dec 2013 20:13:16 -0500 From: "Rafael J. Wysocki" To: Tejun Heo Cc: Nigel Cunningham , "Rafael J. Wysocki" , Jens Axboe , tomaz.solc@tablix.org, aaron.lu@intel.com, linux-kernel@vger.kernel.org, Oleg Nesterov , Greg Kroah-Hartman , Fengguang Wu , Lai Jiangshan , David Howells Subject: Re: [PATCH wq/for-3.14 1/2] workqueue: update max_active clamping rules Date: Fri, 20 Dec 2013 02:26:36 +0100 Message-ID: <26696517.liOUMm9mZy@vostro.rjw.lan> User-Agent: KMail/4.10.5 (Linux/3.12.0-rc6+; KDE/4.10.5; x86_64; ; ) In-Reply-To: <20131219233526.GD22725@htj.dyndns.org> References: <20131213174932.GA27070@htj.dyndns.org> <1735137.dNmBz0IqxU@vostro.rjw.lan> <20131219233526.GD22725@htj.dyndns.org> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thursday, December 19, 2013 06:35:26 PM Tejun Heo wrote: > From bdd220b2a1b86fee14a12b69fb0cadafe60a1dac Mon Sep 17 00:00:00 2001 > From: Tejun Heo > Date: Thu, 19 Dec 2013 18:33:09 -0500 > > @max_active handling is currently inconsistent. > > * In alloc_workqueue(), 0 gets converted to the default and the value > gets clamped to [1, lim]. > > * In workqueue_set_max_active(), 0 is not converted to the default and > the value is clamped to [1, lim]. > > * When a workqueue is exposed through sysfs, input < 1 fails with > -EINVAL; otherwise, the value is clamped to [1, lim]. > > * fscache exposes max_active through a sysctl and clamps the value in > [1, lim]. > > We want to be able to express zero @max_active but as it's a special > case and 0 is already used for default, don't want to use 0 for it. > Update @max_active clamping so that the following rules are followed. > > * In both alloc_workqueue() and workqueue_set_max_active(), 0 is > converted to the default, and a new special value WQ_FROZEN_ACTIVE > becomes 0; otherwise, the value is clamped to [1, lim]. > > * In both sysfs and fscache sysctl, input < 1 fails with -EINVAL; > otherwise, the value is clamped to [1, lim]. > > Signed-off-by: Tejun Heo > Cc: Lai Jiangshan > Cc: David Howells Well, this one looks good to me: Acked-by: Rafael J. Wysocki > --- > fs/fscache/main.c | 10 +++++++--- > include/linux/workqueue.h | 1 + > kernel/workqueue.c | 6 +++++- > 3 files changed, 13 insertions(+), 4 deletions(-) > > diff --git a/fs/fscache/main.c b/fs/fscache/main.c > index 7c27907..9d5a716 100644 > --- a/fs/fscache/main.c > +++ b/fs/fscache/main.c > @@ -62,9 +62,13 @@ static int fscache_max_active_sysctl(struct ctl_table *table, int write, > int ret; > > ret = proc_dointvec(table, write, buffer, lenp, ppos); > - if (ret == 0) > - workqueue_set_max_active(*wqp, *datap); > - return ret; > + if (ret < 0) > + return ret; > + if (*datap < 1) > + return -EINVAL; > + > + workqueue_set_max_active(*wqp, *datap); > + return 0; > } > > ctl_table fscache_sysctls[] = { > diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h > index 594521b..334daa3 100644 > --- a/include/linux/workqueue.h > +++ b/include/linux/workqueue.h > @@ -338,6 +338,7 @@ enum { > __WQ_DRAINING = 1 << 16, /* internal: workqueue is draining */ > __WQ_ORDERED = 1 << 17, /* internal: workqueue is ordered */ > > + WQ_FROZEN_ACTIVE = -1, /* special value for frozen wq */ > WQ_MAX_ACTIVE = 512, /* I like 512, better ideas? */ > WQ_MAX_UNBOUND_PER_CPU = 4, /* 4 * #cpus for unbound wq */ > WQ_DFL_ACTIVE = WQ_MAX_ACTIVE / 2, > diff --git a/kernel/workqueue.c b/kernel/workqueue.c > index 987293d..6748fbf 100644 > --- a/kernel/workqueue.c > +++ b/kernel/workqueue.c > @@ -4136,6 +4136,11 @@ static int wq_clamp_max_active(int max_active, unsigned int flags, > { > int lim = flags & WQ_UNBOUND ? WQ_UNBOUND_MAX_ACTIVE : WQ_MAX_ACTIVE; > > + if (max_active == 0) > + return WQ_DFL_ACTIVE; > + if (max_active == WQ_FROZEN_ACTIVE) > + return 0; > + > if (max_active < 1 || max_active > lim) > pr_warn("workqueue: max_active %d requested for %s is out of range, clamping between %d and %d\n", > max_active, name, 1, lim); > @@ -4176,7 +4181,6 @@ struct workqueue_struct *__alloc_workqueue_key(const char *fmt, > vsnprintf(wq->name, sizeof(wq->name), fmt, args); > va_end(args); > > - max_active = max_active ?: WQ_DFL_ACTIVE; > max_active = wq_clamp_max_active(max_active, flags, wq->name); > > /* init wq */ > -- I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.