[sheepdog] [PATCH 4/4] work: make pending lock fine grain
Liu Yuan
namei.unix at gmail.com
Tue Oct 22 09:36:47 CEST 2013
On Tue, Oct 22, 2013 at 04:13:13PM +0900, Hitoshi Mitake wrote:
> Current queue_work() locks worker_info->pending_lock before growing a
> number of worker threads (if it is required). Clearly this behavior
> harms performance. This patch makes the lock fine grain.
>
> Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
> ---
> lib/work.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/lib/work.c b/lib/work.c
> index 57b38dd..d27aee1 100644
> --- a/lib/work.c
> +++ b/lib/work.c
> @@ -232,12 +232,11 @@ void queue_work(struct work_queue *q, struct work *work)
> struct worker_info *wi = container_of(q, struct worker_info, q);
>
> uatomic_inc(&wi->nr_queued_work);
> - pthread_mutex_lock(&wi->pending_lock);
> -
> if (wq_need_grow(wi))
> /* double the thread pool size */
> create_worker_threads(wi, wi->nr_threads * 2);
>
> + pthread_mutex_lock(&wi->pending_lock);
> list_add_tail(&work->w_list, &wi->q.pending_list);
> pthread_mutex_unlock(&wi->pending_lock);
>
This is wrong because we need pending_lock to protect nr_threads.
Thanks
Yuan
More information about the sheepdog
mailing list