From patchwork Thu Mar 30 14:53:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 77224 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1186070vqo; Thu, 30 Mar 2023 07:56:02 -0700 (PDT) X-Google-Smtp-Source: AKy350Z4TiWTvku39FprF2rYkDZ/9QrhKuMJlyz9ongTdOrVAqxDwAaq1obcDoXVDPeek0gEcnNm X-Received: by 2002:a05:6402:415:b0:500:46f2:e7db with SMTP id q21-20020a056402041500b0050046f2e7dbmr23378452edv.15.1680188162073; Thu, 30 Mar 2023 07:56:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680188162; cv=none; d=google.com; s=arc-20160816; b=E8J8qCNmxTBd8cv1dBQJ8znoNeDbWRedVvkD1QGcCWL6YNqi/QJDljJHzaJdW9aew/ VLZFby8IAi1tsR4OKw2fRP0ynSQys6COjr69nNF9Gnk7m9RoVz+EBy5ntGUTPrL9j6ce CmNYlGRRYf+roguheG3n0SmbZMoGl7bNTQHuzHw+vDCQCt1BK8bfQ/4SbSaSOmpF/430 VgNBZY6581tB7gNBTWiuEzMso3pe1gPXKA3HUrwW9QwvuI2nd+V1gRkY+0C3yL+up9I5 0uyhw4jHDiFyMiUcDJSf5QdZF0lVInwPG2jZyqizpTzAWZr5L8L36J8iNFP1aQu/ilpZ EOOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WWAczytuFz9lGZfCu/Rbuh88s55sTzs57HoEPIGs0GU=; b=FlR2AIp56V6ZOZiOqVh+9c8GMDbbmB8c5G8RiCauRzsDOXSWJaN4cZ8goK1lF0Jis2 waTTmXpTS7gJWG96mrJ6R3ifDDRr6IeWAJ27DP0ijCrQtDCPTeZYb5Jn0Q/wpWnaEk+U Wtv0GapRIVTUlErIHgyxOCyIaa1gUnJctMljzXDnIrxS02j7A9d8Z2UC02m6C8UnVQtk sklHac3OOgSyVlJNMpoi4tSksK0YO2mrnmhp3yX8kqGAgPYQ5nVupcBEhz9mVzElhCDc DLJ80lZwwoCUfFufvTODThpxVdV/NFE2y6Gtv/Ukn2m2C+6uCbOQ6rTWRSGADa420AQv NR/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZPQgYFuW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b17-20020aa7df91000000b004ac8358be51si32776552edy.464.2023.03.30.07.55.37; Thu, 30 Mar 2023 07:56:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZPQgYFuW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232570AbjC3Oyt (ORCPT + 99 others); Thu, 30 Mar 2023 10:54:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232539AbjC3Oyi (ORCPT ); Thu, 30 Mar 2023 10:54:38 -0400 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 8A01BA5D8; Thu, 30 Mar 2023 07:54:37 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id m6-20020a05600c3b0600b003ee6e324b19so11974552wms.1; Thu, 30 Mar 2023 07:54:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680188075; 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=WWAczytuFz9lGZfCu/Rbuh88s55sTzs57HoEPIGs0GU=; b=ZPQgYFuWcz1SvJblTrxSJFLx5OAkM/KL/BYFd0RSfa/H2AiXu8SDOQ5j5v3iJprcop Jx9t48yuY9un4JFMIBZ0Tzqb/jVGOO6oTYOOE87IYBLtZrXfvYaxbD9Fa+ErOFN9ROHZ uEMnKIRmPXJoSZRA4y1uHnQeIGVXv7ebHVolEBgDmcM91gxa9mS4vxV+dLlkfDHiGEUq hrmrqXUi5RXmuK+b/ctz8UsjGEg9kZ6N18KJ9wFAb3LF5mxKTohvByLBmHIrGkRq3Oq7 BDvCISHhLESl1mCXuFCwFrNwydXnxpXpXJZ5vvnRAl9xhNkSijs3wYq93FgJUOh+MifF ecaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680188075; 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=WWAczytuFz9lGZfCu/Rbuh88s55sTzs57HoEPIGs0GU=; b=zBUikyicM/zeIOYvvcF0FJG1rvDA7Xk2osdcEii+KEYCigA6MaeqrJ55SP3+R/sHuS JRgte4vX/mIgB4QkfZaoVwlpX2BhH7z9srWx9J0bIuoD7lkDZ/ItccSEkCA/twjw96hy Nx2nCOvchcjaoA2Bi2X6GRITHdNd9DsXk8UuhDXQmOaVJ+LdbMhpA5U26Dbev3I2PA0F Eo3na+FQgsM52MBQsQ2nRqtwzBrXMpsaJjLmlKhAoixN/dHhdBK5K01Y0FdFM2ELZeH4 LDC57UooIJ3DvKlFzYtJj0zTs5rvpFFNuaaZJW2p11lg+OePSEok2g6YQOjOyOOBboiW 9PvQ== X-Gm-Message-State: AO0yUKXOSbJ1vZxlm6P6SCWtO+UsJeOQpk0t69Gm6YqaoZyy0h7MdHwA Rausc7zmykOLp+pRRrpM2z0YpAu/DBo= X-Received: by 2002:a1c:7702:0:b0:3ed:4f7d:f6ee with SMTP id t2-20020a1c7702000000b003ed4f7df6eemr18359942wmi.14.1680188075498; Thu, 30 Mar 2023 07:54:35 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-231-234.dab.02.net. [82.132.231.234]) by smtp.gmail.com with ESMTPSA id d7-20020adffbc7000000b002d5a8d8442asm28727962wrs.37.2023.03.30.07.54.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 07:54:35 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH 03/11] io_uring: don't put nodes under spinlocks Date: Thu, 30 Mar 2023 15:53:21 +0100 Message-Id: X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761804982438914943?= X-GMAIL-MSGID: =?utf-8?q?1761804982438914943?= io_req_put_rsrc() doesn't need any locking, so move it out of a spinlock section in __io_req_complete_post() and adjust helpers. Signed-off-by: Pavel Begunkov --- io_uring/io_uring.c | 7 +++++-- io_uring/rsrc.h | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 536940675c67..c944833099a6 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -970,6 +970,7 @@ bool io_aux_cqe(struct io_ring_ctx *ctx, bool defer, u64 user_data, s32 res, u32 static void __io_req_complete_post(struct io_kiocb *req) { struct io_ring_ctx *ctx = req->ctx; + struct io_rsrc_node *rsrc_node = NULL; io_cq_lock(ctx); if (!(req->flags & REQ_F_CQE_SKIP)) @@ -990,7 +991,7 @@ static void __io_req_complete_post(struct io_kiocb *req) } io_put_kbuf_comp(req); io_dismantle_req(req); - io_req_put_rsrc(req); + rsrc_node = req->rsrc_node; /* * Selected buffer deallocation in io_clean_op() assumes that * we don't hold ->completion_lock. Clean them here to avoid @@ -1001,6 +1002,8 @@ static void __io_req_complete_post(struct io_kiocb *req) ctx->locked_free_nr++; } io_cq_unlock_post(ctx); + + io_put_rsrc_node(rsrc_node); } void io_req_complete_post(struct io_kiocb *req, unsigned issue_flags) @@ -1117,7 +1120,7 @@ __cold void io_free_req(struct io_kiocb *req) { struct io_ring_ctx *ctx = req->ctx; - io_req_put_rsrc(req); + io_put_rsrc_node(req->rsrc_node); io_dismantle_req(req); io_put_task_remote(req->task, 1); diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h index 950535e2b9f4..8164777279ba 100644 --- a/io_uring/rsrc.h +++ b/io_uring/rsrc.h @@ -115,10 +115,10 @@ static inline void io_rsrc_put_node(struct io_rsrc_node *node, int nr) io_rsrc_node_ref_zero(node); } -static inline void io_req_put_rsrc(struct io_kiocb *req) +static inline void io_put_rsrc_node(struct io_rsrc_node *node) { - if (req->rsrc_node) - io_rsrc_put_node(req->rsrc_node, 1); + if (node) + io_rsrc_put_node(node, 1); } static inline void io_req_put_rsrc_locked(struct io_kiocb *req,