From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: Oleg Nesterov <oleg@tv-sign.ru>, Ingo Molnar <mingo@elte.hu>,
Andrew Morton <akpm@linux-foundation.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH] workqueue: don't alloc_percpu for single workqueue
Date: Wed, 21 Jan 2009 17:42:35 +0800 [thread overview]
Message-ID: <4976EE0B.5090200@cn.fujitsu.com> (raw)
allocating memory for every cpu for single workqueue is waste.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 2f44583..ecd693d 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -99,7 +99,7 @@ static
struct cpu_workqueue_struct *wq_per_cpu(struct workqueue_struct *wq, int cpu)
{
if (unlikely(is_wq_single_threaded(wq)))
- cpu = singlethread_cpu;
+ return wq->cpu_wq;
return per_cpu_ptr(wq->cpu_wq, cpu);
}
@@ -417,7 +417,7 @@ void flush_workqueue(struct workqueue_struct *wq)
lock_map_acquire(&wq->lockdep_map);
lock_map_release(&wq->lockdep_map);
for_each_cpu_mask_nr(cpu, *cpu_map)
- flush_cpu_workqueue(per_cpu_ptr(wq->cpu_wq, cpu));
+ flush_cpu_workqueue(wq_per_cpu(wq, cpu));
}
EXPORT_SYMBOL_GPL(flush_workqueue);
@@ -548,7 +548,7 @@ static void wait_on_work(struct work_struct *work)
cpu_map = wq_cpu_map(wq);
for_each_cpu_mask_nr(cpu, *cpu_map)
- wait_on_cpu_work(per_cpu_ptr(wq->cpu_wq, cpu), work);
+ wait_on_cpu_work(wq_per_cpu(wq, cpu), work);
}
static int __cancel_work_timer(struct work_struct *work,
@@ -752,17 +752,13 @@ int current_is_keventd(void)
}
-static struct cpu_workqueue_struct *
-init_cpu_workqueue(struct workqueue_struct *wq, int cpu)
+static void init_cpu_workqueue(struct workqueue_struct *wq,
+ struct cpu_workqueue_struct *cwq)
{
- struct cpu_workqueue_struct *cwq = per_cpu_ptr(wq->cpu_wq, cpu);
-
cwq->wq = wq;
spin_lock_init(&cwq->lock);
INIT_LIST_HEAD(&cwq->worklist);
init_waitqueue_head(&cwq->more_work);
-
- return cwq;
}
static int create_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu)
@@ -816,7 +812,10 @@ struct workqueue_struct *__create_workqueue_key(const char *name,
if (!wq)
return NULL;
- wq->cpu_wq = alloc_percpu(struct cpu_workqueue_struct);
+ if (singlethread)
+ wq->cpu_wq = kmalloc(sizeof(*cwq), GFP_KERNEL);
+ else
+ wq->cpu_wq = alloc_percpu(struct cpu_workqueue_struct);
if (!wq->cpu_wq) {
kfree(wq);
return NULL;
@@ -830,7 +829,8 @@ struct workqueue_struct *__create_workqueue_key(const char *name,
INIT_LIST_HEAD(&wq->list);
if (singlethread) {
- cwq = init_cpu_workqueue(wq, singlethread_cpu);
+ cwq = wq->cpu_wq;
+ init_cpu_workqueue(wq, cwq);
err = create_workqueue_thread(cwq, singlethread_cpu);
start_workqueue_thread(cwq, -1);
} else {
@@ -851,7 +851,8 @@ struct workqueue_struct *__create_workqueue_key(const char *name,
* lock.
*/
for_each_possible_cpu(cpu) {
- cwq = init_cpu_workqueue(wq, cpu);
+ cwq = per_cpu_ptr(wq->cpu_wq, cpu);
+ init_cpu_workqueue(wq, cwq);
if (err || !cpu_online(cpu))
continue;
err = create_workqueue_thread(cwq, cpu);
@@ -906,6 +907,13 @@ void destroy_workqueue(struct workqueue_struct *wq)
const struct cpumask *cpu_map = wq_cpu_map(wq);
int cpu;
+ if (is_wq_single_threaded(wq)) {
+ cleanup_workqueue_thread(wq->cpu_wq);
+ kfree(wq->cpu_wq);
+ kfree(wq);
+ return;
+ }
+
cpu_maps_update_begin();
spin_lock(&workqueue_lock);
list_del(&wq->list);
next reply other threads:[~2009-01-21 9:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-21 9:42 Lai Jiangshan [this message]
2009-01-21 10:29 ` [PATCH] workqueue: don't alloc_percpu for single workqueue Frédéric Weisbecker
2009-01-21 10:48 ` Ingo Molnar
2009-01-22 1:05 ` Lai Jiangshan
2009-01-21 12:17 ` Oleg Nesterov
2009-01-22 3:42 ` Lai Jiangshan
2009-01-22 16:11 ` Oleg Nesterov
2009-02-16 2:39 ` Lai Jiangshan
2009-01-21 13:01 ` Eric Dumazet
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=4976EE0B.5090200@cn.fujitsu.com \
--to=laijs@cn.fujitsu.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=oleg@tv-sign.ru \
/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