From patchwork Fri Jul 8 18:18:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Yudaken X-Patchwork-Id: 12911604 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 2454EC43334 for ; Fri, 8 Jul 2022 18:19:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238810AbiGHSTA (ORCPT ); Fri, 8 Jul 2022 14:19:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238535AbiGHSSy (ORCPT ); Fri, 8 Jul 2022 14:18:54 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA114823B0 for ; Fri, 8 Jul 2022 11:18:53 -0700 (PDT) Received: from pps.filterd (m0148460.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 268HAatO027372 for ; Fri, 8 Jul 2022 11:18:52 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=lgcixcPTzwnEb+MWYgxBSwdUAkCiiDjL6xo5mS4d2w4=; b=fRtfEihPBbKOVWpjil52uDyJVPZhPMl5x8J8xS251lF1xUDXy/Ygy+LriXOl2DoeUKNs uRE62feq0RSJvhvG5EVKRjtvMSdwL0Vjq4EPNKCLfFEOfP53yI4rsJ+tNnDoI+HemUL7 ZNQS7H7XhfNtyDuEry6oOxWh+wyX71On94A= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3h6eg1ky5r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 08 Jul 2022 11:18:52 -0700 Received: from twshared25478.08.ash9.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:21d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Fri, 8 Jul 2022 11:18:51 -0700 Received: by devbig038.lla2.facebook.com (Postfix, from userid 572232) id 49AD12B9EC58; Fri, 8 Jul 2022 11:18:43 -0700 (PDT) From: Dylan Yudaken To: Jens Axboe , Pavel Begunkov , CC: , Dylan Yudaken Subject: [PATCH for-next 4/4] io_uring: move netmsg recycling into io_uring cleanup Date: Fri, 8 Jul 2022 11:18:38 -0700 Message-ID: <20220708181838.1495428-5-dylany@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220708181838.1495428-1-dylany@fb.com> References: <20220708181838.1495428-1-dylany@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: GZ3rZkJv6jImhti-lLFuOFA-kZ1mbTyI X-Proofpoint-GUID: GZ3rZkJv6jImhti-lLFuOFA-kZ1mbTyI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-08_14,2022-07-08_01,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Specifically will be useful for multishot as the lifetime of a request is a bit more complicated, but generally makes things a bit neater. Signed-off-by: Dylan Yudaken --- io_uring/net.c | 10 ++++------ io_uring/net.h | 1 + io_uring/opdef.c | 2 ++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/io_uring/net.c b/io_uring/net.c index 997c17512694..c1cbafe96c63 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -98,18 +98,18 @@ static bool io_net_retry(struct socket *sock, int flags) return sock->type == SOCK_STREAM || sock->type == SOCK_SEQPACKET; } -static void io_netmsg_recycle(struct io_kiocb *req, unsigned int issue_flags) +bool io_netmsg_recycle(struct io_kiocb *req) { struct io_async_msghdr *hdr = req->async_data; - if (!hdr || issue_flags & IO_URING_F_UNLOCKED) - return; - if (io_alloc_cache_store(&req->ctx->netmsg_cache)) { hlist_add_head(&hdr->cache_list, &req->ctx->netmsg_cache.list); req->async_data = NULL; req->flags &= ~REQ_F_ASYNC_DATA; + return true; } + + return false; } static struct io_async_msghdr *io_recvmsg_alloc_async(struct io_kiocb *req, @@ -261,7 +261,6 @@ int io_sendmsg(struct io_kiocb *req, unsigned int issue_flags) if (kmsg->free_iov) kfree(kmsg->free_iov); req->flags &= ~REQ_F_NEED_CLEANUP; - io_netmsg_recycle(req, issue_flags); if (ret >= 0) ret += sr->done_io; else if (sr->done_io) @@ -583,7 +582,6 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) /* fast path, check for non-NULL to avoid function call */ if (kmsg->free_iov) kfree(kmsg->free_iov); - io_netmsg_recycle(req, issue_flags); req->flags &= ~REQ_F_NEED_CLEANUP; if (ret > 0) ret += sr->done_io; diff --git a/io_uring/net.h b/io_uring/net.h index 576efb602c7f..c5a897e61f10 100644 --- a/io_uring/net.h +++ b/io_uring/net.h @@ -44,6 +44,7 @@ int io_connect_prep_async(struct io_kiocb *req); int io_connect_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); int io_connect(struct io_kiocb *req, unsigned int issue_flags); +bool io_netmsg_recycle(struct io_kiocb *req); void io_flush_netmsg_cache(struct io_ring_ctx *ctx); #else static inline void io_flush_netmsg_cache(struct io_ring_ctx *ctx) diff --git a/io_uring/opdef.c b/io_uring/opdef.c index a7b84b43e6c2..b525e37f397a 100644 --- a/io_uring/opdef.c +++ b/io_uring/opdef.c @@ -153,6 +153,7 @@ const struct io_op_def io_op_defs[] = { .issue = io_sendmsg, .prep_async = io_sendmsg_prep_async, .cleanup = io_sendmsg_recvmsg_cleanup, + .recycle_async = io_netmsg_recycle, #else .prep = io_eopnotsupp_prep, #endif @@ -170,6 +171,7 @@ const struct io_op_def io_op_defs[] = { .issue = io_recvmsg, .prep_async = io_recvmsg_prep_async, .cleanup = io_sendmsg_recvmsg_cleanup, + .recycle_async = io_netmsg_recycle, #else .prep = io_eopnotsupp_prep, #endif