Re: [PATCH 5/8] rcu: eliminate deadlock for rcu read site

2013-08-09 Thread Lai Jiangshan
On 08/09/2013 04:40 AM, Paul E. McKenney wrote: On Wed, Aug 07, 2013 at 06:25:01PM +0800, Lai Jiangshan wrote: Background) Although all articles declare that rcu read site is deadlock-immunity. It is not true for rcu-preempt, it will be deadlock if rcu read site overlaps with scheduler lock

Re: [PATCH 5/8] rcu: eliminate deadlock for rcu read site

2013-08-09 Thread Lai Jiangshan
: On Wed, Aug 07, 2013 at 06:25:01PM +0800, Lai Jiangshan wrote: Background) Although all articles declare that rcu read site is deadlock-immunity. It is not true for rcu-preempt, it will be deadlock if rcu read site overlaps with scheduler lock. ec433f0c, 10f39bb1 and 016a8d5b just partially solve

Re: [PATCH] drivers/net: Use RCU_INIT_POINTER(x, NULL) in tun.c

2014-03-24 Thread Lai Jiangshan
On 03/24/2014 01:25 PM, Eric Dumazet wrote: On Mon, 2014-03-24 at 07:09 +0200, Michael S. Tsirkin wrote: Seems an incredibly strict requirement for something that just silences a warning. What exactly should I test? I intended to just verify this produces same code as before

[PATCH] workqueue: add __WQ_FREEZING and remove POOL_FREEZING

2014-03-25 Thread Lai Jiangshan
when freezable(to simplify pwq_adjust_max_active()), make freeze_workqueues_begin() and thaw_workqueues() fast skip non-freezable wq. Changed from previous patches(requested by tj): 1) added the WARN_ON_ONCE() back 2) merged the two patches as one Signed-off-by: Lai Jiangshan la

[PATCH] workqueue: use manager lock only to protect worker_idr

2014-03-26 Thread Lai Jiangshan
worker_idr is always accessed in manager lock context currently. worker_idr is highly related to managers, it will be unlikely accessed in pool-lock only in future. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 34 ++ 1 files changed

Re: [PATCH] workqueue: use manager lock only to protect worker_idr

2014-03-27 Thread Lai Jiangshan
please omit this patch and wait for my new patchset. Thanks, Lai On 03/26/2014 10:41 PM, Lai Jiangshan wrote: worker_idr is always accessed in manager lock context currently. worker_idr is highly related to managers, it will be unlikely accessed in pool-lock only in future. Signed-off

Re: [PATCH] workqueue: add __WQ_FREEZING and remove POOL_FREEZING

2014-03-27 Thread Lai Jiangshan
On 03/25/2014 05:56 PM, Lai Jiangshan wrote: freezing is nothing related to pools, but POOL_FREEZING adds a connection, and causes freeze_workqueues_begin() and thaw_workqueues() complicated. Since freezing is workqueue instance attribute, so we introduce __WQ_FREEZING to wq-flags instead

[PATCH] workqueue: fix possible race condition when rescuer VS pwq-release

2014-03-27 Thread Lai Jiangshan
, and rescuer_thead will access to corrupted data. Using get_pwq() when send_mayday() will keep @pwq's lifetime and avoid the race condition. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c |7 +++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/kernel/workqueue.c

[PATCH V2] workqueue: fix possible race condition when rescuer VS pwq-release

2014-03-28 Thread Lai Jiangshan
From 11af0cd0306309f0deaf3326cc26d3e7e517e3d1 Mon Sep 17 00:00:00 2001 From: Lai Jiangshan la...@cn.fujitsu.com Date: Fri, 28 Mar 2014 00:20:12 +0800 Subject: [PATCH] workqueue: fix possible race condition when rescuer VS pwq-release There is a race condition between rescuer_thread

Re: [PATCH 01/10] workqueue: use manager lock only to protect worker_idr

2014-05-06 Thread Lai Jiangshan
On Mon, May 5, 2014 at 9:01 PM, Tejun Heo t...@kernel.org wrote: On Sun, Apr 27, 2014 at 12:08:56PM +0800, Lai Jiangshan wrote: worker_idr is highly bound to managers and is always/only accessed in manager lock context. So we don't need pool-lock for it. Signed-off-by: Lai Jiangshan la

Re: [PATCH 02/10] workqueue: destroy_worker() should destroy idle workers only

2014-05-06 Thread Lai Jiangshan
On Mon, May 5, 2014 at 9:13 PM, Tejun Heo t...@kernel.org wrote: Hello, On Sun, Apr 27, 2014 at 12:08:57PM +0800, Lai Jiangshan wrote: @@ -1692,9 +1691,8 @@ static struct worker *alloc_worker(void) * create_worker - create a new workqueue worker * @pool: pool the new worker will belong

Re: [PATCH 03/10] workqueue: async worker destruction

