From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6BA9489877 for ; Fri, 11 Sep 2026 15:42:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789141327; cv=none; b=W0MN6Ocsfr57xFKjY/ToS/jX0XUwwkVFaBd+xReAP5n6L8wZpDgAT1UrKeyAU5j2P+xVQrvLPFts1O7dJjm3A/22d3mRrKV2A+3NZERu6iGmdatEkF7IXkcJ0akRpVnl+Zmoq8Oodr/Mm3nq8ogZLGQiWZjndbVphAN4eb2DHGs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789141327; c=relaxed/simple; bh=0NwaKUmf44Ot+C4Vhin0K2ohE4gDm+QbMEeRlNNgATA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eUUlLjQzz46oicempmRyBoVMzeMo8iAXPWj4BM1AEKjbgE0pQJcVHS7bYgTkp3IbxCuMtgpyKqkZgZGHO4z5R9Tq9R+KUZlvM1NPsM54IFN/uyjaQWFUgtz56QnLDvGQmoAi6ITQ/ww6wiwhn0zhugVb6ImCbJdVSijdPxnKRLM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20251104.gappssmtp.com header.i=@kernel-dk.20251104.gappssmtp.com header.b=g3tLiZG9; arc=none smtp.client-ip=209.85.210.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20251104.gappssmtp.com header.i=@kernel-dk.20251104.gappssmtp.com header.b="g3tLiZG9" Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-8049e44d0c3so560464a34.3 for ; Fri, 11 Sep 2026 08:42:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20251104.gappssmtp.com; s=20251104; t=1789141324; x=1789746124; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=26NN2voef8YBl9mHMwb0pP++w/F7eMXxYYY8spi7/jc=; b=g3tLiZG9SIvwMgDaxYDCMXEg0m2r3sJqQ575QFWcccwf/+OP9S1ZkyTTDcBZ/GEeqc 22T1hHUq7pVox3RSQf8p+jzX+ypj7E+ZgbYIlpQ/UvWonFGKC6qN6ydshnJTBrwK/DQ4 IZcytgIsQHRVwafwNR7ULW8gKzl2NdfXAXjW5oFFaNWWUBenUu+2+Di/uEIQUhYtBJdH AsIACc1hFpYvv3bBqGhVuPl/jW+T86XefpKVdlgM01if0B3YcLaiIPzTCZTjhORT6aCW Tbs3BqGhwkfvp6iIeVdghIRzK670dVENUyFY0gfdmQq8X5a7cUcNLX1zHbonW1n69zrQ FORQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789141324; x=1789746124; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=26NN2voef8YBl9mHMwb0pP++w/F7eMXxYYY8spi7/jc=; b=Z9weFb1DjSiLgiUNpnH57bSgRCcCSS3WEP0fc7Z5KKa7R+en1MHFBNNGQamGZWOgKd PtmgnnSoaRRkV1HnKVZV4UaTGQsuJp+moI2mt6DsKp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05:6820:2903:b0:6ba:3635:7ffd with SMTP id 006d021491bc7-6c0bde5bcd5mr3300243eaf.64.1789141323624; Fri, 11 Sep 2026 08:42:03 -0700 (PDT) Received: from m2max ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-6c09690af1dsm2802199eaf.1.2026.09.11.08.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 08:42:02 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, tglx@kernel.org, mingo@redhat.com, peterz@infradead.org, Jens Axboe Subject: [PATCH 06/15] io_uring: keep the tctx nodes on a list Date: Fri, 11 Sep 2026 09:40:56 -0600 Message-ID: <20260911154148.644489-7-axboe@kernel.dk> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260911154148.644489-1-axboe@kernel.dk> References: <20260911154148.644489-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit tctx->xa is indexed by the ring pointer, which makes it a deep and sparse xarray. Iterating it with xa_for_each() is expensive, 12 usec for a single entry in testing. Keep the nodes on a list as well and walk that instead, lookups by ring stay in the xarray. Signed-off-by: Jens Axboe --- include/linux/io_uring_types.h | 2 ++ io_uring/tctx.c | 10 ++++++---- io_uring/tctx.h | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index 39629ee77b91..4af3d579ead6 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -153,6 +153,8 @@ struct io_uring_task { struct file *registered_rings[IO_RINGFD_REG_MAX]; struct xarray xa; + /* the nodes in ->xa, for walking without the xarray lookup cost */ + struct list_head node_list; struct wait_queue_head wait; atomic_t in_cancel; atomic_t inflight_tracked; diff --git a/io_uring/tctx.c b/io_uring/tctx.c index 466b7300e208..737dfad4a976 100644 --- a/io_uring/tctx.c +++ b/io_uring/tctx.c @@ -105,6 +105,7 @@ __cold struct io_uring_task *io_uring_alloc_task_context(struct task_struct *tas tctx->task = task; xa_init(&tctx->xa); + INIT_LIST_HEAD(&tctx->node_list); init_waitqueue_head(&tctx->wait); atomic_set(&tctx->in_cancel, 0); atomic_set(&tctx->inflight_tracked, 0); @@ -135,6 +136,7 @@ static int io_tctx_install_node(struct io_ring_ctx *ctx, kfree(node); return ret; } + list_add(&node->tctx_link, &tctx->node_list); mutex_lock(&ctx->tctx_lock); list_add(&node->ctx_node, &ctx->tctx_list); @@ -227,6 +229,7 @@ __cold void io_uring_del_tctx_node(unsigned long index) WARN_ON_ONCE(current != node->task); WARN_ON_ONCE(list_empty(&node->ctx_node)); + list_del(&node->tctx_link); mutex_lock(&node->ctx->tctx_lock); list_del(&node->ctx_node); @@ -243,11 +246,10 @@ __cold void io_uring_del_tctx_node(unsigned long index) __cold void io_uring_clean_tctx(struct io_uring_task *tctx) { struct io_wq *wq = tctx->io_wq; - struct io_tctx_node *node; - unsigned long index; + struct io_tctx_node *node, *tmp; - xa_for_each(&tctx->xa, index, node) { - io_uring_del_tctx_node(index); + list_for_each_entry_safe(node, tmp, &tctx->node_list, tctx_link) { + io_uring_del_tctx_node((unsigned long)node->ctx); cond_resched(); } if (wq) { diff --git a/io_uring/tctx.h b/io_uring/tctx.h index 76ad1ad4594e..9a139816ce4f 100644 --- a/io_uring/tctx.h +++ b/io_uring/tctx.h @@ -2,6 +2,8 @@ struct io_tctx_node { struct list_head ctx_node; + /* on tctx->node_list, only ever touched by the owning task */ + struct list_head tctx_link; struct task_struct *task; struct io_ring_ctx *ctx; }; -- 2.55.0