mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: Tejun Heo <tj@kernel.org>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>, linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] workqueue: free worker earlier in worker_thread()
Date: Tue, 18 Feb 2014 00:24:01 +0800	[thread overview]
Message-ID: <1392654243-2829-2-git-send-email-laijs@cn.fujitsu.com> (raw)
In-Reply-To: <1392654243-2829-1-git-send-email-laijs@cn.fujitsu.com>

When @worker is set %WORKER_DIE, it is moved out from
idle_list&idr, no one can access it excepct kthread_data().

And in worker_thread, its task is clearred %PF_WQ_WORKER,
no one can access the @worker via kthread_data(),
we can safely free it.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
 kernel/workqueue.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 783d5f2..fc05700 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1862,7 +1862,6 @@ static void destroy_worker(struct worker *worker)
 
 	kthread_stop(worker->task);
 	put_task_struct(worker->task);
-	kfree(worker);
 
 	spin_lock_irq(&pool->lock);
 }
@@ -2297,6 +2296,8 @@ woke_up:
 		spin_unlock_irq(&pool->lock);
 		WARN_ON_ONCE(!list_empty(&worker->entry));
 		worker->task->flags &= ~PF_WQ_WORKER;
+		/* No one can access to @worker now, free it. */
+		kfree(worker);
 		return 0;
 	}
 
-- 
1.7.7.6


  parent reply	other threads:[~2014-02-17 18:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-15 14:02 [PATCH] workqueue: ensure @task is valid across kthread_stop() Lai Jiangshan
     [not found] ` <1392654243-2829-1-git-send-email-laijs@cn.fujitsu.com>
2014-02-17 16:24   ` Lai Jiangshan [this message]
2014-02-17 16:24   ` [PATCH 2/3] workqueue: async worker destruction Lai Jiangshan
2014-02-18 22:29     ` Tejun Heo
2014-02-17 16:24   ` [PATCH 3/3] workqueue: kick worker to die directly in idle timeout handler Lai Jiangshan
2014-02-18 22:31     ` Tejun Heo
2014-02-18  1:39   ` [PATCH 0/3] workqueue: async worker destruction Lai Jiangshan
2014-02-18 21:37 ` [PATCH wq/for-3.14-fixes] workqueue: ensure @task is valid across kthread_stop() Tejun Heo
2014-02-19  3:39   ` Lai Jiangshan
2014-02-20  0:13     ` Tejun Heo

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=1392654243-2829-2-git-send-email-laijs@cn.fujitsu.com \
    --to=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    /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

Powered by JetHome