From patchwork Thu Jun 29 15:54:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13297123 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 68CA2EB64D9 for ; Thu, 29 Jun 2023 15:55:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 071F88E0002; Thu, 29 Jun 2023 11:55:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F3D198E0001; Thu, 29 Jun 2023 11:55:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB6DC8E0002; Thu, 29 Jun 2023 11:55:29 -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 C563C8E0001 for ; Thu, 29 Jun 2023 11:55:29 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 80E281603B5 for ; Thu, 29 Jun 2023 15:55:29 +0000 (UTC) X-FDA: 80956235178.05.B173362 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf21.hostedemail.com (Postfix) with ESMTP id C230F1C0011 for ; Thu, 29 Jun 2023 15:55:27 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UaOvH6QW; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.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=1688054127; 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=TOAbgctNJNzSTZB1BB4d4WqHvbP5DttnG4JuN21nRvU=; b=JJ2EBTl/RPP3UWvRKyGO/fEYph+PsIMDv+0iwnRm7IrdPEd+PU9BGpWpmknITl7daRaco/ aWzxDuNKaTM+VWYtikJfE2UcNJIG+ZznFl34VtiYY2WRZVuaOFmmjxPLR93gNvKdacVE+q hmMhb2TL9TNMnLBbTdGeGWEStXlLxbs= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UaOvH6QW; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.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=1688054127; a=rsa-sha256; cv=none; b=OpgMEEM1vn3r4FTu3PjIKkkQ4STwuKETlkFsCxGut48rBgqSU0v9b5XiVZNo+KnqgdpFMF SRShNISi7JSj//PG5Q6/Qf1X8kL12srydv4LwZ3XXOrx/GpUUDBSveLUWJIVGd/iVyNUVW L+ZS7t3HfqRPcnzxDbee+/hol8AKxV4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688054127; 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=TOAbgctNJNzSTZB1BB4d4WqHvbP5DttnG4JuN21nRvU=; b=UaOvH6QW9s+npsw3c1RxUrv4d/6X2Wf32TUuPPGY0R6JGIYzI4KqUcWtc3559l04wMe+di 4XQsRiGmto9Op+WeM1CnUrRyPssTHrQqLGXd/p8hV6Cc1mh7WrisvP9zaC+LSpE5z2Q2Aj yR6YNcBMKoTz2SbkOhi1MFVFLPuBT6k= 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-158--w3bQ03qP3q32efbcBKCww-1; Thu, 29 Jun 2023 11:55:21 -0400 X-MC-Unique: -w3bQ03qP3q32efbcBKCww-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 9792B1C06ED8; Thu, 29 Jun 2023 15:54:45 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 398D84CD0C2; Thu, 29 Jun 2023 15:54:44 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , Matthew Wilcox , Dave Chinner , Matt Whitlock , Linus Torvalds , Jens Axboe , linux-fsdevel@kvack.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Christoph Hellwig , linux-fsdevel@vger.kernel.org Subject: [RFC PATCH 4/4] splice: Record some statistics Date: Thu, 29 Jun 2023 16:54:33 +0100 Message-ID: <20230629155433.4170837-5-dhowells@redhat.com> In-Reply-To: <20230629155433.4170837-1-dhowells@redhat.com> References: <20230629155433.4170837-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspamd-Queue-Id: C230F1C0011 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: rj1jstyqcmf6pngsahe7dzepbrwk6bp4 X-HE-Tag: 1688054127-678648 X-HE-Meta: U2FsdGVkX18mwigFmR5EawVJBuphiI2PKX40cTBsgWFJVXmhn//T8mumC5uYO5VC8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z/gyvnMdyWvJiXG4Kv4GpK210BEsbIJG9FHZGIgVGEH5OoncZE7AY3WtU3O8luGYLZEjqetMlKCY8+VPR4avkwCb0bTVQWouTF0tnBOcBpwXbO3gjZ5lN+zgVB2EczDBiBPSm7vfXbiOgOyhRMNBXA4g7Gy/4/MWKV9MQPM27BjLfj5VR1eSJ5oWTKlWh5k0oAqfoG4Qk6u 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: Add a proc file to export some statistics for debugging purposes. Signed-off-by: David Howells cc: Matthew Wilcox cc: Dave Chinner cc: Christoph Hellwig cc: Jens Axboe cc: linux-fsdevel@vger.kernel.org --- fs/splice.c | 28 ++++++++++++++++++++++++++++ include/linux/splice.h | 3 +++ mm/filemap.c | 6 +++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/fs/splice.c b/fs/splice.c index 2b1f109a7d4f..831973ea6b3f 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -36,10 +36,15 @@ #include #include #include +#include #include "../mm/internal.h" #include "internal.h" +atomic_t splice_stat_filemap_copied, splice_stat_filemap_moved; +static atomic_t splice_stat_directly_copied; +static atomic_t vmsplice_stat_copied, vmsplice_stat_stole; + /* * Splice doesn't support FMODE_NOWAIT. Since pipes may set this flag to * indicate they support non-blocking reads or writes, we must clear it @@ -276,6 +281,7 @@ ssize_t copy_splice_read(struct file *in, loff_t *ppos, remain -= chunk; } + atomic_add(keep, &splice_stat_directly_copied); kfree(bv); return ret; } @@ -1299,6 +1305,7 @@ static int splice_try_to_steal_page(struct pipe_inode_info *pipe, unmap_mapping_folio(folio); if (remove_mapping(folio->mapping, folio)) { folio_clear_mappedtodisk(folio); + atomic_inc(&vmsplice_stat_stole); flags |= PIPE_BUF_FLAG_LRU; goto add_to_pipe; } @@ -1316,6 +1323,7 @@ static int splice_try_to_steal_page(struct pipe_inode_info *pipe, folio_put(folio); folio = copy; offset = 0; + atomic_inc(&vmsplice_stat_copied); add_to_pipe: page = folio_page(folio, offset / PAGE_SIZE); @@ -1905,3 +1913,23 @@ SYSCALL_DEFINE4(tee, int, fdin, int, fdout, size_t, len, unsigned int, flags) return error; } + +static int splice_stats_show(struct seq_file *m, void *data) +{ + seq_printf(m, "filemap: copied=%u moved=%u\n", + atomic_read(&splice_stat_filemap_copied), + atomic_read(&splice_stat_filemap_moved)); + seq_printf(m, "direct : copied=%u\n", + atomic_read(&splice_stat_directly_copied)); + seq_printf(m, "vmsplice: copied=%u stole=%u\n", + atomic_read(&vmsplice_stat_copied), + atomic_read(&vmsplice_stat_stole)); + return 0; +} + +static int splice_stats_init(void) +{ + proc_create_single("fs/splice", S_IFREG | 0444, NULL, splice_stats_show); + return 0; +} +late_initcall(splice_stats_init); diff --git a/include/linux/splice.h b/include/linux/splice.h index 3c5abbd49ff2..4f04dc338010 100644 --- a/include/linux/splice.h +++ b/include/linux/splice.h @@ -98,4 +98,7 @@ extern int splice_grow_spd(const struct pipe_inode_info *, struct splice_pipe_de extern void splice_shrink_spd(struct splice_pipe_desc *); extern const struct pipe_buf_operations default_pipe_buf_ops; + +extern atomic_t splice_stat_filemap_copied, splice_stat_filemap_moved; + #endif diff --git a/mm/filemap.c b/mm/filemap.c index dd144b0dab69..38d38cc826fa 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2872,7 +2872,8 @@ ssize_t splice_folio_into_pipe(struct pipe_inode_info *pipe, struct address_space *mapping; struct folio *copy = NULL; struct page *page; - unsigned int flags = 0; + unsigned int flags = 0, count = 0; + atomic_t *stat = &splice_stat_filemap_copied; ssize_t ret; size_t spliced = 0, offset = offset_in_folio(folio, fpos); @@ -2902,6 +2903,7 @@ ssize_t splice_folio_into_pipe(struct pipe_inode_info *pipe, /* If we succeed in removing the mapping, set LRU flag and add it. */ if (remove_mapping(mapping, folio)) { folio_unlock(folio); + stat = &splice_stat_filemap_moved; flags = PIPE_BUF_FLAG_LRU; goto add_to_pipe; } @@ -2940,8 +2942,10 @@ ssize_t splice_folio_into_pipe(struct pipe_inode_info *pipe, page++; spliced += part; offset = 0; + count++; } + atomic_add(count, stat); if (copy) folio_put(copy); return spliced;