Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2883426rwd; Fri, 16 Jun 2023 09:19:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7XCiZlxdkt8mouKj4bkzoKD7InvXjBV+rzb3nfRDTT7byq98EvVAepc384UG6MKL720QgM X-Received: by 2002:a17:902:e847:b0:1b3:ea47:796c with SMTP id t7-20020a170902e84700b001b3ea47796cmr2447507plg.29.1686932391467; Fri, 16 Jun 2023 09:19:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686932391; cv=none; d=google.com; s=arc-20160816; b=jwf32XGG4vTcQ+YAaS22pKvG2fSsWXcwSOJr9E4P+h63yneFkIasjN13AaWv3GTa9B AG2uY8opyY2bFn+CQOpdJ6F0Sgze1DXW+9PGCkfVswBm/kNbkgd10bd/rHSnbviibrUH ePYA7fwQ5rYhWjfaLyRIns3Gsi0z0imfIZsi74qbxgl+r8YYAIfWYlnSeGJnRDcxNAF+ dloV3oD3k8bJ7YXjiPLlO2SbAeOEhScl9yiI5TwhasMvyFRrGomgK0bjuWcgFLC1pM4C GKrzEzvu2lPL2XacdRrjEEsNah6A4OLSic434/uIJZNvcHx37JKqTy5IsqOkQY8Pttmd FttA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=p9xwt/KxOmKt8o2VLLrb8jjs8WGzx+nDwsNmG750aho=; b=kqyVo+EImWXCUUg6pR/0mb0s95w2u2Gwsp30DB5OohlkgP7N2N/8faj+GNF1RGfSqJ CKBVda5Wjygqibvss5cGJrZX3pj8DwvIdj0fc4Kwr2fsLdj+kKleRjg1jkzrSIcLk9Xe nH9xRl0aSzzqOesEjWouHUAWwTC4jPKeJvZNV+fHJIh3rMdrv7mJ37CmUy0A3O9KJjKv gPsEaIIgc2magSuvQA829xw9ug3nDAHFbldvtp6QYh1yM0iwZ/+Pz5gQ4l8bpfUCkiTC 1WiY++BADoGnKgaR176JvauiKmysWhMQHGJG1QVDpLCAM4c/ujP2abuvWNUKvVU4zzJY NGBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Th9ktgTw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 n2-20020a170902d2c200b001b3d8ac8dacsi9522389plc.47.2023.06.16.09.19.37; Fri, 16 Jun 2023 09:19:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=Th9ktgTw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S1345207AbjFPQPv (ORCPT + 99 others); Fri, 16 Jun 2023 12:15:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344851AbjFPQOp (ORCPT ); Fri, 16 Jun 2023 12:14:45 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3013635A6 for ; Fri, 16 Jun 2023 09:13:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686932034; 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=p9xwt/KxOmKt8o2VLLrb8jjs8WGzx+nDwsNmG750aho=; b=Th9ktgTw7a8laXwXyJG3Qxdlda0JH5fizlWlop9n/W3U+x58H6L/Nf/UvHZ0M+Rj9mYfQ3 HwksJaAM1Nu9pt0W5jU6Usjmv4+YzwNdeAgBo+5YjLm4ArMUn2/7lMOFYzh2prGfIpYv70 bsGdhvsZ/3j4oh4M8k8e2BRFsIO20xs= 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-437-eFc4iCLxMeSIHuIkvb1k0A-1; Fri, 16 Jun 2023 12:13:50 -0400 X-MC-Unique: eFc4iCLxMeSIHuIkvb1k0A-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 6958F80120F; Fri, 16 Jun 2023 16:13:49 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E1BD40CF8F6; Fri, 16 Jun 2023 16:13:46 +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, Philipp Reisner , Lars Ellenberg , =?UTF-8?q?Christoph=20B=C3=B6hmwalder?= , drbd-dev@lists.linbit.com, linux-block@vger.kernel.org Subject: [PATCH net-next 13/17] drbd: Use sendmsg(MSG_SPLICE_PAGES) rather than sendpage() Date: Fri, 16 Jun 2023 17:12:56 +0100 Message-ID: <20230616161301.622169-14-dhowells@redhat.com> In-Reply-To: <20230616161301.622169-1-dhowells@redhat.com> References: <20230616161301.622169-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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_NONE, SPF_HELO_NONE,SPF_NONE,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-kernel@vger.kernel.org Use sendmsg() conditionally with MSG_SPLICE_PAGES in _drbd_send_page() rather than calling sendpage() or _drbd_no_send_page(). Signed-off-by: David Howells cc: Philipp Reisner cc: Lars Ellenberg cc: "Christoph Böhmwalder" cc: Jens Axboe cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: drbd-dev@lists.linbit.com cc: linux-block@vger.kernel.org cc: netdev@vger.kernel.org --- drivers/block/drbd/drbd_main.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c index 83987e7a5ef2..c9d84183844c 100644 --- a/drivers/block/drbd/drbd_main.c +++ b/drivers/block/drbd/drbd_main.c @@ -1540,7 +1540,8 @@ static int _drbd_send_page(struct drbd_peer_device *peer_device, struct page *pa int offset, size_t size, unsigned msg_flags) { struct socket *socket = peer_device->connection->data.socket; - int len = size; + struct bio_vec bvec; + struct msghdr msg = { .msg_flags = msg_flags, }; int err = -EIO; /* e.g. XFS meta- & log-data is in slab pages, which have a @@ -1549,33 +1550,33 @@ static int _drbd_send_page(struct drbd_peer_device *peer_device, struct page *pa * put_page(); and would cause either a VM_BUG directly, or * __page_cache_release a page that would actually still be referenced * by someone, leading to some obscure delayed Oops somewhere else. */ - if (drbd_disable_sendpage || !sendpage_ok(page)) - return _drbd_no_send_page(peer_device, page, offset, size, msg_flags); + if (!drbd_disable_sendpage && sendpage_ok(page)) + msg.msg_flags |= MSG_NOSIGNAL | MSG_SPLICE_PAGES; + + bvec_set_page(&bvec, page, offset, size); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, size); - msg_flags |= MSG_NOSIGNAL; drbd_update_congested(peer_device->connection); do { int sent; - sent = socket->ops->sendpage(socket, page, offset, len, msg_flags); + sent = sock_sendmsg(socket, &msg); if (sent <= 0) { if (sent == -EAGAIN) { if (we_should_drop_the_connection(peer_device->connection, socket)) break; continue; } - drbd_warn(peer_device->device, "%s: size=%d len=%d sent=%d\n", - __func__, (int)size, len, sent); + drbd_warn(peer_device->device, "%s: size=%d len=%zu sent=%d\n", + __func__, (int)size, msg_data_left(&msg), sent); if (sent < 0) err = sent; break; } - len -= sent; - offset += sent; - } while (len > 0 /* THINK && device->cstate >= C_CONNECTED*/); + } while (msg_data_left(&msg) /* THINK && device->cstate >= C_CONNECTED*/); clear_bit(NET_CONGESTED, &peer_device->connection->flags); - if (len == 0) { + if (!msg_data_left(&msg)) { err = 0; peer_device->device->send_cnt += size >> 9; }