Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933177AbbFCPCG (ORCPT ); Wed, 3 Jun 2015 11:02:06 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:51338 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S932788AbbFCPBj (ORCPT ); Wed, 3 Jun 2015 11:01:39 -0400 X-IronPort-AV: E=Sophos;i="5.01,1,1399996800"; d="scan'208";a="96378545" From: Lai Jiangshan To: CC: Lai Jiangshan , Tejun Heo Subject: [PATCH 3/4] workqueue: reuse the current default pwq when its attrs unchanged Date: Wed, 3 Jun 2015 22:29:51 +0800 Message-ID: <1433341792-2017-4-git-send-email-laijs@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1433341792-2017-1-git-send-email-laijs@cn.fujitsu.com> References: <1433341792-2017-1-git-send-email-laijs@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.167.226.103] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2132 Lines: 59 When apply_wqattrs_prepare() is called, it is possible that the default pwq is unaffected. It is always true that only the NUMA affinity is being changed and sometimes true that the low level cpumask is being changed. So we try to reuse the current default pwq when its attrs unchanged. After this change, "ctx->dfl_pwq->refcnt++" could be dangerous when ctx->dfl_pwq is a reusing pwq which may be receiving work items or processing work items and hurts concurrency [get|put]_pwq(), so we use get_pwq_unlocked() instead. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 197520b..0c2f819 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -3549,11 +3549,17 @@ apply_wqattrs_prepare(struct workqueue_struct *wq, /* * If something goes wrong during CPU up/down, we'll fall back to * the default pwq covering whole @attrs->cpumask. Always create - * it even if we don't use it immediately. + * it even if we don't use it immediately. Check and reuse the + * current default pwq if the @new_attrs equals the current one. */ - ctx->dfl_pwq = alloc_unbound_pwq(wq, new_attrs); - if (!ctx->dfl_pwq) - goto out_free; + if (wq->dfl_pwq && wqattrs_equal(new_attrs, wq->dfl_pwq->pool->attrs)) { + get_pwq_unlocked(wq->dfl_pwq); + ctx->dfl_pwq = wq->dfl_pwq; + } else { + ctx->dfl_pwq = alloc_unbound_pwq(wq, new_attrs); + if (!ctx->dfl_pwq) + goto out_free; + } for_each_node(node) { if (wq_calc_node_cpumask(new_attrs, node, -1, tmp_attrs->cpumask)) { @@ -3568,7 +3574,7 @@ apply_wqattrs_prepare(struct workqueue_struct *wq, } ctx->pwq_tbl[node] = pwq; } else { - ctx->dfl_pwq->refcnt++; + get_pwq_unlocked(ctx->dfl_pwq); ctx->pwq_tbl[node] = ctx->dfl_pwq; } } -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/