2014-05-06 Thread Lai Jiangshan
On Mon, May 5, 2014 at 11:02 PM, Tejun Heo t...@kernel.org wrote: On Sun, Apr 27, 2014 at 12:08:58PM +0800, Lai Jiangshan wrote: /** + * worker_unbind_pool() - unbind the worker from the pool + * @worker: worker which is bound to its pool + * + * Undo the pool-binding which had been done

Re: [PATCH 06/10] workqueue: convert worker_idr to worker_ida

2014-05-06 Thread Lai Jiangshan
On Mon, May 5, 2014 at 10:59 PM, Tejun Heo t...@kernel.org wrote: On Sun, Apr 27, 2014 at 12:09:01PM +0800, Lai Jiangshan wrote: @@ -2224,6 +2220,9 @@ woke_up: spin_unlock_irq(pool-lock); WARN_ON_ONCE(!list_empty(worker-entry)); worker-task-flags

[PATCH 04/10] workqueue: destroy worker directly in the idle timeout handler

2014-04-26 Thread Lai Jiangshan
POOL_MANAGE_WORKERS and maybe_destroy_worker() and simplify the manage_workers() After POOL_MANAGE_WORKERS is removed, worker_thread() doesn't need to test whether it needs to manage after processed works. So we can remove this test branch. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com

[PATCH 05/10] workqueue: separate iteration role from worker_idr

2014-04-26 Thread Lai Jiangshan
can't allocate id from worker_idr. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 38 -- kernel/workqueue_internal.h |1 + 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/kernel/workqueue.c b/kernel

[PATCH 08/10] workqueue: rename manager_mutex to bind_mutex

2014-04-26 Thread Lai Jiangshan
manager_mutex to bind_mutex without any functionality changed. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 47 +-- kernel/workqueue_internal.h |2 +- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git

[PATCH 09/10] workqueue: separate pool-binding code out from create_worker()

2014-04-26 Thread Lai Jiangshan
The code of pool-binding is unfolded in create_worker(). Separating this code out will make the codes more clear. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 53 --- 1 files changed, 33 insertions(+), 20 deletions

[PATCH 10/10] workqueue: use generic pool-bind/unbind routine for rescuers

2014-04-26 Thread Lai Jiangshan
with the pool across any cpuhotplugs. Using generic pool-bind/unbind routine will solve the above problems, and result much more simple code. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 74 +-- 1 files changed, 8

[PATCH 07/10] workqueue: narrow the protection range of manager_mutex

2014-04-26 Thread Lai Jiangshan
. In put_unbound_pool(), we also narrow the protection of manager_mutex due to destroy_worker() doesn't need manager_mutex. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 42 -- 1 files changed, 8 insertions(+), 34 deletions(-) diff --git a/kernel

[PATCH 03/10] workqueue: async worker destruction

2014-04-26 Thread Lai Jiangshan
worker_unbind_pool() Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 44 1 files changed, 28 insertions(+), 16 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 7690d0c..7ca564d 100644 --- a/kernel/workqueue.c

[PATCH 06/10] workqueue: convert worker_idr to worker_ida

2014-04-26 Thread Lai Jiangshan
We don't need to travell workers via worker_idr, worker_idr is used for allocating/freeing ID only, so we convert it to worker_ida. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 23 +++ 1 files changed, 11 insertions(+), 12 deletions(-) diff

[PATCH 00/10] workqueue: async worker destruction and pool-binding synchronization

2014-04-26 Thread Lai Jiangshan
: moves the pool-binding code out from create_worker() and use it for rescuer. Lai Jiangshan (10): workqueue: use manager lock only to protect worker_idr workqueue: destroy_worker() should destroy idle workers only workqueue: async worker destruction workqueue: destroy worker directly

[PATCH 02/10] workqueue: destroy_worker() should destroy idle workers only

2014-04-26 Thread Lai Jiangshan
, WORKER_STARTED is totally unneeded, so we remove WORKER_STARTED too. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 19 +-- 1 files changed, 9 insertions(+), 10 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 48a22e4..7690d0c

[PATCH 01/10] workqueue: use manager lock only to protect worker_idr

2014-04-26 Thread Lai Jiangshan
worker_idr is highly bound to managers and is always/only accessed in manager lock context. So we don't need pool-lock for it. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 34 ++ 1 files changed, 6 insertions(+), 28 deletions

[PATCH 0/8] idr: fix cleanup

2014-04-18 Thread Lai Jiangshan
Patch1 fix a bug caused by overflow. Patch2,3 add checks for unallocated_id. Patch4 changes to returned error code Patch5-8 cleanup. Lai Jiangshan (8): idr: fix overflow bug for the max-high layer idr: fix unexpected id-removal when idr_remove(unallocated_id) idr: fix NULL pointer

[PATCH 3/8] idr: fix NULL pointer dereference when ida_remove(unallocated_id)

2014-04-18 Thread Lai Jiangshan
. It is not a bug. But it is better to add the proper check and complains instead of crashing the kernel. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- lib/idr.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index a28036d..d200d67 100644 --- a/lib

[PATCH 4/8] idr: fix idr_replace()'s returned error code

2014-04-18 Thread Lai Jiangshan
: -ENOENT. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- lib/idr.c |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index d200d67..104f87f 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -814,10 +814,10 @@ void *idr_replace(struct idr *idp, void

[PATCH 8/8] idr: reduce the unneeded check in free_layer()

2014-04-18 Thread Lai Jiangshan
If idr-hint == p is true, it also implies idr-hint is true(not NULL). Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- lib/idr.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index 314ea5f..08d010c 100644 --- a/lib/idr.c +++ b/lib/idr.c

[PATCH 6/8] idr: avoid ping-pong

2014-04-18 Thread Lai Jiangshan
layer removal in ida_get_new*(). Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- lib/idr.c | 11 --- 1 files changed, 0 insertions(+), 11 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index e4f9965..be0b6ff 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -1001,17 +1001,6 @@ int

[PATCH 7/8] idr: don't need to shink the free list when idr_remove()

2014-04-18 Thread Lai Jiangshan
After idr subsystem is changed to RCU-awared, the free layer will not go to the free list. The free list will not be filled up when idr_remove(). So we don't need to shink it too. #ifndef TEST can't work for user space test now, just remove it. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com

[PATCH 5/8] idr: covert BUG_ON() to WARN_ON_ONCE() if the argument is invalid.

2014-04-18 Thread Lai Jiangshan
When the arguments passed by the caller are invalid, WARN_ON_ONCE() is proper than BUG_ON() which may crash the kernel. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- lib/idr.c |9 + 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index

[PATCH 2/8] idr: fix unexpected id-removal when idr_remove(unallocated_id)

2014-04-18 Thread Lai Jiangshan
unallocated_id, it is caller's fault. It is not a bug. But it is better to add the proper check and complains instead of removing an existed_id silently. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- lib/idr.c |5 + 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/lib/idr.c

[PATCH 1/8] idr: fix overflow bug for the max-high layer

2014-04-18 Thread Lai Jiangshan
. But the idr_get_empty_slot() will call it again with increased @id. So the bug is hided. CC: sta...@vger.kernel.org Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- lib/idr.c |8 +++- 1 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index 2642fa8..4df6792 100644

[PATCH 2/2 V4] workqueue: fix possible race condition when rescuer VS pwq-release

2014-04-18 Thread Lai Jiangshan
() will corrupt wq-maydays list, and rescuer_thead() will access to corrupted data. Using get_pwq() pin it until rescuer is done with it. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 13 + 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/kernel

[PATCH 1/2 V4] workqueue: rescuer_thread() processes all pwqs before exit

2014-04-18 Thread Lai Jiangshan
to free them all(workqueuepwqs) togerther, since the rescuer is stopped. No rescuer nor mayday-timer can access the mayday list. But it is nasty and error-prone in future development. Fix it. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 21 +++-- 1

Re: [PATCH 2/2] workqueue: fix a possible race condition between rescuer and pwq-release

2014-04-18 Thread Lai Jiangshan
and patch description. Moved put_pwq() to after the last @pwq-pool access. This isn't strictly necessarily for correctness but is cleaner as the pool is accessed through the pwq. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com Signed-off-by: Tejun Heo t...@kernel.org Cc: sta

Re: [PATCH 1/8] idr: fix overflow bug for the max-high layer

2014-04-18 Thread Lai Jiangshan
the same problem and may incorrectly fail with -EAGAIN; however, this bug doesn't affect correct operation because idr_get_empty_slot(), which already uses idr_max(), retries with the increased @id in such cases. CC: sta...@vger.kernel.org Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com

Re: [PATCH 6/8] idr: avoid ping-pong

2014-04-19 Thread Lai Jiangshan
On 04/19/2014 01:17 AM, Tejun Heo wrote: On Fri, Apr 18, 2014 at 08:49:53PM +0800, Lai Jiangshan wrote: The ida callers always calls ida_pre_get() before ida_get_new*(). ida_pre_get() will do layer allocation, and ida_get_new*() will do layer removal. It causes an unneeded ping-pong

[PATCH 0/9 V2] idr: fix cleanup

2014-04-19 Thread Lai Jiangshan
Patch1 fix a bug caused by overflow. Patch2,3 add checks for unallocated_id. Patch4 changes to returned error code Patch5-9 cleanup. Lai Jiangshan (9): idr: fix overflow bug during maximum ID calculation at maximum height idr: fix unexpected ID-removal when idr_remove(unallocated_id

[PATCH 2/9 V2] idr: fix unexpected ID-removal when idr_remove(unallocated_id)

2014-04-19 Thread Lai Jiangshan
the similar problem. It happens only when the caller tries to free an unallocated ID which is the caller's fault. It is not a bug. But it is better to add the proper check and complain rather than removing an existing_id silently. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com Acked-by: Tejun Heo t

[PATCH 9/9 V2] idr: remove useless C-PreProcessor branch

2014-04-19 Thread Lai Jiangshan
#ifndef TEST can't work for user space test now, just remove it. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- lib/idr.c |2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index e3c1da0..d77cdca 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -20,11

[PATCH 7/9 V2] idr: don't need to shink the free list when idr_remove()

2014-04-19 Thread Lai Jiangshan
After idr subsystem is changed to RCU-awared, the free layer will not go to the free list. The free list will not be filled up when idr_remove(). So we don't need to shink it too. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com Acked-by: Tejun Heo t...@kernel.org --- lib/idr.c | 16

[PATCH 8/9 V2] idr: reduce the unneeded check in free_layer()

2014-04-19 Thread Lai Jiangshan
If idr-hint == p is true, it also implies idr-hint is true(not NULL). Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com Acked-by: Tejun Heo t...@kernel.org --- lib/idr.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index 4a11c5d..e3c1da0 100644

[PATCH 5/9 V2] idr: covert BUG_ON() to WARN_ON_ONCE() if the argument is invalid.

2014-04-19 Thread Lai Jiangshan
as ida_alloc() does. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- lib/idr.c | 13 - 1 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index e79e051..317fd35 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -559,7 +559,7 @@ void idr_remove(struct

[PATCH 6/9 V2] idr: avoid ping-pong

2014-04-19 Thread Lai Jiangshan
Throw away extra resources one by one can't be achieved. This speculative layer removal in ida_get_new*() can't result expected optimization. So we remove the unneeded layer removal in ida_get_new*(). Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- lib/idr.c | 11 --- 1 files

[PATCH 4/9 V2] idr: fix idr_replace()'s returned error code

2014-04-19 Thread Lai Jiangshan
: -ENOENT. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com Acked-by: Tejun Heo t...@kernel.org --- lib/idr.c |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index 36ff732..e79e051 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -814,10 +814,10 @@ void

[PATCH 1/9 V2] idr: fix overflow bug during maximum ID calculation at maximum height

2014-04-19 Thread Lai Jiangshan
-off-by: Lai Jiangshan la...@cn.fujitsu.com Acked-by: Tejun Heo t...@kernel.org --- lib/idr.c |8 +++- 1 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index 2642fa8..4df6792 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -249,7 +249,7 @@ static int sub_alloc

[PATCH 3/9 V2] idr: fix NULL pointer dereference when ida_remove(unallocated_id)

2014-04-19 Thread Lai Jiangshan
); } It happens only when the caller tries to free an unallocated ID which is the caller's fault. It is not a bug. But it is better to add the proper check and complain rather than crashing the kernel. tj: Updated patch description. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com Acked-by: Tejun Heo t

Re: [PATCH 5/9 V2] idr: covert BUG_ON() to WARN_ON_ONCE() if the argument is invalid.

2014-04-19 Thread Lai Jiangshan
On Sat, Apr 19, 2014 at 9:07 PM, Tejun Heo t...@kernel.org wrote: On Sat, Apr 19, 2014 at 07:38:12PM +0800, Lai Jiangshan wrote: @@ -559,7 +559,7 @@ void idr_remove(struct idr *idp, int id) struct idr_layer *p; struct idr_layer *to_free; - if (id 0) + if (WARN_ON_ONCE

Re: [PATCH 6/8] idr: avoid ping-pong

2014-04-19 Thread Lai Jiangshan
On Sat, Apr 19, 2014 at 9:01 PM, Tejun Heo t...@kernel.org wrote: Hello, On Sat, Apr 19, 2014 at 06:43:41PM +0800, Lai Jiangshan wrote: On 04/19/2014 01:17 AM, Tejun Heo wrote: It only frees one layer. And the ida_pre_get() for the next ida_get_new*() will allocation it back again. The aim

Re: [PATCH 9/9 V2] idr: remove useless C-PreProcessor branch

2014-04-19 Thread Lai Jiangshan
On Sun, Apr 20, 2014 at 7:51 AM, Tejun Heo t...@kernel.org wrote: $SUBJ: idr: remove useless #ifndef TEST On Sat, Apr 19, 2014 at 07:38:16PM +0800, Lai Jiangshan wrote: #ifndef TEST can't work for user space test now, just remove it. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com Acked

Re: [PATCH 0/6] workqueue: simplerbetter workers management synchronization

2014-04-20 Thread Lai Jiangshan
On 04/12/2014 06:50 PM, Lai Jiangshan wrote: Sorry, the cover letter was forgotten to send to LKML. Hi, Tejun Any comments about the patchset. (general comments, high level comments) Thanks. Lai On 04/12/2014 06:45 PM, Lai Jiangshan wrote: Each patches remove codes! Patch12

[PATCH 2/2 V3] workqueue: simple refactor pwq_adjust_max_active()

2014-04-21 Thread Lai Jiangshan
. Reduce wake_up_worker() rate. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 21 +++-- 1 files changed, 11 insertions(+), 10 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index beca98b..59bad6e 100644 --- a/kernel/workqueue.c +++ b

[PATCH 1/2 V3] workqueue: substitute POOL_FREEZING with __WQ_FREEZING

2014-04-21 Thread Lai Jiangshan
. freeze_workqueues_begin()/thaw_workqueues() skip to handle non-freezable wqs and don't touch the non-freezable wqs' flags. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- include/linux/workqueue.h |1 + kernel/workqueue.c| 38 -- 2 files

Re: [PATCH 1/2 V3] workqueue: substitute POOL_FREEZING with __WQ_FREEZING

2014-04-21 Thread Lai Jiangshan
On 04/22/2014 06:20 AM, Tejun Heo wrote: On Mon, Apr 21, 2014 at 07:59:20PM +0800, Lai Jiangshan wrote: Only workqueues have freezable or freezing attribution/state, not worker pools. But POOL_FREEZING adds a suspicious state and makes reviewers confused. And it causes

[PATCH 0/7 V3] idr: fix cleanup

2014-04-22 Thread Lai Jiangshan
Patch1 fix a bug caused by overflow. Patch2,3 add checks for unallocated_id. Patch4 changes to returned error code Patch5-7 cleanup. All patches are acked by Tejun. Thanks Lai Lai Jiangshan (7): idr: fix overflow bug during maximum ID calculation at maximum height idr: fix unexpected ID

[PATCH 5/7 V3] idr: don't need to shink the free list when idr_remove()

2014-04-22 Thread Lai Jiangshan
After idr subsystem is changed to RCU-awared, the free layer will not go to the free list. The free list will not be filled up when idr_remove(). So we don't need to shink it too. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com Acked-by: Tejun Heo t...@kernel.org --- lib/idr.c | 16

[PATCH 4/7 V3] idr: fix idr_replace()'s returned error code

2014-04-22 Thread Lai Jiangshan
: -ENOENT. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com Acked-by: Tejun Heo t...@kernel.org --- lib/idr.c |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index 36ff732..e79e051 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -814,10 +814,10 @@ void

[PATCH 3/7 V3] idr: fix NULL pointer dereference when ida_remove(unallocated_id)

2014-04-22 Thread Lai Jiangshan
); } It happens only when the caller tries to free an unallocated ID which is the caller's fault. It is not a bug. But it is better to add the proper check and complain rather than crashing the kernel. tj: Updated patch description. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com Acked-by: Tejun Heo t

[PATCH 2/7 V3] idr: fix unexpected ID-removal when idr_remove(unallocated_id)

2014-04-22 Thread Lai Jiangshan
the similar problem. It happens only when the caller tries to free an unallocated ID which is the caller's fault. It is not a bug. But it is better to add the proper check and complain rather than removing an existing_id silently. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com Acked-by: Tejun Heo t

[PATCH 1/7 V3] idr: fix overflow bug during maximum ID calculation at maximum height

2014-04-22 Thread Lai Jiangshan
-off-by: Lai Jiangshan la...@cn.fujitsu.com Acked-by: Tejun Heo t...@kernel.org --- lib/idr.c |8 +++- 1 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index 2642fa8..4df6792 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -249,7 +249,7 @@ static int sub_alloc

[PATCH 7/7 V3] idr: remove useless #ifndef TEST

2014-04-22 Thread Lai Jiangshan
#ifndef TEST can't work for user space test now, just remove it. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com Acked-by: Tejun Heo t...@kernel.org --- lib/idr.c |2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index 39158ab..96bb252 100644

[PATCH 6/7 V3] idr: reduce the unneeded check in free_layer()

2014-04-22 Thread Lai Jiangshan
If idr-hint == p is true, it also implies idr-hint is true(not NULL). Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com Acked-by: Tejun Heo t...@kernel.org --- lib/idr.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index 9ed37a7..39158ab 100644

[PATCH 2/4] idr: reduce the number of MAX_IDR_FREE

2014-04-22 Thread Lai Jiangshan
), MAX_IDR_LEVEL) idr_layers is enough. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- lib/idr.c |9 +++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/idr.c b/lib/idr.c index 87c98fc..871991b 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -36,8 +36,13 @@ /* Leave

[PATCH 3/4] ida: in-place ida allocation

2014-04-22 Thread Lai Jiangshan
is not needed any more, we use unsigned long directly and remove all the code of alloc/free struct ida_bitmap. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- include/linux/idr.h | 15 + lib/idr.c | 85 +- 2 files changed

[PATCH 0/4] idr: idr cleanups

2014-04-22 Thread Lai Jiangshan
patch1 is the new version of previous pathset.(it is dropped by previous patchset, this one is new) patch2/3 save a lot memory Lai Jiangshan (4): idr: proper invalid argument handling idr: reduce the number of MAX_IDR_FREE ida: in-place ida allocation idr: reorder the fields

[PATCH 4/4] idr: reorder the fields

2014-04-22 Thread Lai Jiangshan
in near future. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- include/linux/idr.h | 13 - 1 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/linux/idr.h b/include/linux/idr.h index 3a77b33..c537c55 100644 --- a/include/linux/idr.h +++ b/include/linux/idr.h

[PATCH 1/4] idr: proper invalid argument handling

2014-04-22 Thread Lai Jiangshan
returns -ENOSPC when start == end, but it returns -EINVAL when max start while old code returns -ENOSPC. -EINVAL is proper here, the caller must passed wrong arguments. ida_simple_get()'s argument-checks are changed as the same as idr_alloc(). Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- lib

Re: [PATCH 1/2 V3] workqueue: substitute POOL_FREEZING with __WQ_FREEZING

2014-04-22 Thread Lai Jiangshan
On 04/23/2014 04:46 AM, Tejun Heo wrote: Hello, On Tue, Apr 22, 2014 at 09:47:47AM +0800, Lai Jiangshan wrote: Testing workqueue_freezing requires wq_pool_mutex held. Although almost-all pwq_adjust_max_active() are called with wq_pool_mutex held, except workqueue_set_max_active(). But I

Re: [PATCH 3/4] ida: in-place ida allocation

2014-04-22 Thread Lai Jiangshan
On 04/23/2014 04:02 AM, Tejun Heo wrote: On Tue, Apr 22, 2014 at 06:16:20PM +0800, Lai Jiangshan wrote: There are two stages of ida allocation/free, idr_layers and ida_bitmap. They add unneeded foot print and memory waste. When a single ID is first allocated from an ida, this ida requires

Re: [PATCH 2/4] idr: reduce the number of MAX_IDR_FREE

2014-04-22 Thread Lai Jiangshan
On 04/23/2014 03:58 AM, Tejun Heo wrote: On Tue, Apr 22, 2014 at 06:16:19PM +0800, Lai Jiangshan wrote: +/* + * Number of idr_layer structs to leave in free list. + * When idr is not empty, we need atmost (MAX_IDR_LEVEL - 1) idr_layers + * to build up and atmost (MAX_IDR_LEVEL - 1) idr_layers

Re: [PATCH] workqueue: allow changing attributions of ordered workqueue

2014-04-22 Thread Lai Jiangshan
On 04/23/2014 08:04 AM, Frederic Weisbecker wrote: Hi Lai, So actually I'll need to use apply_workqueue_attr() on the next patchset. So I'm considering this patch. Some comments below: On Tue, Apr 15, 2014 at 05:58:08PM +0800, Lai Jiangshan wrote: From

Re: [PATCH V3] workqueue: fix double unlock bug

2014-04-14 Thread Lai Jiangshan
Hi, Tejun Acked-by: Lai Jiangshan la...@cn.fujitsu.com CC: sta...@kernel.org Thanks, Lai On 04/15/2014 07:17 AM, Daeseok Youn wrote: Use default pwq when alloc_unbound_pwq() is failed. And remove if condition for whether pwq is same as wq-dfl_pwq when wq_calc_node_cpumask() returns false

[PATCH] workqueue: allow changing attributions of ordered workqueue

2014-04-15 Thread Lai Jiangshan
From 534f1df8a5a03427b0fc382150fbd34e05648a28 Mon Sep 17 00:00:00 2001 From: Lai Jiangshan la...@cn.fujitsu.com Date: Tue, 15 Apr 2014 17:52:19 +0800 Subject: [PATCH] workqueue: allow changing attributions of ordered workqueue Allow changing ordered workqueue's cpumask Allow changing ordered

Re: [PATCH] workqueue: allow changing attributions of ordered workqueue

2014-04-15 Thread Lai Jiangshan
So IUUC this is to allow registering ordered workqueue as WQ_SYSFS? But I think Making ordered workqueue's attributions changeable was listed in my TODO list. I found it may help for you, so I prioritized it. Never mind, I will push my patch separated if you don't need it. we are going to

Re: [PATCH V2] workqueue: fix possible race condition when rescuer VS pwq-release

2014-04-15 Thread Lai Jiangshan
On 04/16/2014 12:47 AM, Tejun Heo wrote: On Fri, Mar 28, 2014 at 08:07:58PM +0800, Lai Jiangshan wrote: +static inline void get_unbound_pwq(struct pool_workqueue *pwq) +{ +if (pwq-wq-flags WQ_UNBOUND) +get_pwq(pwq); +} + /** * put_pwq - put a pool_workqueue reference

Re: [PATCH V2] workqueue: fix possible race condition when rescuer VS pwq-release

2014-04-16 Thread Lai Jiangshan
On Wed, Apr 16, 2014 at 11:23 PM, Tejun Heo t...@kernel.org wrote: Hello, Lai. On Wed, Apr 16, 2014 at 09:25:16AM +0800, Lai Jiangshan wrote: 1) Our aim is to protect unbound pwq, not percpu pwq which can't be be protected by get_pwq(). 2) get_pwq() will make reviewers confused/surprised

Re: [PATCH 1/2] workqueue: fix bugs in wq_update_unbound_numa() failure path

2014-04-16 Thread Lai Jiangshan
Acked. On Wed, Apr 16, 2014 at 1:32 PM, Daeseok Youn daeseok.y...@gmail.com wrote: wq_update_unbound_numa() failure path has the following two bugs. - alloc_unbound_pwq() is called without holding wq-mutex; however, if the allocation fails, it jumps to out_unlock which tries to unlock

Re: [PATCH V2] workqueue: fix possible race condition when rescuer VS pwq-release

2014-04-16 Thread Lai Jiangshan
On 04/17/2014 12:50 AM, Tejun Heo wrote: Hello, Lai. On Thu, Apr 17, 2014 at 12:21:21AM +0800, Lai Jiangshan wrote: OK. It is better to use get_pwq(). I will also change the above comments to: The base ref and the possible ref from rerscuer(stopped) are never dropped on per-cpu pwqs

[PATCH 1/2] workqueue: rescuer_thread() processes all pwqs before exit

2014-04-16 Thread Lai Jiangshan
to free them all(workqueuepwqs) togerther, since the rescuer is stopped. No rescuer nor mayday-timer can access the mayday list. But it is nasty and error-prone in future develop. Fix it. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 12 ++-- 1 files changed

[PATCH 2/2] workqueue: fix possible race condition when rescuer VS pwq-release

2014-04-16 Thread Lai Jiangshan
() will corrupt wq-maydays list, and rescuer_thead() will access to corrupted data. Using get_pwq() pin it until rescuer is done with it. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 13 + 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/kernel

Re: [PATCH] workqueue: add __WQ_FREEZING and remove POOL_FREEZING

2014-04-16 Thread Lai Jiangshan
On 04/17/2014 03:51 AM, Tejun Heo wrote: Hello, On Tue, Mar 25, 2014 at 05:56:04PM +0800, Lai Jiangshan wrote: freezing is nothing related to pools, but POOL_FREEZING adds a connection, and causes freeze_workqueues_begin() and thaw_workqueues() complicated. Since freezing is workqueue

Re: [PATCH 1/2] workqueue: rescuer_thread() processes all pwqs before exit

2014-04-17 Thread Lai Jiangshan
On Thu, Apr 17, 2014 at 11:27 PM, Tejun Heo t...@kernel.org wrote: Hello, On Thu, Apr 17, 2014 at 07:34:08AM +0800, Lai Jiangshan wrote: Before the rescuer is picked to running, the works of the @pwq may be processed by some other workers, and destroy_workqueue() may called at the same time

Re: [PATCH 1/2] workqueue: rescuer_thread() processes all pwqs before exit

2014-04-17 Thread Lai Jiangshan
On Fri, Apr 18, 2014 at 12:08 AM, Tejun Heo t...@kernel.org wrote: Hello, Lai. On Fri, Apr 18, 2014 at 12:04:29AM +0800, Lai Jiangshan wrote: I don't think this is reliable. What if mayday requests take place between wq_mayday_lock and kthread_should_stop() check? We'll probably need

[PATCH 6/6] workqueue: destroy worker directly in idle timeout handler

2014-04-12 Thread Lai Jiangshan
Since destroy_worker() is working atomically, we move maybe_destroy_worker() out from manager and destroy worker directly in idle timeout handler. And we remove %POOL_MANAGE_WORKERS which help us remove a branch in worker_thread(). Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel

[PATCH 1/6] workqueue: generic routine to restore percpu/unbound pools' workers' cpumask

2014-04-12 Thread Lai Jiangshan
to disable_workers_concurrency(). Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 46 +++--- 1 files changed, 15 insertions(+), 31 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index d845bdd..0b56730 100644

[PATCH 4/6] workqueue: commit worker to pool's concurrency setting atomically.

2014-04-12 Thread Lai Jiangshan
worker_idr, we need to add a ida back we do not save any thing. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 15 +++ 1 files changed, 3 insertions(+), 12 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 6c38aed..3a6be02 100644

[PATCH 5/6] workqueue: remove manager_mutex

2014-04-12 Thread Lai Jiangshan
be called at the some time. so create_and_start_worker() don't need manager_mutex too. All other routines don't need manager_mutex. so manager_workers() don't need manager_mutex too. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 73

[PATCH 2/6] workqueue: generic framework to manage normalrescuer workers' cpumask

2014-04-12 Thread Lai Jiangshan
restore_workers_cpumask() also restore rescuers' cpumask via bind_list. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 129 +++ kernel/workqueue_internal.h |1 + 2 files changed, 57 insertions(+), 73 deletions

[PATCH 3/6] workqueue: make destroy_worker() atomically

2014-04-12 Thread Lai Jiangshan
destroy_worker() faster, but: 1) allow destroy_worker() to be called in timeout handler in future patch. 2) reduce possible latency for create_worker()/cpu-hotplug. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 32 +--- 1 files changed

Re: [PATCH 0/6] workqueue: simplerbetter workers management synchronization

2014-04-12 Thread Lai Jiangshan
Sorry, the cover letter was forgotten to send to LKML. On 04/12/2014 06:45 PM, Lai Jiangshan wrote: Each patches remove codes! Patch12 are the basic patches. They add a *united* mechanism for managing percpu pools' workers' unbound pools' workers' rescuers' CPUMASK. Patch14 make workers

Re: [PATCH] workqueue: fix double unlock bug

2014-04-14 Thread Lai Jiangshan
On 04/14/2014 08:58 AM, Daeseok Youn wrote: mutex_unlock() and put_pwq_unlocked() do not need to be called when alloc_unbound_pwq() is failed. Signed-off-by: Daeseok Youn daeseok.y...@gmail.com --- kernel/workqueue.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff

Re: [PATCH V2] workqueue: fix possible race condition when rescuer VS pwq-release

2014-04-14 Thread Lai Jiangshan
On 04/01/2014 04:06 AM, Tejun Heo wrote: On Mon, Mar 31, 2014 at 10:40:47PM +0800, Lai Jiangshan wrote: Ping Lai, I'll keep the mail tagged but can you pleaes ping me once -rc1 drops? While it is an actual bug, given that it'd be pretty difficult to trigger, I don't think it's too urgent

Re: [PATCH V2] workqueue: fix double unlock bug

2014-04-14 Thread Lai Jiangshan
On Mon, Apr 14, 2014 at 6:41 PM, Daeseok Youn daeseok.y...@gmail.com wrote: mutex_unlock() and put_pwq_unlocked() do not need to be called when alloc_unbound_pwq() is failed. And remove if condition for whether pwq is same as wq-dfl_pwq when wq_calc_node_cpumask() returns false and just use

Re: [PATCH 4/4] workqueue: Include ordered workqueues in anon workqueue sysfs interface

2014-03-31 Thread Lai Jiangshan
On 03/28/2014 01:21 AM, Frederic Weisbecker wrote: Changing the cpu affinity of workqueues through the sysfs interface is done with apply_workqueue_attrs() by replacing the old pwqs of a workqueue with new ones tied to worker pools that are affine to the new cpumask. We can't do that with

Re: [PATCH 4/4] workqueue: Include ordered workqueues in anon workqueue sysfs interface

2014-03-31 Thread Lai Jiangshan
On 03/31/2014 08:50 PM, Lai Jiangshan wrote: On 03/28/2014 01:21 AM, Frederic Weisbecker wrote: Changing the cpu affinity of workqueues through the sysfs interface is done with apply_workqueue_attrs() by replacing the old pwqs of a workqueue with new ones tied to worker pools that are affine

Re: [PATCH V2] workqueue: fix possible race condition when rescuer VS pwq-release

2014-03-31 Thread Lai Jiangshan
Ping On 03/28/2014 08:07 PM, Lai Jiangshan wrote: From 11af0cd0306309f0deaf3326cc26d3e7e517e3d1 Mon Sep 17 00:00:00 2001 From: Lai Jiangshan la...@cn.fujitsu.com Date: Fri, 28 Mar 2014 00:20:12 +0800 Subject: [PATCH] workqueue: fix possible race condition when rescuer VS pwq-release

[PATCH 1/3] workqueue: remove the first check and the return value of maybe_create_worker()

2014-07-10 Thread Lai Jiangshan
the return value of it and adjust the call-site. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 18 +- 1 files changed, 5 insertions(+), 13 deletions(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index f344334..92f7ea0c 100644 --- a/kernel

[PATCH 3/3] workqueue: unfold start_worker() into create_worker()

2014-07-10 Thread Lai Jiangshan
worker is started. The overhead is acceptible since the manager is slow path. Signed-off-by: Lai Jiangshan la...@cn.fujitsu.com --- kernel/workqueue.c | 68 ++-- 1 files changed, 13 insertions(+), 55 deletions(-) diff --git a/kernel/workqueue.c b

[PATCH 0/3] workqueue: manager cleanup

2014-07-10 Thread Lai Jiangshan
Hi, TJ These are the cleanups for which you asked during the prevous development, especailly the patch3 merging start_worker() into create_worker(). Thanks, Lai Lai Jiangshan (3): workqueue: remove the first check and the return value of maybe_create_worker() workqueue: remove

<    2   3   4   5   6   7   8   9   10   11   >