From patchwork Fri Jun 9 12:20:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Xu X-Patchwork-Id: 13273810 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74449C7EE25 for ; Fri, 9 Jun 2023 12:20:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238387AbjFIMUt (ORCPT ); Fri, 9 Jun 2023 08:20:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229903AbjFIMUs (ORCPT ); Fri, 9 Jun 2023 08:20:48 -0400 Received: from out-34.mta0.migadu.com (out-34.mta0.migadu.com [91.218.175.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79630E50 for ; Fri, 9 Jun 2023 05:20:46 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1686313244; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lhlblQ2RrpBpwre9osp84qt/3/ewTJ5oMF21HYvR9Hs=; b=PG7m+3mk7k9WkLMmkTo5aVGlW2dDZtz1au1E4n90cZ/jY+iuFotB5lWXFXf0RIwyR5BoqF 4DycA43tlUQUlhry9QTVnLXvdQzo78x3bR6xW5tWi5evcEHfxky1XIYVZWmhVPErXZx+2n tvkWyRPmXla7Ndju6kl4J3+Eu3eSbbA= From: Hao Xu To: io-uring@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Wanpeng Li , linux-fsdevel@vger.kernel.org Subject: [PATCH 02/11] io-wq: add a new worker flag to indicate worker exit Date: Fri, 9 Jun 2023 20:20:22 +0800 Message-Id: <20230609122031.183730-3-hao.xu@linux.dev> In-Reply-To: <20230609122031.183730-1-hao.xu@linux.dev> References: <20230609122031.183730-1-hao.xu@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Hao Xu Add a new worker flag IO_WORKER_F_EXIT to indicate a worker is going to exit. This is important for fixed workers. Signed-off-by: Hao Xu --- io_uring/io-wq.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c index b70eebec2845..1717f1465613 100644 --- a/io_uring/io-wq.c +++ b/io_uring/io-wq.c @@ -29,6 +29,7 @@ enum { IO_WORKER_F_RUNNING = 2, /* account as running */ IO_WORKER_F_FREE = 4, /* worker on free list */ IO_WORKER_F_BOUND = 8, /* is doing bounded work */ + IO_WORKER_F_EXIT = 16, /* worker is exiting */ }; enum { @@ -592,6 +593,11 @@ static void io_worker_handle_work(struct io_worker *worker) } while (1); } +static bool is_worker_exiting(struct io_worker *worker) +{ + return worker->flags & IO_WORKER_F_EXIT; +} + static int io_wq_worker(void *data) { struct io_worker *worker = data; @@ -609,7 +615,7 @@ static int io_wq_worker(void *data) long ret; set_current_state(TASK_INTERRUPTIBLE); - while (io_acct_run_queue(acct)) + while (!is_worker_exiting(worker) && io_acct_run_queue(acct)) io_worker_handle_work(worker); raw_spin_lock(&wq->lock); @@ -628,6 +634,12 @@ static int io_wq_worker(void *data) raw_spin_unlock(&wq->lock); if (io_run_task_work()) continue; + if (is_worker_exiting(worker)) { + raw_spin_lock(&wq->lock); + acct->nr_workers--; + raw_spin_unlock(&wq->lock); + break; + } ret = schedule_timeout(WORKER_IDLE_TIMEOUT); if (signal_pending(current)) { struct ksignal ksig;