From patchwork Sat Jun 17 12:11:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13283553 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 92F19EB64D9 for ; Sat, 17 Jun 2023 12:12:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E6256B0087; Sat, 17 Jun 2023 08:12:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 294BE6B0088; Sat, 17 Jun 2023 08:12:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 15C6F6B0089; Sat, 17 Jun 2023 08:12:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 04E836B0087 for ; Sat, 17 Jun 2023 08:12:57 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D4E1F1C9101 for ; Sat, 17 Jun 2023 12:12:56 +0000 (UTC) X-FDA: 80912128752.28.9F72703 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 0640A4000F for ; Sat, 17 Jun 2023 12:12:54 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NRU2NMM4; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf27.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=1687003975; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2HlaXseyq5U5o1i8LIFlWuZ5rATyuHBFais1x2nt408=; b=5sdA8FUsM4yyBjlr2rXuw8PYswZSdfFrxQU9lpQgosxHwyR+ME5xBOXziHXx09PzYLA9Gw 4VZjaQNKXuEstDkNXHQv0Mcwh59h1DTaBMhC4yN7wxZKfnGqqGW0Kefmw25hKkQWPPiDnZ lcFov5mFKy2qGdj91CH7oqanRIiDBFU= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NRU2NMM4; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf27.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=1687003975; a=rsa-sha256; cv=none; b=x+bKkoWN+8UzzeWl514kaC8yYPL5neD9eJbvRGKksvJd45yJyIqXp4H+adztUJ7Kh8OBa8 RzeOKHbhOpPz+TNIAFyd2+tsdtAJUDO8W4tvfhhr8pKzupzDtVizKXx5UZtX8uH4J1a6sW rAwwVpA66qMaWakC78IHo3dFpo2Zhv0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687003974; 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=2HlaXseyq5U5o1i8LIFlWuZ5rATyuHBFais1x2nt408=; b=NRU2NMM4IIAb7e40wuFtw7w2v/4OfytCJht/vwUcJSf1OP/qkAYgo/8HF31l8/9J0O6/bH 2tuj6ltMncxDcgz8wFjV0gzNvcPVwgSf84q9xYEtNT9wofy67rpzypMlCtKg/fvUwuJT/x 9IHYjxAyBstcVhHsUM6rUn9EFK+r3Zw= 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-117-NmwNDhxxO3e69TbO3-hfEA-1; Sat, 17 Jun 2023 08:12:49 -0400 X-MC-Unique: NmwNDhxxO3e69TbO3-hfEA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 35E311C08782; Sat, 17 Jun 2023 12:12:48 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30CB0492C1B; Sat, 17 Jun 2023 12:12: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_B=C3=B6hmwa?= =?utf-8?q?lder?= , drbd-dev@lists.linbit.com, linux-block@vger.kernel.org Subject: [PATCH net-next v2 13/17] drbd: Use sendmsg(MSG_SPLICE_PAGES) rather than sendpage() Date: Sat, 17 Jun 2023 13:11:42 +0100 Message-ID: <20230617121146.716077-14-dhowells@redhat.com> In-Reply-To: <20230617121146.716077-1-dhowells@redhat.com> References: <20230617121146.716077-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspamd-Queue-Id: 0640A4000F X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Sign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2rRnKgB9PbIvq/Wc2oqyUP9qyV0YNyfJx2CimFd1PaHa8GxDCVwdtr44B9VmE8nYsTlhPAf4UJDzeedl+7j4lpBcvi9nVIT7fSTVn0kIpz/QEOfmnpyOYa7DIX+lRhGlYXdTgpBB2mgU4STYbjs42CbU50n7zmuKguf57Lo6RDnotGgRjnbkSAsSUxiOA58NxDNmaTu+CL7uEzy2PDCwSHwRGQ5+Kh+QtsHzDJeoFdw2Uw5+AaMFdj+2CZ1NI1PP6Ifa0SNlgxexkXDdEz+mKKLVVDZhqCztTHNaawtxjmnOxtQj2cNunTtqgPzFAXiRJp6mU8MIoRcth2MHeeUIE7GffzmvC7qzdaOu/7NNvt/RFLQr2pSKUHhLWEAN5eB+hBCO6qV1Zdjl35ypRtCOgKFWmTZo3/AFzw0hSYs1wzLTX9CDQBAcQfVL6pgSvaWWPwQBCV5jcOnqEQDycV/is43vaw== 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() 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 --- Notes: ver #2) - Wrap lines at 80. drivers/block/drbd/drbd_main.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c index 83987e7a5ef2..8a01a18a2550 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,35 @@ 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; }