From patchwork Tue Apr 4 12:39:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 79088 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3004705vqo; Tue, 4 Apr 2023 06:00:06 -0700 (PDT) X-Google-Smtp-Source: AKy350bVoHE7RqDJRhznK3K+jl4sPWuT6d6U5PC8NkVqviVmB05f48cs2R/17bZfoPBNJy1n/NQP X-Received: by 2002:aa7:d1cc:0:b0:502:4862:d453 with SMTP id g12-20020aa7d1cc000000b005024862d453mr1974725edp.3.1680613206070; Tue, 04 Apr 2023 06:00:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680613206; cv=none; d=google.com; s=arc-20160816; b=svtb+etI4ikaAjwj7Ld8aYM8/dbgPtf5CEpP0u52vwSNGK9XeNEIIlyKyN+pDjdRm2 6I2FmS2FGb/qlZ1+Ognjj70pi4z8ktp/e6QHkH/ADFMi35E+5uffE0lkelEWReZFQRxj aGpqL800nRGjN+MlAX/+5CDhQIR/2r3dRyHj3Lq3Y28jNo72okKx5GUj9lsSo4mCAiQU zOYqkNDT6vGvitBQIm7ILE+jeFeTg1cWsvYaZaya7rqh3KIFMeIaUunFnEBBlucFyM+2 pDlRGGB9+foa0yFzvdbuADPWOXjPMyEm6QFx+0bgfmInlpj2QMZ7mCEbz0hEr23Vjzv/ cm+w== 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=7NWdR6MPB6XAokVEPIwltF2umB3WBqKQ7V2xA8hlx+8=; b=HtKcXZGFV5TXsYcrMrjAlWTA8KoZB5MQ+TSGJFu14FKR9UequNJFM4MXXgTH3dsX0y /wJj9LA9KF9Ex21pFBOrLMxG0LNZWIMbEYiV6jB3gRMixdmTY+FHLUFhYYIHnth7MZ4K v1by+LzzK6lbRKLU+/o360/buU8iDMsypic2jJM/dZCMZNo54cw5kBlYvlgNfV492yWo IUAzfJyzxtXgtugGMfFQbePhIKKEfZ9UbBFiaQzkn8zQJ9jqdvbaJ+wFjc8hDz1sD6kg EXLSZ/Ephf9UEPADm0TAVzs144k1NlB4AYvAAKaqkB5d+XnvhdFMKbmicIEtxCOfwmLL WA5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=A2Irdkos; 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 gz5-20020a170907a04500b0093a0ef38401si9823680ejc.94.2023.04.04.05.59.41; Tue, 04 Apr 2023 06:00:06 -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=A2Irdkos; 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 S235016AbjDDMlG (ORCPT + 99 others); Tue, 4 Apr 2023 08:41:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234606AbjDDMk5 (ORCPT ); Tue, 4 Apr 2023 08:40:57 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D41D90; Tue, 4 Apr 2023 05:40:54 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id ew6so129934757edb.7; Tue, 04 Apr 2023 05:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680612052; 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=7NWdR6MPB6XAokVEPIwltF2umB3WBqKQ7V2xA8hlx+8=; b=A2IrdkosuU5qJYIAvW+WrYNBZB12BQQqpN7XLYVE2WDD3CO0lAjDS+craxmRF4yOr8 VWgYmj6W6t6FVUYsBh2H+zX3+0PSiwwbio0FdfVaYa7wCbaFqxv9Kefl0oeY0DfR4Mkh 2r9l7gIGgn2N1btGcwHKWbfYxpyJPrO+dLFu69PTsOnZwLZprRHk9atL/e3c167J61Gw NM2yzEY3Km9KctkaAA/EG5BJfMpU5L6uO9y2MSyNIMXAKBfUFYSd4iZtavI9ioeyunj2 nYgOxitaCITguhG50Xf8SD83alXzdBbJmx2waWhFBGpZTPiWJNTmDWIRBtJABJ//oy4x ypug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680612052; 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=7NWdR6MPB6XAokVEPIwltF2umB3WBqKQ7V2xA8hlx+8=; b=SFwvFDgng3m7R6e+hPyc+JeFlMEiRCPXiXAJY+rua//iu8u7ov7PR54yOsKZw2Bb5j SBdz8MGoIaBojCuBoUWPUUUVHVSXiVPBc5XwfXvKSsOUojnwYXgKy6I2SMebtJQmgYjy jSmEb5DP0Gc62DLVJeCeebw2UlkUBdAI1+U2dgB9oEYKbEkaFGmmmnNAlxUC1GUAxcXI pQkLho85XqWW8ejoe49kWFOyuPp5nSXgyINVN6ffgYr/9X2dyQOyhc1DBY/yyxUmY0xf B+aDmXTBg394P03SFnxOaS2q8wjpViBcCCeXh5HsW683c4IRG3dzClccqVU8rjMttPWq 5VWg== X-Gm-Message-State: AAQBX9fICUpX1kz/VehSRF0ZjBQ0lnuStQFuSYEIazHlxsQ6gY3ibOii VR5EcBHxpS2UXhEZAJ+KSpDUh5dAnkY= X-Received: by 2002:a17:906:1786:b0:948:6e9c:273e with SMTP id t6-20020a170906178600b009486e9c273emr2242990eje.62.1680612052400; Tue, 04 Apr 2023 05:40:52 -0700 (PDT) Received: from 127.com ([2620:10d:c092:600::2:2b22]) by smtp.gmail.com with ESMTPSA id g8-20020a170906394800b008cafeec917dsm5978851eje.101.2023.04.04.05.40.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 05:40:52 -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 v2 03/13] io_uring: don't put nodes under spinlocks Date: Tue, 4 Apr 2023 13:39:47 +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?1762250673444656989?= X-GMAIL-MSGID: =?utf-8?q?1762250673444656989?= 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 a0b64831c455..596af20cddb4 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,