Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2126196rwl; Thu, 30 Mar 2023 06:25:31 -0700 (PDT) X-Google-Smtp-Source: AK7set85rWKP4MGjA4g9zyH7NgvlsyanYhM9rWNxyinzlCplBYbVEDH6st4JYrqNQ7pFqD4reSGS X-Received: by 2002:a05:6a20:6d17:b0:d5:6e91:f019 with SMTP id fv23-20020a056a206d1700b000d56e91f019mr19521924pzb.33.1680182731234; Thu, 30 Mar 2023 06:25:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680182731; cv=none; d=google.com; s=arc-20160816; b=bW48heirsDuqxh80UvSZwhTpnFPMsHaO9mDInuXDac564pJhWdc4oJtTbgLoC99hzj tRYQ24g6yZiMVkrpWUSswnqupwRJzaJRr8+nkA418tlDa5PDfzo9R8fQ347okMnVFl4Q HC+lvQalYcACVeAEwnbLrBmn1kH6F+DA31PVkumhFKBhCLDNcUPvwcF3sEWKosAQ7yq0 gzoSIrACdB2VIksTVsPP7tGiu6uo0b7MiHJ8C2HDC2Dsaox6Gx2QA9CShg65E6KkwKzK IYceObwUxkWgje5AW6iRs/pOE+WE+jDEZmanZYv4fxr/y3ryJa/TTgMYB2S/mac7e+uY Z61A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:content-transfer-encoding :content-id:mime-version:subject:cc:to:references:in-reply-to:from :organization:dkim-signature; bh=RJ8WcoQow4ucTg8JtWmjD6YfkfaI8HhqF7kGxaQnvWc=; b=LRCUX8UaMFjrWohbpl6T2dw557/DHYFf8fcowCpwfjhBBNjoHSR9mnRkCEcGUjSxTp PTMLutKXF0ubqSqMq1sjYfH6xEKYWji3odVWzZjhhw16aATYu0uxUb51BDv/gUSdiF40 pUTfC1UJmHPDxkWRiemFniGFr6V6YC0vZQiz5Ec5disRRic/g57Oma6lfDwMG/lS+2wu wxp6oQPXbQEP7+r9ySVej0HSwIik/M+bwkITdhU4LA0HoMgdvencsczGYgxA6Kpo/49U KByevMkz7n07sj/RTGUiTlZ92MlXpmKoMUHhpn+dTjnVV6TAsiFc7VFw5D4ooEP6jgW5 ocAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bUjrdYsB; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i9-20020a635409000000b0051391dd5dbcsi2483197pgb.566.2023.03.30.06.25.12; Thu, 30 Mar 2023 06:25:31 -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=@redhat.com header.s=mimecast20190719 header.b=bUjrdYsB; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231835AbjC3NR3 (ORCPT + 99 others); Thu, 30 Mar 2023 09:17:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbjC3NR2 (ORCPT ); Thu, 30 Mar 2023 09:17:28 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29137AD05 for ; Thu, 30 Mar 2023 06:16:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680182200; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RJ8WcoQow4ucTg8JtWmjD6YfkfaI8HhqF7kGxaQnvWc=; b=bUjrdYsBhZFOIg8AhP9clHLJvE128GPkqABHRaGwUCF5q88pI9UlvR0/maFr2bb7eJFOse S1R0j/CS11pd7+9BaN4dqjBIlLGjRPAFvGZqFntQIHy+1uqL5paczK5NVwKBG5yn1Pi/oy Va1pnrDjbUh2wCPnbiWJdvONX5e+Uqs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-662-RKrPMFXCPma0vF7S411Crg-1; Thu, 30 Mar 2023 09:16:35 -0400 X-MC-Unique: RKrPMFXCPma0vF7S411Crg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A788C8028B2; Thu, 30 Mar 2023 13:16:33 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E391492B00; Thu, 30 Mar 2023 13:16:31 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <812034.1680181285@warthog.procyon.org.uk> References: <812034.1680181285@warthog.procyon.org.uk> <6F2985FF-2474-4F36-BD94-5F8E97E46AC2@oracle.com> <20230329141354.516864-1-dhowells@redhat.com> <20230329141354.516864-41-dhowells@redhat.com> To: Chuck Lever III Cc: dhowells@redhat.com, Matthew Wilcox , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Al Viro , Christoph Hellwig , Jens Axboe , Jeff Layton , Christian Brauner , Linus Torvalds , "open list:NETWORKING [GENERAL]" , linux-fsdevel , Linux Kernel Mailing List , Linux Memory Management List , Trond Myklebust , Anna Schumaker , Linux NFS Mailing List Subject: Re: [RFC PATCH v2 40/48] sunrpc: Use sendmsg(MSG_SPLICE_PAGES) rather then sendpage MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <812754.1680182190.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Thu, 30 Mar 2023 14:16:30 +0100 Message-ID: <812755.1680182190@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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-nfs@vger.kernel.org David Howells wrote: > Chuck Lever III wrote: > = > > Simply replacing the kernel_sendpage() loop would be a > > straightforward change and easy to evaluate and test, and > > I'd welcome that without hesitation. > = > How about the attached for a first phase? > = > It does three sendmsgs, one for the marker + header, one for the body an= d one > for the tail. ... And this as a second phase. David --- sunrpc: Allow xdr->bvec[] to be extended to do a single sendmsg Allow xdr->bvec[] to be extended and insert the marker, the header and the tail into it so that a single sendmsg() can be used to transmit the messag= e. I wonder if it would be possible to insert the marker at the beginning of = the head buffer. Signed-off-by: David Howells cc: Trond Myklebust cc: Anna Schumaker cc: Chuck Lever cc: Jeff Layton cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: linux-nfs@vger.kernel.org cc: netdev@vger.kernel.org --- include/linux/sunrpc/xdr.h | 2 - net/sunrpc/svcsock.c | 46 ++++++++++++++-------------------------= ------ net/sunrpc/xdr.c | 19 ++++++++++-------- net/sunrpc/xprtsock.c | 6 ++--- 4 files changed, 30 insertions(+), 43 deletions(-) diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h index 72014c9216fc..c74ea483228b 100644 --- a/include/linux/sunrpc/xdr.h +++ b/include/linux/sunrpc/xdr.h @@ -137,7 +137,7 @@ void xdr_inline_pages(struct xdr_buf *, unsigned int, struct page **, unsigned int, unsigned int); void xdr_terminate_string(const struct xdr_buf *, const u32); size_t xdr_buf_pagecount(const struct xdr_buf *buf); -int xdr_alloc_bvec(struct xdr_buf *buf, gfp_t gfp); +int xdr_alloc_bvec(struct xdr_buf *buf, gfp_t gfp, unsigned int head, uns= igned int tail); void xdr_free_bvec(struct xdr_buf *buf); = static inline __be32 *xdr_encode_array(__be32 *p, const void *s, unsigned= int len) diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c index 14efcc08c6f8..e55761fe1ccf 100644 --- a/net/sunrpc/svcsock.c +++ b/net/sunrpc/svcsock.c @@ -569,7 +569,7 @@ static int svc_udp_sendto(struct svc_rqst *rqstp) if (svc_xprt_is_dead(xprt)) goto out_notconn; = - err =3D xdr_alloc_bvec(xdr, GFP_KERNEL); + err =3D xdr_alloc_bvec(xdr, GFP_KERNEL, 0, 0); if (err < 0) goto out_unlock; = @@ -1073,45 +1073,29 @@ static int svc_tcp_sendmsg(struct socket *sock, st= ruct xdr_buf *xdr, { const struct kvec *head =3D xdr->head; const struct kvec *tail =3D xdr->tail; - struct kvec kv[2]; - struct msghdr msg =3D { .msg_flags =3D MSG_SPLICE_PAGES | MSG_MORE, }; - size_t sent; + struct msghdr msg =3D { .msg_flags =3D MSG_SPLICE_PAGES, }; + size_t n; int ret; = *sentp =3D 0; - ret =3D xdr_alloc_bvec(xdr, GFP_KERNEL); + ret =3D xdr_alloc_bvec(xdr, GFP_KERNEL, 2, 1); if (ret < 0) return ret; = - kv[0].iov_base =3D ▮ - kv[0].iov_len =3D sizeof(marker); - kv[1] =3D *head; - iov_iter_kvec(&msg.msg_iter, ITER_SOURCE, kv, 2, sizeof(marker) + head->= iov_len); + n =3D 2 + xdr_buf_pagecount(xdr); + bvec_set_virt(&xdr->bvec[0], &marker, sizeof(marker)); + bvec_set_virt(&xdr->bvec[1], head->iov_base, head->iov_len); + bvec_set_virt(&xdr->bvec[n], tail->iov_base, tail->iov_len); + if (tail->iov_len) + n++; + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, xdr->bvec, n, + sizeof(marker) + xdr->len); ret =3D sock_sendmsg(sock, &msg); if (ret < 0) return ret; - sent =3D ret; - - if (!tail->iov_len) - msg.msg_flags &=3D ~MSG_MORE; - iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, xdr->bvec, - xdr_buf_pagecount(xdr), xdr->page_len); - ret =3D sock_sendmsg(sock, &msg); - if (ret < 0) - return ret; - sent +=3D ret; - - if (tail->iov_len) { - msg.msg_flags &=3D ~MSG_MORE; - iov_iter_kvec(&msg.msg_iter, ITER_SOURCE, tail, 1, tail->iov_len); - ret =3D sock_sendmsg(sock, &msg); - if (ret < 0) - return ret; - sent +=3D ret; - } - if (sent > 0) - *sentp =3D sent; - if (sent !=3D sizeof(marker) + xdr->len) + if (ret > 0) + *sentp =3D ret; + if (ret !=3D sizeof(marker) + xdr->len) return -EAGAIN; return 0; } diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c index 36835b2f5446..695821963849 100644 --- a/net/sunrpc/xdr.c +++ b/net/sunrpc/xdr.c @@ -141,18 +141,21 @@ size_t xdr_buf_pagecount(const struct xdr_buf *buf) } = int -xdr_alloc_bvec(struct xdr_buf *buf, gfp_t gfp) +xdr_alloc_bvec(struct xdr_buf *buf, gfp_t gfp, unsigned int head, unsigne= d int tail) { - size_t i, n =3D xdr_buf_pagecount(buf); + size_t i, j =3D 0, n =3D xdr_buf_pagecount(buf); = - if (n !=3D 0 && buf->bvec =3D=3D NULL) { - buf->bvec =3D kmalloc_array(n, sizeof(buf->bvec[0]), gfp); + if (head + n + tail !=3D 0 && buf->bvec =3D=3D NULL) { + buf->bvec =3D kmalloc_array(head + n + tail, + sizeof(buf->bvec[0]), gfp); if (!buf->bvec) return -ENOMEM; - for (i =3D 0; i < n; i++) { - bvec_set_page(&buf->bvec[i], buf->pages[i], PAGE_SIZE, - 0); - } + for (i =3D 0; i < head; i++) + bvec_set_page(&buf->bvec[j++], NULL, 0, 0); + for (i =3D 0; i < n; i++) + bvec_set_page(&buf->bvec[j++], buf->pages[i], PAGE_SIZE, 0); + for (i =3D 0; i < tail; i++) + bvec_set_page(&buf->bvec[j++], NULL, 0, 0); } return 0; } diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index adcbedc244d6..fdf67e84b1c7 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -825,7 +825,7 @@ static int xs_stream_nospace(struct rpc_rqst *req, boo= l vm_wait) = static int xs_stream_prepare_request(struct rpc_rqst *req, struct xdr_buf= *buf) { - return xdr_alloc_bvec(buf, rpc_task_gfp_mask()); + return xdr_alloc_bvec(buf, rpc_task_gfp_mask(), 0, 0); } = /* @@ -954,7 +954,7 @@ static int xs_udp_send_request(struct rpc_rqst *req) if (!xprt_request_get_cong(xprt, req)) return -EBADSLT; = - status =3D xdr_alloc_bvec(xdr, rpc_task_gfp_mask()); + status =3D xdr_alloc_bvec(xdr, rpc_task_gfp_mask(), 0, 0); if (status < 0) return status; req->rq_xtime =3D ktime_get(); @@ -2591,7 +2591,7 @@ static int bc_sendto(struct rpc_rqst *req) int err; = req->rq_xtime =3D ktime_get(); - err =3D xdr_alloc_bvec(xdr, rpc_task_gfp_mask()); + err =3D xdr_alloc_bvec(xdr, rpc_task_gfp_mask(), 0, 0); if (err < 0) return err; err =3D xprt_sock_sendmsg(transport->sock, &msg, xdr, 0, marker, &sent);