mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	Lai Jiangshan <jiangshan.ljs@antgroup.com>,
	ying chen <yc1082463@gmail.com>
Subject: Re: [PATCH V2] workqueue: Process rescuer work items one-by-one using a positional marker
Date: Thu, 20 Nov 2025 16:13:59 -1000	[thread overview]
Message-ID: <aR_K58SDtwO-r54c@slm.duckdns.org> (raw)
In-Reply-To: <20251118093832.81920-1-jiangshanlai@gmail.com>

Hello, Lai.

On Tue, Nov 18, 2025 at 05:38:31PM +0800, Lai Jiangshan wrote:
> @@ -286,6 +286,7 @@ struct pool_workqueue {
>  	struct list_head	pending_node;	/* LN: node on wq_node_nr_active->pending_pwqs */
>  	struct list_head	pwqs_node;	/* WR: node on wq->pwqs */
>  	struct list_head	mayday_node;	/* MD: node on wq->maydays */
> +	struct work_struct	mayday_pos_work;/* L: position on pool->worklist */

Maybe mayday_cursor?

> @@ -1188,6 +1195,15 @@ static bool assign_work(struct work_struct *work, struct worker *worker,
>  
>  	lockdep_assert_held(&pool->lock);
>  
> +	/* The positional work should not be processed */
> +	if (unlikely(work->func == mayday_pos_func)) {
> +		/* only worker_thread() can possibly take this branch */
> +		if (WARN_ON_ONCE(nextp))
> +			*nextp = list_next_entry(work, entry);

I find it confusing to conditionalize the check on @nextp as the fact that
@nextp is only not NULL for worker_thread() is rather incidental. Maybe just
do this in the caller instead?

> +static bool assign_rescue_work(struct pool_workqueue *pwq, struct worker *rescuer)
> +{
> +	struct worker_pool *pool = pwq->pool;
> +	struct work_struct *work, *n;
> +
> +	/* from where to search */
> +	if (list_empty(&pwq->mayday_pos_work.entry))
> +		work = list_first_entry(&pool->worklist, struct work_struct, entry);

Should be fully winged - if () {} else {}. Also, I wonder whether the cursor
handling can be contained on this side. ie. Why does send_mayday() need to
check whether the cursor is on the list?

> +	else {
> +		work = list_next_entry(&pwq->mayday_pos_work, entry);
> +		/* It might be at a new position or not need position anymore */
> +		list_del_init(&pwq->mayday_pos_work.entry);
> +	}
> +
> +	/* need rescue? */
> +	if (!need_to_create_worker(pool))
> +		return false;
> +
> +	/* try to assign a work to rescue */
> +	list_for_each_entry_safe_from(work, n, &pool->worklist, entry) {
> +		if (get_work_pwq(work) == pwq && assign_work(work, rescuer, &n)) {
> +			pwq->stats[PWQ_STAT_RESCUED]++;
> +			/* mark the position for next search */
> +			list_add_tail(&pwq->mayday_pos_work.entry, &n->entry);
> +			return true;
> +		}
> +	}

Would splitting it into two patches make it easier to follow? ie. First
patch to factor out assign_rescuer_work(), the second one to implement
one-at-a-time operation.

>  /* sync @pwq with the current state of its associated wq and link it */
> @@ -6300,6 +6328,8 @@ static void show_pwq(struct pool_workqueue *pwq)
>  
>  	list_for_each_entry(work, &pool->worklist, entry) {
>  		if (get_work_pwq(work) == pwq) {
> +			if (work->func == mayday_pos_func)
> +				continue;

Do we need to skip these? These are debug dumps anyway. Can't we just show
them?

>  			has_pending = true;
>  			break;
>  		}
> @@ -6311,6 +6341,8 @@ static void show_pwq(struct pool_workqueue *pwq)
>  		list_for_each_entry(work, &pool->worklist, entry) {
>  			if (get_work_pwq(work) != pwq)
>  				continue;
> +			if (work->func == mayday_pos_func)
> +				continue;

Ditto.

Thanks.

-- 
tejun

  parent reply	other threads:[~2025-11-21  2:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-18  9:38 Lai Jiangshan
2025-11-18  9:39 ` Lai Jiangshan
2025-11-21  2:13 ` Tejun Heo [this message]
2025-11-21  3:18   ` Lai Jiangshan

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=aR_K58SDtwO-r54c@slm.duckdns.org \
    --to=tj@kernel.org \
    --cc=jiangshan.ljs@antgroup.com \
    --cc=jiangshanlai@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yc1082463@gmail.com \
    /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

all inboxes | Powered by JetHome®