From patchwork Mon Jan 16 16:48:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13103512 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 6CB97C46467 for ; Mon, 16 Jan 2023 17:10:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234329AbjAPRKR (ORCPT ); Mon, 16 Jan 2023 12:10:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234300AbjAPRJb (ORCPT ); Mon, 16 Jan 2023 12:09:31 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A7782CFD8 for ; Mon, 16 Jan 2023 08:50:02 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id h16so28049536wrz.12 for ; Mon, 16 Jan 2023 08:50:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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; bh=1T3jBXVzgA/G4SO0KjENeLs4stjTxYEUqvYDC5sW2Hk=; b=eY0W7g0S78Uz9jv7mRveVrmKSGy2GX1iN6ABYxdAuEl9m7+UIYGB6aQQ4Vc+hG9t0S bpa7uSKzpthBaeWIibnhY84KO/Pm3s0045Y7aAkZ1WrOd13bGCMU2LstVRSd9CDazXdk tH6k1AE7Vov/dcMs1AaRq8KWkw4+BBp8hgJAqEx7eMbusjW0NOhW8DD6+cvYqOZEExBq hIkXdy6HVG9Zpc/SZV/sURN4r/dN6FqSbc5zYvlG862q2EBSoHM5QPqnptJQNp+7Uqmx LEfw3FSlhJwHNeBHeYM2ghKuFK2vz7YfbSun3loPKfO9shYExncmFvzAnWr8euuF6X8S h8ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1T3jBXVzgA/G4SO0KjENeLs4stjTxYEUqvYDC5sW2Hk=; b=GziCNk4IbrO1oacA4OLvkQBxtWgfsoAVQeakcjoSdhbZ5ixNCfMKWqwjlprCY0/qBh DqpJDCguYZd4ZuxjpKt3nLIlFHckK1SlcRJqWCAtfJGLP+xDRp3HC3FblSvt1r92uJrt kUi6NKyEsciXa4618lFT1OvUQO+hHDOygdoL8AcD2Pf0ClfEEdQAwHH/DF6RHQRupEhJ c4Ux5RINbWei8i7V/TWqiyth2bQkXpt3gMAburrB+xwb39h80HEc3q5+wiDxElwTvHOh xdcrAmjqUnSAVL7XQ2mAig7gci9TaHxJO4vLRdskA2VB6GfBn3YF1wE/R0EnrWfWi7lR g0Jw== X-Gm-Message-State: AFqh2kpputBxMNQ6GL9NAtVL9s7hRYo6pa+bAFY0QGH/n3a2EH4ExlN1 qtxS6cVp5P4CSukHriYb/+PR6SWSI4Y= X-Google-Smtp-Source: AMrXdXt6xute1sGHKSufEBJ4M7G78ZLEvceOYsVc2gTjouudBlLthMpxI417xi7hcbWrrgQZ2OC9dg== X-Received: by 2002:a05:6000:71d:b0:2bb:f4bf:e758 with SMTP id bs29-20020a056000071d00b002bbf4bfe758mr137731wrb.48.1673887800404; Mon, 16 Jan 2023 08:50:00 -0800 (PST) Received: from 127.0.0.1localhost (92.41.33.8.threembb.co.uk. [92.41.33.8]) by smtp.gmail.com with ESMTPSA id o7-20020a5d62c7000000b002bbeda3809csm20872372wrv.11.2023.01.16.08.49.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 08:50:00 -0800 (PST) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH for-next 1/5] io_uring: return back links tw run optimisation Date: Mon, 16 Jan 2023 16:48:57 +0000 Message-Id: <6328acdbb5e60efc762b18003382de077e6e1367.1673887636.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org io_submit_flush_completions() may queue new requests for tw execution, especially true for linked requests. Recheck the tw list for emptiness after flushing completions. Signed-off-by: Pavel Begunkov --- io_uring/io_uring.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 718f56baecbd..5570422dc2fb 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -1344,8 +1344,11 @@ static int __io_run_local_work(struct io_ring_ctx *ctx, bool *locked) if (!llist_empty(&ctx->work_llist)) goto again; - if (*locked) + if (*locked) { io_submit_flush_completions(ctx); + if (!llist_empty(&ctx->work_llist)) + goto again; + } trace_io_uring_local_work_run(ctx, ret, loops); return ret; } From patchwork Mon Jan 16 16:48:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13103510 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 C7AF3C677F1 for ; Mon, 16 Jan 2023 17:10:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231465AbjAPRKO (ORCPT ); Mon, 16 Jan 2023 12:10:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234261AbjAPRJb (ORCPT ); Mon, 16 Jan 2023 12:09:31 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C607C30B11 for ; Mon, 16 Jan 2023 08:50:02 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id n7so1990535wrx.5 for ; Mon, 16 Jan 2023 08:50:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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; bh=mFfuY2FIYBGT3MQ4l0bmPjzvtk+g3u3hZ3J6Nx17mmM=; b=fWjCS6PiknUy8oedOnmk3DMiZzXxq7my0qw4+Jeb+NemqBK7Kok39qajOcIZSYrMnc WmWaDPzgPr6bGJ+crAXMc+1O/VG/HmwNqNe/a1BLkPqXUVlfSg6+LU653SRMPekFMQGK LzlRg/7rHgoQsSLNS2VRQxREVsEeyTv9EzG2UyAWJRbsH8LqZvpKe64+hzkDAFa1eDJM PeHqVmzK9Q5torOLAOKgslOdTC+EEcImI99eWgM8CuYp1CMDWiMVqzY6myYJyHxAsktC DMyQOEirJlsfG/fxanTzS8MVWrPFolcPDRgFGeiYBbcQvvagOpP0MdXO1rluSICpdGPV Igtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mFfuY2FIYBGT3MQ4l0bmPjzvtk+g3u3hZ3J6Nx17mmM=; b=p6oMLAZupeeBzmqlb7CmRg9/tBlAJdyr9YEpVQUaOKkPFa87q2WSExGmZ83vXiFSNs iYcnl1FzX5E23vSqKqYD4SC5JhhYIdvpZWWV+iUc6vLxEtTwotCG4/h7QhX8O6rNt4mq cdm5Pw30pt6/jg4XZIo7j/9prMuZkkasLRMGVVGDLGBRAbeHHCiWN4xtfjKl8VYhdvwN dTo+ZVR/WcgT00gkrYhMJXAlmR/7qItcqLYcNYlRtK9Hlazoetx8RQWQbnbCiv3QFbV1 9Ek08d/bk61XF8a1gMeZA6/1lToFBmBiD5cpRWrz7+nISbmeaOsvb+AWxnXYlg4HSWCF vN9Q== X-Gm-Message-State: AFqh2kqFAfZ9F0Jd9Kiu9cixdSunFR+VOixT34wTtJo7HLitVXpjVr+p mxQeUT4TninbIcxR6FcmQC4YrgOXPZo= X-Google-Smtp-Source: AMrXdXvNFYEQ3MgTKt17fYr+OjrWS2fJ0hi/d/6EI+4NKf2GxspQ1+0vJnaMDa/a3bLt5AFD62pqyg== X-Received: by 2002:a5d:4e90:0:b0:2be:127a:6cec with SMTP id e16-20020a5d4e90000000b002be127a6cecmr117624wru.49.1673887801214; Mon, 16 Jan 2023 08:50:01 -0800 (PST) Received: from 127.0.0.1localhost (92.41.33.8.threembb.co.uk. [92.41.33.8]) by smtp.gmail.com with ESMTPSA id o7-20020a5d62c7000000b002bbeda3809csm20872372wrv.11.2023.01.16.08.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 08:50:00 -0800 (PST) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH for-next 2/5] io_uring: don't export io_put_task() Date: Mon, 16 Jan 2023 16:48:58 +0000 Message-Id: <43c7f9227e2ab215f1a6069dadbc5382bed346fe.1673887636.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org io_put_task() is only used in uring.c so enclose it there together with __io_put_task(). Signed-off-by: Pavel Begunkov --- io_uring/io_uring.c | 11 ++++++++++- io_uring/io_uring.h | 10 ---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 5570422dc2fb..1b72ff558c17 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -715,7 +715,7 @@ static void io_cqring_overflow_flush(struct io_ring_ctx *ctx) io_cqring_do_overflow_flush(ctx); } -void __io_put_task(struct task_struct *task, int nr) +static void __io_put_task(struct task_struct *task, int nr) { struct io_uring_task *tctx = task->io_uring; @@ -725,6 +725,15 @@ void __io_put_task(struct task_struct *task, int nr) put_task_struct_many(task, nr); } +/* must to be called somewhat shortly after putting a request */ +static inline void io_put_task(struct task_struct *task, int nr) +{ + if (likely(task == current)) + task->io_uring->cached_refs += nr; + else + __io_put_task(task, nr); +} + void io_task_refs_refill(struct io_uring_task *tctx) { unsigned int refill = -tctx->cached_refs + IO_TCTX_REFS_CACHE_NR; diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h index 5113e0ddb01d..c68edf9872a5 100644 --- a/io_uring/io_uring.h +++ b/io_uring/io_uring.h @@ -70,7 +70,6 @@ void io_wq_submit_work(struct io_wq_work *work); void io_free_req(struct io_kiocb *req); void io_queue_next(struct io_kiocb *req); -void __io_put_task(struct task_struct *task, int nr); void io_task_refs_refill(struct io_uring_task *tctx); bool __io_alloc_req_refill(struct io_ring_ctx *ctx); @@ -319,15 +318,6 @@ static inline void io_commit_cqring_flush(struct io_ring_ctx *ctx) __io_commit_cqring_flush(ctx); } -/* must to be called somewhat shortly after putting a request */ -static inline void io_put_task(struct task_struct *task, int nr) -{ - if (likely(task == current)) - task->io_uring->cached_refs += nr; - else - __io_put_task(task, nr); -} - static inline void io_get_task_refs(int nr) { struct io_uring_task *tctx = current->io_uring; From patchwork Mon Jan 16 16:48:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13103508 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 3C9BBC46467 for ; Mon, 16 Jan 2023 17:10:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234331AbjAPRKM (ORCPT ); Mon, 16 Jan 2023 12:10:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231509AbjAPRJf (ORCPT ); Mon, 16 Jan 2023 12:09:35 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCFED2B616 for ; Mon, 16 Jan 2023 08:50:03 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id h16so28049618wrz.12 for ; Mon, 16 Jan 2023 08:50:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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; bh=JfTXyyDOzpnifxCVJ2//GAjGuuwxv4CrpOLwdQ7dbaA=; b=betWjj1Mm9ThBWoYMUdyrhKJi/aTg4f/O653IuPazocza6Q3SjNLyZcFPC7KpK1aBs jaxo2HGbxAqlO0beXGS2AHvKT/5xJoz9WoQzRrwvnRSdjAemgivrpygqyaBA1oFrbMjc kzDyEOGzQXTIubVrQdALelQ5/EOOUvkf9INbJK6YR12Leao1BcfN+Hau+DDubvvfsWY4 sfAT2sl9DRaRKc8FsYN7bJUVjs2J80xluRnJJeB8JVlqE95VMQlQwiS+GPmWYuQ2imcF 6bvO6kswJM+sOU0uQQbeNX9+JB3F9/8hTY1HmVCxAr2V0bQ7sGzeDf0whp11JUr7wWUA p0cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JfTXyyDOzpnifxCVJ2//GAjGuuwxv4CrpOLwdQ7dbaA=; b=RGaRFBJALC3+HSAR2D/LOGOcwyfjLnvqOE8Mcn0RCrOVsz6nC8AwkOCZ34zosIuVv5 QHo1aROYaTd/ux5cnIbkAMoaDAqdFOk8H+4MCIYwewl23hBTq4Vnf9b6G/bELl86L2Vr gwcZeDEj61fz1FP5M506YmO9wD8blK7fUNEcBnqmyu7JCkLvoYZ5IFKwY3AZAuK/7z6c V9IRqmoc4/D2L74TLLV35Nb76Bzj4vmkem2cRP+CprAeuvOnNGXSLmr6llajRQxBJFTd w7ZVT3THQwFancH/J+wvUoxWNZMX4YowqQmiDSFbs4Tt3mUNqpzsDGCVbaJkW+VEE/7u aJyw== X-Gm-Message-State: AFqh2krBbiPEjRv49y/6lBj8gS+oC4eUBc7ZZM/20JXD8Zzr/+q2jfo7 +kyXP75ZFE6lO3it02yI0Au01bEXLOw= X-Google-Smtp-Source: AMrXdXtbzgs3ylxCOCO5XgU55VdRDlDPbL3t9hFw6ZfGPmwl80Gs8alWy4Hnmjpnemj4gH20V0aBGQ== X-Received: by 2002:a5d:5259:0:b0:2bb:6c90:26a0 with SMTP id k25-20020a5d5259000000b002bb6c9026a0mr150224wrc.43.1673887802050; Mon, 16 Jan 2023 08:50:02 -0800 (PST) Received: from 127.0.0.1localhost (92.41.33.8.threembb.co.uk. [92.41.33.8]) by smtp.gmail.com with ESMTPSA id o7-20020a5d62c7000000b002bbeda3809csm20872372wrv.11.2023.01.16.08.50.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 08:50:01 -0800 (PST) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH for-next 3/5] io_uring: simplify fallback execution Date: Mon, 16 Jan 2023 16:48:59 +0000 Message-Id: <56170e6a0cbfc8edee2794c6613e8f6f1d76d276.1673887636.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Lock the ring with uring_lock in io_fallback_req_func(), which should make it a bit safer and easier. With that we also don't need refs pinning as io_ring_exit_work() will wait until uring_lock is freed. Signed-off-by: Pavel Begunkov --- io_uring/io_uring.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 1b72ff558c17..e690c884dc95 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -245,17 +245,15 @@ static __cold void io_fallback_req_func(struct work_struct *work) fallback_work.work); struct llist_node *node = llist_del_all(&ctx->fallback_llist); struct io_kiocb *req, *tmp; - bool locked = false; + bool locked = true; - percpu_ref_get(&ctx->refs); + mutex_lock(&ctx->uring_lock); llist_for_each_entry_safe(req, tmp, node, io_task_work.node) req->io_task_work.func(req, &locked); - - if (locked) { - io_submit_flush_completions(ctx); - mutex_unlock(&ctx->uring_lock); - } - percpu_ref_put(&ctx->refs); + if (WARN_ON_ONCE(!locked)) + return; + io_submit_flush_completions(ctx); + mutex_unlock(&ctx->uring_lock); } static int io_alloc_hash_table(struct io_hash_table *table, unsigned bits) From patchwork Mon Jan 16 16:49:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13103511 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 65A17C678D8 for ; Mon, 16 Jan 2023 17:10:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234273AbjAPRKP (ORCPT ); Mon, 16 Jan 2023 12:10:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234313AbjAPRJf (ORCPT ); Mon, 16 Jan 2023 12:09:35 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5997D2885B for ; Mon, 16 Jan 2023 08:50:04 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id q10so8741668wrs.2 for ; Mon, 16 Jan 2023 08:50:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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; bh=Hfmfq9bEE+y3Nlnna5Y2xYfaeIGiWD0pI3kCVAp4pI4=; b=QnRqGPzz9UVYY9OhHQl7JuCporK4n3hn/i/AYzvcgK0lnRvI3cBGTib031h0zqp+WR Re+R80dxnaNtcPOH0xDUY8o+QIjSZRm5HVntSLKYOGQZiYWxg92O98D+px+jg8rKIMAc De4CxmireQUtTbEMQjOGUEPkllCWkJwVUJ+U9mVyH81eVTzdCYu57TSKf0yN9qaF6FJz hvvYgihrIi6P11OHZzr5qu6RBDSMkrLINg8XEPpE0PgzymJVL5T+dQHOdV3IVJvCJygj gsa1LooThqePE316e1EfTT64B/K9p1cm0qzRYfhmxEoDdflm1MIk2BV+uQefKpTV9bVv j20g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Hfmfq9bEE+y3Nlnna5Y2xYfaeIGiWD0pI3kCVAp4pI4=; b=P6YIipMIZnqaaqp6vMzgRseYmcIyq71Mt21H+p8bgcFrhzEIfKWf9+12O3AnrVFYj/ +wE/OSSIs/Izjs2g4xcnL/ZC40xHtu4swzxa8izoa9TbPltCRVYMK8SPDxJXLy8EGRcG c/hYXSFLTf0+X1RC1AWa+apvw2zE14sVHcvNwXPMl25ifRXBlRLukwjkPtZSQcW1vK+X nlipeWFuByHXE6cS80PL35kr8lTzn4wDjWkKZuTfHu2mdXdBl8DUqhGjX/ewkIEhI3Al IHnhENhKE6vAGQz4tafWW3QpZim46opFvdNb8+/NvCJjSRt/1rraXsu536YxGg820RYA /Blw== X-Gm-Message-State: AFqh2kp48R+/TKoAQn1Z3Ex43ycUNWP8ukWBdENfkoKoOdoPlNO48nFy tXAj1n+ZUq6tYGKS4YqUx8hPpQrlF/0= X-Google-Smtp-Source: AMrXdXvQ6a81R4CmDvgWqgSlLNq4tHGcYxv20pWCbr/b4m0EU8t0zdDQvMW+0v2yH3IPdlEtL3RxyA== X-Received: by 2002:adf:b608:0:b0:2bd:d76f:23eb with SMTP id f8-20020adfb608000000b002bdd76f23ebmr7921203wre.29.1673887802782; Mon, 16 Jan 2023 08:50:02 -0800 (PST) Received: from 127.0.0.1localhost (92.41.33.8.threembb.co.uk. [92.41.33.8]) by smtp.gmail.com with ESMTPSA id o7-20020a5d62c7000000b002bbeda3809csm20872372wrv.11.2023.01.16.08.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 08:50:02 -0800 (PST) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH for-next 4/5] io_uring: optimise ctx flags layout Date: Mon, 16 Jan 2023 16:49:00 +0000 Message-Id: X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org There may be different cost for reeading just one byte or more, so it's benificial to keep ctx flag bits that we access together in a single byte. That affected code generation of __io_cq_unlock_post_flush() and removed one memory load. Signed-off-by: Pavel Begunkov --- include/linux/io_uring_types.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h index cc0cf0705b8f..0efe4d784358 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -196,17 +196,17 @@ struct io_ring_ctx { /* const or read-mostly hot data */ struct { unsigned int flags; - unsigned int compat: 1; unsigned int drain_next: 1; unsigned int restricted: 1; unsigned int off_timeout_used: 1; unsigned int drain_active: 1; - unsigned int drain_disabled: 1; unsigned int has_evfd: 1; - unsigned int syscall_iopoll: 1; /* all CQEs should be posted only by the submitter task */ unsigned int task_complete: 1; + unsigned int syscall_iopoll: 1; unsigned int poll_activated: 1; + unsigned int drain_disabled: 1; + unsigned int compat: 1; enum task_work_notify_mode notify_method; struct io_rings *rings; From patchwork Mon Jan 16 16:49:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 13103509 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 AB78CC678D4 for ; Mon, 16 Jan 2023 17:10:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231509AbjAPRKN (ORCPT ); Mon, 16 Jan 2023 12:10:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231465AbjAPRJf (ORCPT ); Mon, 16 Jan 2023 12:09:35 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0887B30E96 for ; Mon, 16 Jan 2023 08:50:04 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id r9so5270834wrw.4 for ; Mon, 16 Jan 2023 08:50:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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; bh=wOFxYl+IwkJPDCs4oErn8zIhjGgRCEYtnumZCpr7igY=; b=bY6qNLI69LbTWYsZhHeanhA92zBRD34Nl1jzUKwgKZXDfdQtlfmtP2HHYEqBLXhkcP 4FFSIV71eEW6MQ8NXwMYIKvwVGMK/0zbWc0jf/d7WsSTwU4+HzqK1gWa5ugnMRxF8Md7 Shf1pjuea4jFHBcu69d/pg/PQXalfr2RBvYdrqEX6vela0DQCxblPcBjEI5fPHKWpxpP b2VKWfO3jSGKB9OwQJrxN9kCJYbotmC6g7GU7qT+6Cp7YnjaXqZv71/4J9PqrOUOpN+O KYCsj5x+rNPbMmi+2QQOLAvR3uMO23hwrMZc+SPHyfVhAk+UWcbMGiP5CDjKzIQ6wC8T Vq+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wOFxYl+IwkJPDCs4oErn8zIhjGgRCEYtnumZCpr7igY=; b=eY1GHERimTkFWstFIYIv13PhQzSnNLVSYsAqlZ/fZszF/KSvs/CpgCSMNkKOZOoiz+ h98/TQISYw+uudUTLWFzPDw7WU7VNQP4U2wXTbc8aZbkAQGUXAV0qmPN8wPGRNJq/NOR eIjOfnwvNeqFUwrvOU3FNTSEnnC3Bcq077npyjgcHgej9RCvyWd9lIJjEiJ7d+LJOxsh SnUJIn7dh4cfiK8WPThG5RcS+GGHzo6uo2GElRa7jpGomg6f+OL/A7BO0OA8Kyq8qYw0 286hP/SFeo0x9aTXTwnTXV0TE9mhe/VvCN2WFu2bjoLG8/LHJ3b5pyhJq9HjphS+hAWy /mbA== X-Gm-Message-State: AFqh2kqPpDn0OBIA8kOtIxT1AO7UG2upWGkpzIdIvBoBLzxGKBTd3bCk xIGiFvIzrUdtcaaAGNQA9FWFyI0Bdmo= X-Google-Smtp-Source: AMrXdXuXfnSAbqYz+aKut/5kN9SDDxjx0KMSEAUstOFeKVNj4uKuTwydhxjjFib/34XkUmZGjDd+Sg== X-Received: by 2002:a5d:6a87:0:b0:2b8:fe58:d368 with SMTP id s7-20020a5d6a87000000b002b8fe58d368mr150425wru.29.1673887803498; Mon, 16 Jan 2023 08:50:03 -0800 (PST) Received: from 127.0.0.1localhost (92.41.33.8.threembb.co.uk. [92.41.33.8]) by smtp.gmail.com with ESMTPSA id o7-20020a5d62c7000000b002bbeda3809csm20872372wrv.11.2023.01.16.08.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 08:50:03 -0800 (PST) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH for-next 5/5] io_uring: refactor __io_req_complete_post Date: Mon, 16 Jan 2023 16:49:01 +0000 Message-Id: <2b4fbb42f404a0e75c4d9f0a5b16f314a839d0a9.1673887636.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Keep parts of __io_req_complete_post() relying on req->flags together so the value can be cached. Signed-off-by: Pavel Begunkov --- io_uring/io_uring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index e690c884dc95..27d9abd24a83 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -974,14 +974,14 @@ static void __io_req_complete_post(struct io_kiocb *req) req->link = NULL; } } + io_put_kbuf_comp(req); + io_dismantle_req(req); io_req_put_rsrc(req); /* * Selected buffer deallocation in io_clean_op() assumes that * we don't hold ->completion_lock. Clean them here to avoid * deadlocks. */ - io_put_kbuf_comp(req); - io_dismantle_req(req); io_put_task(req->task, 1); wq_list_add_head(&req->comp_list, &ctx->locked_free_list); ctx->locked_free_nr++;