From patchwork Fri Jun 23 22:55:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13291442 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 D2170C001DC for ; Fri, 23 Jun 2023 22:55:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0599B8D0006; Fri, 23 Jun 2023 18:55:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 044468D0007; Fri, 23 Jun 2023 18:55:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D12F98D0006; Fri, 23 Jun 2023 18:55:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C00148D0001 for ; Fri, 23 Jun 2023 18:55:38 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 97C91140358 for ; Fri, 23 Jun 2023 22:55:38 +0000 (UTC) X-FDA: 80935521156.01.91F0ACB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf21.hostedemail.com (Postfix) with ESMTP id DAC511C0010 for ; Fri, 23 Jun 2023 22:55:35 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NHG1UTsY; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687560936; 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=+W533yCSJmnbFAFKHcDDwIUi7AghOBKSEvqiVzDK1MA=; b=xy2H2zmF4V8YfIgFhJ/ncHNIgzLj5PkFVMJLCpN0r6++PlK988WTMvQDadQ0uvKEXvfEY5 ehzjlSCC68TjchB1/+YxDqVpG2ZQ7Pet3qTGg5DbJKLzP8mXhLvFor4YfnMZHvVsQgVkK7 Yos1ivUW+I7bPUzMHYlRTXIhKXg7Rm0= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NHG1UTsY; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687560936; a=rsa-sha256; cv=none; b=pJ59uUAMT3mlRxJzI2rTF0h7XHN2+HEq4Bqud7mwRPedJpTBWZS212NZwvc0WJhNFkoxM8 THqC01bY0JpRmJrPUBQThl1E7++X1tgXuFIwGzzGNhUeFfXBQ6yjJpB8HpX2IZ2pH+w3vW sbQ0kjmD+CTnxTdZkggj7c6tmleMqYY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687560935; 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=+W533yCSJmnbFAFKHcDDwIUi7AghOBKSEvqiVzDK1MA=; b=NHG1UTsYXyzn13E5+Ms52Q5c/L2dNmcHkU0Rck1V56d0FJZJP91rmTujbYSitOUIwyvFfJ A3P6LxHtMaWJtzC0rpQ+FQX7lNu8V0n/1mIKPgOpQtUvl7SRZiw7nSiSgzglK2cyrlUuWo CSP3p0PxXi2CWDClF4l7k3QbE6smmWU= 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-319-HB5p8tLTOPecSH-Xsdm32Q-1; Fri, 23 Jun 2023 18:55:28 -0400 X-MC-Unique: HB5p8tLTOPecSH-Xsdm32Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 22F78101A54E; Fri, 23 Jun 2023 22:55:27 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5690840C2063; Fri, 23 Jun 2023 22:55:25 +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, Ilya Dryomov , Xiubo Li , Jeff Layton , ceph-devel@vger.kernel.org Subject: [PATCH net-next v5 03/16] ceph: Use sendmsg(MSG_SPLICE_PAGES) rather than sendpage Date: Fri, 23 Jun 2023 23:55:00 +0100 Message-ID: <20230623225513.2732256-4-dhowells@redhat.com> In-Reply-To: <20230623225513.2732256-1-dhowells@redhat.com> References: <20230623225513.2732256-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Queue-Id: DAC511C0010 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 7914h9t7g789zpqb85utsyupceoifcxx X-HE-Tag: 1687560935-940638 X-HE-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NE3JY1aDjlZL0iyUjCE9EhBB7YGj2lpVYM6eqzWgF6NG4b3fEmn+0Bg9G8P9qwBY2y49gqCVdrCwB7jBYnqf0X/yWcXjban2gpG7U6Fio+M0bWCH+qYqd2CJxpkLYBecNx17vbSJ/jc9Qnc5WwZMjjoIcU3vPh5vw7h2LVsX7ey11+3tJuImiAfYkbx3z4hIW1kh/GuqC2ny9EhF2C0VxpAW4vxPztat4yTQmifN2zNbHBFVUrKjzTA2HnYCEOmGc9I7jPJ4rNUJKXM2AQa5RHR1f7GnioWZBo3EzGJBAlgPl47wOyCkn/4bsqADpQGqPUXt7pCKVhtHxYBVjuvjETGYfNlH86SotnpQppQgA2fk/1b8QLfArH5oYnzs08b+tBsNPU20LYzDhK4srwY3UbrnG/aDSa6BcammY4bVx6AUnQFxWV8= 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: Use sendmsg() and MSG_SPLICE_PAGES rather than sendpage in ceph when transmitting data. For the moment, this can only transmit one page at a time because of the architecture of net/ceph/, but if write_partial_message_data() can be given a bvec[] at a time by the iteration code, this would allow pages to be sent in a batch. Signed-off-by: David Howells cc: Ilya Dryomov cc: Xiubo Li cc: Jeff Layton cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: ceph-devel@vger.kernel.org cc: netdev@vger.kernel.org --- Notes: ver #5) - Switch condition for setting MSG_MORE in write_partial_message_data() net/ceph/messenger_v1.c | 60 ++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/net/ceph/messenger_v1.c b/net/ceph/messenger_v1.c index d664cb1593a7..814579f27f04 100644 --- a/net/ceph/messenger_v1.c +++ b/net/ceph/messenger_v1.c @@ -74,37 +74,6 @@ static int ceph_tcp_sendmsg(struct socket *sock, struct kvec *iov, return r; } -/* - * @more: either or both of MSG_MORE and MSG_SENDPAGE_NOTLAST - */ -static int ceph_tcp_sendpage(struct socket *sock, struct page *page, - int offset, size_t size, int more) -{ - ssize_t (*sendpage)(struct socket *sock, struct page *page, - int offset, size_t size, int flags); - int flags = MSG_DONTWAIT | MSG_NOSIGNAL | more; - int ret; - - /* - * sendpage cannot properly handle pages with page_count == 0, - * we need to fall back to sendmsg if that's the case. - * - * Same goes for slab pages: skb_can_coalesce() allows - * coalescing neighboring slab objects into a single frag which - * triggers one of hardened usercopy checks. - */ - if (sendpage_ok(page)) - sendpage = sock->ops->sendpage; - else - sendpage = sock_no_sendpage; - - ret = sendpage(sock, page, offset, size, flags); - if (ret == -EAGAIN) - ret = 0; - - return ret; -} - static void con_out_kvec_reset(struct ceph_connection *con) { BUG_ON(con->v1.out_skip); @@ -464,7 +433,6 @@ static int write_partial_message_data(struct ceph_connection *con) struct ceph_msg *msg = con->out_msg; struct ceph_msg_data_cursor *cursor = &msg->cursor; bool do_datacrc = !ceph_test_opt(from_msgr(con->msgr), NOCRC); - int more = MSG_MORE | MSG_SENDPAGE_NOTLAST; u32 crc; dout("%s %p msg %p\n", __func__, con, msg); @@ -482,6 +450,10 @@ static int write_partial_message_data(struct ceph_connection *con) */ crc = do_datacrc ? le32_to_cpu(msg->footer.data_crc) : 0; while (cursor->total_resid) { + struct bio_vec bvec; + struct msghdr msghdr = { + .msg_flags = MSG_SPLICE_PAGES, + }; struct page *page; size_t page_offset; size_t length; @@ -493,10 +465,13 @@ static int write_partial_message_data(struct ceph_connection *con) } page = ceph_msg_data_next(cursor, &page_offset, &length); - if (length == cursor->total_resid) - more = MSG_MORE; - ret = ceph_tcp_sendpage(con->sock, page, page_offset, length, - more); + if (length != cursor->total_resid) + msghdr.msg_flags |= MSG_MORE; + + bvec_set_page(&bvec, page, length, page_offset); + iov_iter_bvec(&msghdr.msg_iter, ITER_SOURCE, &bvec, 1, length); + + ret = sock_sendmsg(con->sock, &msghdr); if (ret <= 0) { if (do_datacrc) msg->footer.data_crc = cpu_to_le32(crc); @@ -526,7 +501,10 @@ static int write_partial_message_data(struct ceph_connection *con) */ static int write_partial_skip(struct ceph_connection *con) { - int more = MSG_MORE | MSG_SENDPAGE_NOTLAST; + struct bio_vec bvec; + struct msghdr msghdr = { + .msg_flags = MSG_SPLICE_PAGES | MSG_MORE, + }; int ret; dout("%s %p %d left\n", __func__, con, con->v1.out_skip); @@ -534,9 +512,11 @@ static int write_partial_skip(struct ceph_connection *con) size_t size = min(con->v1.out_skip, (int)PAGE_SIZE); if (size == con->v1.out_skip) - more = MSG_MORE; - ret = ceph_tcp_sendpage(con->sock, ceph_zero_page, 0, size, - more); + msghdr.msg_flags &= ~MSG_MORE; + bvec_set_page(&bvec, ZERO_PAGE(0), size, 0); + iov_iter_bvec(&msghdr.msg_iter, ITER_SOURCE, &bvec, 1, size); + + ret = sock_sendmsg(con->sock, &msghdr); if (ret <= 0) goto out; con->v1.out_skip -= ret;