[sheepdog] [PATCH] work queue: introduce dynamic roof to max nr threads

MORITA Kazutaka morita.kazutaka at gmail.com
Mon Mar 4 16:40:34 CET 2013


> +static inline uint64_t wq_get_roof(int tc)
>  {
> -	wi->tm_end_of_protection = get_msec_time() + WQ_PROTECTION_PERIOD;
> +	struct vnode_info *vinfo = get_vnode_info();
> +	int nr_nodes = vinfo->nr_nodes;
> +	uint64_t nr = 0;
> +
> +	put_vnode_info(vinfo);
> +	switch (tc) {
> +	case WQ_DYNAMIC:
> +		/* Only allow at most 2 * nr_nodes threads */
> +		nr = nr_nodes;
> +		break;
> +	case WQ_UNLIMITED:
> +		nr = SIZE_MAX;
> +		break;
> +	default:
> +		panic("Invalid threads control %d", tc);
> +	}

How about returning 1 in case of WQ_ORDERED?  Then we can remove
switch/case in wq_need_grow.

> +	return nr;
> +}
>  
> -	return wi->nr_threads < wi->nr_pending + wi->nr_running &&
> -		wi->nr_threads < wi->max_threads;
> +static bool wq_need_grow(struct worker_info *wi)
> +{
> +	bool ret = false;
> +
> +	switch (wi->tc) {
> +	case WQ_ORDERED:
> +		break;
> +	case WQ_DYNAMIC:
> +	case WQ_UNLIMITED:
> +		wi->tm_end_of_protection = get_msec_time() +
> +			WQ_PROTECTION_PERIOD;
> +
> +		ret = wi->nr_threads < wi->nr_pending + wi->nr_running &&
> +			wi->nr_threads <= wq_get_roof(wi->tc);

Should be wi->nr_threads < wq_get_roof(wi->tc)?  Otherwise,
wi->nr_threads can exceed the return value of wq_get_roof.

Thanks,

Kazutaka



More information about the sheepdog mailing list