Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964796AbbFCPCl (ORCPT ); Wed, 3 Jun 2015 11:02:41 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:41769 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S933091AbbFCPBn (ORCPT ); Wed, 3 Jun 2015 11:01:43 -0400 X-IronPort-AV: E=Sophos;i="5.01,1,1399996800"; d="scan'208";a="96378548" From: Lai Jiangshan To: CC: Lai Jiangshan , Tejun Heo Subject: [PATCH 4/4] workqueue: reuse wq_update_unbound_numa_attrs_buf as temporary attrs Date: Wed, 3 Jun 2015 22:29:52 +0800 Message-ID: <1433341792-2017-5-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: 4450 Lines: 119 tmp_attrs in apply_wqattrs_prepare() is just temporary attrs, we can use wq_update_unbound_numa_attrs_buf for it like wq_update_unbound_numa(); The wq_update_unbound_numa_attrs_buf is renamed to wq_calc_node_attrs_buf since it is used both for apply_wqattrs_prepare() and wq_update_unbound_numa(). The comment for using wq_calc_node_attrs_buf in wq_update_unbound_numa() is also moved to the defination of the wq_calc_node_attrs_buf. This change also avoids frequently alloc/free the tmp_attrs for every workqueue when the low level cpumask is being updated. Signed-off-by: Lai Jiangshan --- kernel/workqueue.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 0c2f819..4a40165 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -295,8 +295,13 @@ module_param_named(power_efficient, wq_power_efficient, bool, 0444); static bool wq_numa_enabled; /* unbound NUMA affinity enabled */ -/* buf for wq_update_unbound_numa_attrs(), protected by CPU hotplug exclusion */ -static struct workqueue_attrs *wq_update_unbound_numa_attrs_buf; +/* + * PL: resulted attrs of wq_calc_node_cpumask() for apply_wqattrs_prepare() + * and wq_update_unbound_numa(). + * We don't wanna alloc/free temporary attrs for each call. Let's preallocate + * one with the access protection of wq_pool_mutex. + */ +static struct workqueue_attrs *wq_calc_node_attrs_buf; static DEFINE_MUTEX(wq_pool_mutex); /* protects pools and workqueues list */ static DEFINE_SPINLOCK(wq_mayday_lock); /* protects wq->maydays list */ @@ -3515,7 +3520,7 @@ apply_wqattrs_prepare(struct workqueue_struct *wq, const struct workqueue_attrs *attrs) { struct apply_wqattrs_ctx *ctx; - struct workqueue_attrs *new_attrs, *tmp_attrs; + struct workqueue_attrs *new_attrs, *tmp_attrs = wq_calc_node_attrs_buf; struct pool_workqueue *pwq; int node; @@ -3525,8 +3530,7 @@ apply_wqattrs_prepare(struct workqueue_struct *wq, GFP_KERNEL); new_attrs = alloc_workqueue_attrs(GFP_KERNEL); - tmp_attrs = alloc_workqueue_attrs(GFP_KERNEL); - if (!ctx || !new_attrs || !tmp_attrs) + if (!ctx || !new_attrs) goto out_free; /* @@ -3585,11 +3589,9 @@ apply_wqattrs_prepare(struct workqueue_struct *wq, ctx->attrs = new_attrs; ctx->wq = wq; - free_workqueue_attrs(tmp_attrs); return ctx; out_free: - free_workqueue_attrs(tmp_attrs); free_workqueue_attrs(new_attrs); apply_wqattrs_cleanup(ctx); return NULL; @@ -3713,7 +3715,7 @@ static void wq_update_unbound_numa(struct workqueue_struct *wq, int cpu, int node = cpu_to_node(cpu); int cpu_off = online ? -1 : cpu; struct pool_workqueue *old_pwq = NULL, *pwq; - struct workqueue_attrs *target_attrs; + struct workqueue_attrs *target_attrs = wq_calc_node_attrs_buf; cpumask_t *cpumask; lockdep_assert_held(&wq_pool_mutex); @@ -3722,14 +3724,6 @@ static void wq_update_unbound_numa(struct workqueue_struct *wq, int cpu, wq->unbound_attrs->no_numa) return; - /* - * We don't wanna alloc/free wq_attrs for each wq for each CPU. - * Let's use a preallocated one. The following buf is protected by - * CPU hotplug exclusion. - */ - target_attrs = wq_update_unbound_numa_attrs_buf; - cpumask = target_attrs->cpumask; - copy_workqueue_attrs(target_attrs, wq->unbound_attrs); /* @@ -3738,6 +3732,7 @@ static void wq_update_unbound_numa(struct workqueue_struct *wq, int cpu, * and create a new one if they don't match. If the target cpumask * equals the default pwq's, the default pwq should be used. */ + cpumask = target_attrs->cpumask; if (wq_calc_node_cpumask(wq->dfl_pwq->pool->attrs, node, cpu_off, cpumask)) { pwq = unbound_pwq_by_node(wq, node); if (cpumask_equal(cpumask, pwq->pool->attrs->cpumask)) @@ -5208,8 +5203,8 @@ static void __init wq_numa_init(void) return; } - wq_update_unbound_numa_attrs_buf = alloc_workqueue_attrs(GFP_KERNEL); - BUG_ON(!wq_update_unbound_numa_attrs_buf); + wq_calc_node_attrs_buf = alloc_workqueue_attrs(GFP_KERNEL); + BUG_ON(!wq_calc_node_attrs_buf); /* * We want masks of possible CPUs of each node which isn't readily -- 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/