From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 303D7146588 for ; Fri, 21 Nov 2025 02:14:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763691241; cv=none; b=GEEuTvJdbVqY7/47T9rLjS0t3WEXSIN6CSCXUNluJmIou4JbziX/Lu9M+KBE8sfK6LKSSjroJUNcmLJe6B+bjuPIX414Oj2RQsNDHkFAglUofPt1SfxMkPZhJx2elu5qbitO0utlol5xgAqTVh+XGJUHZZ8o3ACM338qfcmZQHs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763691241; c=relaxed/simple; bh=Xl1trV7/KeropOPds7HeWakCM2z+13kkxkE+hMLJWx8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PdVrsMo0fauw0/wKyoSJbgqpqhIDpITZHJb2Eg5aEAu2aNK970wqxF5jSRpy2auOVZaxSw0XnYPZo89QF/ly5TlMmB3pYNfjNG8RYyP1clEgwrw3P2VSyzLkODzaMUVFqLVm/+TZNCIdjY1x0Apa19yKljS5KFNhHl+RYoBYVqQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mvqIWnvr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mvqIWnvr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2E74C4CEF1; Fri, 21 Nov 2025 02:14:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763691240; bh=Xl1trV7/KeropOPds7HeWakCM2z+13kkxkE+hMLJWx8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mvqIWnvrd5iwTdtZpnHEkoS5wM1uoAu7gm6QAj2VUDYgs5sDIcgZD+5UERffVgwZY DFPNpTEtLmQbLpGlePYbcSKlLt5stfInaZi5a47tq7EWV4W7xzlPJqPCjrc8JtTomR bBaduukV9NdE1nC5TwibdAWQK+IuQiD6Ghnxmg0jC7hZwHWS5ws3hzrV0CzrXtabBV Q1pblI2bMR0aGfN+G3CV6LGhNdJCWW12xwYOtmEzzCbmeQNQ7Ks3dcH6OR+3JxE8h+ ajTOm4QVp3UxJ3mdDdXvGnbWFu4sBLRpJBlcOH/iVa9yMJzE3E/B94juEWjb+FP2k7 N9JerhuQ1sbhA== Date: Thu, 20 Nov 2025 16:13:59 -1000 From: Tejun Heo To: Lai Jiangshan Cc: linux-kernel@vger.kernel.org, Lai Jiangshan , ying chen Subject: Re: [PATCH V2] workqueue: Process rescuer work items one-by-one using a positional marker Message-ID: References: <20251118093832.81920-1-jiangshanlai@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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