From patchwork Fri Jun 16 16:12:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13282934 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 379C2EB64DB for ; Fri, 16 Jun 2023 16:13:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B349F8E0003; Fri, 16 Jun 2023 12:13:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE51C8E0001; Fri, 16 Jun 2023 12:13:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 95EB58E0003; Fri, 16 Jun 2023 12:13:18 -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 80E188E0001 for ; Fri, 16 Jun 2023 12:13:18 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5B1F080C95 for ; Fri, 16 Jun 2023 16:13:18 +0000 (UTC) X-FDA: 80909105676.12.F222447 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 9A3FEC0020 for ; Fri, 16 Jun 2023 16:13:16 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SqRc0xAk; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.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=1686931996; 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=hLyIcwmfB2andhOIerohYp47fZMshUve8T8pZZkzjqE=; b=Dmv5hIhMzZ5gyfdJ/tC+59Q/hZcN/MpU4IxbKljl3ZqB3uQ8f7MOm6/IkqFSx2CmqOsDWk 4LZcBrf9Kl6L5x4wqtpO4UpttfHZRJf1FdfE+ljv0MsgDhSgD4tBsjCPMOovHIESJqjYn0 zMELuhzuAk9/U5jp7pjrQODFzUBT/0w= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SqRc0xAk; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.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=1686931996; a=rsa-sha256; cv=none; b=dUooI7ukHCuFIveSoGfSvH4vbg7FdL8auOtZxQk7yUPks+Z5LoudWJbz7id7dw4GI1dVhG 1sTcVZlmgogF+0sof6yuelwzrdoZx5OO8HttuXp4P5eviJRkOXqzcg+yAS2fol5r2bVf1p amlGwFq0bYJ6GW/GzoBmALzymVKvjLY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686931996; 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=hLyIcwmfB2andhOIerohYp47fZMshUve8T8pZZkzjqE=; b=SqRc0xAkUlhq9G2rT5xv79wqKiIwkOYsAMLveCNm+dUR+tswExpEAcPwrFthJJ6aArUGKE LUu67nRlQ2lEK+KQOwAwzyApcSEpymD3LJUgwmxKhvepRpWTnL22/3kLIPwFmRue9Sjcyk H+xJlKHkovFG+5JGJFfqwcs+OMcPO2c= 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-237-DuKHWMn7Mna8lkq6yhfy6g-1; Fri, 16 Jun 2023 12:13:14 -0400 X-MC-Unique: DuKHWMn7Mna8lkq6yhfy6g-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C97C43C025B4; Fri, 16 Jun 2023 16:13:13 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 913B348FB01; Fri, 16 Jun 2023 16:13:10 +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 02/17] net: Display info about MSG_SPLICE_PAGES memory handling in proc Date: Fri, 16 Jun 2023 17:12:45 +0100 Message-ID: <20230616161301.622169-3-dhowells@redhat.com> In-Reply-To: <20230616161301.622169-1-dhowells@redhat.com> References: <20230616161301.622169-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Rspamd-Queue-Id: 9A3FEC0020 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 9nixfsepdgd8qashikmj48n4y6qtnjbm X-HE-Tag: 1686931996-874925 X-HE-Meta: U2FsdGVkX1/7iupxSXGsxavj1az1tORcRi9q/tDrNB0Pswcw+cKZH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4XE+/D5H0WY2GbTT+5afwBUYgWerNhMQAj+hMUU14Uq46K9paOd/n0ctj588zPERqmvsOIl5KxQZRCIt+6lLCRZy1w+yIqCU9NMhy+G92BMBjNe7iBSAwr3rRpwUXzejqriVd6aDyIp5MLediQIBLUx0nHubrEMw17/+p3As5M4WhwhzxWlXU1BpPYxViyii0Je6e/E0ywa2ui9qr0Mdipj2ZqTdNE/bQGVF+KUdA0rAL2FP9b9yVrWOXQJ219Yz7uCbVzY21Sic5NLtzoe506qy/kplC7nBQMb42sfQUHk5BIaQdy3IEE5WN3qSD/B/D0LOI5FPwusi9/MguglNDZoBJ69ic8q3/YhA/Sdricc5bLbUjXJbF0Hwg5IeaPvjEKWlrePGq0jcYI6HdjX07KsiX1/V5wcAdnHY6nheAohY8PrlRRAk/oAqIPbLeJ2z/I= 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 9bd8d6bf6c21..c388a73e5d4e 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: @@ -7008,3 +7037,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);