From patchwork Fri Jun 23 11:44:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13290406 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88FB6C0015E for ; Fri, 23 Jun 2023 11:44:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D79D18D0009; Fri, 23 Jun 2023 07:44:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D022F8D0001; Fri, 23 Jun 2023 07:44:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7AE08D0009; Fri, 23 Jun 2023 07:44:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A9FD98D0001 for ; Fri, 23 Jun 2023 07:44:55 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2646C80F08 for ; Fri, 23 Jun 2023 11:44:55 +0000 (UTC) X-FDA: 80933830950.04.CF295F4 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 6297440009 for ; Fri, 23 Jun 2023 11:44:53 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dy96EYlB; spf=pass (imf04.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687520693; a=rsa-sha256; cv=none; b=p2ulDPewEWZny7sKrgax8ZDdIcsAt4OVlKTDuDEgUtU4xcLUNd6PDHzoaurt7/pbPjGmps NZ1GgRH/5M04XcM7zCaPQ5UzEQYlobNnaW86RkoIbo95t8gpDv4S+n04b+UJrhSkWbkW7u oqpMQNLiO0XXrlhBaehaS0cwkaXIEEE= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dy96EYlB; spf=pass (imf04.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687520693; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=W+/sbivnn4SSL91vpgGdKmYtGhKmLadJeuepui2ZFTU=; b=BDdB2LYSem5nlvSphMjFFwWqVMT4HMEgslPRtx6tTkVyTQqkfU2QbcstWVf126lw25bn+s KFaW+sAWec2vERPGGzC8VFsiH0rVaGJV39M/KTRqKMOftqx+h6kB8eWh46KgHjswqMccOU qY3qOXhGI3km4T72lG2syqLsCiXru88= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687520692; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=W+/sbivnn4SSL91vpgGdKmYtGhKmLadJeuepui2ZFTU=; b=dy96EYlBj3JFeXvB7wqQYeyUzVWvOtGsIdJk7b1ovwXZ6byitbKuDahDCqXLPKM/wkyLFZ ON+sFxtnpwJ0ytfTAP2Lktbw6gKtmBcA4m0EG6iWQ0q1661G7RX73eO0iGmAUV3RzpWO/a QZTNbqwOcuG3icFrC47MiyBbIND8WsI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-547-oy5Qkzx6N9eqWFkhdXf48g-1; Fri, 23 Jun 2023 07:44:48 -0400 X-MC-Unique: oy5Qkzx6N9eqWFkhdXf48g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6CCDC3C0F696; Fri, 23 Jun 2023 11:44:47 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 52893C1ED97; Fri, 23 Jun 2023 11:44:45 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , Alexander Duyck , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sagi Grimberg , Willem de Bruijn , Keith Busch , Jens Axboe , Christoph Hellwig , Chaitanya Kulkarni , linux-nvme@lists.infradead.org Subject: [PATCH net-next v4 07/15] nvme-tcp: Use sendmsg(MSG_SPLICE_PAGES) rather then sendpage Date: Fri, 23 Jun 2023 12:44:17 +0100 Message-ID: <20230623114425.2150536-8-dhowells@redhat.com> In-Reply-To: <20230623114425.2150536-1-dhowells@redhat.com> References: <20230623114425.2150536-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 6297440009 X-Stat-Signature: 6nmh35cf75mg47cj4rdf44e9ssh58zrk X-Rspam-User: X-HE-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DMrA6dXLR5XoX2+FkpWvBkUv3voLrRznHdVhMgHlZJpTQ750oF72TQI+EBMDOZ+dNbm8Ry1/i06Lbcn1YOdqjrUrOpBpqQMlxgd0OrDu2jkSL40iiU0YVlIZKIRget+E9SKCCLFmaPT9hYPP7paoEYKYHylBlgAEmQz82QeSGAVQqd0yItbNII4Leok+nKiIMPXxi/wYsvlB+vzPvV083zOyQIUggJGJI4qqWBgAaSOqosrU2g6uLXdxDi4WwC8yzmGgU59YdQId+0a7IjTLS7aCVRFtRhWsdLq7/Bw2DKk6aE26fh5znG9zPmlLh8WAXuRGTUKNxkAu0gjoNM6Y+yK/zTpzAfKftdIFuG6UPKTTajPP30UBbndRzBbm/k7TRsQnkyZ0LwBiurJv+b7/YJZF/JPHb4EG5ycyTbB6dogXC/xUHQ5a8QQ/NE5eVyfslRnH9muugQvcVKWUNno+qyhJnyOtwmvMQ3INaoFivbrAsNme7V2+H8bEr6VLMikmzozcLKOWH5GgUafUoAJY8pc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When transmitting data, call down into TCP using a sendmsg with MSG_SPLICE_PAGES instead of sendpage. Signed-off-by: David Howells Tested-by: Sagi Grimberg Acked-by: Willem de Bruijn cc: Keith Busch cc: Jens Axboe cc: Christoph Hellwig cc: Chaitanya Kulkarni cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: linux-nvme@lists.infradead.org cc: netdev@vger.kernel.org --- Notes: ver #4) - Cancel MSG_SPLICE_PAGES if the page being sent fails sendpage_ok(). ver #3) - Split nvme/host from nvme/target changes. ver #2) - Wrap lines at 80. drivers/nvme/host/tcp.c | 49 +++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index bf0230442d57..47ae17f16c05 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -997,25 +997,28 @@ static int nvme_tcp_try_send_data(struct nvme_tcp_request *req) u32 h2cdata_left = req->h2cdata_left; while (true) { + struct bio_vec bvec; + struct msghdr msg = { + .msg_flags = MSG_DONTWAIT | MSG_SPLICE_PAGES, + }; struct page *page = nvme_tcp_req_cur_page(req); size_t offset = nvme_tcp_req_cur_offset(req); size_t len = nvme_tcp_req_cur_length(req); bool last = nvme_tcp_pdu_last_send(req, len); int req_data_sent = req->data_sent; - int ret, flags = MSG_DONTWAIT; + int ret; if (last && !queue->data_digest && !nvme_tcp_queue_more(queue)) - flags |= MSG_EOR; + msg.msg_flags |= MSG_EOR; else - flags |= MSG_MORE | MSG_SENDPAGE_NOTLAST; + msg.msg_flags |= MSG_MORE; - if (sendpage_ok(page)) { - ret = kernel_sendpage(queue->sock, page, offset, len, - flags); - } else { - ret = sock_no_sendpage(queue->sock, page, offset, len, - flags); - } + if (!sendpage_ok(page)) + msg.msg_flags &= ~MSG_SPLICE_PAGES, + + bvec_set_page(&bvec, page, len, offset); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, len); + ret = sock_sendmsg(queue->sock, &msg); if (ret <= 0) return ret; @@ -1054,22 +1057,24 @@ static int nvme_tcp_try_send_cmd_pdu(struct nvme_tcp_request *req) { struct nvme_tcp_queue *queue = req->queue; struct nvme_tcp_cmd_pdu *pdu = nvme_tcp_req_cmd_pdu(req); + struct bio_vec bvec; + struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_SPLICE_PAGES, }; bool inline_data = nvme_tcp_has_inline_data(req); u8 hdgst = nvme_tcp_hdgst_len(queue); int len = sizeof(*pdu) + hdgst - req->offset; - int flags = MSG_DONTWAIT; int ret; if (inline_data || nvme_tcp_queue_more(queue)) - flags |= MSG_MORE | MSG_SENDPAGE_NOTLAST; + msg.msg_flags |= MSG_MORE; else - flags |= MSG_EOR; + msg.msg_flags |= MSG_EOR; if (queue->hdr_digest && !req->offset) nvme_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); - ret = kernel_sendpage(queue->sock, virt_to_page(pdu), - offset_in_page(pdu) + req->offset, len, flags); + bvec_set_virt(&bvec, (void *)pdu + req->offset, len); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, len); + ret = sock_sendmsg(queue->sock, &msg); if (unlikely(ret <= 0)) return ret; @@ -1093,6 +1098,8 @@ static int nvme_tcp_try_send_data_pdu(struct nvme_tcp_request *req) { struct nvme_tcp_queue *queue = req->queue; struct nvme_tcp_data_pdu *pdu = nvme_tcp_req_data_pdu(req); + struct bio_vec bvec; + struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_MORE, }; u8 hdgst = nvme_tcp_hdgst_len(queue); int len = sizeof(*pdu) - req->offset + hdgst; int ret; @@ -1101,13 +1108,11 @@ static int nvme_tcp_try_send_data_pdu(struct nvme_tcp_request *req) nvme_tcp_hdgst(queue->snd_hash, pdu, sizeof(*pdu)); if (!req->h2cdata_left) - ret = kernel_sendpage(queue->sock, virt_to_page(pdu), - offset_in_page(pdu) + req->offset, len, - MSG_DONTWAIT | MSG_MORE | MSG_SENDPAGE_NOTLAST); - else - ret = sock_no_sendpage(queue->sock, virt_to_page(pdu), - offset_in_page(pdu) + req->offset, len, - MSG_DONTWAIT | MSG_MORE); + msg.msg_flags |= MSG_SPLICE_PAGES; + + bvec_set_virt(&bvec, (void *)pdu + req->offset, len); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, len); + ret = sock_sendmsg(queue->sock, &msg); if (unlikely(ret <= 0)) return ret;