From nobody Mon Jun 29 18:40:32 2026 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 853D9C433FE for ; Thu, 3 Feb 2022 18:24:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353471AbiBCSYt (ORCPT ); Thu, 3 Feb 2022 13:24:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353446AbiBCSYq (ORCPT ); Thu, 3 Feb 2022 13:24:46 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 438ECC061714 for ; Thu, 3 Feb 2022 10:24:46 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id m14so6646665wrg.12 for ; Thu, 03 Feb 2022 10:24:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m/kvsV2Fw6mBqvpDjxp3WYmDCchAjKBAAZ5SIZ3OfkM=; b=66N4tAnImIxy+NlELi2dsVP1q3BoPC3FBsRayVINw1iV1gn3jyQb/nnEeBx8tYerW1 qfo/nhQCtq0YiimNVcNgBTNmacq2XaGjneq1FGX9x1dd3i7KdFTNzl5bbk+YymP8OWhH +6LvXt39ZCF0ciyN04sZtY8FFCmJpArQrkGsLNHvQwRgvjeugUrxqnFJjvTozitgFvbf UQEWK8pmQT4DYn5pgUsknZE9KKx2uHG4hpyWoek1n/9xHfo4xXbWN2id99moPZCsEria qAjZ9cRmRcQapkQdYKmQgAjEGN6xxNOPkruyKAx4iN6otFHJi7wzXEAYgGf9QLrMxxDJ 3RUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m/kvsV2Fw6mBqvpDjxp3WYmDCchAjKBAAZ5SIZ3OfkM=; b=jiBfMO1dFofB7zbNqrrvtAmC8EtO+T85TGgcMfbX0D6l9xy6fBxupR4y/vyCZuP/1b l1tCz4M9ycTg98nsNOsBpcTtv5fEhpF606wLAI6NSXXPWRbTnJAaVG6VadqYpEGcTCUW vf2dtaJVJCmTlczJSculzvd+jK5MRIx3LL4cEqeGy8Wk0Uf65tQbBBOQnLY8uVXdPQKn FJr7RoIMXouF6QMBTdh0okhHhmxXT1UhlDJWPozFS/E5VK2wELdkSOGmPbOjMx/O6XNE s57fAVrkI06pr4lrWQ0K8anc+0sIbGPxfcSQ+NJE47iUWtZz/ii5139cOU42ku/mwzHF 9ehw== X-Gm-Message-State: AOAM533giWw/wZ5iGxpXhjS7jjbvBppMqaWGh4zBXxy2pBl3YfiiQqHq /9S0F8YVuCRbD/k/E30Xb2K8Rw== X-Google-Smtp-Source: ABdhPJxz13ks1JrRWqeu3h079pyf4S696ocGGUkjgRzLTsXit0psjiM2uwnCICw2aFzxwjT4mD0pew== X-Received: by 2002:adf:e408:: with SMTP id g8mr20681027wrm.288.1643912684895; Thu, 03 Feb 2022 10:24:44 -0800 (PST) Received: from usaari01.cust.communityfibre.co.uk ([2a02:6b6d:f804:0:28c2:5854:c832:e580]) by smtp.gmail.com with ESMTPSA id h18sm3540056wro.9.2022.02.03.10.24.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 10:24:44 -0800 (PST) From: Usama Arif To: io-uring@vger.kernel.org, axboe@kernel.dk, asml.silence@gmail.com, linux-kernel@vger.kernel.org Cc: fam.zheng@bytedance.com, Usama Arif Subject: [PATCH v4 1/3] io_uring: remove trace for eventfd Date: Thu, 3 Feb 2022 18:24:39 +0000 Message-Id: <20220203182441.692354-2-usama.arif@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220203182441.692354-1-usama.arif@bytedance.com> References: <20220203182441.692354-1-usama.arif@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The information on whether eventfd is registered is not very useful and would result in the tracepoint being enclosed in an rcu_readlock in a later patch that tries to avoid ring quiesce for registering eventfd. Suggested-by: Jens Axboe Signed-off-by: Usama Arif --- fs/io_uring.c | 3 +-- include/trace/events/io_uring.h | 13 +++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 2e04f718319d..21531609a9c6 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -11171,8 +11171,7 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd= , unsigned int, opcode, mutex_lock(&ctx->uring_lock); ret =3D __io_uring_register(ctx, opcode, arg, nr_args); mutex_unlock(&ctx->uring_lock); - trace_io_uring_register(ctx, opcode, ctx->nr_user_files, ctx->nr_user_buf= s, - ctx->cq_ev_fd !=3D NULL, ret); + trace_io_uring_register(ctx, opcode, ctx->nr_user_files, ctx->nr_user_buf= s, ret); out_fput: fdput(f); return ret; diff --git a/include/trace/events/io_uring.h b/include/trace/events/io_urin= g.h index 7346f0164cf4..098beda7601a 100644 --- a/include/trace/events/io_uring.h +++ b/include/trace/events/io_uring.h @@ -57,10 +57,9 @@ TRACE_EVENT(io_uring_create, * @opcode: describes which operation to perform * @nr_user_files: number of registered files * @nr_user_bufs: number of registered buffers - * @cq_ev_fd: whether eventfs registered or not * @ret: return code * - * Allows to trace fixed files/buffers/eventfds, that could be registered = to + * Allows to trace fixed files/buffers, that could be registered to * avoid an overhead of getting references to them for every operation. Th= is * event, together with io_uring_file_get, can provide a full picture of h= ow * much overhead one can reduce via fixing. @@ -68,16 +67,15 @@ TRACE_EVENT(io_uring_create, TRACE_EVENT(io_uring_register, =20 TP_PROTO(void *ctx, unsigned opcode, unsigned nr_files, - unsigned nr_bufs, bool eventfd, long ret), + unsigned nr_bufs, long ret), =20 - TP_ARGS(ctx, opcode, nr_files, nr_bufs, eventfd, ret), + TP_ARGS(ctx, opcode, nr_files, nr_bufs, ret), =20 TP_STRUCT__entry ( __field( void *, ctx ) __field( unsigned, opcode ) __field( unsigned, nr_files ) __field( unsigned, nr_bufs ) - __field( bool, eventfd ) __field( long, ret ) ), =20 @@ -86,14 +84,13 @@ TRACE_EVENT(io_uring_register, __entry->opcode =3D opcode; __entry->nr_files =3D nr_files; __entry->nr_bufs =3D nr_bufs; - __entry->eventfd =3D eventfd; __entry->ret =3D ret; ), =20 TP_printk("ring %p, opcode %d, nr_user_files %d, nr_user_bufs %d, " - "eventfd %d, ret %ld", + "ret %ld", __entry->ctx, __entry->opcode, __entry->nr_files, - __entry->nr_bufs, __entry->eventfd, __entry->ret) + __entry->nr_bufs, __entry->ret) ); =20 /** --=20 2.25.1 From nobody Mon Jun 29 18:40:32 2026 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 08291C433EF for ; Thu, 3 Feb 2022 18:24:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239876AbiBCSYy (ORCPT ); Thu, 3 Feb 2022 13:24:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353453AbiBCSYs (ORCPT ); Thu, 3 Feb 2022 13:24:48 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A874C061714 for ; Thu, 3 Feb 2022 10:24:47 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id k18so6673606wrg.11 for ; Thu, 03 Feb 2022 10:24:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EVCTgqaqhd6XkJVbAQ3XRZlsjlSz2NkMW74pu+sTtmI=; b=7aExreDuZWnTRLTccRIxQ+K2jnuPv8F74gCaaRZFyGE26nVLIlAKi0V5AvS0SUFPXP JOpT/y7dROZZyiVCW4Y8dXS98V7lxyXnLybwaYPf9AUjV99k/XUTR8QrawqpAei5alCj QY81EBEn+6nZXjS3L1lzWND0FHtQU0DbWQSisS2g6jOu2vVA/xw9dw93Lq1K6Z4m8hok RneQnKa8NAkYW5F6x/RflLj2w48/vlu2ZGclt9p8gN9KIQF1WR6kuml97++DVGhWBK6X cdA1pGveuwWMt3ZQL/8aM/aRUhV8pY0EqKNDEiNNzAoeEi/qLOcpRzectDkudI9ELue9 ov5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EVCTgqaqhd6XkJVbAQ3XRZlsjlSz2NkMW74pu+sTtmI=; b=1KNQb4Nq9Cig3xH/MjGFuyQL5nH63PVos1udC59q0EqnRPiRDlR0v2fgtgdK2WDSP+ OGur9fVyqL9Ra3cwLEMFxny1wt0oSOojWKtxiZndohF9jKn7BKkRwXMzbXAd/Ok00Vlq iCAISl7Bw4gtuKTUt+428SdaZBBgAxySCV7VoAejvu287GXmQtjr1CjkcZs+Rr/4o6Zk lypx0ZL+NFXUtxmdPnBGBtdyspwf8hSF8y4gGAkTAe2wYLq7bzRh4Ipv2pLDw5N90sgq I4yUGfb2chXO7Y36pB+GdxSBtkkHFUsn3G4nwOaMjRYdt+plOBFUvxlleHmluSeC7Gb/ gyNw== X-Gm-Message-State: AOAM53362YxRX14P7//HS17kk2cOri+qUe/XzrVFAuxmeOZWczinISWk xQqKKHQrii99alrV20VDQ3mz43K4aG2Q4g== X-Google-Smtp-Source: ABdhPJxNNNsUUM8RU6RUIThJph+QWGplVAKpvVGdpDi+Y45SThdk0Kq/9G24tXHWyr1xePOHWKYy2A== X-Received: by 2002:adf:ffd2:: with SMTP id x18mr29643939wrs.672.1643912685972; Thu, 03 Feb 2022 10:24:45 -0800 (PST) Received: from usaari01.cust.communityfibre.co.uk ([2a02:6b6d:f804:0:28c2:5854:c832:e580]) by smtp.gmail.com with ESMTPSA id h18sm3540056wro.9.2022.02.03.10.24.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 10:24:45 -0800 (PST) From: Usama Arif To: io-uring@vger.kernel.org, axboe@kernel.dk, asml.silence@gmail.com, linux-kernel@vger.kernel.org Cc: fam.zheng@bytedance.com, Usama Arif Subject: [PATCH v4 2/3] io_uring: avoid ring quiesce while registering/unregistering eventfd Date: Thu, 3 Feb 2022 18:24:40 +0000 Message-Id: <20220203182441.692354-3-usama.arif@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220203182441.692354-1-usama.arif@bytedance.com> References: <20220203182441.692354-1-usama.arif@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This is done by creating a new RCU data structure (io_ev_fd) as part of io_ring_ctx that holds the eventfd_ctx. The function io_eventfd_signal is executed under rcu_read_lock with a single rcu_dereference to io_ev_fd so that if another thread unregisters the eventfd while io_eventfd_signal is still being executed, the eventfd_signal for which io_eventfd_signal was called completes successfully. The process of registering/unregistering eventfd is done under a lock so multiple threads don't enter a race condition while registering/unregistering eventfd. With the above approach ring quiesce can be avoided which is much more expensive then using RCU lock. On the system tested, io_uring_reigster with IORING_REGISTER_EVENTFD takes less than 1ms with RCU lock, compared to 15ms before with ring quiesce. Signed-off-by: Usama Arif --- fs/io_uring.c | 104 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 79 insertions(+), 25 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 21531609a9c6..7a8f4ac7a785 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -326,6 +326,12 @@ struct io_submit_state { struct blk_plug plug; }; =20 +struct io_ev_fd { + struct eventfd_ctx *cq_ev_fd; + struct io_ring_ctx *ctx; + struct rcu_head rcu; +}; + struct io_ring_ctx { /* const or read-mostly hot data */ struct { @@ -399,7 +405,8 @@ struct io_ring_ctx { struct { unsigned cached_cq_tail; unsigned cq_entries; - struct eventfd_ctx *cq_ev_fd; + struct io_ev_fd __rcu *io_ev_fd; + struct mutex ev_fd_lock; struct wait_queue_head cq_wait; unsigned cq_extra; atomic_t cq_timeouts; @@ -1448,6 +1455,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(s= truct io_uring_params *p) xa_init_flags(&ctx->io_buffers, XA_FLAGS_ALLOC1); xa_init_flags(&ctx->personalities, XA_FLAGS_ALLOC1); mutex_init(&ctx->uring_lock); + mutex_init(&ctx->ev_fd_lock); init_waitqueue_head(&ctx->cq_wait); spin_lock_init(&ctx->completion_lock); spin_lock_init(&ctx->timeout_lock); @@ -1726,13 +1734,24 @@ static inline struct io_uring_cqe *io_get_cqe(struc= t io_ring_ctx *ctx) return &rings->cqes[tail & mask]; } =20 -static inline bool io_should_trigger_evfd(struct io_ring_ctx *ctx) +static void io_eventfd_signal(struct io_ring_ctx *ctx) { - if (likely(!ctx->cq_ev_fd)) - return false; + struct io_ev_fd *ev_fd; + + rcu_read_lock(); + /* rcu_dereference ctx->io_ev_fd once and use it for both for checking an= d eventfd_signal */ + ev_fd =3D rcu_dereference(ctx->io_ev_fd); + + if (likely(!ev_fd)) + goto out; if (READ_ONCE(ctx->rings->cq_flags) & IORING_CQ_EVENTFD_DISABLED) - return false; - return !ctx->eventfd_async || io_wq_current_is_worker(); + goto out; + + if (!ctx->eventfd_async || io_wq_current_is_worker()) + eventfd_signal(ev_fd->cq_ev_fd, 1); + +out: + rcu_read_unlock(); } =20 /* @@ -1751,8 +1770,7 @@ static void io_cqring_ev_posted(struct io_ring_ctx *c= tx) */ if (wq_has_sleeper(&ctx->cq_wait)) wake_up_all(&ctx->cq_wait); - if (io_should_trigger_evfd(ctx)) - eventfd_signal(ctx->cq_ev_fd, 1); + io_eventfd_signal(ctx); } =20 static void io_cqring_ev_posted_iopoll(struct io_ring_ctx *ctx) @@ -1764,8 +1782,7 @@ static void io_cqring_ev_posted_iopoll(struct io_ring= _ctx *ctx) if (waitqueue_active(&ctx->cq_wait)) wake_up_all(&ctx->cq_wait); } - if (io_should_trigger_evfd(ctx)) - eventfd_signal(ctx->cq_ev_fd, 1); + io_eventfd_signal(ctx); } =20 /* Returns true if there are no backlogged entries after the flush */ @@ -9353,35 +9370,70 @@ static int __io_sqe_buffers_update(struct io_ring_c= tx *ctx, =20 static int io_eventfd_register(struct io_ring_ctx *ctx, void __user *arg) { + struct io_ev_fd *ev_fd; __s32 __user *fds =3D arg; - int fd; + int fd, ret; =20 - if (ctx->cq_ev_fd) - return -EBUSY; + mutex_lock(&ctx->ev_fd_lock); + ret =3D -EBUSY; + if (rcu_dereference_protected(ctx->io_ev_fd, lockdep_is_held(&ctx->ev_fd_= lock))) { + rcu_barrier(); + if(rcu_dereference_protected(ctx->io_ev_fd, lockdep_is_held(&ctx->ev_fd_= lock))) + goto out; + } =20 + ret =3D -EFAULT; if (copy_from_user(&fd, fds, sizeof(*fds))) - return -EFAULT; + goto out; =20 - ctx->cq_ev_fd =3D eventfd_ctx_fdget(fd); - if (IS_ERR(ctx->cq_ev_fd)) { - int ret =3D PTR_ERR(ctx->cq_ev_fd); + ret =3D -ENOMEM; + ev_fd =3D kmalloc(sizeof(*ev_fd), GFP_KERNEL); + if (!ev_fd) + goto out; =20 - ctx->cq_ev_fd =3D NULL; - return ret; + ev_fd->cq_ev_fd =3D eventfd_ctx_fdget(fd); + if (IS_ERR(ev_fd->cq_ev_fd)) { + ret =3D PTR_ERR(ev_fd->cq_ev_fd); + kfree(ev_fd); + goto out; } + ev_fd->ctx =3D ctx; =20 - return 0; + rcu_assign_pointer(ctx->io_ev_fd, ev_fd); + ret =3D 0; + +out: + mutex_unlock(&ctx->ev_fd_lock); + return ret; +} + +static void io_eventfd_put(struct rcu_head *rcu) +{ + struct io_ev_fd *ev_fd =3D container_of(rcu, struct io_ev_fd, rcu); + struct io_ring_ctx *ctx =3D ev_fd->ctx; + + eventfd_ctx_put(ev_fd->cq_ev_fd); + kfree(ev_fd); + rcu_assign_pointer(ctx->io_ev_fd, NULL); } =20 static int io_eventfd_unregister(struct io_ring_ctx *ctx) { - if (ctx->cq_ev_fd) { - eventfd_ctx_put(ctx->cq_ev_fd); - ctx->cq_ev_fd =3D NULL; - return 0; + struct io_ev_fd *ev_fd; + int ret; + + mutex_lock(&ctx->ev_fd_lock); + ev_fd =3D rcu_dereference_protected(ctx->io_ev_fd, lockdep_is_held(&ctx->= ev_fd_lock)); + if (ev_fd) { + call_rcu(&ev_fd->rcu, io_eventfd_put); + ret =3D 0; + goto out; } + ret =3D -ENXIO; =20 - return -ENXIO; +out: + mutex_unlock(&ctx->ev_fd_lock); + return ret; } =20 static void io_destroy_buffers(struct io_ring_ctx *ctx) @@ -10960,6 +11012,8 @@ static bool io_register_op_must_quiesce(int op) case IORING_REGISTER_FILES: case IORING_UNREGISTER_FILES: case IORING_REGISTER_FILES_UPDATE: + case IORING_REGISTER_EVENTFD: + case IORING_UNREGISTER_EVENTFD: case IORING_REGISTER_PROBE: case IORING_REGISTER_PERSONALITY: case IORING_UNREGISTER_PERSONALITY: --=20 2.25.1 From nobody Mon Jun 29 18:40:32 2026 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 3FED4C433EF for ; Thu, 3 Feb 2022 18:24:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353507AbiBCSY5 (ORCPT ); Thu, 3 Feb 2022 13:24:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353466AbiBCSYt (ORCPT ); Thu, 3 Feb 2022 13:24:49 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 693FBC061741 for ; Thu, 3 Feb 2022 10:24:48 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id bg19-20020a05600c3c9300b0034565e837b6so4173307wmb.1 for ; Thu, 03 Feb 2022 10:24:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Nbb/JonlYt2gwQTccH2YTHZ8fFvVyRbc8c63+KA/SXs=; b=tIGn+9IvEdbkXn5xnNLy09gK3SY2EFeBj/BT39em5zIXMjreIH0iirlTjng4muT1re iqgntSWn1lpNoVerckRjRAvdhLtLuHRymFX88dZi47LvqLyQFnGVfmf1H0AyReqDmx/n BVQvPiqTc63TJTO75Y/SmZrRXGCWz1QEGbVZA/VP7r91FFphT1FX9pS2MWkuZR5viui8 fpvguOV37Xq9Zlxlqm6EsKxFrhCtXzdLEUtPO6EUUEkETmysOeQiRlj1Aaslysc0afL3 tJgWWVpfWQEF+juElhCDyExWrDjLzjJ9YwYnXInIhchz30cDe92A1MC2PQWwdAuM+NOI aR+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Nbb/JonlYt2gwQTccH2YTHZ8fFvVyRbc8c63+KA/SXs=; b=OdNsDgCj/J4A0hhUz0Oe6KJGgJnuLvdfej09CdrkUq1ADr/IP1prWeThy4LBzyA/2Y fCTH+A0C7DJ/kGLWqQR6WVGeeDagG7DwwLy4TzOJYDqU8CzgzLZfdU0CfHmgbPm4udIT jaABShN6AGSm7oYtu/h++mhpGGc4zNg+F6aUBgKrcrxuQ2iXe4OZ/gn3JBL6llPVjPnm zSaaNLPD3d8KWcmObYfGw0pHysVTTIdhAtxEuslkMDnN6LMHs6GZb5mKJM4Qm1VhQbLW qY3QQqUBFNN86RXLFHYwO1TS3DpQUt2AfY2yWLORO25D70y66NO/fww9oVrpP7KuzmGR mD4w== X-Gm-Message-State: AOAM533dqjj6CMGw18sy3ycv/mBqG9XKwuagPkhIjZrQ9enDOAGbj8Fy UbHOyvq4COyQvaf9Xq55Il3TqQ== X-Google-Smtp-Source: ABdhPJy8kFjgZA7GepNZjH7o49H9W94lbEP8JvFAcXl7hMwg0rlZPQMT0bcsqkgE3yBPSknYYP+iTA== X-Received: by 2002:a7b:c0c8:: with SMTP id s8mr11511762wmh.3.1643912687002; Thu, 03 Feb 2022 10:24:47 -0800 (PST) Received: from usaari01.cust.communityfibre.co.uk ([2a02:6b6d:f804:0:28c2:5854:c832:e580]) by smtp.gmail.com with ESMTPSA id h18sm3540056wro.9.2022.02.03.10.24.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 10:24:46 -0800 (PST) From: Usama Arif To: io-uring@vger.kernel.org, axboe@kernel.dk, asml.silence@gmail.com, linux-kernel@vger.kernel.org Cc: fam.zheng@bytedance.com, Usama Arif Subject: [PATCH v4 3/3] io_uring: avoid ring quiesce for IORING_REGISTER_EVENTFD_ASYNC Date: Thu, 3 Feb 2022 18:24:41 +0000 Message-Id: <20220203182441.692354-4-usama.arif@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220203182441.692354-1-usama.arif@bytedance.com> References: <20220203182441.692354-1-usama.arif@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This is done using the RCU data structure (io_ev_fd). eventfd_async is moved from io_ring_ctx to io_ev_fd which is RCU protected hence avoiding ring quiesce which is much more expensive than an RCU lock. io_should_trigger_evfd is already under rcu_read_lock so there is no extra RCU read-side critical section needed. Signed-off-by: Usama Arif --- fs/io_uring.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 7a8f4ac7a785..e287fc61879f 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -329,6 +329,7 @@ struct io_submit_state { struct io_ev_fd { struct eventfd_ctx *cq_ev_fd; struct io_ring_ctx *ctx; + unsigned int eventfd_async: 1; struct rcu_head rcu; }; =20 @@ -341,7 +342,6 @@ struct io_ring_ctx { unsigned int flags; unsigned int compat: 1; unsigned int drain_next: 1; - unsigned int eventfd_async: 1; unsigned int restricted: 1; unsigned int off_timeout_used: 1; unsigned int drain_active: 1; @@ -1747,7 +1747,7 @@ static void io_eventfd_signal(struct io_ring_ctx *ctx) if (READ_ONCE(ctx->rings->cq_flags) & IORING_CQ_EVENTFD_DISABLED) goto out; =20 - if (!ctx->eventfd_async || io_wq_current_is_worker()) + if (!ev_fd->eventfd_async || io_wq_current_is_worker()) eventfd_signal(ev_fd->cq_ev_fd, 1); =20 out: @@ -9368,7 +9368,8 @@ static int __io_sqe_buffers_update(struct io_ring_ctx= *ctx, return done ? done : err; } =20 -static int io_eventfd_register(struct io_ring_ctx *ctx, void __user *arg) +static int io_eventfd_register(struct io_ring_ctx *ctx, void __user *arg, + unsigned int eventfd_async) { struct io_ev_fd *ev_fd; __s32 __user *fds =3D arg; @@ -9398,6 +9399,7 @@ static int io_eventfd_register(struct io_ring_ctx *ct= x, void __user *arg) goto out; } ev_fd->ctx =3D ctx; + ev_fd->eventfd_async =3D eventfd_async; =20 rcu_assign_pointer(ctx->io_ev_fd, ev_fd); ret =3D 0; @@ -11013,6 +11015,7 @@ static bool io_register_op_must_quiesce(int op) case IORING_UNREGISTER_FILES: case IORING_REGISTER_FILES_UPDATE: case IORING_REGISTER_EVENTFD: + case IORING_REGISTER_EVENTFD_ASYNC: case IORING_UNREGISTER_EVENTFD: case IORING_REGISTER_PROBE: case IORING_REGISTER_PERSONALITY: @@ -11113,17 +11116,16 @@ static int __io_uring_register(struct io_ring_ctx= *ctx, unsigned opcode, ret =3D io_register_files_update(ctx, arg, nr_args); break; case IORING_REGISTER_EVENTFD: - case IORING_REGISTER_EVENTFD_ASYNC: ret =3D -EINVAL; if (nr_args !=3D 1) break; - ret =3D io_eventfd_register(ctx, arg); - if (ret) + ret =3D io_eventfd_register(ctx, arg, 0); + break; + case IORING_REGISTER_EVENTFD_ASYNC: + ret =3D -EINVAL; + if (nr_args !=3D 1) break; - if (opcode =3D=3D IORING_REGISTER_EVENTFD_ASYNC) - ctx->eventfd_async =3D 1; - else - ctx->eventfd_async =3D 0; + ret =3D io_eventfd_register(ctx, arg, 1); break; case IORING_UNREGISTER_EVENTFD: ret =3D -EINVAL; --=20 2.25.1