From nobody Mon Jun 29 18:40:41 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 5425AC43217 for ; Fri, 4 Feb 2022 14:51:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359478AbiBDOv0 (ORCPT ); Fri, 4 Feb 2022 09:51:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359463AbiBDOvY (ORCPT ); Fri, 4 Feb 2022 09:51:24 -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 9C6D3C061714 for ; Fri, 4 Feb 2022 06:51:23 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id m14so11751282wrg.12 for ; Fri, 04 Feb 2022 06:51:23 -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=U8a5uvKULW29WgDNmVvh+nRbtIswUa3SQ4qySlVWMlW+aM61ecXxU2MT53lkUDGd8B cpMe5Ij5Waf7VTrsXJxP/zGPxYc8DqKobZnVksXUBU3Yo6bifO4BB6y2ZgyCzSlVy2Q/ wG12GqYgNHGvWzv1GnKm6Y1hRAMRDEvqJ680XT9wfCkl9o0wCuyCU1AN8RMT4fsapznY 00lOVJ0uYH74taLHib0BFSxJgeTkv84lQSRLqjxRxX864gT//OLxQZyFBaCwrKO9y6eD VPfjmzAbQfU3JUkO+kHl7qOOtsXTlJIpmlekpDVQ4WhU92rWZYF8GAPAud300cptu8Jr rl0g== 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=XUvbQKXeOnQ4/7L3aAliS7rtS4Enuf5LmpYa3oS+zRpiZ3/l3LVtmXlJ+jX3gOFxBP YA8fhIerzlQZzX9w24aALx2NuzOu1W8/W3mL0mBBq+guhPC6LtdgEBzZXBylrelGmVrD vFF8V0soanAZAYz++Eh2ysc4ikriiXZhjZSXqNnIChf33bgVO4CS3im54lA5yw9oTbHx ZtvOrhbMn8CtK/0zH6RDohYhnzYd/SDmmO/5oBoy5YLywSIJbwNJEP+KPsPHZOyKXQfy nI4S9cat09/684j3jsNQPeYsqtY0MBaXuPR4yIaUPDb+IU/S36OrwT+URJinzMgipLvw n2lA== X-Gm-Message-State: AOAM533rzr4rs5PDYrAos5jJBiDEcT83jFkJpPmwz+qIudK9NkEZiur1 4rbEJjkqOWlrjGosMubI58J9Yiz2b3MoYw== X-Google-Smtp-Source: ABdhPJycijml2DzFeokJ4zrRH7pCBK74aSNf5O9gpSPx9wDfcLqCAh87qk99xXm3hqOr/UuaYTPnCg== X-Received: by 2002:a5d:5049:: with SMTP id h9mr2781950wrt.502.1643986282275; Fri, 04 Feb 2022 06:51:22 -0800 (PST) Received: from usaari01.cust.communityfibre.co.uk ([2a02:6b6d:f804:0:e94c:d0f2:1084:a0d3]) by smtp.gmail.com with ESMTPSA id c11sm2552898wri.43.2022.02.04.06.51.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 06:51:22 -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 v6 1/5] io_uring: remove trace for eventfd Date: Fri, 4 Feb 2022 14:51:13 +0000 Message-Id: <20220204145117.1186568-2-usama.arif@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204145117.1186568-1-usama.arif@bytedance.com> References: <20220204145117.1186568-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:41 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 CE6AAC43217 for ; Fri, 4 Feb 2022 14:51:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359497AbiBDOva (ORCPT ); Fri, 4 Feb 2022 09:51:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359462AbiBDOvZ (ORCPT ); Fri, 4 Feb 2022 09:51:25 -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 CBB05C061714 for ; Fri, 4 Feb 2022 06:51:24 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id j25so11111503wrb.2 for ; Fri, 04 Feb 2022 06:51:24 -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=CkttKNdOSNMa9Axq1SN1XcS0adDHYYOmAEpZi/phyh0=; b=bi6MmRZsaJ9wAqMcXzbH8GB8yzGcIBSVOEpMEEok/XSl55fs4Ye2g7KdINgMxb7ESt wgxKDplzu7nYqxkQ3mIv+iw3SqzTD/eXkhAxztY0aZiQL6laPj5c1mUfGBiBrgiKoxOa bjohi6ZSHoRhzizqMLp97D8ZJDIP5Ett5cu+knj19Flmoca0rsw0/UxknQ5W8fo9KtEF Bco1+HZitYEcd7sz0VZXX8R7/oPX7h/7Yk/ENXMaFnIB7ocMKBm4atek9pesScrL/OXK Sw32eL/+pOGzFxIsKjrNYWiC1ulTau+5mIKikg/1j2tQYy7LWwCsEOyXGNXjqUJyH9ja EtzA== 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=CkttKNdOSNMa9Axq1SN1XcS0adDHYYOmAEpZi/phyh0=; b=C8InLFMV25Fb7g5pcY686u1ry9Jnr993O5AUZX2/bsrGLc0EogtKyLzz/poqulQG81 yxObk48P3YcNZtfepqBjfcpCWBuoNX5x6HdWDvCIULHj/HIe48fcF0gHwt/o/QXsiRqP 1nj1Xytw8Nl12RlgjMM0hgLejEFgcGc9mMaTUtPap4PmHY39SIc6DQl88SQN9S96VTE3 Z6jdt47Z3scHAGNgyOK9x7iji3wWp6nUG8PTCP69gtpWZRDwamUa63c6LfTT9PFiFHbc PdAxru7zhJjEHzHex2QVoiaUwbuB515zDLnqN/fv0aAagtpVHN0hQTGDaqUVhDiOt3KS nhKQ== X-Gm-Message-State: AOAM533eLSqjT6sovzokdAA8k6Xi9hj0mu37U7SO1rMvXkoAfiuMqw08 G8CbopahaxJlMDlO58cmWErOrw== X-Google-Smtp-Source: ABdhPJxZZPEf5Vk7WcRS6OgFDfREWzBw5sT237wVW8bTzerK0b/yN0C4AyFWZzfJMFxkhz2lOIuyTg== X-Received: by 2002:adf:dfcf:: with SMTP id q15mr2772385wrn.276.1643986283443; Fri, 04 Feb 2022 06:51:23 -0800 (PST) Received: from usaari01.cust.communityfibre.co.uk ([2a02:6b6d:f804:0:e94c:d0f2:1084:a0d3]) by smtp.gmail.com with ESMTPSA id c11sm2552898wri.43.2022.02.04.06.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 06:51:23 -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 v6 2/5] io_uring: avoid ring quiesce while registering/unregistering eventfd Date: Fri, 4 Feb 2022 14:51:14 +0000 Message-Id: <20220204145117.1186568-3-usama.arif@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204145117.1186568-1-usama.arif@bytedance.com> References: <20220204145117.1186568-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 already done under uring_lock so multiple threads won'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 | 81 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 20 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 21531609a9c6..ad6361aeaca7 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -326,6 +326,11 @@ struct io_submit_state { struct blk_plug plug; }; =20 +struct io_ev_fd { + struct eventfd_ctx *cq_ev_fd; + struct rcu_head rcu; +}; + struct io_ring_ctx { /* const or read-mostly hot data */ struct { @@ -399,7 +404,7 @@ 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 wait_queue_head cq_wait; unsigned cq_extra; atomic_t cq_timeouts; @@ -1726,13 +1731,32 @@ 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; + + /* Return quickly if ctx->io_ev_fd doesn't exist */ + if (likely(!rcu_dereference_raw(ctx->io_ev_fd))) + return; + + 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); + + /* + * Check again if ev_fd exists incase an io_eventfd_unregister call compl= eted between + * the NULL check of ctx->io_ev_fd at the start of the function and rcu_r= ead_lock. + */ + if (unlikely(!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 +1775,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 +1787,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,31 +9375,48 @@ 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) + ev_fd =3D rcu_dereference_protected(ctx->io_ev_fd, lockdep_is_held(&ctx->= uring_lock)); + if (ev_fd) return -EBUSY; =20 if (copy_from_user(&fd, fds, sizeof(*fds))) return -EFAULT; =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); + ev_fd =3D kmalloc(sizeof(*ev_fd), GFP_KERNEL); + if (!ev_fd) + return -ENOMEM; =20 - ctx->cq_ev_fd =3D NULL; + 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); return ret; } =20 - return 0; + rcu_assign_pointer(ctx->io_ev_fd, ev_fd); + 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); + + eventfd_ctx_put(ev_fd->cq_ev_fd); + kfree(ev_fd); } =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; + struct io_ev_fd *ev_fd; + + ev_fd =3D rcu_dereference_protected(ctx->io_ev_fd, lockdep_is_held(&ctx->= uring_lock)); + if (ev_fd) { + rcu_assign_pointer(ctx->io_ev_fd, NULL); + call_rcu(&ev_fd->rcu, io_eventfd_put); return 0; } =20 @@ -10960,6 +10999,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:41 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 D0F18C433EF for ; Fri, 4 Feb 2022 14:51:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359522AbiBDOvc (ORCPT ); Fri, 4 Feb 2022 09:51:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359475AbiBDOv0 (ORCPT ); Fri, 4 Feb 2022 09:51:26 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2119C061401 for ; Fri, 4 Feb 2022 06:51:25 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id s18so11805370wrv.7 for ; Fri, 04 Feb 2022 06:51:25 -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=5zc8mYGQQbklzCfEPq5ixDqvUH1Mr0RGq4NsmzowtCU=; b=q7cQX7sIPSRmOALm6TBpWQ/mo+y2c7GlrThj3wILGB7n2WzpXU+8SZremYwVxzsGij G4wbfSz+fec2keuXRmpWplZXoU2vxrq6jPyHhQLVAKWuAerYySuGY+3DyvIwOas7Xxue bJt0BgDjxeDxViSaqlitN225zUj03fM9SAae8IDkFXjvPYwTDeqRr08cjukhfdroSDZy MIh8Ofdt5LlhPny7r6Yji8K9glZwtL4zPbnuq/CRld5WZCybRx60kBazZ5temZpPbccT MSr3bITJgpVF3sBCebcZE9muZSJvPqrswt/BPmf/n+NEwCoaCnzY+UXCiCudufpnOyC2 49tQ== 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=5zc8mYGQQbklzCfEPq5ixDqvUH1Mr0RGq4NsmzowtCU=; b=u6LhkzYq59jT6blXyLLzkJGrQyl/sTvgASDKPOh0ag2J9ppVYT5VaigvfQ5sRL0pe+ dqKz9Af5j6GqL8QrXx6otSXmDPLCGeli1YEnX3YS/KZnFfb5q50gFmOlGjSk0LQtTtCQ 78XRSF08LqaGYheRxP3B9K+kawPmG41bxJw3W51koZHf8Y3cw7Jm8eOCom+fl3BZZ9fK cxHjCyapVoNJd9WL1Pp61dmABNYQj3+vka+ghbt9eM5e/F4Ecj7yrqva7DQ0sYYoIuLX 6CJ7u2unlgfAsGyLPHv+zo2NsKEtIRqzcEWriEjWgc3qRoE7UEmnuMf3Z9YFC1eMWaf+ Jqyw== X-Gm-Message-State: AOAM533P4rby6kzsf/DuBgvjR6iafvFiCeT1b5JjSb1pInuMO5Po6ojr DeN5QVaQn+fgvOtbZ8QeaCtvwA== X-Google-Smtp-Source: ABdhPJz3r/hgUNyu1JFddlat0A+D16hlkSO3MwsYWonb403K1rS4BB2N+fCYnF6gfCI/1pQ27pBarA== X-Received: by 2002:a5d:4cc7:: with SMTP id c7mr2656075wrt.233.1643986284356; Fri, 04 Feb 2022 06:51:24 -0800 (PST) Received: from usaari01.cust.communityfibre.co.uk ([2a02:6b6d:f804:0:e94c:d0f2:1084:a0d3]) by smtp.gmail.com with ESMTPSA id c11sm2552898wri.43.2022.02.04.06.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 06:51:24 -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 v6 3/5] io_uring: avoid ring quiesce while registering async eventfd Date: Fri, 4 Feb 2022 14:51:15 +0000 Message-Id: <20220204145117.1186568-4-usama.arif@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204145117.1186568-1-usama.arif@bytedance.com> References: <20220204145117.1186568-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. The place where eventfd_async is read 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 ad6361aeaca7..671c57f9c1fa 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -328,6 +328,7 @@ struct io_submit_state { =20 struct io_ev_fd { struct eventfd_ctx *cq_ev_fd; + unsigned int eventfd_async: 1; struct rcu_head rcu; }; =20 @@ -340,7 +341,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; @@ -1752,7 +1752,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: @@ -9373,7 +9373,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; @@ -9396,6 +9397,7 @@ static int io_eventfd_register(struct io_ring_ctx *ct= x, void __user *arg) kfree(ev_fd); return ret; } + ev_fd->eventfd_async =3D eventfd_async; =20 rcu_assign_pointer(ctx->io_ev_fd, ev_fd); return ret; @@ -11000,6 +11002,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: @@ -11100,17 +11103,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 From nobody Mon Jun 29 18:40:41 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 4CAC7C433F5 for ; Fri, 4 Feb 2022 14:51:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359491AbiBDOvf (ORCPT ); Fri, 4 Feb 2022 09:51:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359484AbiBDOv1 (ORCPT ); Fri, 4 Feb 2022 09:51:27 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FC38C061748 for ; Fri, 4 Feb 2022 06:51:26 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id r17so2750591wrr.6 for ; Fri, 04 Feb 2022 06:51:26 -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=ymoa5X9VDt1Lo7923G6xQz+2XF6WMF2nPpUrkksIMss=; b=Xopc4Nkg8x7cYq22CMvzmComoF0CuwSoz//ulwpXuNdB841RjSYEx8qZRKc6BHGmU5 EPXcpzWtRzbpveFJQAKHvcgxcwz6OmxZQVSz5o9xJeTL/Tx2IU998rs9wHupVWJHcW61 G8xjIDSkxMItkiCWo2THoUZMQolHmRRBLBXsjYEeXRLsejRRzZZwcE2w+UbCZ59w3smU 3fNcS3DL4k1XSN068MgJeeV3nDtzGUUEOCFWcfV4762t1hNXbZIpUNyy+i/djzqv65t0 Cv1cTnwGEU68aaI3K5vesGD0Y66vVvhTBH1Tn3bD9q9CwnXcEqC6HAcbARH45YJnJzsU ChNw== 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=ymoa5X9VDt1Lo7923G6xQz+2XF6WMF2nPpUrkksIMss=; b=6nNyTW1piaxP+gecP8IVc8duNLhJld3uFm2RvL8x/1roJhjytGy+PYw6CZOm8nHJ/E 137qbMKWZIpHioj+Wmi5GPq5W8xfqDbzVjSBuFV9AOLmA/7fp2+X8NkdRqR7sEVLZeHE W/BzyRbaNVShR854GRlUgqnmHiZhSVWZoVIwRrjPeOXvyuMzDlkaU2OIu5MtYtohky54 GBD5CY9KTNkmh38t39EFleTOKsel15YNueWdSRb9AjXebZ1q6HWuqmQZBoSWuFvp0DP2 zDeFB7CwUh3CZg17txe97G3xW3jNBGMcMNTga2J7Aa/Ll4pKFhzHlK30v2IhhDHrejWa vyCA== X-Gm-Message-State: AOAM531+obxJyxmLk1Vkvt7BwfhayUuFv4Qcv74uZxaz3gwYKrAV0Bwz EPDsPKtguPcwZ5/1y6YmqTRK2Q== X-Google-Smtp-Source: ABdhPJykTMrOCuJ93oe7UN/RWNzj2G8gPRf2kOv+qJS1PEv/rFiPf7S0PHstOzbImEPkHrt2QrJSUg== X-Received: by 2002:a5d:5342:: with SMTP id t2mr1775121wrv.602.1643986285245; Fri, 04 Feb 2022 06:51:25 -0800 (PST) Received: from usaari01.cust.communityfibre.co.uk ([2a02:6b6d:f804:0:e94c:d0f2:1084:a0d3]) by smtp.gmail.com with ESMTPSA id c11sm2552898wri.43.2022.02.04.06.51.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 06:51:24 -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 v6 4/5] io_uring: avoid ring quiesce while registering restrictions and enabling rings Date: Fri, 4 Feb 2022 14:51:16 +0000 Message-Id: <20220204145117.1186568-5-usama.arif@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204145117.1186568-1-usama.arif@bytedance.com> References: <20220204145117.1186568-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" IORING_SETUP_R_DISABLED prevents submitting requests and so there will be no requests until IORING_REGISTER_ENABLE_RINGS is called. And IORING_REGISTER_RESTRICTIONS works only before IORING_REGISTER_ENABLE_RINGS is called. Hence ring quiesce is not needed for these opcodes. Signed-off-by: Usama Arif --- fs/io_uring.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index 671c57f9c1fa..a2ce2601d4de 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -11007,6 +11007,8 @@ static bool io_register_op_must_quiesce(int op) case IORING_REGISTER_PROBE: case IORING_REGISTER_PERSONALITY: case IORING_UNREGISTER_PERSONALITY: + case IORING_REGISTER_ENABLE_RINGS: + case IORING_REGISTER_RESTRICTIONS: case IORING_REGISTER_FILES2: case IORING_REGISTER_FILES_UPDATE2: case IORING_REGISTER_BUFFERS2: --=20 2.25.1 From nobody Mon Jun 29 18:40:41 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 1E7EDC433EF for ; Fri, 4 Feb 2022 14:51:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359575AbiBDOvm (ORCPT ); Fri, 4 Feb 2022 09:51:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359489AbiBDOv1 (ORCPT ); Fri, 4 Feb 2022 09:51:27 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85306C06173E for ; Fri, 4 Feb 2022 06:51:27 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id j5-20020a05600c1c0500b0034d2e956aadso3934190wms.4 for ; Fri, 04 Feb 2022 06:51:27 -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=2CaJ8vk5yyQY0T2mdc+r8fsmHsQDS+9ThebmdKt84DM=; b=WViNpK9iFN/B/XayGYeKNnTmyaV5k1IqBAmyt+A0jrJME4LyZwKmAREWJz1eCRUArJ mfRXZb4JacNW893IU/rb7firli+D+csTpY8sQSb/Mmq3qgXEf6RQa+aQeEhwNTInFtQt aCgQ+5slbpSSi9YiDAqIksTSFt1MZDGCj1hZRy5sztAEHVLOOGEDzF4X/PIs+dIW5u86 8XspjFZJ9UYx61ZBfv3k2Vi14UGeymswLdJoivfAA+CsLeHybjnEDGvo+2Ugb7d9QTMn 2fgsbTeSPVQz4NYQE9BBZHYAMSpTq7POpUjArVi68EHzdjIzMM4rUSwZVg7DwvhHwfWA DtxQ== 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=2CaJ8vk5yyQY0T2mdc+r8fsmHsQDS+9ThebmdKt84DM=; b=u8sd/c2PYRJaHLsC6yte50YnRsFoKsjcr3BUDVEGIJ9383FDqHI4NS03L6btV9Z+uj Trj1Fe4Gj5/ZGuBW3sCVh9+F3ySr8iywdbCVp0bD1/y4wiQsl4UYgzY2Ismy4GaZcvo3 EbL+HA+dx4oANzz9ZjaoMNP3fYxFsXjMqefKxDFP1c3TlotQY04HwVBk18ueJo/0A7io FzfASoMK0R6DUOFgwFL/w+0yQHyy3Zb5Rd/aolbgTMEj6OaUIrq4KR5zOt444/Vxhh/x o0294FomV09kvc5uB3p6bKAUcwJWoQuBqANNURL/9ZlVu7Ibpad7Cm3oC/giVZq0DdDa ZfDg== X-Gm-Message-State: AOAM532iNCkTgTyjrn2hSgcMvh/0xYokBxo79Pt1CW7nA8neX3QiKgJw E7+o55xzsZ+nZPhA5MEhFSPXeQ== X-Google-Smtp-Source: ABdhPJwQshqJLL/4yrbgwioourFtbu/7Ak+InZgBQiYRuzefDcbbDOMvqCXJznsRF3DWLEoHdooK4Q== X-Received: by 2002:a7b:c117:: with SMTP id w23mr2547498wmi.63.1643986286182; Fri, 04 Feb 2022 06:51:26 -0800 (PST) Received: from usaari01.cust.communityfibre.co.uk ([2a02:6b6d:f804:0:e94c:d0f2:1084:a0d3]) by smtp.gmail.com with ESMTPSA id c11sm2552898wri.43.2022.02.04.06.51.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Feb 2022 06:51:25 -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 v6 5/5] io_uring: remove ring quiesce for io_uring_register Date: Fri, 4 Feb 2022 14:51:17 +0000 Message-Id: <20220204145117.1186568-6-usama.arif@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220204145117.1186568-1-usama.arif@bytedance.com> References: <20220204145117.1186568-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" None of the opcodes in io_uring_register use ring quiesce anymore. Hence io_register_op_must_quiesce always returns false and io_ctx_quiesce is never called. Signed-off-by: Usama Arif --- fs/io_uring.c | 83 --------------------------------------------------- 1 file changed, 83 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index a2ce2601d4de..ad8f84376955 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -1292,18 +1292,6 @@ static inline unsigned int io_put_kbuf(struct io_kio= cb *req) return __io_put_kbuf(req); } =20 -static void io_refs_resurrect(struct percpu_ref *ref, struct completion *c= ompl) -{ - bool got =3D percpu_ref_tryget(ref); - - /* already at zero, wait for ->release() */ - if (!got) - wait_for_completion(compl); - percpu_ref_resurrect(ref); - if (got) - percpu_ref_put(ref); -} - static bool io_match_task(struct io_kiocb *head, struct task_struct *task, bool cancel_all) __must_hold(&req->ctx->timeout_lock) @@ -10993,66 +10981,6 @@ static __cold int io_register_iowq_max_workers(str= uct io_ring_ctx *ctx, return ret; } =20 -static bool io_register_op_must_quiesce(int op) -{ - switch (op) { - case IORING_REGISTER_BUFFERS: - case IORING_UNREGISTER_BUFFERS: - case IORING_REGISTER_FILES: - 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: - case IORING_UNREGISTER_PERSONALITY: - case IORING_REGISTER_ENABLE_RINGS: - case IORING_REGISTER_RESTRICTIONS: - case IORING_REGISTER_FILES2: - case IORING_REGISTER_FILES_UPDATE2: - case IORING_REGISTER_BUFFERS2: - case IORING_REGISTER_BUFFERS_UPDATE: - case IORING_REGISTER_IOWQ_AFF: - case IORING_UNREGISTER_IOWQ_AFF: - case IORING_REGISTER_IOWQ_MAX_WORKERS: - return false; - default: - return true; - } -} - -static __cold int io_ctx_quiesce(struct io_ring_ctx *ctx) -{ - long ret; - - percpu_ref_kill(&ctx->refs); - - /* - * Drop uring mutex before waiting for references to exit. If another - * thread is currently inside io_uring_enter() it might need to grab the - * uring_lock to make progress. If we hold it here across the drain - * wait, then we can deadlock. It's safe to drop the mutex here, since - * no new references will come in after we've killed the percpu ref. - */ - mutex_unlock(&ctx->uring_lock); - do { - ret =3D wait_for_completion_interruptible_timeout(&ctx->ref_comp, HZ); - if (ret) { - ret =3D min(0L, ret); - break; - } - - ret =3D io_run_task_work_sig(); - io_req_caches_free(ctx); - } while (ret >=3D 0); - mutex_lock(&ctx->uring_lock); - - if (ret) - io_refs_resurrect(&ctx->refs, &ctx->ref_comp); - return ret; -} - static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode, void __user *arg, unsigned nr_args) __releases(ctx->uring_lock) @@ -11076,12 +11004,6 @@ static int __io_uring_register(struct io_ring_ctx = *ctx, unsigned opcode, return -EACCES; } =20 - if (io_register_op_must_quiesce(opcode)) { - ret =3D io_ctx_quiesce(ctx); - if (ret) - return ret; - } - switch (opcode) { case IORING_REGISTER_BUFFERS: ret =3D io_sqe_buffers_register(ctx, arg, nr_args, NULL); @@ -11186,11 +11108,6 @@ static int __io_uring_register(struct io_ring_ctx = *ctx, unsigned opcode, break; } =20 - if (io_register_op_must_quiesce(opcode)) { - /* bring the ctx back to life */ - percpu_ref_reinit(&ctx->refs); - reinit_completion(&ctx->ref_comp); - } return ret; } =20 --=20 2.25.1