From patchwork Tue Jun 20 14:53:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13286009 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 EDBE0C0015E for ; Tue, 20 Jun 2023 14:56:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C5B88D000B; Tue, 20 Jun 2023 10:56:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 74DEA8D0001; Tue, 20 Jun 2023 10:56:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5EEE48D000B; Tue, 20 Jun 2023 10:56:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4A5208D0001 for ; Tue, 20 Jun 2023 10:56:32 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 048B981157 for ; Tue, 20 Jun 2023 14:56:32 +0000 (UTC) X-FDA: 80923427424.13.48A2684 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf07.hostedemail.com (Postfix) with ESMTP id 21E0140007 for ; Tue, 20 Jun 2023 14:56:29 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZV3zqbRv; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.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=1687272990; a=rsa-sha256; cv=none; b=5ailybJ+ug0phmajDeKWkjV1dczmML8KZHbfUXWy+5/ual5Rub8OgY1c0f8Thc3KBWyRgJ tiEBhx7rDHcu8jL1XczP/5BSkVnQCxEikP4sblI7W/N2c5pUYeSWgVKi5RtN0TLXpBfpg9 CMFkLXD8Eo0vfDPL/dTYmauLlPuyyew= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZV3zqbRv; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf07.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=1687272990; 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=Xe+E3y9iF5WoqF9RAoI5mIYI7LZ4lxxn5w1KkKAWiNw=; b=kcL4G1kMJ1gRFoya+wz0gVbBS/BUdLBg2vHbonDuejuulmK2RDGnOq1dxSk655xgrh0BGl YKNUZls04N0o+NasKHGiBywPrV3Winb/0p0yQcMETKzRp6Db93wkwUQkC47qhgY4SjEuwR Kq+dQw85VD2NRZlUzXjWfbjRdMtWaNA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687272989; 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=Xe+E3y9iF5WoqF9RAoI5mIYI7LZ4lxxn5w1KkKAWiNw=; b=ZV3zqbRvSAZNZyxoW6WCjZVYszEY9DLDim/UB4rfBC4oJcECgEewwQgrflboC5jq6++E/u I/vtAfEpyuyg283GRiGSDMpoXjhYWWEv7n/gwDBys72T9wpHvfwKn1b/hamOWZ6+E3yL0V Bx2Lbl0RBeZUBVVFJM1SIc6dNZNwL3o= 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-601-lKmh20CrMjqnzvPqQo7SgA-1; Tue, 20 Jun 2023 10:56:26 -0400 X-MC-Unique: lKmh20CrMjqnzvPqQo7SgA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 24F888E6CDA; Tue, 20 Jun 2023 14:53:45 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FEFB2166B26; Tue, 20 Jun 2023 14:53:43 +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, Menglong Dong Subject: [PATCH net-next v3 01/18] net: Copy slab data for sendmsg(MSG_SPLICE_PAGES) Date: Tue, 20 Jun 2023 15:53:20 +0100 Message-ID: <20230620145338.1300897-2-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 21E0140007 X-Stat-Signature: qbpxc8n1bqu5fbpk4sgqu3e4n4pao3ag X-HE-Tag: 1687272989-444011 X-HE-Meta: U2FsdGVkX19HUcz5qzg6Ptac/lFcnkfxLeTKtZvbpsOmgR8fR/xKz9QOGlXUhTVTfJ1BU3letSHs2KDv8Ty79vKyn0t1i0RaffYpllNB4/TFORW1EfLKGFxVNMbVxzwEv8vBwwn7b/3iVXYOBhKOBYfR8nvDpNMF2AXBfNTwQjU5OXMMJXCDHs1ygQlx/9JffTUb/oen0hsqPVUCk7Yayjoow9cW8X7ceAgNM3VQVELcv3/NCfClOWZX8wgSs16uIDcMQHZ0VVQC9dcet1kqm0c9dsdAuUwWoz6WLNHWuzUgXMfiS1qJrt8x2/bscCmbeCKl19MNzJ2qWLn9EjdtY9oi31UKbJb7CTjFit2AdT6e5vn/9I0G4r8IO/xRjYWtGrQ0hp7nGk3I07hOExtlQ7UE6NL58Bqk6CgPdxU7hBSD4cp6JR1Dw+kYJl2tjCzGZGzGynLHp3UMYXCCQk6ALQk2D4icSfecHiQzltCBDul6Syr4otuskMzo3hxDW0HD2gNFO1cnKgiyq8mlFOeIwUHuXETUqzAeYa/SftUWrRZYYFrDWhuE2kmUG+GBhUrs+cSD2b3x0oz97EcoAilz+S+EpyK+5TX5bu9Sq3z58RQc0rRRR8OxFSK+fxeoTPN/78CH44D2yvhKswNCTBRqXcxQKdVB6sPiaGdCBcy97IuuBDkRZeYtTQUbCKJLAC1ukTNrL/qrEzy1i/+K/Va9U+9TG6bwswxB9NrW9JdYvyMUL2eikJv1wAlPWTc11RodS3TJFySMPHKEDutGthny7ULemylhiC4pTTzKUGXc5BfVh5I4K8kK5eNVQS54YKpTiFWyPp38EhUA17r2iXcRaTd0w2nl7/DJjZsw9jNxJ30xyHNyYRBSMAapPSYdrpbl5ukyNWWsnnGAq5rdFMnNxgi3ZzKTJN4S63l4JCakImch0335dd19o9hoEcpz7LLkqYKRjT7H/Cln6GWOvrJ nLxdR/FT NyxdAvf294Zhlaa6BhLwpbeWmwGERExC1TpbYiLKXdZBe7c59MGjNWTzsk+b/+BoHVL/DnV0d3vEjFfU8EZbbyJdfx9t3zx8sJE9bsazS0k1l1S0aYbhH8+ZNZM7g8qq4AU5Gv01njZQhNzuh908v8JnMhJ+DPG2ccH6p1qLOyCOI32sCmzGvxCze0u56VaYFquiuMLnmYS5erv+Bs8g4EWm9+khkyRowF+FgHJuyUBidhYKuagThNoEVOKos8Ac8E0OW/q99Djrx/t6Ojwi9bZLgfJnXPOwXPmdSIufUateZq0VhCtBC8BZkWQEYDTcbaQbxgaUWU5Ugd1DxwqgexvnKEgumJ9hU0/5GfDIREsNjwxq3zc/YpeQGvYLc/T/P7/F4BVtRQj4I8qh4P5YHgx8JYiA3r30NqIUAlwcDF23ICmxfbMSktrgSCOLgPA96T6EcYI9APsDUh22P1fcqxNdnCu+nj8aOGZ2/zFI6tLI7pevJaTfkGIgtd4PteU6QmUZxexmwczyWG1vnqnIHeSGpEYgie1JaIj7NFucsSHFz7sxl4H44cP8MP9sJV4HYP1TvxbRxVjLYfHQ= 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: If sendmsg() is passed MSG_SPLICE_PAGES and is given a buffer that contains some data that's resident in the slab, copy it rather than returning EIO. This can be made use of by a number of drivers in the kernel, including: iwarp, ceph/rds, dlm, nvme, ocfs2, drdb. It could also be used by iscsi, rxrpc, sunrpc, cifs and probably others. skb_splice_from_iter() is given it's own fragment allocator as page_frag_alloc_align() can't be used because it does no locking to prevent parallel callers from racing. alloc_skb_frag() uses a separate folio for each cpu and locks to the cpu whilst allocating, reenabling cpu migration around folio allocation. This could allocate a whole page instead for each fragment to be copied, as alloc_skb_with_frags() would do instead, but that would waste a lot of space (most of the fragments look like they're going to be small). This allows an entire message that consists of, say, a protocol header or two, a number of pages of data and a protocol footer to be sent using a single call to sock_sendmsg(). The callers could be made to copy the data into fragments before calling sendmsg(), but that then penalises them if MSG_SPLICE_PAGES gets ignored. Signed-off-by: David Howells cc: Alexander Duyck cc: Eric Dumazet cc: "David S. Miller" cc: David Ahern cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: Menglong Dong cc: netdev@vger.kernel.org --- Notes: ver #3) - Remove duplicate decl of skb_splice_from_iter(). ver #2) - Fix parameter to put_cpu_ptr() to have an '&'. include/linux/skbuff.h | 2 + net/core/skbuff.c | 171 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 170 insertions(+), 3 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 91ed66952580..5f53bd5d375d 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -5037,6 +5037,8 @@ static inline void skb_mark_for_recycle(struct sk_buff *skb) #endif } +void *alloc_skb_frag(size_t fragsz, gfp_t gfp); +void *copy_skb_frag(const void *s, size_t len, gfp_t gfp); ssize_t skb_splice_from_iter(struct sk_buff *skb, struct iov_iter *iter, ssize_t maxsize, gfp_t gfp); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index fee2b1c105fe..d962c93a429d 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6755,6 +6755,145 @@ nodefer: __kfree_skb(skb); smp_call_function_single_async(cpu, &sd->defer_csd); } +struct skb_splice_frag_cache { + struct folio *folio; + void *virt; + unsigned int offset; + /* we maintain a pagecount bias, so that we dont dirty cache line + * containing page->_refcount every time we allocate a fragment. + */ + unsigned int pagecnt_bias; + bool pfmemalloc; +}; + +static DEFINE_PER_CPU(struct skb_splice_frag_cache, skb_splice_frag_cache); + +/** + * alloc_skb_frag - Allocate a page fragment for using in a socket + * @fragsz: The size of fragment required + * @gfp: Allocation flags + */ +void *alloc_skb_frag(size_t fragsz, gfp_t gfp) +{ + struct skb_splice_frag_cache *cache; + struct folio *folio, *spare = NULL; + size_t offset, fsize; + void *p; + + if (WARN_ON_ONCE(fragsz == 0)) + fragsz = 1; + + cache = get_cpu_ptr(&skb_splice_frag_cache); +reload: + folio = cache->folio; + offset = cache->offset; +try_again: + if (fragsz > offset) + goto insufficient_space; + + /* Make the allocation. */ + cache->pagecnt_bias--; + offset = ALIGN_DOWN(offset - fragsz, SMP_CACHE_BYTES); + cache->offset = offset; + p = cache->virt + offset; + put_cpu_ptr(&skb_splice_frag_cache); + if (spare) + folio_put(spare); + return p; + +insufficient_space: + /* See if we can refurbish the current folio. */ + if (!folio || !folio_ref_sub_and_test(folio, cache->pagecnt_bias)) + goto get_new_folio; + if (unlikely(cache->pfmemalloc)) { + __folio_put(folio); + goto get_new_folio; + } + + fsize = folio_size(folio); + if (unlikely(fragsz > fsize)) + goto frag_too_big; + + /* OK, page count is 0, we can safely set it */ + folio_set_count(folio, PAGE_FRAG_CACHE_MAX_SIZE + 1); + + /* Reset page count bias and offset to start of new frag */ + cache->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1; + offset = fsize; + goto try_again; + +get_new_folio: + if (!spare) { + cache->folio = NULL; + put_cpu_ptr(&skb_splice_frag_cache); + +#if PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE + spare = folio_alloc(gfp | __GFP_NOWARN | __GFP_NORETRY | + __GFP_NOMEMALLOC, + PAGE_FRAG_CACHE_MAX_ORDER); + if (!spare) +#endif + spare = folio_alloc(gfp, 0); + if (!spare) + return NULL; + + cache = get_cpu_ptr(&skb_splice_frag_cache); + /* We may now be on a different cpu and/or someone else may + * have refilled it + */ + cache->pfmemalloc = folio_is_pfmemalloc(spare); + if (cache->folio) + goto reload; + } + + cache->folio = spare; + cache->virt = folio_address(spare); + folio = spare; + spare = NULL; + + /* Even if we own the page, we do not use atomic_set(). This would + * break get_page_unless_zero() users. + */ + folio_ref_add(folio, PAGE_FRAG_CACHE_MAX_SIZE); + + /* Reset page count bias and offset to start of new frag */ + cache->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1; + offset = folio_size(folio); + goto try_again; + +frag_too_big: + /* The caller is trying to allocate a fragment with fragsz > PAGE_SIZE + * but the cache isn't big enough to satisfy the request, this may + * happen in low memory conditions. We don't release the cache page + * because it could make memory pressure worse so we simply return NULL + * here. + */ + cache->offset = offset; + put_cpu_ptr(&skb_splice_frag_cache); + if (spare) + folio_put(spare); + return NULL; +} +EXPORT_SYMBOL(alloc_skb_frag); + +/** + * copy_skb_frag - Copy data into a page fragment. + * @s: The data to copy + * @len: The size of the data + * @gfp: Allocation flags + */ +void *copy_skb_frag(const void *s, size_t len, gfp_t gfp) +{ + void *p; + + p = alloc_skb_frag(len, gfp); + if (!p) + return NULL; + + return memcpy(p, s, len); +} +EXPORT_SYMBOL(copy_skb_frag); + static void skb_splice_csum_page(struct sk_buff *skb, struct page *page, size_t offset, size_t len) { @@ -6808,17 +6947,43 @@ ssize_t skb_splice_from_iter(struct sk_buff *skb, struct iov_iter *iter, break; } + if (space == 0 && + !skb_can_coalesce(skb, skb_shinfo(skb)->nr_frags, + pages[0], off)) { + iov_iter_revert(iter, len); + break; + } + i = 0; do { struct page *page = pages[i++]; size_t part = min_t(size_t, PAGE_SIZE - off, len); - - ret = -EIO; - if (WARN_ON_ONCE(!sendpage_ok(page))) + bool put = false; + + if (PageSlab(page)) { + const void *p; + void *q; + + p = kmap_local_page(page); + q = copy_skb_frag(p + off, part, gfp); + kunmap_local(p); + if (!q) { + iov_iter_revert(iter, len); + ret = -ENOMEM; + goto out; + } + page = virt_to_page(q); + off = offset_in_page(q); + put = true; + } else if (WARN_ON_ONCE(!sendpage_ok(page))) { + ret = -EIO; goto out; + } ret = skb_append_pagefrags(skb, page, off, part, frag_limit); + if (put) + put_page(page); if (ret < 0) { iov_iter_revert(iter, len); goto out; From patchwork Tue Jun 20 14:53:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13285992 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 C0AB3EB64D8 for ; Tue, 20 Jun 2023 14:55:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57BC78D0006; Tue, 20 Jun 2023 10:55:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 504D18D0001; Tue, 20 Jun 2023 10:55:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 37E058D0006; Tue, 20 Jun 2023 10:55:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 211D68D0001 for ; Tue, 20 Jun 2023 10:55:02 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E989AC117B for ; Tue, 20 Jun 2023 14:55:01 +0000 (UTC) X-FDA: 80923423602.13.2820F7F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 93B581C001E for ; Tue, 20 Jun 2023 14:54:58 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="O/1SHXea"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.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=1687272898; 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=+u30ziD9KgNs/SO68HcOpUwCa+4S9m3KYto4qjbvl9U=; b=MecwfOWRIKlFyiskQsL5pYOnIDxkXZBGKX9MpEIoBxo7jkxzcYs5RQ9ZEWn5PH91QqJYX1 McTAvEOWqUq9idJ4TBDraABCLr7V9c3UC/2K1Exp88hxNKmJw3KyXpbcPdfQNbYO6ebflA H/A2CmNjSD8dXqarqVnHkZyWREcI7LA= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="O/1SHXea"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.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=1687272898; a=rsa-sha256; cv=none; b=LGjazVbMxo3MnTvi5EyjCFXg2abSzg9FMmFMmAAZvhHLT+1BGkjCqDXNQWjf2aby/p1ycl 7heb7WeA4eMvyUMXTL9jDfadLbrv07d+sJbzFohJQWFkZZbQW5eO/xNBrzuVB97DV8BnZN gSpeKpVdxQIPj34Trc7QwUMbQYMOiZc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687272897; 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=+u30ziD9KgNs/SO68HcOpUwCa+4S9m3KYto4qjbvl9U=; b=O/1SHXeaSvylngGmI6UvWm3Gk7eh3jfy/VDCM+L6YPHnz7YfJulelLtWmhEtgaCC35UeLm YWwlvRA/azdlzVKI/pl9NPlEqGxq6fN30tdxDxPzoK5k9UBvpF37fIfOk4ue4UNQKDoEHZ DiHH+psPa9ch3HSuOMzo6HhcbfhpmpQ= 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-43-AZi11j61MEqhDouArFBQJA-1; Tue, 20 Jun 2023 10:54:52 -0400 X-MC-Unique: AZi11j61MEqhDouArFBQJA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 341D238117F0; Tue, 20 Jun 2023 14:53:47 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD2FE40C6CD2; Tue, 20 Jun 2023 14:53: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, Menglong Dong Subject: [PATCH net-next v3 02/18] net: Display info about MSG_SPLICE_PAGES memory handling in proc Date: Tue, 20 Jun 2023 15:53:21 +0100 Message-ID: <20230620145338.1300897-3-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 93B581C001E X-Stat-Signature: ixkfimdd8scpr79e9g7pbca7x8jta1i3 X-HE-Tag: 1687272898-150410 X-HE-Meta: U2FsdGVkX1+1FnGPTSdJnMs8+tYkjNWQgwSN4RvMCab+/KyRHrVlhopslrTdZlNnQIblTPFmYWqVpgnBzzJmuDdLnJtYt6DOyoU09vjM9cMmiu0zmvaVIaVP5GImxBUUrte7SnL38B1GhKFzWjqNi8M78I5jUuaKZnGIVzksFFRQdHkB7Xwx3y4ceCtBoN/J2SPvdVyCqXWMNlWcvUOPNSJ/r8P+rZiXjgmX6wpTlfnhe0fYqTZfCd8tNq1lsfATSIanvq4vBsBhzQMYWU9KSOLk8lxnIKxcOEVkW4/ptJ2bKZkfY75ipWFZpzXaeVcva9PXAwlZ9u2/NnTMx7N1Vo7lx+efbOXaLN7LLzOjhZCEXk3eoFf3PK4aiES4SdfrwPFjylT+2NDTr9Tl+Ve62wdHuwEAEbpBSzVnDrO4aVu5JQ6Jh6+pC1rA7iFN19zCxJAtcN2rOuoDGt6Rh6pzpyzSH33BeMxIGvznOJezO6CW/PN3Ky5pbDa4Cu7GULzDH/yiTnk4IzIaODSOJ73wXW6+8vdbfNWN7injx/0K3udj2D5P/bdkQfKVYmkati7wpI2lr4tNcQaWrs1OG9f8aecRVxyjU6bujWuzfsOjr1iinHyizlPiCDwBM5qBaMjS4x3uDnBULgHlagxz1lAHBJwYViH4+hfvKUK22ewVQDaWm9IBIi25kpXG3gf9JgchfIfG4WOsYMhaSSfSeFjzoRfvhnhSdjvyLissf05PgJKio1oxIVoto6J4dhhB3ntLZE9uTd3Q7kcb6Ancim0uSfueQB01Eax9YE8dU0xzvnQluyM2Mu/GZr0AEdACQry1DVZUDyRH2B+aNBcyTdgfAB2Jib4tSM1UExX3dMl805J3SqntMV6VameesvChfJurngkH5ohGeQM1DUHL59d3UzjC0upHP3iVikfZnvrSlmwMJXqv8jup2vfdDIVkfAI8S1GOm5Ud83lXzbqLVEI yjD0/UKb NScVxEpgJE9dbg8Sn5Ioato7mFaT+auF11KFeM9HF5DxnqROFfKFTbh6Vnzwi7fGDDU61BeLP3NuHsdsgAxk1BFP6/jI1Y+mNaISAbDW7dFhnN9o+/pHVltkKB56Ui9s2a/ogaH2gy2DcZuw1TcVmiq7+sp9axyUQ0FalKYtzDdN479lD8aCzlG68ySi3m8B8S6gb4UIhQKu75mtkaThuMBEZXSFCrrAajbhLCOo+g57/v4cB/G/ow/hXbDelUv0A/d9L2slIAHrfVlVKZgB3ycF5W5Kso399ebwdvxJgmd0EPPVgoWLK1ecdICZImANxj9Ioj43CUhSFgNLeG9ZI9/84iyWCqnX9XbQBGjNwhKdzePNM8RlL966WasOmjy5Q947nN4oWhgFAlAFH0dfCJ4OlX7HjwVyzICyrsXouHdiJXVRW+Ev2lfaisG8QxHdNR4NhfxAtlWA7GjKod2iMDFGQsnaoc5BS0hWimdCJriPVhPoy8ilGj7Jlf3vyPr7vSVVkoYMggiks0Gm+CP5129AqULxefJkKbGjsct4mrsFQ1rASt4cuwg/Ls8aJ3HPcPABfpKNTCQL8Lpc= 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: Display information about the memory handling MSG_SPLICE_PAGES does to copy slabbed data into page fragments. For each CPU that has a cached folio, it displays the folio pfn, the offset pointer within the folio and the size of the folio. It also displays the number of pages refurbished and the number of pages replaced. Signed-off-by: David Howells cc: Alexander Duyck cc: Eric Dumazet cc: "David S. Miller" cc: David Ahern cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: Menglong Dong cc: netdev@vger.kernel.org --- net/core/skbuff.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index d962c93a429d..36605510a76d 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -83,6 +83,7 @@ #include #include #include +#include #include "dev.h" #include "sock_destructor.h" @@ -6758,6 +6759,7 @@ nodefer: __kfree_skb(skb); struct skb_splice_frag_cache { struct folio *folio; void *virt; + unsigned int fsize; unsigned int offset; /* we maintain a pagecount bias, so that we dont dirty cache line * containing page->_refcount every time we allocate a fragment. @@ -6767,6 +6769,26 @@ struct skb_splice_frag_cache { }; static DEFINE_PER_CPU(struct skb_splice_frag_cache, skb_splice_frag_cache); +static atomic_t skb_splice_frag_replaced, skb_splice_frag_refurbished; + +static int skb_splice_show(struct seq_file *m, void *data) +{ + int cpu; + + seq_printf(m, "refurb=%u repl=%u\n", + atomic_read(&skb_splice_frag_refurbished), + atomic_read(&skb_splice_frag_replaced)); + + for_each_possible_cpu(cpu) { + const struct skb_splice_frag_cache *cache = + per_cpu_ptr(&skb_splice_frag_cache, cpu); + + seq_printf(m, "[%u] %lx %u/%u\n", + cpu, folio_pfn(cache->folio), + cache->offset, cache->fsize); + } + return 0; +} /** * alloc_skb_frag - Allocate a page fragment for using in a socket @@ -6803,17 +6825,21 @@ void *alloc_skb_frag(size_t fragsz, gfp_t gfp) insufficient_space: /* See if we can refurbish the current folio. */ - if (!folio || !folio_ref_sub_and_test(folio, cache->pagecnt_bias)) + if (!folio) goto get_new_folio; + if (!folio_ref_sub_and_test(folio, cache->pagecnt_bias)) + goto replace_folio; if (unlikely(cache->pfmemalloc)) { __folio_put(folio); - goto get_new_folio; + goto replace_folio; } fsize = folio_size(folio); if (unlikely(fragsz > fsize)) goto frag_too_big; + atomic_inc(&skb_splice_frag_refurbished); + /* OK, page count is 0, we can safely set it */ folio_set_count(folio, PAGE_FRAG_CACHE_MAX_SIZE + 1); @@ -6822,6 +6848,8 @@ void *alloc_skb_frag(size_t fragsz, gfp_t gfp) offset = fsize; goto try_again; +replace_folio: + atomic_inc(&skb_splice_frag_replaced); get_new_folio: if (!spare) { cache->folio = NULL; @@ -6848,6 +6876,7 @@ void *alloc_skb_frag(size_t fragsz, gfp_t gfp) cache->folio = spare; cache->virt = folio_address(spare); + cache->fsize = folio_size(spare); folio = spare; spare = NULL; @@ -6858,7 +6887,7 @@ void *alloc_skb_frag(size_t fragsz, gfp_t gfp) /* Reset page count bias and offset to start of new frag */ cache->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1; - offset = folio_size(folio); + offset = cache->fsize; goto try_again; frag_too_big: @@ -7007,3 +7036,10 @@ ssize_t skb_splice_from_iter(struct sk_buff *skb, struct iov_iter *iter, return spliced ?: ret; } EXPORT_SYMBOL(skb_splice_from_iter); + +static int skb_splice_init(void) +{ + proc_create_single("pagefrags", S_IFREG | 0444, NULL, &skb_splice_show); + return 0; +} +late_initcall(skb_splice_init); From patchwork Tue Jun 20 14:53:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13286015 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 5FDBFEB64DC for ; Tue, 20 Jun 2023 14:57:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 024318D0010; Tue, 20 Jun 2023 10:57:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F16098D0001; Tue, 20 Jun 2023 10:57:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDD298D0010; Tue, 20 Jun 2023 10:57:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id CBDDA8D0001 for ; Tue, 20 Jun 2023 10:57:15 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9FA9F1211CB for ; Tue, 20 Jun 2023 14:57:15 +0000 (UTC) X-FDA: 80923429230.19.3DFE054 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id B11AB16001B for ; Tue, 20 Jun 2023 14:57:13 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gfKiCLSm; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.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=1687273033; 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=8t7wtWM3aEB5I+3bAZDQAyKBMtXipfmjmHgxZgR4FXg=; b=MSQD+dmKQz9smBhk+90Vvv0MTB4hUdsZFVT+6lnYbE2LiUTBDxEwACj9gMjkFfM+iCycKx DbTnn7Df9UQ13xCgJIkENyZPFsCPr1RBGJPUJkQoThmu3R//+pELARMJ5sCeSUGTvF5Tpm QqfNVrSgQwae02omOvuO2PeE8peXjzQ= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gfKiCLSm; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.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=1687273033; a=rsa-sha256; cv=none; b=wKbRIhAOYMCaWjakDkYN9RdWy7no24BfuBYGFQM82vYwTDHMugBr1EYJ8JUTRd7Au6//x8 S+VvauVJ6s6i/7t8iiLU+v9j+cfijwRuXXBDDyIDifdVIlQERPiSLflDPAtOy/5DwU9cSI Eq6OJviT83V+1MiToM4ZJZvZd3I+Y4I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687273032; 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=8t7wtWM3aEB5I+3bAZDQAyKBMtXipfmjmHgxZgR4FXg=; b=gfKiCLSmEqk9W5N3iFN/OSrhONTDRBxSLNP9F+1W98WUPdxWSwo2WLeAnseYnBLTwbaCUp KH8oN9cSbXbdQB7S+ITl/fUmTj2qDPP7gudsfE+6HQnxVQwZmkcttLMXR2Vn1MJDrvZ7o0 hhMDWkrX0pFLWAohh53AXfpTWl+Qn+c= 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-189-70MSteDdOnyTFFxz8b5FjQ-1; Tue, 20 Jun 2023 10:57:10 -0400 X-MC-Unique: 70MSteDdOnyTFFxz8b5FjQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A140B89CA6F; Tue, 20 Jun 2023 14:53:50 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id D2D2440462B8; Tue, 20 Jun 2023 14:53:47 +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, John Fastabend , Jakub Sitnicki , Karsten Graul , Wenjia Zhang , Jan Karcher , "D. Wythe" , Tony Lu , Wen Gu , Boris Pismenny , Steffen Klassert , Herbert Xu , bpf@vger.kernel.org, linux-s390@vger.kernel.org Subject: [PATCH net-next v3 03/18] tcp_bpf, smc, tls, espintcp: Reduce MSG_SENDPAGE_NOTLAST usage Date: Tue, 20 Jun 2023 15:53:22 +0100 Message-ID: <20230620145338.1300897-4-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Queue-Id: B11AB16001B X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: py39q5gij48qmkpxd7xffj95go3mkzny X-HE-Tag: 1687273033-668882 X-HE-Meta: U2FsdGVkX18bK+bQWFxzN6yo+ry8mSih3tH52ypfPRtIWCTus2pD5UFHAPB9zJ9+SCifAQ4VmCMywykyB3LEEFpj/gFxFb4mSU5H1ws65oTXJYjj7JHwiOTJVCNirdKGFuIs8bxCI6tTNKCrfoETtANCpiSs46WfuYRIg4a5fgk1LPzLP/GuqoYRsmOImFQ83dO1pYrHf0ArpL/NdRhLjRGTqRuq26wZO8LL/FuuptIEy/iS2uhlppBQGoiZlq23mkd0JvIMqPykLHLvFgcDPybSjMl/h4JUny7s9RkUXv5tyx+UDjgdSFNIw3XNHA6TODJdV2uvjtwaGXv5RSzYSOHrM/EcUVcB+lPi2x3Lj2xgnQEa7+BgIS1EsxjVloS6vI87seLaES2X6EcqgByTFp9WKrvuiQFnW0p55p0NONqgucW5KvzdOkYeEWTYr6ediOIlbe4ucwXe/N0usZ+14o/a6gGuX6uf+JQ9PSEiS9tCsE5+Cclk1BuVKoo55m0IOIMN7bRYdbnRWepWHaIfUwRuwSK1fNW5hgqL7Z7xtrSt+V1ZxNlX3FYOYbXOEdWdqZe5pru62sj5ESjXmf7i0uEf7D90FdBClqEf9CamoMotOz+ORymYlb4J2eXa+LOUrlLCQ/tfIapTgNBII5CoO5LC1BLSYK1IODKY+hSKWaJmgekRGWwJSOyoBaC7dpyIPro0itErNF62/eJE61RfzTGCAT6+IAXygxXpuXHxN8HeSmv8GW7vUUZJDuKtiGIlvDVKzu/99cOZ6pbVASI8DHtit12/Pvy9XgZGkvOLd0U+PTRFgIix6HlzXZqFgiE+Xn2V06Eu2rjBGfLmYRV8lZH/0LpTXcgbGX8QWWBo147Zpc+bepzSsGvuTmWrkz6YNTddYgmhjaicAAl/w7z1NoYwjdhBUOVkXlWOSQZofIShihWEit+NZ37VE9kiH+CmVJxjq6LqsLLe7srEl5h c/Q0fqjP ARrIzcQnrudgSb3yGLElOOvxKZHaYWhYSi2sn/BzkW4SEc9Lqb9Dx8n+ClQnLCMXeDm2KqDXMO5CwNCYKL4G9x7pKoXD24bnwU1pJmxGf38J3SIX+yRNO/yAZ2f4T/JM7VN+R1qlPLeejJnXo9pWzvu1Lb4W3riiKJZIl4su9tT4Ex1AhewfYsFqToOuLLPJ1ojg82tj6MyRoGCzNimc5vwA7zgxehjulEg5NzM2kx/hIkhFRowYViBRqcG6X+EjqkO5CdT8iFzRG4/Rl1c5+qqF3liJePpLbRL4TVXVo4Uqd5hvAJ0fr07HgB3mvuB2XWy2Js3zvZzNGwianF5wKGo5hoap9Z0/OQgae6CX2g8sfrXHwv9VLdSTlDM3sy9LunnjazeP7w8iCdWFqmuChtlhjTHLubB6MuTzj5Bl6nldpBiVzOtA9v7s+1Jzi+MpwfQND71+DsMn93ziar2VN5AKtfCeu+1Fqw6Y/UR2dcq9ojg+1fDyhziek4EhdNjyLK17wf6WY3CSiGwlsEm8xJfF4ostASmYaDlGElXL0xr5kesZ5CjKtsdbtBkxDUfK6CdjgzZ0bRmx+GDEBLM0C7T8Rj9fal5awBnn6FnJNsU7ARzSByy9DHO+N7QfmPiT68XGnwqGAfgkggRrWwUPw53luy/p5Spt8cCTB 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: As MSG_SENDPAGE_NOTLAST is being phased out along with sendpage(), don't use it further in than the sendpage methods, but rather translate it to MSG_MORE and use that instead. Signed-off-by: David Howells cc: Willem de Bruijn cc: John Fastabend cc: Jakub Sitnicki cc: Eric Dumazet cc: "David S. Miller" cc: David Ahern cc: Jakub Kicinski cc: Paolo Abeni cc: Karsten Graul cc: Wenjia Zhang cc: Jan Karcher cc: "D. Wythe" cc: Tony Lu cc: Wen Gu cc: Boris Pismenny cc: Steffen Klassert cc: Herbert Xu cc: netdev@vger.kernel.org cc: bpf@vger.kernel.org cc: linux-s390@vger.kernel.org --- Notes: ver #3) - In tcp_bpf, reset msg_flags on each iteration to clear MSG_MORE. - In tcp_bpf, set MSG_MORE if there's more data in the sk_msg. net/ipv4/tcp_bpf.c | 5 +++-- net/smc/smc_tx.c | 6 ++++-- net/tls/tls_device.c | 4 ++-- net/xfrm/espintcp.c | 10 ++++++---- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c index 5a84053ac62b..31d6005cea9b 100644 --- a/net/ipv4/tcp_bpf.c +++ b/net/ipv4/tcp_bpf.c @@ -88,9 +88,9 @@ static int bpf_tcp_ingress(struct sock *sk, struct sk_psock *psock, static int tcp_bpf_push(struct sock *sk, struct sk_msg *msg, u32 apply_bytes, int flags, bool uncharge) { + struct msghdr msghdr = {}; bool apply = apply_bytes; struct scatterlist *sge; - struct msghdr msghdr = { .msg_flags = flags | MSG_SPLICE_PAGES, }; struct page *page; int size, ret = 0; u32 off; @@ -107,11 +107,12 @@ static int tcp_bpf_push(struct sock *sk, struct sk_msg *msg, u32 apply_bytes, tcp_rate_check_app_limited(sk); retry: + msghdr.msg_flags = flags | MSG_SPLICE_PAGES; has_tx_ulp = tls_sw_has_ctx_tx(sk); if (has_tx_ulp) msghdr.msg_flags |= MSG_SENDPAGE_NOPOLICY; - if (flags & MSG_SENDPAGE_NOTLAST) + if (size < sge->length && msg->sg.start != msg->sg.end) msghdr.msg_flags |= MSG_MORE; bvec_set_page(&bvec, page, size, off); diff --git a/net/smc/smc_tx.c b/net/smc/smc_tx.c index 45128443f1f1..9b9e0a190734 100644 --- a/net/smc/smc_tx.c +++ b/net/smc/smc_tx.c @@ -168,8 +168,7 @@ static bool smc_tx_should_cork(struct smc_sock *smc, struct msghdr *msg) * should known how/when to uncork it. */ if ((msg->msg_flags & MSG_MORE || - smc_tx_is_corked(smc) || - msg->msg_flags & MSG_SENDPAGE_NOTLAST) && + smc_tx_is_corked(smc)) && atomic_read(&conn->sndbuf_space)) return true; @@ -306,6 +305,9 @@ int smc_tx_sendpage(struct smc_sock *smc, struct page *page, int offset, struct kvec iov; int rc; + if (flags & MSG_SENDPAGE_NOTLAST) + msg.msg_flags |= MSG_MORE; + iov.iov_base = kaddr + offset; iov.iov_len = size; iov_iter_kvec(&msg.msg_iter, ITER_SOURCE, &iov, 1, size); diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index b82770f68807..975299d7213b 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -449,7 +449,7 @@ static int tls_push_data(struct sock *sk, return -sk->sk_err; flags |= MSG_SENDPAGE_DECRYPTED; - tls_push_record_flags = flags | MSG_SENDPAGE_NOTLAST; + tls_push_record_flags = flags | MSG_MORE; timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT); if (tls_is_partially_sent_record(tls_ctx)) { @@ -532,7 +532,7 @@ static int tls_push_data(struct sock *sk, if (!size) { last_record: tls_push_record_flags = flags; - if (flags & (MSG_SENDPAGE_NOTLAST | MSG_MORE)) { + if (flags & MSG_MORE) { more = true; break; } diff --git a/net/xfrm/espintcp.c b/net/xfrm/espintcp.c index 3504925babdb..d3b3f9e720b3 100644 --- a/net/xfrm/espintcp.c +++ b/net/xfrm/espintcp.c @@ -205,13 +205,15 @@ static int espintcp_sendskb_locked(struct sock *sk, struct espintcp_msg *emsg, static int espintcp_sendskmsg_locked(struct sock *sk, struct espintcp_msg *emsg, int flags) { - struct msghdr msghdr = { .msg_flags = flags | MSG_SPLICE_PAGES, }; + struct msghdr msghdr = { + .msg_flags = flags | MSG_SPLICE_PAGES | MSG_MORE, + }; struct sk_msg *skmsg = &emsg->skmsg; + bool more = flags & MSG_MORE; struct scatterlist *sg; int done = 0; int ret; - msghdr.msg_flags |= MSG_SENDPAGE_NOTLAST; sg = &skmsg->sg.data[skmsg->sg.start]; do { struct bio_vec bvec; @@ -221,8 +223,8 @@ static int espintcp_sendskmsg_locked(struct sock *sk, emsg->offset = 0; - if (sg_is_last(sg)) - msghdr.msg_flags &= ~MSG_SENDPAGE_NOTLAST; + if (sg_is_last(sg) && !more) + msghdr.msg_flags &= ~MSG_MORE; p = sg_page(sg); retry: From patchwork Tue Jun 20 14:53:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13286008 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 1DFD3EB64D8 for ; Tue, 20 Jun 2023 14:56:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF9868D000A; Tue, 20 Jun 2023 10:56:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A5B378D0001; Tue, 20 Jun 2023 10:56:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8FC6C8D000A; Tue, 20 Jun 2023 10:56:28 -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 7C20A8D0001 for ; Tue, 20 Jun 2023 10:56:28 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 53C8481170 for ; Tue, 20 Jun 2023 14:56:28 +0000 (UTC) X-FDA: 80923427256.18.46ED18B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 81FEAC0004 for ; Tue, 20 Jun 2023 14:56:26 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ic679a4u; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1687272986; 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=VjthvFXeQGZeDxQ7unAKOEBDdmvRqvLtJxvDci7YFS0=; b=Lew6CSS2kyimDkuyjbXZ+lVEj3hM/pDYCzXt8R3MKFurmLTDJYSe90Osr5UolJsrA/5cE1 UohKff1D8iOhY7s5AzO9wAv7tpFS7zoYyBtOOGqZ1u9UHbp7sl8Z7s5NBU0yjlnIhkikDv dUWddqSv+v91DBEGLuTkq4GInWmzUg8= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ic679a4u; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf10.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687272986; a=rsa-sha256; cv=none; b=8S1jUozJsXxujUp+m+5curEmZ0gD7+CQStszjfp04TFresm8s3OdtCI++omzRTxe7znvjV Xokd3+5NcA6pj1xRZL9v/ZY0+ApYZTxQ5wIvdcL+k5lHVcCiXLw3+v93/E7Pjwl0p0x3is eLwavI1JbFhbws3doPORUCF7G9lep2s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687272985; 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=VjthvFXeQGZeDxQ7unAKOEBDdmvRqvLtJxvDci7YFS0=; b=Ic679a4uW/2nh+IwWXflpHUoqjQ/vGI1ej1xpzMss1a2RiNWNj+ruiYUUtcpnoKil0TjDO 17/iCZVTmg0axpCqJ+YMf2dDmcZ8LkPEKp6HpcUDVhmzBXfLUjvN9zYqO5WJ/QQpE+2Fl+ iXVP3gawexfv26LgT00m2yXaS8jMtLc= 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-414-iKtTzmMANW2P_f63qnZVtw-1; Tue, 20 Jun 2023 10:56:20 -0400 X-MC-Unique: iKtTzmMANW2P_f63qnZVtw-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 36AF58A6967; Tue, 20 Jun 2023 14:53:53 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 35FACC1ED97; Tue, 20 Jun 2023 14:53:51 +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, Bernard Metzler , Tom Talpey , Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org Subject: [PATCH net-next v3 04/18] siw: Use sendmsg(MSG_SPLICE_PAGES) rather than sendpage to transmit Date: Tue, 20 Jun 2023 15:53:23 +0100 Message-ID: <20230620145338.1300897-5-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspam-User: X-Stat-Signature: o95yqsrerkjz3dfeqsjr1b6dfshns5z8 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 81FEAC0004 X-HE-Tag: 1687272986-657945 X-HE-Meta: U2FsdGVkX1/iCgpQONcfKJOmFrpy8Shcbc2tlbemBx2upNTMbVfu5aTYQSZd8bbrlzo4Kfrd+UXmWhCZgFsQBCkuqlg+bk7yyYWi5US6ds2NP0i1IFDM1gcwMseA+Bz1oy0jZHL5M6OwyB6nYa+Khq38x24oyK8TR2ZdTR2+MjdpSH6AuFzSV0lcL3IRRq8tVZZkHeKGfUO//XFTcyRPNbF20V8wQwKRdhvvZ2wMQjTYfogS+/pg2Am+pYme1QQbcV9cgKS6hksBjN2kuBfXcCM3R5vz0bsYOmeVPXD/s4FxNhMxBenbbHTlC4SUF0HtVNGlDTSY4KsXT39kn/L4Gk83yL9YUPSSs2dpyAQPCu1yVmcJKxRhoPS3cBFQNvk030Sd1R3AiLtXepazVbfPQFOUJ4MpXGqpOQGoer3EMny0tm8E16YB93zyMau6JwIBimPns1Y+OpQiEI5V7M0dC+6ZcMEwnflHq7Qq8izklv8ueclaEDzQUIjFApUTVpZ4Yqj3ruwWm5iH4VCaRJz2499q3FdDBMGccNbacMyOoCjgLmERjKpmT6Xi/uqBPY774xZtglubrDN2sc9Pt0AK7eLSZnSnRt35Fa5V4OvGEZZV5Pzw0beQyRInsMZvH7HlxzguVXSFR2Seu5kgMcBCoSn4c8Ao7ZUTqe7iHbrVERrwwfbNNbAffOaWMDZcZP1C9vNjBfII99/cDbSQRv+BPknCIK2OzrcKPElMPl7jVYM7o4VXhxK2oPwdi8fQBv9uxcIwG9wChPHQxLJ6RqIv6ReUCBBCyTm8Gn8DY6B0FyxQ3SVeHyI/Dn3TDG34k/jh4M+WHh0Y5TTKjnhBZHqRoo/v8+FsRrVHdWTsgl4X2y4osGHNcqfReqoWHIzjj38ucn6TLIeXIE54iM0U14vfQiOMJXEsOc4hmv+x1suI8Tu1TdBy/BhE8jcuPvbVXBAPwd8Fr+VnhXB3DwGqH4l CTxcdnx0 SdXSCeANDQHsEqQgJZLvmJk8+kK0fl343EIADnKa5VYHUJ43ipKAETDFmoeFWjS1Ling7qLRnPZHniZU/npo0LDpOeNJRKlFn9V3ZcKOESS4+mXxDvrvBvcBYLqmiwUAAAFekajUKrJZXSkho9cH5Rs5lkTt0ee8iV9CcEUTeAv6vCdnYjDYPSaS2MbxblOQ0rH91lSIgdhPCZfYetXXrM+GQBwppOuIGQglmu1mklQFQTi/7kqW3atDcIoPoBoBdOHZsOGAtpn9OpBAGEEAJMMgjOCYRURn8dzK3HhkrTfMVlPokA7URL2lEOdfrElQ9RH6H2CXNFE4hRV+LMA8rIfLL+xSm1lnskbyObJE6Q2V4kGTLjeMmKfyQj9kQoQ7F9z9KRPmEP0KfbjqxIG77Uvp6IeYIWj8OECbuvb87zaDjYKDluAite2d2cH7ylYVxP3+aQRHV76NVkmf6IsGQuOJGcINzL+icltzZoeUCSvsBFFzNUF/lNhPJ/q8c3sGi/P3ZPFGxlF0c3ndLM6/sfFmuwq7nbKJXNMm5vnaQUcXn126oPr/UmnG4f4KmdpNFvah9eu9CifHSniSJzjGNKZWDP8LP/6nTMYWN4tq85/Xb3l2geyX3zpffdF4IeiamGYLn 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 single sendmsg with MSG_SPLICE_PAGES to indicate that content should be spliced rather than performing several sendmsg and sendpage calls to transmit header, data pages and trailer. To make this work, the data is assembled in a bio_vec array and attached to a BVEC-type iterator. The header and trailer (if present) are copied into page fragments that can be freed with put_page(). Signed-off-by: David Howells cc: Bernard Metzler cc: Tom Talpey cc: Jason Gunthorpe cc: Leon Romanovsky cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: linux-rdma@vger.kernel.org cc: netdev@vger.kernel.org Reviewed-by: Bernard Metzler --- Notes: ver #2) - Wrap lines at 80. drivers/infiniband/sw/siw/siw_qp_tx.c | 231 ++++---------------------- 1 file changed, 36 insertions(+), 195 deletions(-) diff --git a/drivers/infiniband/sw/siw/siw_qp_tx.c b/drivers/infiniband/sw/siw/siw_qp_tx.c index ffb16beb6c30..2584f9da0dd8 100644 --- a/drivers/infiniband/sw/siw/siw_qp_tx.c +++ b/drivers/infiniband/sw/siw/siw_qp_tx.c @@ -311,114 +311,8 @@ static int siw_tx_ctrl(struct siw_iwarp_tx *c_tx, struct socket *s, return rv; } -/* - * 0copy TCP transmit interface: Use MSG_SPLICE_PAGES. - * - * Using sendpage to push page by page appears to be less efficient - * than using sendmsg, even if data are copied. - * - * A general performance limitation might be the extra four bytes - * trailer checksum segment to be pushed after user data. - */ -static int siw_tcp_sendpages(struct socket *s, struct page **page, int offset, - size_t size) -{ - struct bio_vec bvec; - struct msghdr msg = { - .msg_flags = (MSG_MORE | MSG_DONTWAIT | MSG_SENDPAGE_NOTLAST | - MSG_SPLICE_PAGES), - }; - struct sock *sk = s->sk; - int i = 0, rv = 0, sent = 0; - - while (size) { - size_t bytes = min_t(size_t, PAGE_SIZE - offset, size); - - if (size + offset <= PAGE_SIZE) - msg.msg_flags &= ~MSG_SENDPAGE_NOTLAST; - - tcp_rate_check_app_limited(sk); - bvec_set_page(&bvec, page[i], bytes, offset); - iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, size); - -try_page_again: - lock_sock(sk); - rv = tcp_sendmsg_locked(sk, &msg, size); - release_sock(sk); - - if (rv > 0) { - size -= rv; - sent += rv; - if (rv != bytes) { - offset += rv; - bytes -= rv; - goto try_page_again; - } - offset = 0; - } else { - if (rv == -EAGAIN || rv == 0) - break; - return rv; - } - i++; - } - return sent; -} - -/* - * siw_0copy_tx() - * - * Pushes list of pages to TCP socket. If pages from multiple - * SGE's, all referenced pages of each SGE are pushed in one - * shot. - */ -static int siw_0copy_tx(struct socket *s, struct page **page, - struct siw_sge *sge, unsigned int offset, - unsigned int size) -{ - int i = 0, sent = 0, rv; - int sge_bytes = min(sge->length - offset, size); - - offset = (sge->laddr + offset) & ~PAGE_MASK; - - while (sent != size) { - rv = siw_tcp_sendpages(s, &page[i], offset, sge_bytes); - if (rv >= 0) { - sent += rv; - if (size == sent || sge_bytes > rv) - break; - - i += PAGE_ALIGN(sge_bytes + offset) >> PAGE_SHIFT; - sge++; - sge_bytes = min(sge->length, size - sent); - offset = sge->laddr & ~PAGE_MASK; - } else { - sent = rv; - break; - } - } - return sent; -} - #define MAX_TRAILER (MPA_CRC_SIZE + 4) -static void siw_unmap_pages(struct kvec *iov, unsigned long kmap_mask, int len) -{ - int i; - - /* - * Work backwards through the array to honor the kmap_local_page() - * ordering requirements. - */ - for (i = (len-1); i >= 0; i--) { - if (kmap_mask & BIT(i)) { - unsigned long addr = (unsigned long)iov[i].iov_base; - - kunmap_local((void *)(addr & PAGE_MASK)); - } - } -} - /* * siw_tx_hdt() tries to push a complete packet to TCP where all * packet fragments are referenced by the elements of one iovec. @@ -438,30 +332,21 @@ static int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s) { struct siw_wqe *wqe = &c_tx->wqe_active; struct siw_sge *sge = &wqe->sqe.sge[c_tx->sge_idx]; - struct kvec iov[MAX_ARRAY]; - struct page *page_array[MAX_ARRAY]; + struct bio_vec bvec[MAX_ARRAY]; struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_EOR }; + void *trl; int seg = 0, do_crc = c_tx->do_crc, is_kva = 0, rv; unsigned int data_len = c_tx->bytes_unsent, hdr_len = 0, trl_len = 0, sge_off = c_tx->sge_off, sge_idx = c_tx->sge_idx, pbl_idx = c_tx->pbl_idx; - unsigned long kmap_mask = 0L; if (c_tx->state == SIW_SEND_HDR) { - if (c_tx->use_sendpage) { - rv = siw_tx_ctrl(c_tx, s, MSG_DONTWAIT | MSG_MORE); - if (rv) - goto done; + void *hdr = &c_tx->pkt.ctrl + c_tx->ctrl_sent; - c_tx->state = SIW_SEND_DATA; - } else { - iov[0].iov_base = - (char *)&c_tx->pkt.ctrl + c_tx->ctrl_sent; - iov[0].iov_len = hdr_len = - c_tx->ctrl_len - c_tx->ctrl_sent; - seg = 1; - } + hdr_len = c_tx->ctrl_len - c_tx->ctrl_sent; + bvec_set_virt(&bvec[0], hdr, hdr_len); + seg = 1; } wqe->processed += data_len; @@ -477,28 +362,9 @@ static int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s) } else { is_kva = 1; } - if (is_kva && !c_tx->use_sendpage) { - /* - * tx from kernel virtual address: either inline data - * or memory region with assigned kernel buffer - */ - iov[seg].iov_base = - ib_virt_dma_to_ptr(sge->laddr + sge_off); - iov[seg].iov_len = sge_len; - - if (do_crc) - crypto_shash_update(c_tx->mpa_crc_hd, - iov[seg].iov_base, - sge_len); - sge_off += sge_len; - data_len -= sge_len; - seg++; - goto sge_done; - } while (sge_len) { size_t plen = min((int)PAGE_SIZE - fp_off, sge_len); - void *kaddr; if (!is_kva) { struct page *p; @@ -511,33 +377,12 @@ static int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s) p = siw_get_upage(mem->umem, sge->laddr + sge_off); if (unlikely(!p)) { - siw_unmap_pages(iov, kmap_mask, seg); wqe->processed -= c_tx->bytes_unsent; rv = -EFAULT; goto done_crc; } - page_array[seg] = p; - - if (!c_tx->use_sendpage) { - void *kaddr = kmap_local_page(p); - - /* Remember for later kunmap() */ - kmap_mask |= BIT(seg); - iov[seg].iov_base = kaddr + fp_off; - iov[seg].iov_len = plen; - - if (do_crc) - crypto_shash_update( - c_tx->mpa_crc_hd, - iov[seg].iov_base, - plen); - } else if (do_crc) { - kaddr = kmap_local_page(p); - crypto_shash_update(c_tx->mpa_crc_hd, - kaddr + fp_off, - plen); - kunmap_local(kaddr); - } + + bvec_set_page(&bvec[seg], p, plen, fp_off); } else { /* * Cast to an uintptr_t to preserve all 64 bits @@ -545,12 +390,17 @@ static int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s) */ u64 va = sge->laddr + sge_off; - page_array[seg] = ib_virt_dma_to_page(va); - if (do_crc) - crypto_shash_update( - c_tx->mpa_crc_hd, - ib_virt_dma_to_ptr(va), - plen); + bvec_set_virt(&bvec[seg], + ib_virt_dma_to_ptr(va), plen); + } + + if (do_crc) { + void *kaddr = + kmap_local_page(bvec[seg].bv_page); + crypto_shash_update(c_tx->mpa_crc_hd, + kaddr + bvec[seg].bv_offset, + bvec[seg].bv_len); + kunmap_local(kaddr); } sge_len -= plen; @@ -560,13 +410,12 @@ static int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s) if (++seg >= (int)MAX_ARRAY) { siw_dbg_qp(tx_qp(c_tx), "to many fragments\n"); - siw_unmap_pages(iov, kmap_mask, seg-1); wqe->processed -= c_tx->bytes_unsent; rv = -EMSGSIZE; goto done_crc; } } -sge_done: + /* Update SGE variables at end of SGE */ if (sge_off == sge->length && (data_len != 0 || wqe->processed < wqe->bytes)) { @@ -575,15 +424,8 @@ static int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s) sge_off = 0; } } - /* trailer */ - if (likely(c_tx->state != SIW_SEND_TRAILER)) { - iov[seg].iov_base = &c_tx->trailer.pad[4 - c_tx->pad]; - iov[seg].iov_len = trl_len = MAX_TRAILER - (4 - c_tx->pad); - } else { - iov[seg].iov_base = &c_tx->trailer.pad[c_tx->ctrl_sent]; - iov[seg].iov_len = trl_len = MAX_TRAILER - c_tx->ctrl_sent; - } + /* Set the CRC in the trailer */ if (c_tx->pad) { *(u32 *)c_tx->trailer.pad = 0; if (do_crc) @@ -596,23 +438,23 @@ static int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s) else if (do_crc) crypto_shash_final(c_tx->mpa_crc_hd, (u8 *)&c_tx->trailer.crc); - data_len = c_tx->bytes_unsent; - - if (c_tx->use_sendpage) { - rv = siw_0copy_tx(s, page_array, &wqe->sqe.sge[c_tx->sge_idx], - c_tx->sge_off, data_len); - if (rv == data_len) { - rv = kernel_sendmsg(s, &msg, &iov[seg], 1, trl_len); - if (rv > 0) - rv += data_len; - else - rv = data_len; - } + /* Copy the trailer and add it to the output list */ + if (likely(c_tx->state != SIW_SEND_TRAILER)) { + trl = &c_tx->trailer.pad[4 - c_tx->pad]; + trl_len = MAX_TRAILER - (4 - c_tx->pad); } else { - rv = kernel_sendmsg(s, &msg, iov, seg + 1, - hdr_len + data_len + trl_len); - siw_unmap_pages(iov, kmap_mask, seg); + trl = &c_tx->trailer.pad[c_tx->ctrl_sent]; + trl_len = MAX_TRAILER - c_tx->ctrl_sent; } + bvec_set_virt(&bvec[seg], trl, trl_len); + + data_len = c_tx->bytes_unsent; + + if (c_tx->use_sendpage) + msg.msg_flags |= MSG_SPLICE_PAGES; + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, bvec, seg + 1, + hdr_len + data_len + trl_len); + rv = sock_sendmsg(s, &msg); if (rv < (int)hdr_len) { /* Not even complete hdr pushed or negative rv */ wqe->processed -= data_len; @@ -673,7 +515,6 @@ static int siw_tx_hdt(struct siw_iwarp_tx *c_tx, struct socket *s) } done_crc: c_tx->do_crc = 0; -done: return rv; } From patchwork Tue Jun 20 14:53:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13285994 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 25FFCEB64DB for ; Tue, 20 Jun 2023 14:55:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E8D98D0007; Tue, 20 Jun 2023 10:55:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0733A8D0001; Tue, 20 Jun 2023 10:55:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1AE48D0007; Tue, 20 Jun 2023 10:55:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B64C88D0001 for ; Tue, 20 Jun 2023 10:55:43 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7C861411C0 for ; Tue, 20 Jun 2023 14:55:43 +0000 (UTC) X-FDA: 80923425366.28.A786B39 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 921C420015 for ; Tue, 20 Jun 2023 14:55:41 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eZOvktRr; spf=pass (imf13.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1687272941; 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=1DmsLXNf6UEopicQGVGHzvB3R+Io/k4xNBk1zidfJPQ=; b=vgxtQ3P2+tWPlES+u+n0IEKG9hiN/XaYpsM/BHrW4VMRQfJjBz0bULucGu2+pnM7Qk6KE3 1+ijG6VaSezlT31aZFI4LRoyJaV98y20IZ2UMSeS9eIS3ZWSBd/zLqCnagjYhsIhlOscSk Wy7uYEvd9HKcfhNMhK6HElVS5kSt49s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687272941; a=rsa-sha256; cv=none; b=hjKQ1XgQpfkAFvz/e6Eg4Vp+svXAfalpDijhmU/8Xl7izJXn73TJglKTc2v7wNmrwh1t2n uGKA361n3uX0GUdqPt9FS+XzzmVyQBHLTPMwzSExIfLTiOauQBYITqY3b9SbM2vabxcT9f iyzQnVWCfBpqDGOr5JB16TwvnSkOI00= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=eZOvktRr; spf=pass (imf13.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687272940; 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=1DmsLXNf6UEopicQGVGHzvB3R+Io/k4xNBk1zidfJPQ=; b=eZOvktRr3vJRixEPxcduNGJmxz8sB5lSuNQeyyb76cELvo/sfEZL8wTtCE77wSCojOw088 +7OZHMiP5uKZpd+DEyDzv8aTX4dQbD8LL7tLEEsMMaoNyzWC71KIJMS7vmggsphXD2YGku rWee3S/+RPHavl2G1+S/brYGvrb9ztw= 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-644-q3ToHJJIOfyekEbhjCK1ZA-1; Tue, 20 Jun 2023 10:55:36 -0400 X-MC-Unique: q3ToHJJIOfyekEbhjCK1ZA-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 A0FD23814975; Tue, 20 Jun 2023 14:53:55 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id D552B492C13; Tue, 20 Jun 2023 14:53:53 +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 v3 05/18] ceph: Use sendmsg(MSG_SPLICE_PAGES) rather than sendpage Date: Tue, 20 Jun 2023 15:53:24 +0100 Message-ID: <20230620145338.1300897-6-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspamd-Queue-Id: 921C420015 X-Rspam-User: X-Stat-Signature: md3zdbd5oi9hdrb8a3nxnjjxgtu1bjrc X-Rspamd-Server: rspam03 X-HE-Tag: 1687272941-148915 X-HE-Meta: U2FsdGVkX1/wm/nPcTsFjo/ESrp1Lv7A6VPt14f8GcABsOgooEwIGbp8ur4e7yzhCwTv6QN4wzIPVKQ66yAgDMHrOk+ZqiXdOGWgyz6uQFWWqCMlNi4kQwuo5FJCXGKWsftl/FSpbTt4FuWuISYfiS2K+0IK84a0k70mkMoapkvmHNv0tpc/WuAy/kjgJw2EpgWYfcg4ZucFVzhr/yNQuMFyLYN926qY57koY14PWWnAMyXmTyzI/YXjCcDSioE4lzJSxgE+4kP0P8ncFFHu7J5odINt9NpBoemZGVUXQ/cDBOz1q00GkXKNGia6p0sx2XqiK3iwh/Gn+UrlvZSgOwSD9R23trLL/YIi0/cT20Hn7zeGfsdWlzr3zeBECqw2iTsBSwL3Hr5l+moXNxOeuyEtGSOsoA4aCB8EeoaRDpgTbuRvCKsPnf2kqZtiD9tez4+Blw07iz0AWds+O9rrblOsRG/Ad5pm1RnhWKLr/AsSulvVMNuOMg7qRPlFK+jAV2rXffL4g61Z2WEPM+1k5q8rfsE0IhD/MiHksfjyF9AX9kTBinacOCJ7XR/Fa4DR2O274PRht1+pYpiomT+9HFMsyZVDwlDkR/6M+/rAydMB2njfrWK1gNA7B0jCPdcQwgFrnZOnZUNi4qfKrRflo9C9E48pX76hlYzb+ry/CCjQl4jVLd+ZJ6I3bH5q+NvnF/jjp6LeGuvvKw2tziqlI6X4RjAfSh9xwbnZVjbw5XkIJLXohl2idm01kk4jSA6sEra0Vfu02kI1+roymJPgO9XxeV1b0aYZJkv+ghKpKYflqUD3ymHg2YjELfVNIQDgVedpv9+671ZnLFwZ1iBNWvYF2HD3po37z9LU7ZPEzPSeg0nQJkh56ufOj+YnH+e32UPXWCjl9bKfUT3GU+q2mzu3bF1hEeZeRdYJ1ZQSxEfUzHqnW/DjrjhMu9+4foYrI3jWjBIdMwjE6ziy7fC hhjDFrPr PVn0YFCjzQ1NOqNjBCG4UI9knDgjvIplbXR6owvDJfqp/TlUgr3ToBKxOSdr88TO19Wwz2E34FeZIC1fWsKtPkxADZc9NVnfqGBBVgZfyvKh0jui2/2KtMIHs12uYW0KkkS8iICfN8dquYk3AEJr/mvP7sQeOlUF1VLrH7B9pLWzjUzllmwe7Z8GFXX8uiANdH9BoKk4wFUAPgK/28M3UQYABUK9HdrpnJgJ3bdwShd8SOV70GyGBy59vAw5Ei7pzs7DU072YGbY1CDrVccwBjVf7l/g45hyjC6i5AYESNTXePsUXeV8CKp6RXjOHiDrfE4YVmDyHpIn3TYYj9Zvb2AIkKboAKW5oivOKAOo7+WEbtXA4zhcFtps/PEK636fZ65dX4fKsuGQsaXtmQuu7its/29J56nRTYXwk2Ln13hHLWHUZCtTz+i0pirCkizPM/Kz9ESGLKJJZx+OoJMr88I5p/Lsr5SDvtcrfUtPHPWYyMEGcNq7R97HYhROCFy1mQlUDV80eZ0mLRwk= 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 --- net/ceph/messenger_v1.c | 58 ++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 39 deletions(-) diff --git a/net/ceph/messenger_v1.c b/net/ceph/messenger_v1.c index d664cb1593a7..f082e5c780a3 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; @@ -494,9 +466,12 @@ 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); + 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; From patchwork Tue Jun 20 14:53:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13285995 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 014F9EB64D7 for ; Tue, 20 Jun 2023 14:56:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7296F8D0008; Tue, 20 Jun 2023 10:56:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B2318D0001; Tue, 20 Jun 2023 10:56:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52BE68D0008; Tue, 20 Jun 2023 10:56:00 -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 40D028D0001 for ; Tue, 20 Jun 2023 10:56:00 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 18AB3A11A0 for ; Tue, 20 Jun 2023 14:56:00 +0000 (UTC) X-FDA: 80923426080.14.F9DF0F1 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 47BA71C0003 for ; Tue, 20 Jun 2023 14:55:57 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=A9R5RvLb; spf=pass (imf21.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=1687272958; 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=XZXyJFmNcOo4OqBa8WBusNB3ZLLcguzSLjkBKTvuk5o=; b=Mq1hHkVhbS6ZbC9q5wZBUJxuQupO3TLMSoayZO+WiIIBdRxFHyIdQQzKQTiiJfYZuFEne5 3w2Lq/t+WaI200CGAZi2zcDAUZNXpG6dYw7uR0Zo4aAQVJ1HxiFndCVXgAe1F6hdnP0RF6 kADeGpMqtu8a3gX0ffRbUZ9E7uaTY2w= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687272958; a=rsa-sha256; cv=none; b=RzMGviRGkrgi6PXrSUa+bG3yKVTEGV6afH7E7yXMkdZwPKsuwig6T/ceq0tfX89Ze6lyg4 qbBQT9E2jfqlOId9dxdls8EYuHGqP3W+aQ1RUp1Me6HQ/G929RMzTlrDRSNZeDGp0rsu6y rlV8sJ+rKNbXV4K2Vjshk3gqJtt3c40= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=A9R5RvLb; spf=pass (imf21.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687272957; 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=XZXyJFmNcOo4OqBa8WBusNB3ZLLcguzSLjkBKTvuk5o=; b=A9R5RvLbzpUdYA2ko2tF3IFmD5bQaOh8y8HRi3nTsbCHgFXBswPCTQTp5jOsdrzgejuJHy 91qfe08Qqwql4+nE3cJpuX9L8SkOxJj5KSoFhw2UpO9HJtPNHVbQ63uVxUYHbCMyhjX4XE jnbo/cjxU5JkTFcpuBpMBgZfHropjL4= 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-549-puJs86kMOViK6oXJMspZfg-1; Tue, 20 Jun 2023 10:55:52 -0400 X-MC-Unique: puJs86kMOViK6oXJMspZfg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9CF2B3C10EE0; Tue, 20 Jun 2023 14:53:57 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 372FB112132E; Tue, 20 Jun 2023 14:53:56 +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 Subject: [PATCH net-next v3 06/18] net: Use sendmsg(MSG_SPLICE_PAGES) not sendpage in skb_send_sock() Date: Tue, 20 Jun 2023 15:53:25 +0100 Message-ID: <20230620145338.1300897-7-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Stat-Signature: wfcmfs1ypdeyag5prz75nh1yjk6f91hd X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 47BA71C0003 X-Rspam-User: X-HE-Tag: 1687272957-894248 X-HE-Meta: U2FsdGVkX1/s7URkoesl+XynVm5rV/WLvAh5FDoGNAnsaxwdf10yAlBKLC6nGOiew84SoHqPmkzKrmvmA6GTBXjY/3gX0++4O/2V/n1LgtwHkjFKSTgL3kFXB29HDfALSCMD36MscxRUo5tUhRBHBO5SzJMpzdvHeSrZSMWRPF08GYyRcs0YS4DmrTrDBOShq/fWa2/WuqBKZyUK47cl9TgXYHsjUhiV1U+eOETJpNSMnT/Zi86yIwXwyN+HmKrcRlbRa8WDef3fk7G0UgxSb1PgFrRDdp8Sr4ZLofWZT1SJwfbzWdT1jFpjKW1wVRCyfxjUvu78p6bise7xOcm4TyD1fiStTpcvy6U9o1IKOi5VAP/KMo2O7iKcf/37KHtH24Pvds97yziidtR7QppOECiuSBDTA2ptFY3UyD+XqLLBa/VwOCuJFLfkMiTO464xUp4hOZIL7XzJfyB43lPzI4N9+WQdgT+UVCRy2nWfaKQXIlSr8hb4a6beppowiLBEkb6GtxanVeXn4Jkbp98eZIDqiMjAiTMVcq9XDiJP8qcnTEV8rXT8xHrOqtq1Ug+dDzAie5rFgNJi9x8kyuDr8MRSq+jWBK3eICVNlHf09y2xqYR2OFtYZVu1Wge6AVQZOrv+N9Jxn4g2NskIjfKZRlZAD+iyne0tQVjSa5/RvN+ieWz+XCSfqNy8a4GVityU/44HM+RpT5uk+B1ogtSRfjdVH78UjpKuBkKZeIz9PSCciqz454KJRyO8GEmzvX8VklnNnwzyC4rS6mTq5HWx4efscZ2sYptIQhNQDupsGPK3n0ujiIhOa0R2c6yz86Jot17aKi6E1+CsStYsTWnHx9l3mBxe0uc5mo0N/C6B8WRos3QXMnWWyWALkhnSLV0nLqTWSXjVV5bL2Zr1hizCk08I2O4rqPmXoIPxe7gAbFLK1jjySRCdRZdYS5Bly/uzPMRLId+sBjMcZPtsjLa 8AAK0ZXV dvDu3NuaiNWB3uBZVIJB3a8BIdQ5xLicYXTpSI4mUTf3DBlC2xLhbIKlYNQYbx730+tqSolcGECtuV4/AHKdKCetr2ALkEnjjaPJqbMl1wTBs1L/G4lzgQtQ4whANguZ0QxOKEZRHQ74nv3gdb4pOwEjBvojQ3fAV7t0ZApMhvGLOqE0ESIs6nU4z+0Qp576ZlxQLjRpMpSAB3QL6P4MZh6j9t7XRp9FJ1F0rsuQzVP33NoL0T81LIefnTZ7zpn9sORWcKhwFRBEp94bVkkFgWRz/t2g7gGSwawDwRubnRc1YNFRAgWvZJOUqHBXWdJSGBillfFjGHOhrontUauwoPAEgBlKMDQd3hkyM6t1IG7JdqV5cpMtj81U4csFGIStA1zT93DvPXREZ95P7YvCcbTjdR69XkooLs+0DjPXEQbV/fkpdo6VvdnQ7BNwvdDrEfhDQjCR1jY0Xjh60jWANNCHBxRo197KCXUQ5ZNKqixUhcWhQx6I1ZeyHmg== 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() with MSG_SPLICE_PAGES rather than sendpage in skb_send_sock(). This causes pages to be spliced from the source iterator if possible. This allows ->sendpage() to be replaced by something that can handle multiple multipage folios in a single transaction. Note that this could perhaps be improved to fill out a bvec array with all the frags and then make a single sendmsg call, possibly sticking the header on the front also. Signed-off-by: David Howells cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- Notes: ver #2) - Wrap lines at 80. net/core/skbuff.c | 50 ++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 36605510a76d..ee2fc8fe31cb 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -2990,32 +2990,32 @@ int skb_splice_bits(struct sk_buff *skb, struct sock *sk, unsigned int offset, } EXPORT_SYMBOL_GPL(skb_splice_bits); -static int sendmsg_unlocked(struct sock *sk, struct msghdr *msg, - struct kvec *vec, size_t num, size_t size) +static int sendmsg_locked(struct sock *sk, struct msghdr *msg) { struct socket *sock = sk->sk_socket; + size_t size = msg_data_left(msg); if (!sock) return -EINVAL; - return kernel_sendmsg(sock, msg, vec, num, size); + + if (!sock->ops->sendmsg_locked) + return sock_no_sendmsg_locked(sk, msg, size); + + return sock->ops->sendmsg_locked(sk, msg, size); } -static int sendpage_unlocked(struct sock *sk, struct page *page, int offset, - size_t size, int flags) +static int sendmsg_unlocked(struct sock *sk, struct msghdr *msg) { struct socket *sock = sk->sk_socket; if (!sock) return -EINVAL; - return kernel_sendpage(sock, page, offset, size, flags); + return sock_sendmsg(sock, msg); } -typedef int (*sendmsg_func)(struct sock *sk, struct msghdr *msg, - struct kvec *vec, size_t num, size_t size); -typedef int (*sendpage_func)(struct sock *sk, struct page *page, int offset, - size_t size, int flags); +typedef int (*sendmsg_func)(struct sock *sk, struct msghdr *msg); static int __skb_send_sock(struct sock *sk, struct sk_buff *skb, int offset, - int len, sendmsg_func sendmsg, sendpage_func sendpage) + int len, sendmsg_func sendmsg) { unsigned int orig_len = len; struct sk_buff *head = skb; @@ -3035,8 +3035,9 @@ static int __skb_send_sock(struct sock *sk, struct sk_buff *skb, int offset, memset(&msg, 0, sizeof(msg)); msg.msg_flags = MSG_DONTWAIT; - ret = INDIRECT_CALL_2(sendmsg, kernel_sendmsg_locked, - sendmsg_unlocked, sk, &msg, &kv, 1, slen); + iov_iter_kvec(&msg.msg_iter, ITER_SOURCE, &kv, 1, slen); + ret = INDIRECT_CALL_2(sendmsg, sendmsg_locked, + sendmsg_unlocked, sk, &msg); if (ret <= 0) goto error; @@ -3067,11 +3068,18 @@ static int __skb_send_sock(struct sock *sk, struct sk_buff *skb, int offset, slen = min_t(size_t, len, skb_frag_size(frag) - offset); while (slen) { - ret = INDIRECT_CALL_2(sendpage, kernel_sendpage_locked, - sendpage_unlocked, sk, - skb_frag_page(frag), - skb_frag_off(frag) + offset, - slen, MSG_DONTWAIT); + struct bio_vec bvec; + struct msghdr msg = { + .msg_flags = MSG_SPLICE_PAGES | MSG_DONTWAIT, + }; + + bvec_set_page(&bvec, skb_frag_page(frag), slen, + skb_frag_off(frag) + offset); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, + slen); + + ret = INDIRECT_CALL_2(sendmsg, sendmsg_locked, + sendmsg_unlocked, sk, &msg); if (ret <= 0) goto error; @@ -3108,16 +3116,14 @@ static int __skb_send_sock(struct sock *sk, struct sk_buff *skb, int offset, int skb_send_sock_locked(struct sock *sk, struct sk_buff *skb, int offset, int len) { - return __skb_send_sock(sk, skb, offset, len, kernel_sendmsg_locked, - kernel_sendpage_locked); + return __skb_send_sock(sk, skb, offset, len, sendmsg_locked); } EXPORT_SYMBOL_GPL(skb_send_sock_locked); /* Send skb data on a socket. Socket must be unlocked. */ int skb_send_sock(struct sock *sk, struct sk_buff *skb, int offset, int len) { - return __skb_send_sock(sk, skb, offset, len, sendmsg_unlocked, - sendpage_unlocked); + return __skb_send_sock(sk, skb, offset, len, sendmsg_unlocked); } /** From patchwork Tue Jun 20 14:53:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13286014 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 288DBEB64DB for ; Tue, 20 Jun 2023 14:57:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BBCA08D000F; Tue, 20 Jun 2023 10:57:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B6C588D0001; Tue, 20 Jun 2023 10:57:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0D8C8D000F; Tue, 20 Jun 2023 10:57:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8D53F8D0001 for ; Tue, 20 Jun 2023 10:57:03 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6413C1C9684 for ; Tue, 20 Jun 2023 14:57:03 +0000 (UTC) X-FDA: 80923428726.16.D070D15 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 9429D180009 for ; Tue, 20 Jun 2023 14:57:01 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bwK7r9mO; spf=pass (imf24.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=1687273021; 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=fSQZQ6YboxRaXsiohOL5R9kf0uRRv2lhrE9A+pyCn4U=; b=ytfbmh4BMHUl/ChEzRoQa8W2Kd2ozZUxbV54zhTy4hLNhbhUsNE8+mGX09p4HlpsQwGyUA +2req1xQ0CgBa/PzRvTfq5qxaphOKtJsAjqeQ3w3tyzIHjM+VF1uUE/p2E6pDGAeVz9Dns 3xveNDVLKW9Fsf5IYVeqDYj4wxcHYxk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687273021; a=rsa-sha256; cv=none; b=6gSX/Pygp9T4ijm5cR9mxxqk5Vy9C2H/mO3C9EDtTa3X/csFSVnYBz04J5qyfKi/x1y9TV btJyYIZ5RzVX2vyRNh+OcFcF/7VaCs73TinNh4lbPmj3NsGMCkSHpz81fFsdXH76If2cOX PsyVMiHxlZL+tnGk6urn/8fTS/kuZnU= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bwK7r9mO; spf=pass (imf24.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687273020; 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=fSQZQ6YboxRaXsiohOL5R9kf0uRRv2lhrE9A+pyCn4U=; b=bwK7r9mOkS554t7CClHkhuML0HuXm0IRSHco2bemxpPL8svNcjNQiRWf+b4ztfnwbqpeNs 5U2JKMPoElR1m+vznmxP8+xdRlmsjIKmifttZKwJZCv5y1wQvr4igF50RKtx+L3ZGWU9Xw 4wr+89NDgVWOHYH2W3dWGy43ZIvA7UQ= 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-629-Z9ENlngsPYSmfCtfvR07VA-1; Tue, 20 Jun 2023 10:56:46 -0400 X-MC-Unique: Z9ENlngsPYSmfCtfvR07VA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 157BC3823A0C; Tue, 20 Jun 2023 14:54:18 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30210200C0DA; Tue, 20 Jun 2023 14:53:58 +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 v3 07/18] ceph: Use sendmsg(MSG_SPLICE_PAGES) rather than sendpage() Date: Tue, 20 Jun 2023 15:53:26 +0100 Message-ID: <20230620145338.1300897-8-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Stat-Signature: meomcimrij8oykwrwr8tn6dsstdctqm8 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9429D180009 X-Rspam-User: X-HE-Tag: 1687273021-923204 X-HE-Meta: U2FsdGVkX19eVm2kjC08OmcXs3GulvrMPoEsP5dEcFfIyuihPKblWfQiIjSw4LqksaXFrYUDwEZEh0b2VeH9M7H/f0M19g2rOwL+6Nm+CBY8hhbNJ8FT8xFF669bDMeuuHgk5burSRN5Z9uHw/UqvUb3IeD+algN507sU3b2w23hHfiee8GsrxghUFwmUPo4NMJR4NiHAfDxAoYZLpSHoQLPy8N/pgc9DkKKtRf0dPlfUtd9iIw6lafCKovDW6NdBSVkrwW/NqZ+89dYQ4Vn1HXO5XA2cT1yMOIGR4SdlMUhjYl8oWiV0oGRmyt+2avssNf90T1VrwM/IRtJbKOvWyTRJ27LKpeHyp6uziB1rC+qpIQmo/9pX0+R7plrPhP3LYlQTfI4zUUrOYuZ2MSKSCBBFCAkfdH6thktrRy2ceK0Vk8BUZKhwkSFU/4o5O9UgnncjQbOKUYztHpi/pQ6vWz9TtstmgyipY5aslvLZ2l/pQhV3bNUuLyk85UPS7n1Vo38coqvS1dC07Bs0WgPlXwhcD3jtsz8HBHZLMn/yqEwVCM9Lc/Kzj/Vi8RTlh8b8eis3He8xkKSc8x4RQx7WQcREfueFFgdfB/fO7DXr1V577UhoH5sRaij1x0AVs3SteObnSItYmGNMlQmM5tdt6SDiEK0EufDgNh4jSLO1ehq3o2NpqS34hLb8IeDuKjh1UYXnuF8NFmq3DQpIqoVpxLWDd7j4xTnkpLeHDFRLgfekv2dA0UsocFKrlnFmaC5S2a2umWy9wQ94WcLaSI+y4AH423PoFvxiUedJfvqlzeApFmFFhI6MIIKtiFQ12rr6BaL+ddpJTv5GTHOGh9QAdDtfYhxpdAzN8q/lRyCAjAiknJdBPzq5RBiSAec4htibiNB0iICNk7WEwG6Ua8gmOeeD0Sf1RF2DZ9MrjjAwwV39ZDW03XNyi/6EiRy0mJArCnRHU1JON5tV6uBIjw yDeLCESv 7hcUHs7LF2A0tKibf4gMxwDMv7FRSsR3+OD0v2Wtn9Gqw4M4Qm0jYe1c9XWSJxWQ6AsmyTjVDczmtx7i1Sp6ToRlrbKr/x7/CIfn3A1RPccTao7yFi++fOCm2wLwgqChZQ+vfBOD938FN6/64I2Fq//u6NsI7TOJ0JePnkLJPMKXoxoPdmJM4IXFx0iDg2RBAw3WQIj6R4v3ucWW8uUQex8/AIhrhAGe9vMW3GKiRRhnEocvbES54VqeJqpgxQfnIrkT/svnn7mTQ+aaYzFMSnsve2OYVITZR74rJ6oEerSZp53WqDZVYLULlyYAMIhvofpzi/URUc4PilPaAcN5jbEEUA6THt70/2EUvQtE3FrIdwbCEetZN0VV1UGNoG7mG1XB+xCxXLlWaI6TxArPvIX5grAVZKfUoRro6Zn4Ddvtzpc/LPVK4TZwiJaIYqfBFgsPeHRdlvlZQZlOJarnWwAL/uG4YVqwUuhpyJf6nVEXUqJu4R2On2llBP0bzBnV2EkGHDYxW5GKRLgE= 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 --- net/ceph/messenger_v2.c | 91 +++++++++-------------------------------- 1 file changed, 19 insertions(+), 72 deletions(-) diff --git a/net/ceph/messenger_v2.c b/net/ceph/messenger_v2.c index 301a991dc6a6..87ac97073e75 100644 --- a/net/ceph/messenger_v2.c +++ b/net/ceph/messenger_v2.c @@ -117,91 +117,38 @@ static int ceph_tcp_recv(struct ceph_connection *con) return ret; } -static int do_sendmsg(struct socket *sock, struct iov_iter *it) -{ - struct msghdr msg = { .msg_flags = CEPH_MSG_FLAGS }; - int ret; - - msg.msg_iter = *it; - while (iov_iter_count(it)) { - ret = sock_sendmsg(sock, &msg); - if (ret <= 0) { - if (ret == -EAGAIN) - ret = 0; - return ret; - } - - iov_iter_advance(it, ret); - } - - WARN_ON(msg_data_left(&msg)); - return 1; -} - -static int do_try_sendpage(struct socket *sock, struct iov_iter *it) -{ - struct msghdr msg = { .msg_flags = CEPH_MSG_FLAGS }; - struct bio_vec bv; - int ret; - - if (WARN_ON(!iov_iter_is_bvec(it))) - return -EINVAL; - - while (iov_iter_count(it)) { - /* iov_iter_iovec() for ITER_BVEC */ - bvec_set_page(&bv, it->bvec->bv_page, - min(iov_iter_count(it), - it->bvec->bv_len - it->iov_offset), - it->bvec->bv_offset + it->iov_offset); - - /* - * 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(bv.bv_page)) { - ret = sock->ops->sendpage(sock, bv.bv_page, - bv.bv_offset, bv.bv_len, - CEPH_MSG_FLAGS); - } else { - iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bv, 1, bv.bv_len); - ret = sock_sendmsg(sock, &msg); - } - if (ret <= 0) { - if (ret == -EAGAIN) - ret = 0; - return ret; - } - - iov_iter_advance(it, ret); - } - - return 1; -} - /* * Write as much as possible. The socket is expected to be corked, - * so we don't bother with MSG_MORE/MSG_SENDPAGE_NOTLAST here. + * so we don't bother with MSG_MORE here. * * Return: - * 1 - done, nothing (else) to write + * >0 - done, nothing (else) to write * 0 - socket is full, need to wait * <0 - error */ static int ceph_tcp_send(struct ceph_connection *con) { + struct msghdr msg = { + .msg_iter = con->v2.out_iter, + .msg_flags = CEPH_MSG_FLAGS, + }; int ret; + if (WARN_ON(!iov_iter_is_bvec(&con->v2.out_iter))) + return -EINVAL; + + if (con->v2.out_iter_sendpage) + msg.msg_flags |= MSG_SPLICE_PAGES; + dout("%s con %p have %zu try_sendpage %d\n", __func__, con, iov_iter_count(&con->v2.out_iter), con->v2.out_iter_sendpage); - if (con->v2.out_iter_sendpage) - ret = do_try_sendpage(con->sock, &con->v2.out_iter); - else - ret = do_sendmsg(con->sock, &con->v2.out_iter); + + ret = sock_sendmsg(con->sock, &msg); + if (ret > 0) + iov_iter_advance(&con->v2.out_iter, ret); + else if (ret == -EAGAIN) + ret = 0; + dout("%s con %p ret %d left %zu\n", __func__, con, ret, iov_iter_count(&con->v2.out_iter)); return ret; From patchwork Tue Jun 20 14:53:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13286010 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 57E0AEB64D7 for ; Tue, 20 Jun 2023 14:56:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDF6D8D0005; Tue, 20 Jun 2023 10:56:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D68A08D0001; Tue, 20 Jun 2023 10:56:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C303A8D0005; Tue, 20 Jun 2023 10:56:39 -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 AEAC48D0001 for ; Tue, 20 Jun 2023 10:56:39 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 54B7F1A116B for ; Tue, 20 Jun 2023 14:56:39 +0000 (UTC) X-FDA: 80923427718.21.D8DA0EC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 2F346100004 for ; Tue, 20 Jun 2023 14:56:36 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K11U+9Mq; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1687272997; 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=Fr8R9cUCocDj4LYXtGmeXkCgA5OgO4hqxYPqdNjfTX8=; b=oRfPQReHgIszVbnfFvNYfBVaWsYvxIN0x+yvPWnWM+j/yA9AQZVqNylKQX3p4h0CNPQZHz YkdiMJhWQZtCbJam6kDpZl84k7JNxWNBMySTd/LzTIl+693oQDLIZ+zk75Eux77AuumGFb JU751es4d7/KekrQbQ0Piec4DdPwizA= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=K11U+9Mq; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687272997; a=rsa-sha256; cv=none; b=iBmznTnisgOy9FRgNuP89SZ1FQGEZPdxkK85Fj3pQ0Q6hr1xjZvKJrCwDNMb85bXQHzh28 ZZ/gNhQP/iV38cmNZ1txj/6CArRb6FcmfWOdgR6uN3kJCWnfqBKyZpHp69crqD7m97btyA 5tw3fha7+FJpjKg5mLJ/qEhJ6RdrHKQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687272996; 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=Fr8R9cUCocDj4LYXtGmeXkCgA5OgO4hqxYPqdNjfTX8=; b=K11U+9MqYcMS/Ny2dYdvbS9vqB/ZmJFQs3131VgiGMKgXUGuyOHaCSa7u2ZpdVDmB1KfUJ YwWTedBB5V1nYxxncvx36o17ft+HmoDeRRX/LXvniPbOWoWktyEZm0LMYlYUwi+5fvXta9 ByesKlN3mzAXlH5oux2oSnOIK4dI17g= 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-264-MX17dbQIPO-VqzbjHhAp6A-1; Tue, 20 Jun 2023 10:56:30 -0400 X-MC-Unique: MX17dbQIPO-VqzbjHhAp6A-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 767F18D142C; Tue, 20 Jun 2023 14:54:20 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6327C1ED97; Tue, 20 Jun 2023 14:54:18 +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, Santosh Shilimkar , linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com Subject: [PATCH net-next v3 08/18] rds: Use sendmsg(MSG_SPLICE_PAGES) rather than sendpage Date: Tue, 20 Jun 2023 15:53:27 +0100 Message-ID: <20230620145338.1300897-9-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Queue-Id: 2F346100004 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: u9rjbwf6b7zfc8d951ce46sk58rw4gfu X-HE-Tag: 1687272996-82908 X-HE-Meta: U2FsdGVkX1/kdL2xsj0I94t5kRJ1llmI8ojZUC8IOF9ha61cw3Ulb754j5YTrHvrnTh/BBUvsMtep7WgqCpNbQK9niKHgJSNCw5e5nh4OCL0HnzhLV8f3loJCmaQR6QcPvg5tjsHG5Jz+Vwh316CRAB2So4eU6dXSxJJMlMcmcenKd+bat1qyGpkenn7qGUMK41z8A7L2xCRNTM8Z84RQ9fZPI+ziJLKUjFO2lXxWfIKbbvnYAzEFictM0X9U9mhnhhMizJ6oAzXMB5Asguh4sV4QVgx0smc9lByiWeGrFnqz7EGIQX/g1SEkrtpOiiJavxxCtphalYIq2f7pOU8Uz3jF1rjgsirOmYmHAItVSfqj8pZ+n3TLK4pqBQdZhQrXpaaSnAYIybgM2MdA9z0MgKU8HUYwa+UYvtv5cNvmZQXeJxgKbrt88d9QQKjLKvu4Um45Kr33CxM0Cm1JOQSypCiC+dbh8wGb619ixFUOULHkIBuOdanIKts23MZfGz21iDjg73L4vbl7/2JVyCPYn9lAivA1QekwxTzzS9DTpXd1RuyI+O5q5TTJkgV6fddAag4B3CDdi7jUyOQjXuBgFca5sXg2pWNQ6QQRDK+rSdtWtOd9EWMyUrfAO/CWz38TbtAfRnWc7s3RCY7Loxt1zt0DunfGlEmEKJZiqGpD+TCYF6PVURBiVN7x1Fn2XDg10W7/MYOICs07xkVeH6pFo27d7u4ZtTCFy3vJ0eD2jJYA7moDVSJDIsqwn0BsrbMF0rtiqOQuuro4ssYi8uSKUnJI6PyiPB4dmd+KP7r3AVp+1CPIxaEmbJOTjnVLXYTPjtG5Hy/KjlKnVnfnaGNuxJrl/HVY83Eax14koVkZFLO2hvPI3SzgPdP4JCz8AgIVFzGIsy7DNBmGePby9mRXZPZyv8RvYTpoau3ORqATkPCOw0mPiGq6XIUS8t05hEXVS4St1Uqi8RkC+othEw XOHGTkyU KMcJG92GdbA2AuRmMTQVtv3cCiA8dkGRMzkzdr80bmM8+SeuGUBTmRleoZ/a8xF+o4mtKtF0NPVqJDIgo8rm6s9nA2SmVDSOjmomtBBaxzVdI36j8JxUukZkmdy6bXrXPe2PfF5wpx6foxsL44Zel9EpkidHITjjrM0SbplXRUx3nmWBgXVjJq8yxOK3Wfyg0fJkMKxX5w+rmFj2TfyU0HAXOd93HY8h0JMDP5fIIoQa7HJBAbZhsBKm0TMk7uBhEgaj/u+j/oh5Va7kPsl//WgTJ3p8oHx8lhtdc+dSCMWLo9eKCF2Sxq9a9lATDmk6zSQwQ2F2SquZQDVAgPO/MVVZCpQkS0C5oZMmMd8pXRernUZmn+rlCbicuQSdvhKy2nQi4PxlKA+q/E9yfvrRumcUniQApwD/G4mRQy2pidhzRZfxww/iT9aqJ5m/YpaCmbE+iezn8WGEjW7OTc8cqIMqBy26oONij0z1kqfsEXvGxSDpZ04YLzncBGWZg5dOs6wwoNglFygob2sc= 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 single sendmsg with MSG_SPLICE_PAGES to indicate that content should be spliced rather than performing several sendmsg and sendpage calls to transmit header and data pages. To make this work, the data is assembled in a bio_vec array and attached to a BVEC-type iterator. The header are copied into memory acquired from zcopy_alloc() which just breaks a page up into small pieces that can be freed with put_page(). Signed-off-by: David Howells cc: Santosh Shilimkar cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: linux-rdma@vger.kernel.org cc: rds-devel@oss.oracle.com cc: netdev@vger.kernel.org --- net/rds/tcp_send.c | 74 +++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 47 deletions(-) diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c index 8c4d1d6e9249..550390d5ff2b 100644 --- a/net/rds/tcp_send.c +++ b/net/rds/tcp_send.c @@ -52,29 +52,23 @@ void rds_tcp_xmit_path_complete(struct rds_conn_path *cp) tcp_sock_set_cork(tc->t_sock->sk, false); } -/* the core send_sem serializes this with other xmit and shutdown */ -static int rds_tcp_sendmsg(struct socket *sock, void *data, unsigned int len) -{ - struct kvec vec = { - .iov_base = data, - .iov_len = len, - }; - struct msghdr msg = { - .msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL, - }; - - return kernel_sendmsg(sock, &msg, &vec, 1, vec.iov_len); -} - /* the core send_sem serializes this with other xmit and shutdown */ int rds_tcp_xmit(struct rds_connection *conn, struct rds_message *rm, unsigned int hdr_off, unsigned int sg, unsigned int off) { struct rds_conn_path *cp = rm->m_inc.i_conn_path; struct rds_tcp_connection *tc = cp->cp_transport_data; + struct msghdr msg = { + .msg_flags = MSG_SPLICE_PAGES | MSG_DONTWAIT | MSG_NOSIGNAL, + }; + struct bio_vec *bvec; + unsigned int i, size = 0, ix = 0; int done = 0; - int ret = 0; - int more; + int ret = -ENOMEM; + + bvec = kmalloc_array(1 + sg, sizeof(struct bio_vec), GFP_KERNEL); + if (!bvec) + goto out; if (hdr_off == 0) { /* @@ -101,41 +95,26 @@ int rds_tcp_xmit(struct rds_connection *conn, struct rds_message *rm, /* see rds_tcp_write_space() */ set_bit(SOCK_NOSPACE, &tc->t_sock->sk->sk_socket->flags); - ret = rds_tcp_sendmsg(tc->t_sock, - (void *)&rm->m_inc.i_hdr + hdr_off, - sizeof(rm->m_inc.i_hdr) - hdr_off); - if (ret < 0) - goto out; - done += ret; - if (hdr_off + done != sizeof(struct rds_header)) - goto out; + bvec_set_virt(&bvec[ix], (void *)&rm->m_inc.i_hdr + hdr_off, + sizeof(rm->m_inc.i_hdr) - hdr_off); + size += bvec[ix].bv_len; + ix++; } - more = rm->data.op_nents > 1 ? (MSG_MORE | MSG_SENDPAGE_NOTLAST) : 0; - while (sg < rm->data.op_nents) { - int flags = MSG_DONTWAIT | MSG_NOSIGNAL | more; - - ret = tc->t_sock->ops->sendpage(tc->t_sock, - sg_page(&rm->data.op_sg[sg]), - rm->data.op_sg[sg].offset + off, - rm->data.op_sg[sg].length - off, - flags); - rdsdebug("tcp sendpage %p:%u:%u ret %d\n", (void *)sg_page(&rm->data.op_sg[sg]), - rm->data.op_sg[sg].offset + off, rm->data.op_sg[sg].length - off, - ret); - if (ret <= 0) - break; - - off += ret; - done += ret; - if (off == rm->data.op_sg[sg].length) { - off = 0; - sg++; - } - if (sg == rm->data.op_nents - 1) - more = 0; + for (i = sg; i < rm->data.op_nents; i++) { + bvec_set_page(&bvec[ix], + sg_page(&rm->data.op_sg[i]), + rm->data.op_sg[i].length - off, + rm->data.op_sg[i].offset + off); + off = 0; + size += bvec[ix].bv_len; + ix++; } + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, bvec, ix, size); + ret = sock_sendmsg(tc->t_sock, &msg); + rdsdebug("tcp sendmsg-splice %u,%u ret %d\n", ix, size, ret); + out: if (ret <= 0) { /* write_space will hit after EAGAIN, all else fatal */ @@ -158,6 +137,7 @@ int rds_tcp_xmit(struct rds_connection *conn, struct rds_message *rm, } if (done == 0) done = ret; + kfree(bvec); return done; } From patchwork Tue Jun 20 14:53:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13286012 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 938B1EB64DC for ; Tue, 20 Jun 2023 14:56:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 309DD8D000D; Tue, 20 Jun 2023 10:56:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B9DE8D0001; Tue, 20 Jun 2023 10:56:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 181DE8D000D; Tue, 20 Jun 2023 10:56:53 -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 027AC8D0001 for ; Tue, 20 Jun 2023 10:56:53 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6EC231A1169 for ; Tue, 20 Jun 2023 14:56:52 +0000 (UTC) X-FDA: 80923428264.17.73B3DAC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 9A12A18001E for ; Tue, 20 Jun 2023 14:56:50 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=jWE18q01; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1687273010; 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=CX0szcw738ZS8htZ0RxEmjBFgUMhbKSUPMuc1XxmplE=; b=zfD7IU8b5oDc9vGWu0vJKGIZIgcgMpkTCMW9XC+nzVCRNbaMHoacW5CH4mDSQw9NX3+ABK oNSpv+BwnopFqx73ZvfRb+vczPpOPfC4EgXJrIYyCIRRo4nZwfIeZ37vClDk7yisgfpdHT Xd4yD+oHN19OZeQprQh2Fm3aI21TZUw= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=jWE18q01; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687273010; a=rsa-sha256; cv=none; b=uo0UGe2Cc/2i/lRKbilY40Nl2scQHyA2zRQxRveXJuyiw9sYJaN/lXHnuk1N3G0NckYZ2c ViEPIfXgOQIJC8KkX3UIvN63y1XUGyCJquAMx70kQx23gTts3YDyOaHNNQy7lxolyM++oU hsVWnwQh8VNL9476XeBjgPsbGZJcIf8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687273009; 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=CX0szcw738ZS8htZ0RxEmjBFgUMhbKSUPMuc1XxmplE=; b=jWE18q01LhPP0e+dexrU18mFdZWZSsQIkRz4L9Td4ppfexkM7ka5qd4yrg0b9lkaGHoHUS Ige1i1haVQuxEmPOono0J+8fI+T9qAvnE7CX5dcQJUfL7GM2m03mvrdknjI/7VVBRHXyzu wUdC4QpbDhFpBVPuub0oQtI1N5pZUns= 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-398-CpGHSxxIP-O4lq_Pb2IfNQ-1; Tue, 20 Jun 2023 10:56:37 -0400 X-MC-Unique: CpGHSxxIP-O4lq_Pb2IfNQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BD2BE8A51E9; Tue, 20 Jun 2023 14:54:22 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B0949E9C; Tue, 20 Jun 2023 14:54:20 +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, Christine Caulfield , David Teigland , cluster-devel@redhat.com Subject: [PATCH net-next v3 09/18] dlm: Use sendmsg(MSG_SPLICE_PAGES) rather than sendpage Date: Tue, 20 Jun 2023 15:53:28 +0100 Message-ID: <20230620145338.1300897-10-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspam-User: X-Stat-Signature: zgpqefpz3wptrj448cp31h1565rkfccu X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9A12A18001E X-HE-Tag: 1687273010-512172 X-HE-Meta: U2FsdGVkX1+h16j8pheODmWd2NO4ecvcABVeqG/l9cC7UHcPwlFwarptp+l4Ze8DuXwyNg7g6OibuiMgTb19cbOdMOCgNfSkIbFrPPBdwuaRns0+ADiLIdR2QKppuj/DiOI5CJrHIT20+10ABk1jr5MfLtW0C6gu5YHpfUfvFLgFiBaKL/VE5XI7EKY56F+ZpEGobX487FueC3FGSxdqud5Wz+JXq5usi75swGlMnAKv5V32x7EbFZouZpLZnyeYPueX9rwYEm2fXJUttVIxHkWyL6BHQwBCLeC+QoLaXuwOcj7iB82Ej/QL9decDj/uQTFj9Z4DsBk1q1rnBelZxoJsFg5Rf3vQp3RP4g2qqFv3Dozrwb48C4MIbCycZj4Eb8FH+kqdVSaZFPiRaFI4qhMDB+VYDRHNGg0/yVO9ptdt4gfCsjuRIVXqdFFTG9Ywidw0yorS6dF9Zd62usgK2LmePDpjvLxzvM7kpwP9Y6M9+q5Hrr/OZwhYaMeKYcdK+6gGsRAdbZmaYkp7gw2aVxuA1bJY0NfXKptosBGlwacpykqDPo2UjlfDE4pdXI4cPyuwa9ax+I9w7/x537o2n6/eWjLLSuARsUv6FAq2tOQxm2MAuGOtUUTvdILubaw2c1AW777eb68j8cvlGHLTIqeKXe7TIyDadEPtS7zmPuh5WnE/VUX0uzXVZjc3CgS/C28dd6qL970iM+5g+4nqPi7f3w9uAFZc0eoyqe/optftDb74012H1BLwadXhZYw5c5/QInWkapeLyIgNtVhSkcDe65Jp2Tms1vw1mxI3mLTWiqEILZZkDjrOuw7AOaGHvnibtCqgWp8juKKQcsPLKBWX/dYmVneDWU/6LLC1DM9sdeZefBXhdNTMiaBKzHbkr3JvnMTcTbSjfPhAxJEiP1caNTQvfzIj8WsA02Q/SEyMujQiGsOSmh4u48zxZdcBImGsrld1nNYZYhHHwq9 BmDE2Z1R T82jcmdKeAPpfR4vaOf0GEm1EVbuwf+TFbA44YqmoJ2pv+DIGIz8idpREeaRYTgyl8KdsfBYDk4wxTotm7fX4f73Cxsythlsw/Zpt1ULrIsxasg2UHwRjpbnIFNQuZKZAey+gK1HMC7EMt1WC45CpG2HQoMTTnmvMcXk1bk1nfK90cRldEA1tUPlRNMIYA7FyizLVnz9v6ZoYr35A5656rsxOmRIhQAXPE908Y4gqWgmYC0H4XlydK/G2B+dytYaghn5+1SbV53WaE5HUOvStSol09lZtwX+xTMZa/XkhMEcRXVQ99i2KaB6y4CxkuqiGdFBInThQ7plHIw1K/i1z6Ke+05Xq/V/HeYONsmR0KlCe60+/WRWWeUmWV8BFcd0/a81oNlzpzn/FD2Xnr5W6t4pc1fCXpf/I6LeGnL9W9QxhvoXed+oD9lcAEZgO78K9LVpMnTPHa4HP+6QISyIxxNSDwmGkMMKqblVR6b77MsvWyFaG1f6LcBoHaQ== 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 a layer using a single sendmsg with MSG_SPLICE_PAGES to indicate that content should be spliced rather using sendpage. This allows ->sendpage() to be replaced by something that can handle multiple multipage folios in a single transaction. Signed-off-by: David Howells cc: Christine Caulfield cc: David Teigland cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: cluster-devel@redhat.com cc: netdev@vger.kernel.org --- fs/dlm/lowcomms.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c index 3d3802c47b8b..5c12d8cdfc16 100644 --- a/fs/dlm/lowcomms.c +++ b/fs/dlm/lowcomms.c @@ -1395,8 +1395,11 @@ int dlm_lowcomms_resend_msg(struct dlm_msg *msg) /* Send a message */ static int send_to_sock(struct connection *con) { - const int msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL; struct writequeue_entry *e; + struct bio_vec bvec; + struct msghdr msg = { + .msg_flags = MSG_SPLICE_PAGES | MSG_DONTWAIT | MSG_NOSIGNAL, + }; int len, offset, ret; spin_lock_bh(&con->writequeue_lock); @@ -1412,8 +1415,9 @@ static int send_to_sock(struct connection *con) WARN_ON_ONCE(len == 0 && e->users == 0); spin_unlock_bh(&con->writequeue_lock); - ret = kernel_sendpage(con->sock, e->page, offset, len, - msg_flags); + bvec_set_page(&bvec, e->page, len, offset); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, len); + ret = sock_sendmsg(con->sock, &msg); trace_dlm_send(con->nodeid, ret); if (ret == -EAGAIN || ret == 0) { lock_sock(con->sock->sk); From patchwork Tue Jun 20 14:53:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13286019 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 88345EB64D7 for ; Tue, 20 Jun 2023 14:57:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 246138D0014; Tue, 20 Jun 2023 10:57:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F6528D0001; Tue, 20 Jun 2023 10:57:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0BEE18D0014; Tue, 20 Jun 2023 10:57:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id EF44A8D0001 for ; Tue, 20 Jun 2023 10:57:30 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C3544A1156 for ; Tue, 20 Jun 2023 14:57:30 +0000 (UTC) X-FDA: 80923429860.02.8D5CB75 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 041DD100004 for ; Tue, 20 Jun 2023 14:57:28 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bLVz3b0M; spf=pass (imf14.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=1687273049; 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=kX6Xzyb5DYMqpSrTmxybyUGZQ2hNwo35+Ji3qVw7rrY=; b=oTEehPRohCSKe/mIa55ZeyvrD0hh2YjnDQ+Zd10bVEKmjLOJ4LJWOpUKpnq6/NDF1FmCD8 8HpF4SHYwJTYQnWbt7yOY0I2uJJjv5fl3B4kGbRGjAR+LJLp0ET7z0bVnd3KGs9mWYfXXf p3e1BuXpCC8mPWJcd2WASXiIiTsCBV0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687273049; a=rsa-sha256; cv=none; b=ordvUM8B7wcl5KFm/S0dSEfxPl9gFSyB7Xm2xMM9g0+O6K99LYH5TNFWzA1xqq+InEWdUk pGvaQdI5sH8w3nQ6W7dxZJ9DdC1j3d1VB0RgZwNoOMAnGA1dsqaMwSjlvE5uNzL4/wndcj S1KUkDXmxzDiiXQ+oMDr01VBaa4fgVw= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bLVz3b0M; spf=pass (imf14.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687273048; 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=kX6Xzyb5DYMqpSrTmxybyUGZQ2hNwo35+Ji3qVw7rrY=; b=bLVz3b0McvX0QLoDw+TW1If/fhJD0XctdKOUDTFk/RkF+neJmxtfAzxDn9k8XlNu/tqv54 SOx+e5LRxBNXxjAZeFcuMOXyk6vNEnoARdFQKLlMWAD0LbjUaF+540HlkWwqr0dShlHN5z WzwOZNPj8PkGDXxdiaQcC1lJoV/fcyg= 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-481-ICwZLUEsPqKT1b5qYpONaQ-1; Tue, 20 Jun 2023 10:57:22 -0400 X-MC-Unique: ICwZLUEsPqKT1b5qYpONaQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6D7458B5AF6; Tue, 20 Jun 2023 14:54:25 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 554F914682FA; Tue, 20 Jun 2023 14:54:23 +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 v3 10/18] nvme/host: Use sendmsg(MSG_SPLICE_PAGES) rather then sendpage Date: Tue, 20 Jun 2023 15:53:29 +0100 Message-ID: <20230620145338.1300897-11-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Rspamd-Queue-Id: 041DD100004 X-Rspam-User: X-Stat-Signature: xh7i7abbb6i8ca85bdb7kiryouurfqe4 X-Rspamd-Server: rspam03 X-HE-Tag: 1687273048-843764 X-HE-Meta: U2FsdGVkX1+tk0Y7P0cboUHUymWj+CXDtPkr923dPH9YBtVH2IledIa/z4LmsB7IRfXpoZJthaID0BQwrssjB5FjT8esqTmDCGpfJPOTR4bn0EEG5L2ABf0Gcw9ypK3zfKme8neI6IInP3h7wBUg1mIAScsoZc5NEOHdObvI4pUwswJm34hxEqong6Z871Q7Qg9l1ZcE8C0XhoFos/WxuL8MalvhbGL3cmbg7CwVU+kZ2sU6E1HDkZ3AvGYTlnHMrZr4lnDYJ3O00lCtOs21Z3TfegR1DYnAS47fbrNoMaskWuBZOyxfNWgd8LhE0SXKgjtQ0t+6kN6XUUzbYaenMFWxIXaBfOH9TY8r9xLNP39igB09XH/pqoumwG8Gje+owckD+BvPKp8wLfAzKuqg6cHMIq/Fc1gl7I7QrAI+jskSNV4Aob1mVDB1vh0OCNn47uxPc29rbCAZxYAOdqw7bdn0j8rvhpCgpPmy6AOKWTlvYYasn87rPOs7Rx3B4GDUvUfTfMM92f14XzGQ7sQsjlq2UoBMdlB61VA+o05hbedoSgrpnTfNnC175d/9MRrIkiL1gA6qlaUAKUDvTOZm47l4i7TZZxJEaawHuKrgAKuGHjwzDpNrSt1vwGKn0GGeYn+LvWoZLki/0EXpF4Khg7zcNxdgBoZJ9h+tohjU5AvU0K3scvlXsMrNZjddkrlyc9ZkGYnZauz9ePFEiqFP9rDeU6mH4jyL4plMENkhCcUCB5uYTUfBqddHMOXBZMPcre5H08QClb5sNLoji7xlJaUlZGHagmaEXUtXx8SRkgg8GUYqTaUkGSBFvXDn028Vihy8GNycF0sbwCMhWfy/OfYraW7osNmuavN9xlxZbypat+zvUmhbxCa/b7dhno7smZUW4D+3vWKIZyVO40pLKiZbmbQ8eDK6CI7yQWqIFNB07rZjFxdvmK0pZCJbPBgbx5RYFPwyIoGsZKfrOOE B56cGfJ0 OJFJVDMiMfaYxUVQa2Q2aEEOeapWoN83JBVHJpHQzr+kM4171UJhUB/XyHSMG37cpYD9mJyAsKKXxa1A9xmCGJYOJApGobELVXvjiZ1rmxpIj6zfJi1RgTq30rvjhqTD8qTF+aFACh8sPJd/GorA6O7fksH+0FRXoSiSUW/8czNijBqqXtYYaoffqDbxNaOaYSxJCWBMiHk9Y8TUu3FW/3RvADmjN7eYqwjoy9mCwrBwQbtJJ0rqQ2aeez5/wRCeTzme+AN58bxkLa2NVUq8XlrX4PWdYXDZbhKaiKQxWu160GhYK94R/vr0eYu3nBjdurxbqALJfeHySGyDVps5taR42VA5myPe82cohISkhy7pTzSk3HB5QxPw2AlFWOH7ewYBjhGRIcZGTVHe+xDnFZ661omIx9HX4sgdJfJlFa+aUr4sN1+ifhJfSNM4lmZmMa6JTxo/BRZAqHhMDhf9LZl0ZTIikmFt0AMUyWf3Z+EGOUS9/vIdBmScmUdcwB609TMIoJwqFU7Q+Hr91cpGgbWcNotzLrS/sjGyBFpmYsbzYDegrM2QOsWhJNfvHWL6/StQn 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 single sendmsg with MSG_SPLICE_PAGES to indicate that content should be spliced rather than performing several sendmsg and sendpage calls to transmit header, data pages and trailer. 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 Reviewed-by: Sagi Grimberg --- Notes: ver #2) - Wrap lines at 80. ver #3) - Split nvme/host from nvme/target changes. drivers/nvme/host/tcp.c | 46 +++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index bf0230442d57..6f31cdbb696a 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -997,25 +997,25 @@ 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); - } + 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 +1054,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 +1095,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 +1105,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; From patchwork Tue Jun 20 14:53:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13286011 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 9166BEB64D7 for ; Tue, 20 Jun 2023 14:56:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E7768D000C; Tue, 20 Jun 2023 10:56:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 070958D0001; Tue, 20 Jun 2023 10:56:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E7A578D000C; Tue, 20 Jun 2023 10:56:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D21AC8D0001 for ; Tue, 20 Jun 2023 10:56:47 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8B0951A116B for ; Tue, 20 Jun 2023 14:56:47 +0000 (UTC) X-FDA: 80923428054.04.621AA80 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id A2B29120009 for ; Tue, 20 Jun 2023 14:56:45 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=StIuGDro; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.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=1687273005; 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=SOw9ClnSc9r47uoXD4terkn/PQVkRnQZDq9J97sUBoI=; b=UJe3FTv6iN5MR5lRRKCNJBSJyrStjD5t8BgbMeoHpPP5DgTyJfvmfLekRhmvh4rcLdbHyc WNDtQUKrYRZKTbo/QoUvemvHz1iM8C8GI5em6hjQKtHaehKPDLtn/XFfuK+6DO2RX3QB14 DXe2BWIS+xwUhC6ggrOD3A/YdF/ic4A= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=StIuGDro; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf29.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=1687273005; a=rsa-sha256; cv=none; b=bLTYUy6fjw9J/p+9OFhChbcTlvL/JAik5+5UzFSHAfx5P3IQWm2RuQbiXjGn8hTSJAdskG CqR5VXTM7+9B5v6MT26p3FpcguGwZJlersa4WljQ/6Px3gELqRTAPwI9da58ghwEJC35Id AZ7clTsnmBohd56WGfhwhMAhuk6jHTA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687273004; 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=SOw9ClnSc9r47uoXD4terkn/PQVkRnQZDq9J97sUBoI=; b=StIuGDroV0JZZj5vFLPjtd1WcT0smO3Z5iiqMPvvJbwcTpZCKSX/D+5gO6TapDt7OCSlwk GZIpLALYTEHxL9AguVfJ+zztXtCD4/Ersty0Vi4ujeINrcIrn0JWLA6NbSeEOkXTlZwK9t QOlvzED08e54h1vE5dNnjPmfqdxJjEo= 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-207-8YJyb2soPem25NlFFJ-W_g-1; Tue, 20 Jun 2023 10:56:40 -0400 X-MC-Unique: 8YJyb2soPem25NlFFJ-W_g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 27CFB8925DC; Tue, 20 Jun 2023 14:54:28 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 19014112132C; Tue, 20 Jun 2023 14:54:26 +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 v3 11/18] nvme/target: Use sendmsg(MSG_SPLICE_PAGES) rather then sendpage Date: Tue, 20 Jun 2023 15:53:30 +0100 Message-ID: <20230620145338.1300897-12-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Queue-Id: A2B29120009 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: unpf55jtxj4p1c1s4r4aujfun84pftef X-HE-Tag: 1687273005-356749 X-HE-Meta: U2FsdGVkX1+Kx5T/8LeLMy92214I1UMAbCSq48D1qcES5M3JsA3KqHA3zXnq4ekldj7yOVU/otVIuIBULh9qJelTfSZDRqpcIcY35g6pOUoJmmOEdZSYrNfO7/jLOKsU8qA295l6c9jfJeEjy/WIk/pWhCcxXfSl+yYtfNkz3p2vloAIo0MVTuCbq9mXvTOCvRHSU2/CH/pVI7N4ZcT0jRMWVX0Jk3KGNeF+rfgLcizwcEZj6lJAozMzqO0xdHdGTUfuBa1NQ5V1XxwG1QVUOYKJSYmxs9zOM2oOFTTEHz6h0De9mq6I1DyUzmLCqnZU3aB6a8JvMV+L1vDTATiewYOLcpo9JBGwtzRLFgwkl+mI1teptlBDANFc4yDue1m0yWbVmfvHX+6f9KsWGmdTCxyTVL+vvmLLejHzPsOXIprebOSmxUJm9hBlR65/CN+/lkdcRKF9rvDr7CaiQckAJFV1A40NT0L6ZHveAyFC++WnqU9xA7D/PdnfWhTjPaxVzarcWynrHrAdBgp39ZEJOlYF8h24rDUDcAYgKCyA/O/c1lESbshn9UHFXWhWjRQaPIFsnpdJMbl6Ic6VxG3SHxqY/lFYzZ09mODQgaspP1lpylUuRfaBVCGjd6j3cFHrYEroGDwv7mswwSpcw18L9m0pSFpjUxgl3yWQVmCNz6D67+4GV6ZmrdziVahnzQybeKyJe7wrs24nvH2Uka2NioWJnKIwqWOtU4LhCtiWii8EOcR53GXgAmV8CAdQ4EjvDmMNWYBZ98RINry/S37A0nvaltGHIFH/yANb1sL+2+ccECzTW3i65+WKDO0V5RPFxx9v1YHfS8WZP9lM3zVNDSYth+64OFgrciRndk5IQ1JV9iTWRUKIk45j/3+P0q8qfr9GEPSPlepz7fFYvWn7hTk5F3kKUKhdcMKKJI+3kXs4afLVI/DcmWaSkxwS7E9v21XMpJvWQHCvk2RDQJP LS9Ekhu9 ksyiF3wD4hAZNyR1z5fVJVQzMda0sZabTbI4p62m3i1KWiIMK1WBXkIIu+E2ONVtZzLqtvGHymFpx4EPGNuSI+sQ67/sVkJSFXaHvI1abW6sP5MdZ/+rM7Bn8Xj837Q0gqd/hMEb1kB2Mgy/Wa0zr3UshObCMKoWCZwl8EHiqrQnmm+UJjkoX1R9VmB6I4hv02gBjU9Y/QxZ0qEDnH0eCUhJZtHeg2XbQk2ohgjCnqJGcE/jvMTisSe9WPMkVDjAvX0baFnMDjdcaeU62X4Pl0z7ZbgbGK9M/ld1bQO6vjlXb7guTbDQPcBqw8vwWm2hLwrvSkcXzfpXS4bIXSokYFcNajGAje+iSaQlg666FP4TgVed/m8sZre+cwCdJHNlAPnVeTAcHakUUiXUSSN1j/7lcfJgEEDINRwTuchQblJlVVUagIO4TGxKWnZm8KJ4nGs4nWy0a69zhd64VI+l+SARCQf0t909FW6WW6o4ny7+Zuk6+CShwtPteBZjBVix8fy7qkCQMT05Mw50Fe167jPJ2/ZUroDts6P9nL5W1jFkDnKYuhYb7GYSGMFrMfKwvmsakXRxsBfX6lRU= 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 single sendmsg with MSG_SPLICE_PAGES to indicate that content should be spliced rather than performing several sendmsg and sendpage calls to transmit header, data pages and trailer. 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 #3) - Split nvme/host from nvme/target changes. ver #2) - Wrap lines at 80. drivers/nvme/target/tcp.c | 46 ++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index ed98df72c76b..868aa4de2e4c 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -576,13 +576,17 @@ static void nvmet_tcp_execute_request(struct nvmet_tcp_cmd *cmd) static int nvmet_try_send_data_pdu(struct nvmet_tcp_cmd *cmd) { + struct msghdr msg = { + .msg_flags = MSG_DONTWAIT | MSG_MORE | MSG_SPLICE_PAGES, + }; + struct bio_vec bvec; u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); int left = sizeof(*cmd->data_pdu) - cmd->offset + hdgst; int ret; - ret = kernel_sendpage(cmd->queue->sock, virt_to_page(cmd->data_pdu), - offset_in_page(cmd->data_pdu) + cmd->offset, - left, MSG_DONTWAIT | MSG_MORE | MSG_SENDPAGE_NOTLAST); + bvec_set_virt(&bvec, (void *)cmd->data_pdu + cmd->offset, left); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, left); + ret = sock_sendmsg(cmd->queue->sock, &msg); if (ret <= 0) return ret; @@ -603,17 +607,21 @@ static int nvmet_try_send_data(struct nvmet_tcp_cmd *cmd, bool last_in_batch) int ret; while (cmd->cur_sg) { + struct msghdr msg = { + .msg_flags = MSG_DONTWAIT | MSG_SPLICE_PAGES, + }; struct page *page = sg_page(cmd->cur_sg); + struct bio_vec bvec; u32 left = cmd->cur_sg->length - cmd->offset; - int flags = MSG_DONTWAIT; if ((!last_in_batch && cmd->queue->send_list_len) || cmd->wbytes_done + left < cmd->req.transfer_len || queue->data_digest || !queue->nvme_sq.sqhd_disabled) - flags |= MSG_MORE | MSG_SENDPAGE_NOTLAST; + msg.msg_flags |= MSG_MORE; - ret = kernel_sendpage(cmd->queue->sock, page, cmd->offset, - left, flags); + bvec_set_page(&bvec, page, left, cmd->offset); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, left); + ret = sock_sendmsg(cmd->queue->sock, &msg); if (ret <= 0) return ret; @@ -649,18 +657,20 @@ static int nvmet_try_send_data(struct nvmet_tcp_cmd *cmd, bool last_in_batch) static int nvmet_try_send_response(struct nvmet_tcp_cmd *cmd, bool last_in_batch) { + struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_SPLICE_PAGES, }; + struct bio_vec bvec; u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); int left = sizeof(*cmd->rsp_pdu) - cmd->offset + hdgst; - int flags = MSG_DONTWAIT; int ret; if (!last_in_batch && cmd->queue->send_list_len) - flags |= MSG_MORE | MSG_SENDPAGE_NOTLAST; + msg.msg_flags |= MSG_MORE; else - flags |= MSG_EOR; + msg.msg_flags |= MSG_EOR; - ret = kernel_sendpage(cmd->queue->sock, virt_to_page(cmd->rsp_pdu), - offset_in_page(cmd->rsp_pdu) + cmd->offset, left, flags); + bvec_set_virt(&bvec, (void *)cmd->rsp_pdu + cmd->offset, left); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, left); + ret = sock_sendmsg(cmd->queue->sock, &msg); if (ret <= 0) return ret; cmd->offset += ret; @@ -677,18 +687,20 @@ static int nvmet_try_send_response(struct nvmet_tcp_cmd *cmd, static int nvmet_try_send_r2t(struct nvmet_tcp_cmd *cmd, bool last_in_batch) { + struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_SPLICE_PAGES, }; + struct bio_vec bvec; u8 hdgst = nvmet_tcp_hdgst_len(cmd->queue); int left = sizeof(*cmd->r2t_pdu) - cmd->offset + hdgst; - int flags = MSG_DONTWAIT; int ret; if (!last_in_batch && cmd->queue->send_list_len) - flags |= MSG_MORE | MSG_SENDPAGE_NOTLAST; + msg.msg_flags |= MSG_MORE; else - flags |= MSG_EOR; + msg.msg_flags |= MSG_EOR; - ret = kernel_sendpage(cmd->queue->sock, virt_to_page(cmd->r2t_pdu), - offset_in_page(cmd->r2t_pdu) + cmd->offset, left, flags); + bvec_set_virt(&bvec, (void *)cmd->r2t_pdu + cmd->offset, left); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, left); + ret = sock_sendmsg(cmd->queue->sock, &msg); if (ret <= 0) return ret; cmd->offset += ret; From patchwork Tue Jun 20 14:53:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13286013 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 D561EEB64D7 for ; Tue, 20 Jun 2023 14:56:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 777BD8D000E; Tue, 20 Jun 2023 10:56:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 726AB8D0001; Tue, 20 Jun 2023 10:56:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5EEE28D000E; Tue, 20 Jun 2023 10:56:56 -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 4EED68D0001 for ; Tue, 20 Jun 2023 10:56:56 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DF0871C9693 for ; Tue, 20 Jun 2023 14:56:54 +0000 (UTC) X-FDA: 80923428348.29.E8F029C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id CBA8E20023 for ; Tue, 20 Jun 2023 14:56:52 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=euyB9UC+; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.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=1687273012; 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=iAUCq6AQpwiSNlqp6e2886GYsbEpCz4tvlCIXkUtiq4=; b=ERr2UiCajw8p3prfljdrzzdH/t98Fxhk8WrzMiFYCv8QgYgLZcEWRb23iy3iM05R9+xm6z eX3bK27CewbHyqsiwt2snkB79LFyMtFAsZJKmqj+FY+lq+ETfCMeICjaN4lG4zqyvg72Fh Xw6eFRa+fWhlhuIUby+Tj51mZXQDgKE= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=euyB9UC+; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.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=1687273012; a=rsa-sha256; cv=none; b=gRP413dgME3VWf+B0tkYLsFRHS72heKzvd/5rNJPoQ3jPbY5PBcnW5WkNbq2W56dIoBURI JwNMq91KJ7Qupe9KU/PGeHw3Ba4ZUZOomw7edu4q1iLvad7yXSpeDXBWOk71dz/Z6Eqj9J qJmjFTU0k0TQXKgk6vjOWcl6AbJNbCs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687273012; 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=iAUCq6AQpwiSNlqp6e2886GYsbEpCz4tvlCIXkUtiq4=; b=euyB9UC+VnIArbCJBaj8gKO7/jV/U5HLYbjWMcJ/w/nm85/FqMeIrbu8IGZ4uvz3WQgRis tfkKKwB6uxKOsKR31oeR2ZJo8VhXftwXaovLDQmcRSBfJb3/MJ3GWLMKTDNXlhZjrKPcb6 5XF/ezM0+G6Tj5Ug1ABsgIP26sZ1y+w= 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-269-aatl8iayPtWLIAC2EOAbnw-1; Tue, 20 Jun 2023 10:56:49 -0400 X-MC-Unique: aatl8iayPtWLIAC2EOAbnw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C3B3A8870EA; Tue, 20 Jun 2023 14:54:30 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1AD5200A398; Tue, 20 Jun 2023 14:54:28 +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, Karsten Graul , Wenjia Zhang , Jan Karcher , "D. Wythe" , Tony Lu , Wen Gu , linux-s390@vger.kernel.org Subject: [PATCH net-next v3 12/18] smc: Drop smc_sendpage() in favour of smc_sendmsg() + MSG_SPLICE_PAGES Date: Tue, 20 Jun 2023 15:53:31 +0100 Message-ID: <20230620145338.1300897-13-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: CBA8E20023 X-Stat-Signature: j3dbsnorbar1bjryzdp6c6z541jj1xpk X-Rspam-User: X-HE-Tag: 1687273012-414065 X-HE-Meta: U2FsdGVkX18DJxV/KG5SCvXGM3tSEUC9jtzvzzjUcQlNinoaGrmGFLYKHXPfjVAUsHnxbKfyvB/NeCJH6ivCSAi/1Y+7+5yDTDHmmOrR21/2cbHxwcQlDB7PktMILD7d0ypa/PA2PtU325/eQEuGJA1ddBfn8i3WscqgTPdoZnLtpNgcrJr+w1wHZK4HTlOypL5BRPVLrBQ98K8tFSA1EJ/d1Jhf17cR5MOMefjdoGVPeK7WR4K9anECTHoRIunD400yFLqfufAHKH0pTf9PQPNMejPkpELYOeeelNFl6ezv10gIrv2O5nLUYLMyw2/EgLAXGd5UyPt9I82NtoinwA0QNaSndJ1Zx7c2IRGZvaOUEbETYikzjC6AEaj8i8IWQ+27RUm5LdHVUY2JvTQP5AQJfiUZ77TtRyqLUp2QHpgIYKo8mQNFldUA7RKKh2PXXWkxvWH5ChpwZTY8Ku74LEg63LtMJhfnyhP6Xh8PYQzzVG4Xug6BYioVNbdIg/miqAHDQGNjxi0+om3PbqNr7osPzXUL3DzOwg/f44iKbnOhDDp9PPjuH0By+gNiwYrbqxip+ix+DnV5Q77CSLsRNLrEkNDXsslFtQ5uT9DttpI5ykKoZehYP28cgQV09TgUgAmUE20qlTbR9TrWgSXFS25DYaZv33JjGFNsn+koYuj2purL2gObop0DCvw4Li2OHaq5I3dpjnMCYDSo2VyV28hb3O57YBtqHQ6fVI2Jh/xRevEIMfjI8c4De1po554cJlpbATytCBdO5bKB5TBehCnsZUXiyo3Yb+qqVbZj/deYk1I4yjHz5h0EHf9OXxuZSr2R82qmfwsffkZijLGBKJUrlCD+BiSu4NNRtbVoPnRd9zyTTE0WimOSUIwUQCCD4fqDAbHEatlzviHM4TPdSt/8gxIIpDGHfJE/Fo4SaSqnwRTsirODJwVMWqjmhyDAEKh1rW2Y9X7K9LGQUXD HnZSy/2k Z+h4uDR+oRJ9qHhY4bpiYIHxbQZf3iwTXBdu4+NewxNVRf7vjs7e7kQcDvEAk81Hh0T3LtRl88kYgo9IzhIDjlOjxQaJFMY31rEFxR55kVQLGN+gHqc8ck0a41XJLHRbJdAlWjFbSv8uNnIzCBjLKNtxYBLHfmxNA2POvr8pMRetDHN+h4BukiIWQOsqXLb6KeEccclQbNnQdHM6iV415bk8gMIWQemL253aYHaFmR8jyfRUDwd8i7Nu4KXi9xCR8j/lVBVpdeXuJegBeUrEEejuEAq+0hs9k2OGgzjVzqoYmMg/hAd8bBX9WoCY4JXv0dAD7wmmj4sXGbYIRxUXKXG/TvjviuS3ywVqlDW79BGhOLPgpP5dk21gREcKfhYmEI0iwa2MF4nVGNaGMdivpGIlPFgrwSqMXtl+ke4sNIzzMV+PqIoy2F0fweHtgu7slslYCCO+PNpTU0rl1uG8oPRDjAD50YoRl2DWvzJvjqiygc2owkSH36SAFSTm8n3swj9cGcuD2evmHi68IbAnmL9GeqTUtWRGt9aP8 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: Drop the smc_sendpage() code as smc_sendmsg() just passes the call down to the underlying TCP socket and smc_tx_sendpage() is just a wrapper around its sendmsg implementation. Signed-off-by: David Howells cc: Karsten Graul cc: Wenjia Zhang cc: Jan Karcher cc: "D. Wythe" cc: Tony Lu cc: Wen Gu cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: linux-s390@vger.kernel.org cc: netdev@vger.kernel.org --- net/smc/af_smc.c | 29 ----------------------------- net/smc/smc_stats.c | 2 +- net/smc/smc_stats.h | 1 - net/smc/smc_tx.c | 22 +--------------------- net/smc/smc_tx.h | 2 -- 5 files changed, 2 insertions(+), 54 deletions(-) diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index 538e9c6ec8c9..a7f887d91d89 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -3133,34 +3133,6 @@ static int smc_ioctl(struct socket *sock, unsigned int cmd, return put_user(answ, (int __user *)arg); } -static ssize_t smc_sendpage(struct socket *sock, struct page *page, - int offset, size_t size, int flags) -{ - struct sock *sk = sock->sk; - struct smc_sock *smc; - int rc = -EPIPE; - - smc = smc_sk(sk); - lock_sock(sk); - if (sk->sk_state != SMC_ACTIVE) { - release_sock(sk); - goto out; - } - release_sock(sk); - if (smc->use_fallback) { - rc = kernel_sendpage(smc->clcsock, page, offset, - size, flags); - } else { - lock_sock(sk); - rc = smc_tx_sendpage(smc, page, offset, size, flags); - release_sock(sk); - SMC_STAT_INC(smc, sendpage_cnt); - } - -out: - return rc; -} - /* Map the affected portions of the rmbe into an spd, note the number of bytes * to splice in conn->splice_pending, and press 'go'. Delays consumer cursor * updates till whenever a respective page has been fully processed. @@ -3232,7 +3204,6 @@ static const struct proto_ops smc_sock_ops = { .sendmsg = smc_sendmsg, .recvmsg = smc_recvmsg, .mmap = sock_no_mmap, - .sendpage = smc_sendpage, .splice_read = smc_splice_read, }; diff --git a/net/smc/smc_stats.c b/net/smc/smc_stats.c index e80e34f7ac15..ca14c0f3a07d 100644 --- a/net/smc/smc_stats.c +++ b/net/smc/smc_stats.c @@ -227,7 +227,7 @@ static int smc_nl_fill_stats_tech_data(struct sk_buff *skb, SMC_NLA_STATS_PAD)) goto errattr; if (nla_put_u64_64bit(skb, SMC_NLA_STATS_T_SENDPAGE_CNT, - smc_tech->sendpage_cnt, + 0, SMC_NLA_STATS_PAD)) goto errattr; if (nla_put_u64_64bit(skb, SMC_NLA_STATS_T_CORK_CNT, diff --git a/net/smc/smc_stats.h b/net/smc/smc_stats.h index 84b7ecd8c05c..b60fe1eb37ab 100644 --- a/net/smc/smc_stats.h +++ b/net/smc/smc_stats.h @@ -71,7 +71,6 @@ struct smc_stats_tech { u64 clnt_v2_succ_cnt; u64 srv_v1_succ_cnt; u64 srv_v2_succ_cnt; - u64 sendpage_cnt; u64 urg_data_cnt; u64 splice_cnt; u64 cork_cnt; diff --git a/net/smc/smc_tx.c b/net/smc/smc_tx.c index 9b9e0a190734..5147207808e5 100644 --- a/net/smc/smc_tx.c +++ b/net/smc/smc_tx.c @@ -167,8 +167,7 @@ static bool smc_tx_should_cork(struct smc_sock *smc, struct msghdr *msg) * sndbuf_space is still available. The applications * should known how/when to uncork it. */ - if ((msg->msg_flags & MSG_MORE || - smc_tx_is_corked(smc)) && + if ((msg->msg_flags & MSG_MORE || smc_tx_is_corked(smc)) && atomic_read(&conn->sndbuf_space)) return true; @@ -297,25 +296,6 @@ int smc_tx_sendmsg(struct smc_sock *smc, struct msghdr *msg, size_t len) return rc; } -int smc_tx_sendpage(struct smc_sock *smc, struct page *page, int offset, - size_t size, int flags) -{ - struct msghdr msg = {.msg_flags = flags}; - char *kaddr = kmap(page); - struct kvec iov; - int rc; - - if (flags & MSG_SENDPAGE_NOTLAST) - msg.msg_flags |= MSG_MORE; - - iov.iov_base = kaddr + offset; - iov.iov_len = size; - iov_iter_kvec(&msg.msg_iter, ITER_SOURCE, &iov, 1, size); - rc = smc_tx_sendmsg(smc, &msg, size); - kunmap(page); - return rc; -} - /***************************** sndbuf consumer *******************************/ /* sndbuf consumer: actual data transfer of one target chunk with ISM write */ diff --git a/net/smc/smc_tx.h b/net/smc/smc_tx.h index 34b578498b1f..a59f370b8b43 100644 --- a/net/smc/smc_tx.h +++ b/net/smc/smc_tx.h @@ -31,8 +31,6 @@ void smc_tx_pending(struct smc_connection *conn); void smc_tx_work(struct work_struct *work); void smc_tx_init(struct smc_sock *smc); int smc_tx_sendmsg(struct smc_sock *smc, struct msghdr *msg, size_t len); -int smc_tx_sendpage(struct smc_sock *smc, struct page *page, int offset, - size_t size, int flags); int smc_tx_sndbuf_nonempty(struct smc_connection *conn); void smc_tx_sndbuf_nonfull(struct smc_sock *smc); void smc_tx_consumer_update(struct smc_connection *conn, bool force); From patchwork Tue Jun 20 14:53:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13286018 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 A8D5DEB64DB for ; Tue, 20 Jun 2023 14:57:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 41BA78D0013; Tue, 20 Jun 2023 10:57:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CC598D0001; Tue, 20 Jun 2023 10:57:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26C318D0013; Tue, 20 Jun 2023 10:57:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 169928D0001 for ; Tue, 20 Jun 2023 10:57:23 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DAE651410EE for ; Tue, 20 Jun 2023 14:57:22 +0000 (UTC) X-FDA: 80923429524.13.BDC79EE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf26.hostedemail.com (Postfix) with ESMTP id DEDB4140002 for ; Tue, 20 Jun 2023 14:57:20 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MsdUC5o5; spf=pass (imf26.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1687273041; 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=LPVmbLfi9bgga9t/1pR/YmjTCDUThBHs3vchY9icGtA=; b=IVMgs6oyYd+1W1Yesazc2KJ9dZtrY73xPhd+kdpsgolFaqHaDyNFTJPXGB3OvPKZ2FOPa1 EeQbW2RdzoUdQHjIIcgpuLxG0VvNA28+GM9cdOgEO/QQfFstN0fdEaW+lyDxjORBFDEpBJ 7wRBXWZt0nOC7n7JJjuQATqc8Ge4UzI= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=MsdUC5o5; spf=pass (imf26.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1687273041; a=rsa-sha256; cv=none; b=46Fm3WzYaA4seSfrS6MYaUH+jmSLkqIn3jhdI819FWbJ8gOtrOTzvDo5E9/V38SJIhK1+E IHj0DVBewT2HYBqHnN15fD18BOO3pHbbgjobGfOfy9wCjSxqPAhTHLIw6GZKE0cD3aSOhP IaNBHK8SoJ3K7aHSncjNI5yGD4VuzGg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687273040; 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=LPVmbLfi9bgga9t/1pR/YmjTCDUThBHs3vchY9icGtA=; b=MsdUC5o52FZFpwxiI2KIo1CiMTCfAKAnNSIDh7v1SThbkWSoCQvCF58J2J4KiXXGAKNycq x3m0sK3ML+lzIdQ24sCEzvOOHdCTGGUoSRBVnGlafs7G4Nc//QxzDJnfHaV7x/sxRd5Ng/ VhIZilSKjdq6cMJZ3YjmnxVlxUkABPo= 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-572-azJhDjRHOim524o5jKEhlw-1; Tue, 20 Jun 2023 10:57:14 -0400 X-MC-Unique: azJhDjRHOim524o5jKEhlw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 543CA3C1A5FB; Tue, 20 Jun 2023 14:54:33 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F4C51400C34; Tue, 20 Jun 2023 14:54:31 +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, Mark Fasheh , Joel Becker , Joseph Qi , ocfs2-devel@oss.oracle.com Subject: [PATCH net-next v3 13/18] ocfs2: Use sendmsg(MSG_SPLICE_PAGES) rather than sendpage() Date: Tue, 20 Jun 2023 15:53:32 +0100 Message-ID: <20230620145338.1300897-14-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Rspamd-Queue-Id: DEDB4140002 X-Rspam-User: X-Stat-Signature: fdz456n51yy9m3r3xbh9ntu4im7bjwun X-Rspamd-Server: rspam01 X-HE-Tag: 1687273040-729817 X-HE-Meta: U2FsdGVkX1+VU/vmt4eO7udzBPEj/HbOOYTiLsjhaVb/ZJV+/nzyXZ74Z6QSbFFBrwIK6EtiUHCrBpTw9+l3t5fkokmHYuUHzLQsSz26csVQISobvDh3t9rDFjwbtqpQJnhflqUmfGhEPe5oQb7QQhAUvHW25Ik9b0RdqYvXKJTa2pFBwpOq7EsbNezfvZ9EsxWOgOAC9qDTnwxKIhmA6OSLVcOyI7w6LVbtfaXh/3mzV8+QRn9HAzWUTouLNVRauznGffDL2lqgnHFSqms/yUkage3Fq0/x3t6lIccIrQ24AQzr98HBFGfVaqhfjt5CVMFMFpI9GkqI/dE9gnzstS9+6CKRBFSXbYtP0GqSlcLQLPlzHDbe0QtcsCQBF5jYGj/WIlHS1Vfyy+DnWDtVECpTSzObJCryv183FqIw06XBlwfG8RBbKXpDIzg/LbrL7LtZaZxAY/5K6n1q2pOIMjFLiScLOnZ1vFZZ2RDbBH3FSSiUAkQKHC0aaSj7cYn8zrTCk7VHJI/aXt1NjRSa7pCCR81JKRonx0yOPTSllt6PimyFIk6KBRMAyJxtn+hketrxB11pl7U4EdZvD8hoApsBjPGM47OfOYlE3QZ1KVRX/vovUfiZE5dFyJXnyOKk2CCl4o+O3LefOEXHlgWb8YOhr5z/DiiEu46+Uz5D3MT8RP5Jcj+otNTgSkd6Xs+b8pMNcJOsOVPpFVHwtPlBEYZhuCCiKbRA3McAB//holiXj4IxuZtvn0AQrpaGMnWYSoniM3hDMP3pWjqNAJssmWCYaG0D3YT1Hv1cBFwpK6Vp821PYjRI/uCk1ftJHB8U/+AeAmZGAVUTytqKaHtnLpHygeNziOdmIaH8PYG0pLg8CGpTlknIrQ/oT8Z42HaduYJydySfTXgNW6zl++XP+Oslb1gFEVcKdzG6KF5j+P4S4lt4pWgpw3mey2Q3EnmoQAmIi8BPRRfhYvdGD+8 xDeBv4Cr yZqprxgjThY3xeW5knjHFz3G/dECoZESuK/QQmnJs0Fv2CxOGtStxlhh49c6gV1j9dgfkKC+GQ/bPPtf4NGE9QX3k7lqP2eFsqKTm5mHfaOyFbPhTLV9Jp6K8jP/P9KZz16p3Ej0vAhze/t5wPAs+oq5r8Xr4/L9zn0bgtFo25H2v3jmSZDG3zq4XY/D7iBhHNqZ7/4HOcmXNob5FPWD5wHUZtoPU5cZDFJcSM7ZU0wFhYHQVULjCM6kTYEiDKuM0wyMkmIdBmfBwSrXD4DDFdSXgaj/09XZ90K34WwWWnQVdaFk+YEkg5JNsL9B67vd3SKO4fcqdfHRHNK9aTKqzIODhSbOtrYMJjJKOuPfeFsSjA2vt/VVi15//kK2Cd1zFqcX6WrSU3u8lfPMRdHzkiMzY55nyOHQC37nT6YhwAIcR16FsjbHUbEK2Njwzc9fuArS0XNUIChWjdJLpV4hvkJq/NStpKZ16rw8FhEZcusRHP9rObEJe8C3QvmQmvp9euE4DiytoTsSEAQoDmwBhLQXm6BkMeaYuZb2IJtvWDxjFfjAWw7hxRAjN52M1/dL4BTL2qJA7mf0kfK+/FgvCPzmuH+No02JD39q5 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: Fix ocfs2 to use the page fragment allocator rather than kzalloc in order to allocate the buffers for the handshake message and keepalive request and reply messages. Switch from using sendpage() to using sendmsg() + MSG_SPLICE_PAGES so that sendpage can be phased out. Signed-off-by: David Howells cc: Mark Fasheh cc: Joel Becker cc: Joseph Qi cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: ocfs2-devel@oss.oracle.com cc: netdev@vger.kernel.org --- Notes: ver #2) - Wrap lines at 80. fs/ocfs2/cluster/tcp.c | 109 +++++++++++++++++++++++------------------ 1 file changed, 60 insertions(+), 49 deletions(-) diff --git a/fs/ocfs2/cluster/tcp.c b/fs/ocfs2/cluster/tcp.c index aecbd712a00c..969d347ed9fa 100644 --- a/fs/ocfs2/cluster/tcp.c +++ b/fs/ocfs2/cluster/tcp.c @@ -110,9 +110,6 @@ static struct work_struct o2net_listen_work; static struct o2hb_callback_func o2net_hb_up, o2net_hb_down; #define O2NET_HB_PRI 0x1 -static struct o2net_handshake *o2net_hand; -static struct o2net_msg *o2net_keep_req, *o2net_keep_resp; - static int o2net_sys_err_translations[O2NET_ERR_MAX] = {[O2NET_ERR_NONE] = 0, [O2NET_ERR_NO_HNDLR] = -ENOPROTOOPT, @@ -930,19 +927,22 @@ static int o2net_send_tcp_msg(struct socket *sock, struct kvec *vec, } static void o2net_sendpage(struct o2net_sock_container *sc, - void *kmalloced_virt, - size_t size) + void *virt, size_t size) { struct o2net_node *nn = o2net_nn_from_num(sc->sc_node->nd_num); + struct msghdr msg = {}; + struct bio_vec bv; ssize_t ret; + bvec_set_virt(&bv, virt, size); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bv, 1, size); + while (1) { + msg.msg_flags = MSG_DONTWAIT | MSG_SPLICE_PAGES; mutex_lock(&sc->sc_send_lock); - ret = sc->sc_sock->ops->sendpage(sc->sc_sock, - virt_to_page(kmalloced_virt), - offset_in_page(kmalloced_virt), - size, MSG_DONTWAIT); + ret = sock_sendmsg(sc->sc_sock, &msg); mutex_unlock(&sc->sc_send_lock); + if (ret == size) break; if (ret == (ssize_t)-EAGAIN) { @@ -1168,6 +1168,7 @@ static int o2net_process_message(struct o2net_sock_container *sc, struct o2net_msg *hdr) { struct o2net_node *nn = o2net_nn_from_num(sc->sc_node->nd_num); + struct o2net_msg *keep_resp; int ret = 0, handler_status; enum o2net_system_error syserr; struct o2net_msg_handler *nmh = NULL; @@ -1186,8 +1187,17 @@ static int o2net_process_message(struct o2net_sock_container *sc, be32_to_cpu(hdr->status)); goto out; case O2NET_MSG_KEEP_REQ_MAGIC: - o2net_sendpage(sc, o2net_keep_resp, - sizeof(*o2net_keep_resp)); + keep_resp = alloc_skb_frag(sizeof(*keep_resp), + GFP_KERNEL); + if (!keep_resp) { + ret = -ENOMEM; + goto out; + } + memset(keep_resp, 0, sizeof(*keep_resp)); + keep_resp->magic = + cpu_to_be16(O2NET_MSG_KEEP_RESP_MAGIC); + o2net_sendpage(sc, keep_resp, sizeof(*keep_resp)); + folio_put(virt_to_folio(keep_resp)); goto out; case O2NET_MSG_KEEP_RESP_MAGIC: goto out; @@ -1439,15 +1449,23 @@ static void o2net_rx_until_empty(struct work_struct *work) sc_put(sc); } -static void o2net_initialize_handshake(void) +static struct o2net_handshake *o2net_initialize_handshake(void) { - o2net_hand->o2hb_heartbeat_timeout_ms = cpu_to_be32( - O2HB_MAX_WRITE_TIMEOUT_MS); - o2net_hand->o2net_idle_timeout_ms = cpu_to_be32(o2net_idle_timeout()); - o2net_hand->o2net_keepalive_delay_ms = cpu_to_be32( - o2net_keepalive_delay()); - o2net_hand->o2net_reconnect_delay_ms = cpu_to_be32( - o2net_reconnect_delay()); + struct o2net_handshake *hand; + + hand = alloc_skb_frag(sizeof(*hand), GFP_KERNEL); + if (!hand) + return NULL; + + memset(hand, 0, sizeof(*hand)); + hand->protocol_version = cpu_to_be64(O2NET_PROTOCOL_VERSION); + hand->connector_id = cpu_to_be64(1); + hand->o2hb_heartbeat_timeout_ms = + cpu_to_be32(O2HB_MAX_WRITE_TIMEOUT_MS); + hand->o2net_idle_timeout_ms = cpu_to_be32(o2net_idle_timeout()); + hand->o2net_keepalive_delay_ms = cpu_to_be32(o2net_keepalive_delay()); + hand->o2net_reconnect_delay_ms = cpu_to_be32(o2net_reconnect_delay()); + return hand; } /* ------------------------------------------------------------ */ @@ -1456,16 +1474,22 @@ static void o2net_initialize_handshake(void) * rx path will see the response and mark the sc valid */ static void o2net_sc_connect_completed(struct work_struct *work) { + struct o2net_handshake *hand; struct o2net_sock_container *sc = container_of(work, struct o2net_sock_container, sc_connect_work); + hand = o2net_initialize_handshake(); + if (!hand) + goto out; + mlog(ML_MSG, "sc sending handshake with ver %llu id %llx\n", (unsigned long long)O2NET_PROTOCOL_VERSION, - (unsigned long long)be64_to_cpu(o2net_hand->connector_id)); + (unsigned long long)be64_to_cpu(hand->connector_id)); - o2net_initialize_handshake(); - o2net_sendpage(sc, o2net_hand, sizeof(*o2net_hand)); + o2net_sendpage(sc, hand, sizeof(*hand)); + folio_put(virt_to_folio(hand)); +out: sc_put(sc); } @@ -1475,8 +1499,15 @@ static void o2net_sc_send_keep_req(struct work_struct *work) struct o2net_sock_container *sc = container_of(work, struct o2net_sock_container, sc_keepalive_work.work); + struct o2net_msg *keep_req; - o2net_sendpage(sc, o2net_keep_req, sizeof(*o2net_keep_req)); + keep_req = alloc_skb_frag(sizeof(*keep_req), GFP_KERNEL); + if (keep_req) { + memset(keep_req, 0, sizeof(*keep_req)); + keep_req->magic = cpu_to_be16(O2NET_MSG_KEEP_REQ_MAGIC); + o2net_sendpage(sc, keep_req, sizeof(*keep_req)); + folio_put(virt_to_folio(keep_req)); + } sc_put(sc); } @@ -1780,6 +1811,7 @@ static int o2net_accept_one(struct socket *sock, int *more) struct socket *new_sock = NULL; struct o2nm_node *node = NULL; struct o2nm_node *local_node = NULL; + struct o2net_handshake *hand; struct o2net_sock_container *sc = NULL; struct o2net_node *nn; unsigned int nofs_flag; @@ -1882,8 +1914,11 @@ static int o2net_accept_one(struct socket *sock, int *more) o2net_register_callbacks(sc->sc_sock->sk, sc); o2net_sc_queue_work(sc, &sc->sc_rx_work); - o2net_initialize_handshake(); - o2net_sendpage(sc, o2net_hand, sizeof(*o2net_hand)); + hand = o2net_initialize_handshake(); + if (hand) { + o2net_sendpage(sc, hand, sizeof(*hand)); + folio_put(virt_to_folio(hand)); + } out: if (new_sock) @@ -2090,21 +2125,8 @@ int o2net_init(void) unsigned long i; o2quo_init(); - o2net_debugfs_init(); - o2net_hand = kzalloc(sizeof(struct o2net_handshake), GFP_KERNEL); - o2net_keep_req = kzalloc(sizeof(struct o2net_msg), GFP_KERNEL); - o2net_keep_resp = kzalloc(sizeof(struct o2net_msg), GFP_KERNEL); - if (!o2net_hand || !o2net_keep_req || !o2net_keep_resp) - goto out; - - o2net_hand->protocol_version = cpu_to_be64(O2NET_PROTOCOL_VERSION); - o2net_hand->connector_id = cpu_to_be64(1); - - o2net_keep_req->magic = cpu_to_be16(O2NET_MSG_KEEP_REQ_MAGIC); - o2net_keep_resp->magic = cpu_to_be16(O2NET_MSG_KEEP_RESP_MAGIC); - for (i = 0; i < ARRAY_SIZE(o2net_nodes); i++) { struct o2net_node *nn = o2net_nn_from_num(i); @@ -2122,21 +2144,10 @@ int o2net_init(void) } return 0; - -out: - kfree(o2net_hand); - kfree(o2net_keep_req); - kfree(o2net_keep_resp); - o2net_debugfs_exit(); - o2quo_exit(); - return -ENOMEM; } void o2net_exit(void) { o2quo_exit(); - kfree(o2net_hand); - kfree(o2net_keep_req); - kfree(o2net_keep_resp); o2net_debugfs_exit(); } From patchwork Tue Jun 20 14:53:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13286020 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 3F9E1EB64DB for ; Tue, 20 Jun 2023 14:57:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B229E8D0015; Tue, 20 Jun 2023 10:57:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD0EA8D0001; Tue, 20 Jun 2023 10:57:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9994C8D0015; Tue, 20 Jun 2023 10:57:40 -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 88B4C8D0001 for ; Tue, 20 Jun 2023 10:57:40 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 61971411C7 for ; Tue, 20 Jun 2023 14:57:39 +0000 (UTC) X-FDA: 80923430238.20.286CF05 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 72A99100007 for ; Tue, 20 Jun 2023 14:57:37 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YZpuNF1H; spf=pass (imf05.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1687273057; 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=Z9Is+zezypuAnWTrr1pH940xiURYaMG5aMPeMP0eWBEwLcn+OThZ0DBsEnrazhMFL4fBty 2f138gSj/mljy+NJxRxB+RJOpAAHlmNA3yLcncj2sw4MoLpIQKkqRxv4+HUzzmbYV3JV7C FMQSKroyi0irz2XxAbxRVlfiQ5SsWYs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687273057; a=rsa-sha256; cv=none; b=J5v8L2erT1yJTl8EJ2NnknPmlYxxURsFMOTwyu14wndK2uIcezNbCoQDeMzDXlT7aeXxg+ 6WOwoqt9q2kbW7gyM2J5rPOlSF00L25jKVUu7/XYi3bdrOxkHKqHZvuGY7f2etn20LvmdC XtnQ8gT38jK0eE5Cl6e2a4ZIT1aSEIM= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=YZpuNF1H; spf=pass (imf05.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687273056; 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=YZpuNF1HX91baq6JeAs6f8ep0puXfiHN9iIwsGI/gShSoPJHzr87+3yycpEKE4GZJPkHaD lE/Fdu57c7ECv1+IneZjHRuTmGbWXDmqN6fRyLMZanXB/B1sDyecCzasJgfSZ7Xzq3DtG5 OsxybJj+m4yNHRDEM4adkBivsyImS/M= 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-448-QZ1cyihYMfqFmIoZXCbVIQ-1; Tue, 20 Jun 2023 10:57:28 -0400 X-MC-Unique: QZ1cyihYMfqFmIoZXCbVIQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 88D0B29ABA3F; Tue, 20 Jun 2023 14:54:36 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id E58D02166B26; Tue, 20 Jun 2023 14:54:33 +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 v3 14/18] drbd: Use sendmsg(MSG_SPLICE_PAGES) rather than sendpage() Date: Tue, 20 Jun 2023 15:53:33 +0100 Message-ID: <20230620145338.1300897-15-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Queue-Id: 72A99100007 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: dgiopexwwnf6dps1mu75osfamf9cysw5 X-HE-Tag: 1687273057-927587 X-HE-Meta: U2FsdGVkX1+dpAgpDFc46/srkewnfNdrep/YPD+GKzvsKiVlBhinkyhojRCIfexxQiDX55xSOuTRzX0lQzxypcVF8GA0lfSQW65GAKuOWZ3b3CzzGCZLF0nKnXAAI4POn/GRX0FMLLn/HbVt2jFAeBRpxv3KELDi+QxU/pIonx7nImiyclXMRQ9BNZkgXo+2J7D0m9hL5uXX3MZNE9M/rdplzZyJ54gF/fhUhvs94uOO9CuF7h8otJHQLAZEACrPfb90OwTphTV/pSSFNPTN7Zb8TX4ME7E6PAocquj1Nxy3l9LduC7wQndi9CpuMN3/deCV+RuSX73E7w5LgKDBQe1wcZQCityYzih265+AWlKg996k2vfAp18pNKdGCOYAaouRlbcjECPKKa85PYz/Dcw5A3fFPZEVdXm9Z3y6BjAbvBl4zJuefisWsOKZPbbvFbxKBOShTdMndClwIKtdmE10g2363xLLnM0sBqXq7uK5I/XImcPTJExjQQcGDI377Z951iXO76OT53CuUPcGHz/qGIC8k3QpWf1rwqyqjsOn6kqv9WxFlS8atu8mjkUhYiFWtmEscyHbY+oWuJ3i0e4gHbWa0Z6buHutgh5YOFVsgp/yah/aTNHtzhdV3UiwDsU4kVV6glDM2rMwcj0q52cpMKfuqSI2wLTD12FyH72cfORUqZkSpk8ewJV3v6auLxZJs88ehxBjD6phf18KXzp3JQB6ubXZDBNMC8452E2g/URTjf1+vUNChpqbCQe5git5QlSs/TZt4Rh+JztbjK3FO2U4yDdsO580tHdrYkimXHEaADfhZDJevp/Po7xrL5KahXXQEhERDOW4mT9wCiXfIc5vpwFmOOfeAhVxc/7GJDYlwjXTVYhF83SiSqiQ3FwgDC1iU2dCkdNpkQzJ3xSfcGMuoDyCH9/w2Qj1gKZZdDbaQXRmNpp1Y8Eb9I+YAXjswb5ae8Gdw6o6SQW 2rf2apkD xv6bVazBkPNCtsMwiGSupZNdqe9AM89FBABXLmiYczgRwrqDnY+HIME7/k76UEPH0s0GR5D/bbuulA1qQMv4IV9UMjOxq8irfTR37GFMRVPiH1Ra/TmgbPvXmw8dORpXumRBXX/Asjr2/sr55GM/JW4yzf4m33CLRYcUsKCXaFMzXQuBtZkHncsKEn5sJ1lOwNkPdQ7+gY47n8OH7N2LTOLF538rxVA8GtsPROMucPr12rBXV2hipLSXFAbPmtUBMCFQw1ShhjaxGFnr1SAB3Fg2ON/QEFKxBFskkPQeLzlPr14k7iw+vOYn63Cl7g1IHqwwex54OitQNbAIBL48ZWUMkKwPGywIzHt+jMBb5ajM8ZIcbh0VgYJOSRL8+t8wepyFqxUdipsb4TUOKTq0cqW5rp2HHAVLqbFivME5uQYahi4JdC4FNmaC95X70Q+5ok4d9Jg2UJqkUT+xeypDfRUPk8TqW/CNA4hM2mvLw5qq0fuXxenDIM4acLA== 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; } From patchwork Tue Jun 20 14:53:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13286016 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 B7626EB64DB for ; Tue, 20 Jun 2023 14:57:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 490CA8D0011; Tue, 20 Jun 2023 10:57:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 440E78D0001; Tue, 20 Jun 2023 10:57:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E1AE8D0011; Tue, 20 Jun 2023 10:57:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 13C918D0001 for ; Tue, 20 Jun 2023 10:57:17 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DB8301A061B for ; Tue, 20 Jun 2023 14:57:16 +0000 (UTC) X-FDA: 80923429272.07.0515E08 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id A9217A000C for ; Tue, 20 Jun 2023 14:57:14 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JPxjPY4P; spf=pass (imf15.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1687273034; 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=XKse4vF5Frqs4bdWsYMKttBmqWRsH1PFiAHwvjH79qA=; b=rr3nWKD9B5QeoL3CIhSZGxhywvwkFWBOxD3DUx+dyM6f/PGEcJqoFwG8uXqzHvpdloMJiE Z3Bg5q27ptfKdfw6TRfmB3ZOxySA+OajjiheC9bhpJpwKK2/0m0zgJD47MQO8hgVJXalBJ /1S3GwwSe/bluJjbdcYABq3ENiONOis= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687273034; a=rsa-sha256; cv=none; b=dU/s9eqyRSp6auolMbqpeSfIJLhymLZX+oQkcIAiL/4umF70XoOuHpOgq3/R8H0JISOTVk lgtjNxaRba8vXOLzHLU/+ijYw7yVclrU8NHY9aW/rDkGTYmR00C4Kw6Xr0rAoeeLXckdZM 1w7DI8VXw4nDBDc8Hc32B8jkODuKBgU= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JPxjPY4P; spf=pass (imf15.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687273034; 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=XKse4vF5Frqs4bdWsYMKttBmqWRsH1PFiAHwvjH79qA=; b=JPxjPY4PDmL9ZbtXTfjKDZnyAmqdVXlsUcdv6agqeCBsGvE547yLchHb49YHBEJpX1Zbbi Nvjyn+nZ7jD2UZsHKkJvSJCmPa9aljl8GrOjSoGQvLQleorD79bTjauOfGID4g/AXibfci GyXvOOinWQjIU0kBORhebAc8UtfuiSQ= 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-620-Q6NvzJ07NxKczalwLXSO3g-1; Tue, 20 Jun 2023 10:57:10 -0400 X-MC-Unique: Q6NvzJ07NxKczalwLXSO3g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1552E1064B1B; Tue, 20 Jun 2023 14:54:39 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 341B5200A398; Tue, 20 Jun 2023 14:54:37 +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 v3 15/18] drdb: Send an entire bio in a single sendmsg Date: Tue, 20 Jun 2023 15:53:34 +0100 Message-ID: <20230620145338.1300897-16-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Queue-Id: A9217A000C X-Rspam-User: X-Stat-Signature: pui8phm8pg65qptbxjmqxfzgd19yxqub X-Rspamd-Server: rspam03 X-HE-Tag: 1687273034-912441 X-HE-Meta: U2FsdGVkX1/Sm7xSprXo1goF4Nfbh+MbmfVUCDfT/UnKXTzsZjerZBrIlcGpPQizYD2kgAcT3Qhtd9HBslGFXiVnR+Q35gzvv6/1Yn7h4g9wP7AG7qrCmKKUl3IUekNBvTAi4YqXqiMHjyGjVbCPHDiD5zloeyF+O3CRKYAu8U7hkFJAOuk2Djpv3IzvdD8XqjyOUBJ0rvznpxmCgYVA5saSzm91RKevAiVd0zHkRTp/JlYLqXOimWru7X/9mWGAKP6rpBag7Y2zSoaO22i1Xqu1xbvwgOkyDqPrTUqxj3V4C/mEL6622rgwBE+esV3Tr2HC5AcxVuutRYONBrrIfGuGDF/TQmY0q5+mQFPsAay5GUyGdhtCk5YFUZo8pXAnuFrc7G7B24OfDalKRS055tUJAutRApEN0dEoyVkVskzDYRra1fFD6+HD4m9kAea+aWFMw4D+MpF/5ExYQHGhF+WSXGGCDB5DOGsXtFBO/ZI2pgEiaGcyJlwX2QlEk840bq+/J3o0z1/R8mcm0HZ9OsXZ34vjmm8H1nsCrL5xC0sOgejU1BHexBAx09Xxsqqkrpcx7f4Sc2Bgheioz9qicwv0YuOPkbIINSHBFBLp3YkWt4V8F2c9rSe33RmjbL8kFFwEymME6f6gxJX0pnznZKEWtjyR08ko614JHYnniGUuyqkRn7vHPFmmhXCLXSZoQaEHZRANyeg/cCiZ4EwFwgFVwIegLBwF7NHUlc7+luyFQjpTbXFpEG7C3uyjnOEdtrVfxZM/XEtTgxllRsReQ2ge3jfYEI+lU6v+jxn6TSA+aTLt2xy0Cmm6PJxnCwEgMvxglD23OPFYewYQqgOORTcbA0lQGHBi8g6+r9fUeP0bI2XJTpleJ+mupbJSb/xO/ev3KGmbfQ6Lt0CuFTmZyhxZzzHfcn+5xpRSnotY5YxDysLmkpwyMgJyrOvwQUuP7L5bw8OQmo1mQIKGcI0 PxZDp4D1 hUp11WD0b1tU4dZpNxYFBVUcobo6qLInWLzI3/KmmJ24uXnAN/cOysYEJRwkLX8X59AJ03R0ycLF7p9PKgHN4dMWC7jD25/CsPc8EO+G1zU3zLpXo2z+9Fdb4SKR4jK+4w+VHyq0nn8gFoendcHV6U2cqJE4+9u3ymJr28qrR/Fa9/lCucQj19Awqh1M5ekHxPUgl29AsLexo6qnIspGTeE8EAUloMMSB3VX9A1YO1o69OAZE6PMteT7i08/Ze6l6ZNKE84Jc550ZNmtL9upwlXZw8YjR2cSv1fulxY9VXgpNq6tIxCAvF5F5v/X9SNX/qmX3IvPCSP4mt9wdzcO0svG3c/cctxZ2nXvXqgxiAotc0gRR0opzpDCyXpB4MN66zkQMMTx3/3ihOE6ORowbwtxZjwVVqHz44FA7tMq4ChgHu14LyTeNVKnsTYcnwUhyLk7k6l7UZzT1Qek= 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: Since _drdb_sendpage() is now using sendmsg to send the pages rather sendpage, pass the entire bio in one go using a bvec iterator instead of doing it piecemeal. 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) - Use "unsigned int" rather than "unsigned". drivers/block/drbd/drbd_main.c | 77 +++++++++++----------------------- 1 file changed, 25 insertions(+), 52 deletions(-) diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c index 8a01a18a2550..beba74ae093b 100644 --- a/drivers/block/drbd/drbd_main.c +++ b/drivers/block/drbd/drbd_main.c @@ -1520,28 +1520,15 @@ static void drbd_update_congested(struct drbd_connection *connection) * As a workaround, we disable sendpage on pages * with page_count == 0 or PageSlab. */ -static int _drbd_no_send_page(struct drbd_peer_device *peer_device, struct page *page, - int offset, size_t size, unsigned msg_flags) -{ - struct socket *socket; - void *addr; - int err; - - socket = peer_device->connection->data.socket; - addr = kmap(page) + offset; - err = drbd_send_all(peer_device->connection, socket, addr, size, msg_flags); - kunmap(page); - if (!err) - peer_device->device->send_cnt += size >> 9; - return err; -} - -static int _drbd_send_page(struct drbd_peer_device *peer_device, struct page *page, - int offset, size_t size, unsigned msg_flags) +static int _drbd_send_pages(struct drbd_peer_device *peer_device, + struct iov_iter *iter, unsigned int msg_flags) { struct socket *socket = peer_device->connection->data.socket; - struct bio_vec bvec; - struct msghdr msg = { .msg_flags = msg_flags, }; + struct msghdr msg = { + .msg_flags = msg_flags | MSG_NOSIGNAL, + .msg_iter = *iter, + }; + size_t size = iov_iter_count(iter); int err = -EIO; /* e.g. XFS meta- & log-data is in slab pages, which have a @@ -1550,11 +1537,8 @@ 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)) - 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); + if (drbd_disable_sendpage) + msg.msg_flags &= ~(MSG_NOSIGNAL | MSG_SPLICE_PAGES); drbd_update_congested(peer_device->connection); do { @@ -1587,39 +1571,22 @@ static int _drbd_send_page(struct drbd_peer_device *peer_device, struct page *pa static int _drbd_send_bio(struct drbd_peer_device *peer_device, struct bio *bio) { - struct bio_vec bvec; - struct bvec_iter iter; + struct iov_iter iter; - /* hint all but last page with MSG_MORE */ - bio_for_each_segment(bvec, bio, iter) { - int err; + iov_iter_bvec(&iter, ITER_SOURCE, bio->bi_io_vec, bio->bi_vcnt, + bio->bi_iter.bi_size); - err = _drbd_no_send_page(peer_device, bvec.bv_page, - bvec.bv_offset, bvec.bv_len, - bio_iter_last(bvec, iter) - ? 0 : MSG_MORE); - if (err) - return err; - } - return 0; + return _drbd_send_pages(peer_device, &iter, 0); } static int _drbd_send_zc_bio(struct drbd_peer_device *peer_device, struct bio *bio) { - struct bio_vec bvec; - struct bvec_iter iter; + struct iov_iter iter; - /* hint all but last page with MSG_MORE */ - bio_for_each_segment(bvec, bio, iter) { - int err; + iov_iter_bvec(&iter, ITER_SOURCE, bio->bi_io_vec, bio->bi_vcnt, + bio->bi_iter.bi_size); - err = _drbd_send_page(peer_device, bvec.bv_page, - bvec.bv_offset, bvec.bv_len, - bio_iter_last(bvec, iter) ? 0 : MSG_MORE); - if (err) - return err; - } - return 0; + return _drbd_send_pages(peer_device, &iter, MSG_SPLICE_PAGES); } static int _drbd_send_zc_ee(struct drbd_peer_device *peer_device, @@ -1631,10 +1598,16 @@ static int _drbd_send_zc_ee(struct drbd_peer_device *peer_device, /* hint all but last page with MSG_MORE */ page_chain_for_each(page) { + struct iov_iter iter; + struct bio_vec bvec; unsigned l = min_t(unsigned, len, PAGE_SIZE); - err = _drbd_send_page(peer_device, page, 0, l, - page_chain_next(page) ? MSG_MORE : 0); + bvec_set_page(&bvec, page, 0, l); + iov_iter_bvec(&iter, ITER_SOURCE, &bvec, 1, l); + + err = _drbd_send_pages(peer_device, &iter, + MSG_SPLICE_PAGES | + (page_chain_next(page) ? MSG_MORE : 0)); if (err) return err; len -= l; From patchwork Tue Jun 20 14:53:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13286017 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 51219EB64D7 for ; Tue, 20 Jun 2023 14:57:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA3B88D0012; Tue, 20 Jun 2023 10:57:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E52ED8D0001; Tue, 20 Jun 2023 10:57:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF3F48D0012; Tue, 20 Jun 2023 10:57:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id BD5548D0001 for ; Tue, 20 Jun 2023 10:57:20 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 332331410ED for ; Tue, 20 Jun 2023 14:57:20 +0000 (UTC) X-FDA: 80923429440.06.A98B103 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 5073980005 for ; Tue, 20 Jun 2023 14:57:17 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Tm0JM7GF; spf=pass (imf30.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1687273038; a=rsa-sha256; cv=none; b=E9XYZEKgzSX+B3xjGe7kp6fVNpxe/yGByh5GZNKb7exhrVCfO16XNGT3t7RIHv24iSMsS9 vmy8yStgpN7jAM41ug0v11pi9jflIG3ZNjSQ310WYBN5zo6X9OfmIHzVXoQMS2ZzeN4Wnj Tx31b/7EX+BjMLFnPwxZbpWbFjUFcEQ= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Tm0JM7GF; spf=pass (imf30.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1687273038; 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=bszGYXAPCfyFrCrKXBgf4DyEzlv1vS1+csO6wWtbX4c=; b=Za5JxyoLpli/dK5VaWQOhpCsJYjw8SUtin+IGCLIlvgypUp03YmF7javvbAHqBuTaiKbA3 f7WWa82kfQhmCOAnPGyyHnINc3ZcmmDfoHREebrRIMEK2Zu7n8Yw3T0czFdeAt5yd5YaI8 HgjZre8Srg15cjTAYf3pDouMq387ukU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687273037; 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=bszGYXAPCfyFrCrKXBgf4DyEzlv1vS1+csO6wWtbX4c=; b=Tm0JM7GFotiHjE80465qJxTcDuCZtVEFvbAt6v7EwsyC/iYNAP6PwKZ7YgMy6tN6+w3dJb NO1F5uHgmaMmAhJoIvSOai6fiZ35rst66OniaQruPwblUOITrqA+VJ2+jBFRSQQ1Qsv5jt RVgxkwF870LM5nnJive3zsnP/cKS5E0= 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-180-5iBq3k2zOLaeVvGBHbh90g-1; Tue, 20 Jun 2023 10:57:13 -0400 X-MC-Unique: 5iBq3k2zOLaeVvGBHbh90g-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 176203C1BFD2; Tue, 20 Jun 2023 14:54:42 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E84B422B0; Tue, 20 Jun 2023 14:54:39 +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, Lee Duncan , Chris Leech , Mike Christie , Maurizio Lombardi , "James E.J. Bottomley" , "Martin K. Petersen" , Al Viro , open-iscsi@googlegroups.com, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org Subject: [PATCH net-next v3 16/18] iscsi: Use sendmsg(MSG_SPLICE_PAGES) rather than sendpage Date: Tue, 20 Jun 2023 15:53:35 +0100 Message-ID: <20230620145338.1300897-17-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 5073980005 X-Stat-Signature: btmznsn1wtf4iwikeqm1ddqpijs3bdp7 X-Rspam-User: X-HE-Tag: 1687273037-286713 X-HE-Meta: U2FsdGVkX1/YLrdpAKBLe5uHFgM+g7yHusDo9cks61NYxtyAfm81cb8NcAqI58u9aXe7Nd0MzQs/zp1X3RqIxZag+Sl982Yy4Lq2ChsXoi7Lw78cedalfUiyb+abddxhyUGrQQV76ANEAKA4VhVlXhJwPA7Jxlk4ImY2KyBleXPzb2zzbRhYGvP4m7XMARCQVoLdupDfGrKC0wCVYd/0itn6315HGvx2Y4XQUkUCuMJ4Nocbtm+9gg9t0MSX3c6ZFwRJ5HxcermeXkWRs/LUNKz7uJDBGvlZBlyh/4xVvjQPq/XbesoMC5jj8An101I+tOmUqo/b6YL/Np4i+yi+3y5Xs2vIG6DkdlfzDIVi5O0Xbr9DbceHfhX8YIHxaaPo42CO5/sDzxWDZ/V2YJabVEuD+DQaFFPTPlph61r//OuwPu4s39/XHubmDtf5FTck5K63hlrHKTverW1xB1EImX+gjzwyDjSAItgyARfKxpd6Ug1NpMNgtVJur9/OqmWafg+c/Gpk44kCnRP+HPgT3mEobPuXatr+RT8PhHAcQh8uFqrT3nZytee7XZlEkC4oEWA/pDPwce75vkuMrVYyCQuBRa1p6/b10/3ywjqWXYB2wD2MyfO+QP5Ncw0mxZrgHKYBS/o1U4Y1aXgBK5eEILaAYWOC7FMtxkrbkK/t7L9189tyJxwAKukURs+kpUrcksYDIhCq+cAZ25CxNDTd6pAZQ3Ec4DJbhlNzMOvjoX26QOQN4sXmWySTp3n1LTOblyhjvZjVodNhQzTIB+NT47IwpZzs02wjipPsTt+FSOgIrZkHuSP+wGOE2xnbmcHcKokjOy5o/8EOY2qPlgYzPBtsTnMmGQ3tGq6qNj6sFHEObYp0vVl4kTKe5lOuDBSKFOg/FdWsHgc/UhdmQzA1z6DDWKsnL8iHF4uM7cdLIejixDLST0PCaEhc9PEzQURbFnZg3a4a+DYaBlGLTCH K/0QCWB6 QZieTUdKInRVANvhz+tILteXpxSB9yjiluivJboFbYVgIwVYaZZOYqnJhIKhYMGiln7jxOrgjY/9xxPGscbS3GJG6TQ7wWYPL5bmURly/F0upwQcstjr2JW2rWeMpj/e+mCSGYwQhtoQuqrqzZPy72UHkM+zto6CR1R3WAePJf8hysuedcCfEZc0EnNxtimy+/2Rt7ndJIATdqE+T5shcT4Y4MunmW+oZ8A083VKCc+I4QMH3RY/1+mYUbeSdd+pFUBMpPu2QBUtpnNe8XZAvac2ZmwPjfT9LuigxfCfOyIzMlp1AhUx5qshY1sp3Alvxbh8fpWgifZuELcdeGibkrxSFEs84t/SyzkG0hz1pStOeG//oVVAPtvSe33zK0FtKScO3G9pj5aNzHLJDtcOYpHTXqK3twMAuJnMkBhbIwdR+ZQieObmEs5nGGCAachrWGgopbmf0Kb7GpYG35NseOi7l4FXxM9oWiccNSIzdToUNuIuJjcSjVFEOvApnjAhS/eVWLZBk3HI90EF4Pqhp7EdXxrXQWcher4CI8USuSfJUC0W6seqLLjKhtB2HHBTLHXxKhF5dB6fe54npJta2aIq4u4r7JV0sTKn6GwowL1Z0IEi8qDGBISBXtmaIgoFyQfc4bjrwUho5N4ViWtB6bnHLpqtJR5dDa6ju3g1Gsv7ZmpHd+8YuwXSz+jUH8jMgOUvFMc5Y608e3XA7gWK1W8qNCA== 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() with MSG_SPLICE_PAGES rather than sendpage. This allows multiple pages and multipage folios to be passed through. TODO: iscsit_fe_sendpage_sg() should perhaps set up a bio_vec array for the entire set of pages it's going to transfer plus two for the header and trailer and page fragments to hold the header and trailer - and then call sendmsg once for the entire message. Signed-off-by: David Howells cc: Lee Duncan cc: Chris Leech cc: Mike Christie cc: Maurizio Lombardi cc: "James E.J. Bottomley" cc: "Martin K. Petersen" cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: Al Viro cc: open-iscsi@googlegroups.com cc: linux-scsi@vger.kernel.org cc: target-devel@vger.kernel.org cc: netdev@vger.kernel.org --- Notes: ver #2) - Wrap lines at 80. drivers/scsi/iscsi_tcp.c | 26 +++++++++--------------- drivers/scsi/iscsi_tcp.h | 2 +- drivers/target/iscsi/iscsi_target_util.c | 15 ++++++++------ 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c index 9637d4bc2bc9..9ab8555180a3 100644 --- a/drivers/scsi/iscsi_tcp.c +++ b/drivers/scsi/iscsi_tcp.c @@ -301,35 +301,32 @@ static int iscsi_sw_tcp_xmit_segment(struct iscsi_tcp_conn *tcp_conn, while (!iscsi_tcp_segment_done(tcp_conn, segment, 0, r)) { struct scatterlist *sg; + struct msghdr msg = {}; + struct bio_vec bv; unsigned int offset, copy; - int flags = 0; r = 0; offset = segment->copied; copy = segment->size - offset; if (segment->total_copied + segment->size < segment->total_size) - flags |= MSG_MORE | MSG_SENDPAGE_NOTLAST; + msg.msg_flags |= MSG_MORE; if (tcp_sw_conn->queue_recv) - flags |= MSG_DONTWAIT; + msg.msg_flags |= MSG_DONTWAIT; - /* Use sendpage if we can; else fall back to sendmsg */ if (!segment->data) { + if (!tcp_conn->iscsi_conn->datadgst_en) + msg.msg_flags |= MSG_SPLICE_PAGES; sg = segment->sg; offset += segment->sg_offset + sg->offset; - r = tcp_sw_conn->sendpage(sk, sg_page(sg), offset, - copy, flags); + bvec_set_page(&bv, sg_page(sg), copy, offset); } else { - struct msghdr msg = { .msg_flags = flags }; - struct kvec iov = { - .iov_base = segment->data + offset, - .iov_len = copy - }; - - r = kernel_sendmsg(sk, &msg, &iov, 1, copy); + bvec_set_virt(&bv, segment->data + offset, copy); } + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bv, 1, copy); + r = sock_sendmsg(sk, &msg); if (r < 0) { iscsi_tcp_segment_unmap(segment); return r; @@ -746,7 +743,6 @@ iscsi_sw_tcp_conn_bind(struct iscsi_cls_session *cls_session, sock_no_linger(sk); iscsi_sw_tcp_conn_set_callbacks(conn); - tcp_sw_conn->sendpage = tcp_sw_conn->sock->ops->sendpage; /* * set receive state machine into initial state */ @@ -777,8 +773,6 @@ static int iscsi_sw_tcp_conn_set_param(struct iscsi_cls_conn *cls_conn, return -ENOTCONN; } iscsi_set_param(cls_conn, param, buf, buflen); - tcp_sw_conn->sendpage = conn->datadgst_en ? - sock_no_sendpage : tcp_sw_conn->sock->ops->sendpage; mutex_unlock(&tcp_sw_conn->sock_lock); break; case ISCSI_PARAM_MAX_R2T: diff --git a/drivers/scsi/iscsi_tcp.h b/drivers/scsi/iscsi_tcp.h index 68e14a344904..d6ec08d7eb63 100644 --- a/drivers/scsi/iscsi_tcp.h +++ b/drivers/scsi/iscsi_tcp.h @@ -48,7 +48,7 @@ struct iscsi_sw_tcp_conn { uint32_t sendpage_failures_cnt; uint32_t discontiguous_hdr_cnt; - ssize_t (*sendpage)(struct socket *, struct page *, int, size_t, int); + bool can_splice_to_tcp; }; struct iscsi_sw_tcp_host { diff --git a/drivers/target/iscsi/iscsi_target_util.c b/drivers/target/iscsi/iscsi_target_util.c index b14835fcb033..6231fa4ef5c6 100644 --- a/drivers/target/iscsi/iscsi_target_util.c +++ b/drivers/target/iscsi/iscsi_target_util.c @@ -1129,6 +1129,8 @@ int iscsit_fe_sendpage_sg( struct iscsit_conn *conn) { struct scatterlist *sg = cmd->first_data_sg; + struct bio_vec bvec; + struct msghdr msghdr = { .msg_flags = MSG_SPLICE_PAGES, }; struct kvec iov; u32 tx_hdr_size, data_len; u32 offset = cmd->first_data_sg_off; @@ -1172,17 +1174,18 @@ int iscsit_fe_sendpage_sg( u32 space = (sg->length - offset); u32 sub_len = min_t(u32, data_len, space); send_pg: - tx_sent = conn->sock->ops->sendpage(conn->sock, - sg_page(sg), sg->offset + offset, sub_len, 0); + bvec_set_page(&bvec, sg_page(sg), sub_len, sg->offset + offset); + iov_iter_bvec(&msghdr.msg_iter, ITER_SOURCE, &bvec, 1, sub_len); + + tx_sent = conn->sock->ops->sendmsg(conn->sock, &msghdr, + sub_len); if (tx_sent != sub_len) { if (tx_sent == -EAGAIN) { - pr_err("tcp_sendpage() returned" - " -EAGAIN\n"); + pr_err("sendmsg/splice returned -EAGAIN\n"); goto send_pg; } - pr_err("tcp_sendpage() failure: %d\n", - tx_sent); + pr_err("sendmsg/splice failure: %d\n", tx_sent); return -1; } From patchwork Tue Jun 20 14:53:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13286021 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 74ACDEB64DB for ; Tue, 20 Jun 2023 14:58:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 15BEC8D0006; Tue, 20 Jun 2023 10:58:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 10D0F8D0001; Tue, 20 Jun 2023 10:58:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF0738D0006; Tue, 20 Jun 2023 10:58:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DDD148D0001 for ; Tue, 20 Jun 2023 10:58:12 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B299A1211B8 for ; Tue, 20 Jun 2023 14:58:12 +0000 (UTC) X-FDA: 80923431624.05.5643A91 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id D90671C0013 for ; Tue, 20 Jun 2023 14:58:09 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NLlktuRX; spf=pass (imf18.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1687273089; 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=096kfvQCNbO3jjvPJlb61wpL4gpNse4m8jbz5dQcH+U=; b=RmriIdl/rbOljO6qeukt0ZkdxBDQOlR73WfHl+czHuEOC2GP8RtU9eL1JJDVIdMwgmFkkR JjXBbw9kEXb6q1ERxe3usSNjXVwDlqJ0b6RGIzzawRmLcEtA8UFDNEIil2P7pvx3b/1WBw kh+LD/wA48yWLuFiTj4zXH3nD4sgkpE= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=NLlktuRX; spf=pass (imf18.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.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=1687273089; a=rsa-sha256; cv=none; b=b45HGPev25/ivlYqlz6GXk377hiY7HLEcAp4/Im4N1lRmyoyc34TVuRd91fKBEKLItadhq gWGzZ5UYmY1OeDgh5a2gw/GIsQFxYPHjWOKw6aX8TwcNjcswe+AWdzGA7BX1DrhfXEJsuR K1cNVzHKBB9M02iU5sOqTYpo1DKUpYQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687273089; 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=096kfvQCNbO3jjvPJlb61wpL4gpNse4m8jbz5dQcH+U=; b=NLlktuRXYst77c5i95xqGRYVxnBScqks2uhsnBPnfT50M3wKth80NqcUCDQHDnqu0h7gDY AO94U3AdF5Hsc8yGTxLAllSVG+9kZ1uUCowcYltlmzC2hKBDYFkEBVQm3yGUuz+hvVNRTI rH4d+VaalQeuqpDIuTOSpieAEpFQuVs= 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-246-cetdja7_MNaYUIl_PdTHIQ-1; Tue, 20 Jun 2023 10:58:01 -0400 X-MC-Unique: cetdja7_MNaYUIl_PdTHIQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D63E710665CD; Tue, 20 Jun 2023 14:54:49 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id D321E40C6CD2; Tue, 20 Jun 2023 14:54: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, bpf@vger.kernel.org, dccp@vger.kernel.org, linux-afs@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-can@vger.kernel.org, linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-hams@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-rdma@vger.kernel.org, linux-sctp@vger.kernel.org, linux-wpan@vger.kernel.org, linux-x25@vger.kernel.org, mptcp@lists.linux.dev, rds-devel@oss.oracle.com, tipc-discussion@lists.sourceforge.net, virtualization@lists.linux-foundation.org Subject: [PATCH net-next v3 18/18] net: Kill MSG_SENDPAGE_NOTLAST Date: Tue, 20 Jun 2023 15:53:37 +0100 Message-ID: <20230620145338.1300897-19-dhowells@redhat.com> In-Reply-To: <20230620145338.1300897-1-dhowells@redhat.com> References: <20230620145338.1300897-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Queue-Id: D90671C0013 X-Rspam-User: X-Stat-Signature: te7pz1ti4sq1sopc1az7uucij98poy5d X-Rspamd-Server: rspam01 X-HE-Tag: 1687273089-6202 X-HE-Meta: U2FsdGVkX1+dRnDFkcGTPKU9OQVriI3MkIWo7LFLZ1r/l/EF9XI2Z4rGD2zwEnx2RWr+xuSofRQHXbvhcw+dgD0vQJzHngiZ+RdY5avTk+2F+f9k+Z6kcdBjWqyy5iDHZMwc5XkmwqQhA+iYmHRG4dTWEUF7uTojJvDE/SiuawmpOvvNlcH8HThCP4V/u+ZJ/MAU1aRyL1QFZa9oNq1b6kU2vCbPPlgYz5V4usJLzcL5GNdLifZbQnPRhIoT9PDH4iL/jLPWDqSD0Gk+NwukNduf0GvNSok4BNctb1cIg4iA7v45kjnny4/fhynADj2PE+C6P98rgWeHgiL54tBZFtMwspvFABaWk61Sci5fq/sHAfg6riakNTPj32G0gwGZ9yWO2V5XzcUZv7z0hd6DnAg19Du1R4t48ihSGe9VP6VyH2i5WKLkTXYDe/sxM2H/cNAyjIHtt5e4u+yCn8rWs8vRHzXhuUh1ofqHrWtPLSRhL+dHIdk9hi0z4AQYBgh3nU4KgO6gTm7xtVT8dSdgj1DJ7U/IrPel4HG+fEkUQI/B8FAz9Kw+1XEAygOIT9wAwGTRHo/hrtwMS9BOzHAw+9jwU6dAxttDZWSiMhJt0GsAGMcioOcRFCTbqjVYS3PR95/sh0hAnVFHfIdz7TEhcHLWvczrVME/7D5ShXUnvic6+Cn+SBQT5D64Q3+O9XeClFAm9yzCDiEWFpDAcclUN4IOzVH0gV5CpfG2VRtWiEcnRAY4xPbN9byn/141lyGDE7YZ+K/nygxJbN/gnsGJSQWQZ3b0RZ6VHPi2+F40DYOXHzey1o4TP5qKihwWJT+O2l8wDuA+AjVVadY42tgzYRN7s4b5YXavXLrWgaNG8TR/ArwDVymfeVqJx687N3++UT+nloBnlAeS5o7woq7Vc41kzbliijbKngAzT7f4m0vvTlbPgXw3H0uNQvpsWQApll9U5H177YaI0e2q5jo lt7UM03q f1zbUnyB9oyaUqQfIGs9zh8YFHuUbD1h5TLQLuL2ibHBnF1uJufmsUwuLPzgQRLPSs8Y+PgD1DhTKFbg3HxAWrUwqKwKbHBCfU0ANhgbDc6JC6xCR2wvg496ENZ+9RTR2zi33RZUuaWxvQAnsw1hsx/+Vviggmf4g8bujVQMVFcq3pWK31joQxJKNBB0JiPq7IF0S4jxRWV41/tJdU7Upx+ttLh8BrglDWhVsYyUIHReySnz8RZUe47nEW8mS1+CmHeqUvHS7yEwVau1ofNJdgGpWFGROEwCqpLdkasGdnl2e43ZPKM4gCyc++1v5G9L8oVwP/ltwM7K3xn8cZM7slX+MEiTwAQr3TymiFChJr0FSpiFCNSBc6f4QmxRXglHmEpmNZqiMBzXnaJR6ddolchitEfByIYjw9kWn5zglKeE3uKLvV433r2yMCbCkRIokoaSpzsBppuJbXCyB/5AB/u81uhUoAWkjSy40loVwNEpOYUwZrxjgBkvFf51x64VDdAyMD4f5ya+WdBhbmTTaSKoCwGSe7q0IIys/rDWQqCZvtGTXhe4Uw6uehpiy1Q/+2bKjlFnAyCngMTpAnZH6io4TXK4WEn496m8O 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: Now that ->sendpage() has been removed, MSG_SENDPAGE_NOTLAST can be cleaned up. Things were converted to use MSG_MORE instead, but the protocol sendpage stubs still convert MSG_SENDPAGE_NOTLAST to MSG_MORE, which is now unnecessary. Signed-off-by: David Howells cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: bpf@vger.kernel.org cc: dccp@vger.kernel.org cc: linux-afs@lists.infradead.org cc: linux-arm-msm@vger.kernel.org cc: linux-can@vger.kernel.org cc: linux-crypto@vger.kernel.org cc: linux-doc@vger.kernel.org cc: linux-hams@vger.kernel.org cc: linux-perf-users@vger.kernel.org cc: linux-rdma@vger.kernel.org cc: linux-sctp@vger.kernel.org cc: linux-wpan@vger.kernel.org cc: linux-x25@vger.kernel.org cc: mptcp@lists.linux.dev cc: netdev@vger.kernel.org cc: rds-devel@oss.oracle.com cc: tipc-discussion@lists.sourceforge.net cc: virtualization@lists.linux-foundation.org --- Notes: ver #3) - tcp_bpf is now handled by an earlier patch. include/linux/socket.h | 4 +--- net/tls/tls_device.c | 3 +-- net/tls/tls_main.c | 2 +- net/tls/tls_sw.c | 2 +- tools/perf/trace/beauty/include/linux/socket.h | 1 - tools/perf/trace/beauty/msg_flags.c | 3 --- 6 files changed, 4 insertions(+), 11 deletions(-) diff --git a/include/linux/socket.h b/include/linux/socket.h index 58204700018a..39b74d83c7c4 100644 --- a/include/linux/socket.h +++ b/include/linux/socket.h @@ -319,7 +319,6 @@ struct ucred { #define MSG_MORE 0x8000 /* Sender will send more */ #define MSG_WAITFORONE 0x10000 /* recvmmsg(): block until 1+ packets avail */ #define MSG_SENDPAGE_NOPOLICY 0x10000 /* sendpage() internal : do no apply policy */ -#define MSG_SENDPAGE_NOTLAST 0x20000 /* sendpage() internal : not the last page */ #define MSG_BATCH 0x40000 /* sendmmsg(): more messages coming */ #define MSG_EOF MSG_FIN #define MSG_NO_SHARED_FRAGS 0x80000 /* sendpage() internal : page frags are not shared */ @@ -341,8 +340,7 @@ struct ucred { /* Flags to be cleared on entry by sendmsg and sendmmsg syscalls */ #define MSG_INTERNAL_SENDMSG_FLAGS \ - (MSG_SPLICE_PAGES | MSG_SENDPAGE_NOPOLICY | MSG_SENDPAGE_NOTLAST | \ - MSG_SENDPAGE_DECRYPTED) + (MSG_SPLICE_PAGES | MSG_SENDPAGE_NOPOLICY | MSG_SENDPAGE_DECRYPTED) /* Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx */ #define SOL_IP 0 diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index 840ee06f1708..2021fe557e50 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -441,8 +441,7 @@ static int tls_push_data(struct sock *sk, long timeo; if (flags & - ~(MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL | MSG_SENDPAGE_NOTLAST | - MSG_SPLICE_PAGES)) + ~(MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL | MSG_SPLICE_PAGES)) return -EOPNOTSUPP; if (unlikely(sk->sk_err)) diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index d5ed4d47b16e..b6896126bb92 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -127,7 +127,7 @@ int tls_push_sg(struct sock *sk, { struct bio_vec bvec; struct msghdr msg = { - .msg_flags = MSG_SENDPAGE_NOTLAST | MSG_SPLICE_PAGES | flags, + .msg_flags = MSG_SPLICE_PAGES | flags, }; int ret = 0; struct page *p; diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index 9b3aa89a4292..53f944e6d8ef 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -1194,7 +1194,7 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) if (msg->msg_flags & ~(MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL | MSG_CMSG_COMPAT | MSG_SPLICE_PAGES | - MSG_SENDPAGE_NOTLAST | MSG_SENDPAGE_NOPOLICY)) + MSG_SENDPAGE_NOPOLICY)) return -EOPNOTSUPP; ret = mutex_lock_interruptible(&tls_ctx->tx_lock); diff --git a/tools/perf/trace/beauty/include/linux/socket.h b/tools/perf/trace/beauty/include/linux/socket.h index 13c3a237b9c9..3bef212a24d7 100644 --- a/tools/perf/trace/beauty/include/linux/socket.h +++ b/tools/perf/trace/beauty/include/linux/socket.h @@ -318,7 +318,6 @@ struct ucred { #define MSG_MORE 0x8000 /* Sender will send more */ #define MSG_WAITFORONE 0x10000 /* recvmmsg(): block until 1+ packets avail */ #define MSG_SENDPAGE_NOPOLICY 0x10000 /* sendpage() internal : do no apply policy */ -#define MSG_SENDPAGE_NOTLAST 0x20000 /* sendpage() internal : not the last page */ #define MSG_BATCH 0x40000 /* sendmmsg(): more messages coming */ #define MSG_EOF MSG_FIN #define MSG_NO_SHARED_FRAGS 0x80000 /* sendpage() internal : page frags are not shared */ diff --git a/tools/perf/trace/beauty/msg_flags.c b/tools/perf/trace/beauty/msg_flags.c index ea68db08b8e7..b5b580e5a77e 100644 --- a/tools/perf/trace/beauty/msg_flags.c +++ b/tools/perf/trace/beauty/msg_flags.c @@ -8,9 +8,6 @@ #ifndef MSG_WAITFORONE #define MSG_WAITFORONE 0x10000 #endif -#ifndef MSG_SENDPAGE_NOTLAST -#define MSG_SENDPAGE_NOTLAST 0x20000 -#endif #ifndef MSG_FASTOPEN #define MSG_FASTOPEN 0x20000000 #endif