Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp34484802rwd; Sun, 9 Jul 2023 13:07:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlEvpt4cldzcManZV4ISQrBkzaChKhESGkal8anoqIbAGJ1dEcWc5AkjBoHYlRQSIfpxbjT/ X-Received: by 2002:a05:6512:1116:b0:4f8:74b5:b4ec with SMTP id l22-20020a056512111600b004f874b5b4ecmr10741688lfg.41.1688933264359; Sun, 09 Jul 2023 13:07:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688933264; cv=none; d=google.com; s=arc-20160816; b=CxJiEdYP392MjO4bfRsTQX4KmPuK5SnFX3wu91YHyeP0jRYHNvY0FK17whrVxYvF9U bo+Kf/lMqZ4cpYsbU72HwuiP0t5HPepdT27bUOQud/qwRfyrBRUL93Y7IusdERQrT7Yx FTScTnK560WBoYV3MzD1smKi7Wt7XA8ragK8pUuBHgrxUQ7eeswtrGdzpVEBGyYO3ZxV PMM2gxhpRjrDeGCHigG/oHR0fHJ4UfsHqA/EW85dRmcwblLQ/5wH3WfpKCSAFygndid6 I0tNaRCaq4rUsgtJJWY0d21qXgjlUuBP20f1G9qvUBYWQJ9omRtdnSQvBkwFJ7Kh7kAR cwow== 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 :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:dkim-signature; bh=X9DbMze5yqeIT2sGARV1aRU+d+pVKo64HJoYB9Vhtg4=; fh=iQHwiA7FZuvMYxj4m3vUghWUupm1yRArsFyW9hT/dD4=; b=UV3k+ZVX+0KQTulJgibHVdjvvzcVy90ceHc4s+VNm93KA7wqk3d6Kyflysphk7OA85 x9Cvh7/VnF04EZ0QVpHgcewddDn7g49I0TYuXDTrWSmZqGzHreXhLrlQuCH+NDPvPB+6 Nx8MsvB2//H0nHxYpYKhFF1F3h4pnOxQU835wKek1sGysq+rERB8lR02awYoIfn7R2uL DciiCJfuVNV6sNQNa6KGvBFCYTVsTAEehyGLwsW8U7JBlgX83/7LsRQc1mpOjCkCuC5g jpMweua7M9pcspA5AaeX4tyPgCr6XOk7V58WWJFcMc8igzwCsPHrLAgYaTtyjx22aq6e wEsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oyY8eUPF; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w10-20020aa7cb4a000000b0051dd3277614si7440165edt.137.2023.07.09.13.07.19; Sun, 09 Jul 2023 13:07:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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=@kernel.org header.s=k20201202 header.b=oyY8eUPF; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229624AbjGIUFW (ORCPT + 99 others); Sun, 9 Jul 2023 16:05:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjGIUFV (ORCPT ); Sun, 9 Jul 2023 16:05:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F466FE for ; Sun, 9 Jul 2023 13:05:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F22F760C20 for ; Sun, 9 Jul 2023 20:05:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2FA5CC433C8; Sun, 9 Jul 2023 20:05:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688933119; bh=f6izZdO3VuQUntLxWUjulGDu7AYVq4c1pjyxSeg2vZU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=oyY8eUPF/0med4CPeMC5FGwDSUh0l1qGh+uXCOXlkojZOP4KfzNSX/WKWCheRkWXR 1otknn1YBf74GKmgUFKHeq8SyXHScONivQP5kdTbA40CP+XmyoO6IuJz7Y0ap3m57W rNgWC0Bk8oHwbGLt1ukY9BHySqLUn+QG0MwFAOh/lm3pGAaRoLcqPUU3IzRogUmDUS lAQuQv8ED8YU7Ul3qASqiS9Kall+F+tJqjXCRs3AK4GPl7GwHdr7ghC03oV5GxwmPY J9oRyuNzAZESLzwu/Kn2WJ/b3+iSD3UHXb15iizPyb6jH6s4+3JvUZikuMFV47DRG0 /H4qJhsoiLuyA== Subject: [PATCH RFC 4/4] SUNRPC: Send RPC message on TCP with a single sock_sendmsg() call From: Chuck Lever To: linux-nfs@vger.kernel.org Cc: David Howells , Chuck Lever , dhowells@redhat.com Date: Sun, 09 Jul 2023 16:05:18 -0400 Message-ID: <168893311819.1949.12216126239653940727.stgit@manet.1015granger.net> In-Reply-To: <168893265677.1949.1632048925203798962.stgit@manet.1015granger.net> References: <168893265677.1949.1632048925203798962.stgit@manet.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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-nfs@vger.kernel.org From: Chuck Lever There is now enough infrastructure in place to combine the stream record marker into the biovec array used to send each outgoing RPC message. The whole message can be more efficiently sent with a single call to sock_sendmsg() using a bio_vec iterator. Note that this also helps with RPC-with-TLS: the TLS implementation can now clearly see where the upper layer message boundaries are. Before, it would send each component of the xdr_buf in a separate TLS record. Suggested-by: David Howells Signed-off-by: Chuck Lever --- include/linux/sunrpc/svcsock.h | 2 ++ net/sunrpc/svcsock.c | 33 ++++++++++++++++++--------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/include/linux/sunrpc/svcsock.h b/include/linux/sunrpc/svcsock.h index 4efae760f3cb..55446136499f 100644 --- a/include/linux/sunrpc/svcsock.h +++ b/include/linux/sunrpc/svcsock.h @@ -38,6 +38,8 @@ struct svc_sock { /* Number of queued send requests */ atomic_t sk_sendqlen; + struct page_frag_cache sk_frag_cache; + struct completion sk_handshake_done; struct bio_vec sk_recv_bvec[RPCSVC_MAXPAGES] diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c index 6f672cb0b0b3..19cab73229e4 100644 --- a/net/sunrpc/svcsock.c +++ b/net/sunrpc/svcsock.c @@ -1247,29 +1247,28 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp) static int svc_tcp_sendmsg(struct svc_sock *svsk, struct xdr_buf *xdr, rpc_fraghdr marker, unsigned int *sentp) { - struct kvec rm = { - .iov_base = &marker, - .iov_len = sizeof(marker), - }; struct msghdr msg = { - .msg_flags = MSG_MORE, + .msg_flags = MSG_SPLICE_PAGES, }; unsigned int count; + void *tmp; int ret; *sentp = 0; - ret = kernel_sendmsg(svsk->sk_sock, &msg, &rm, 1, rm.iov_len); - if (ret < 0) - return ret; - *sentp += ret; - if (ret != rm.iov_len) - return -EAGAIN; - - count = svc_sock_xdr_to_bvecs(svsk->sk_send_bvec, xdr); - msg.msg_flags = MSG_SPLICE_PAGES; + /* The stream record marker is copied into a temporary page + * buffer so that it can be included in sk_send_bvec. + */ + tmp = page_frag_alloc(&svsk->sk_frag_cache, sizeof(marker), + GFP_KERNEL); + if (!tmp) + return -ENOMEM; + memcpy(tmp, &marker, sizeof(marker)); + bvec_set_virt(svsk->sk_send_bvec, tmp, sizeof(marker)); + + count = svc_sock_xdr_to_bvecs(svsk->sk_send_bvec + 1, xdr); iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, svsk->sk_send_bvec, - count, xdr->len); + 1 + count, sizeof(marker) + xdr->len); ret = sock_sendmsg(svsk->sk_sock, &msg); if (ret < 0) return ret; @@ -1648,6 +1647,7 @@ static void svc_tcp_sock_detach(struct svc_xprt *xprt) static void svc_sock_free(struct svc_xprt *xprt) { struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt); + struct page_frag_cache *pfc = &svsk->sk_frag_cache; struct socket *sock = svsk->sk_sock; trace_svcsock_free(svsk, sock); @@ -1657,5 +1657,8 @@ static void svc_sock_free(struct svc_xprt *xprt) sockfd_put(sock); else sock_release(sock); + if (pfc->va) + __page_frag_cache_drain(virt_to_head_page(pfc->va), + pfc->pagecnt_bias); kfree(svsk); }