From: Amir Goldstein <amir73il@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
linux-unionfs@vger.kernel.org, containers@lists.linux.dev,
linux-fsdevel@vger.kernel.org
Subject: [PATCH v2 1/6] fs: add iostats counters to struct mount
Date: Mon, 28 Feb 2022 13:39:05 +0200 [thread overview]
Message-ID: <20220228113910.1727819-2-amir73il@gmail.com> (raw)
In-Reply-To: <20220228113910.1727819-1-amir73il@gmail.com>
With config MOUNT_IO_STATS, add an array of counters to struct mnt_pcp
that will be used to collect I/O statistics.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
fs/Kconfig | 9 +++++++++
fs/mount.h | 32 ++++++++++++++++++++++++++++++++
fs/namespace.c | 17 +++++++++++++++++
3 files changed, 58 insertions(+)
diff --git a/fs/Kconfig b/fs/Kconfig
index 6c7dc1387beb..60baa861b3e4 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -15,6 +15,15 @@ config VALIDATE_FS_PARSER
Enable this to perform validation of the parameter description for a
filesystem when it is registered.
+config FS_MOUNT_STATS
+ bool "Enable per-mount I/O statistics"
+ depends on SMP
+ help
+ Enable this to allow collecting per-mount I/O statistics and display
+ them in /proc/<pid>/mountstats.
+
+ Say N if unsure.
+
config FS_IOMAP
bool
diff --git a/fs/mount.h b/fs/mount.h
index 0b6e08cf8afb..b22169b4d24c 100644
--- a/fs/mount.h
+++ b/fs/mount.h
@@ -24,9 +24,25 @@ struct mnt_namespace {
unsigned int pending_mounts;
} __randomize_layout;
+/* Similar to task_io_accounting members */
+enum {
+ MNTIOS_CHARS_RD, /* bytes read via syscalls */
+ MNTIOS_CHARS_WR, /* bytes written via syscalls */
+ MNTIOS_SYSCALLS_RD, /* # of read syscalls */
+ MNTIOS_SYSCALLS_WR, /* # of write syscalls */
+ _MNTIOS_COUNTERS_NUM
+};
+
+struct mnt_iostats {
+ s64 counter[_MNTIOS_COUNTERS_NUM];
+};
+
struct mnt_pcp {
int mnt_count;
int mnt_writers;
+#ifdef CONFIG_FS_MOUNT_STATS
+ struct mnt_iostats iostats;
+#endif
};
struct mountpoint {
@@ -148,3 +164,19 @@ static inline bool is_anon_ns(struct mnt_namespace *ns)
}
extern void mnt_cursor_del(struct mnt_namespace *ns, struct mount *cursor);
+
+static inline void mnt_iostats_counter_inc(struct mount *mnt, int id)
+{
+#ifdef CONFIG_FS_MOUNT_STATS
+ this_cpu_inc(mnt->mnt_pcp->iostats.counter[id]);
+#endif
+}
+
+static inline void mnt_iostats_counter_add(struct mount *mnt, int id, s64 n)
+{
+#ifdef CONFIG_FS_MOUNT_STATS
+ this_cpu_add(mnt->mnt_pcp->iostats.counter[id], n);
+#endif
+}
+
+extern s64 mnt_iostats_counter_read(struct mount *mnt, int id);
diff --git a/fs/namespace.c b/fs/namespace.c
index de6fae84f1a1..3fb8f11a42a1 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -306,6 +306,23 @@ static unsigned int mnt_get_writers(struct mount *mnt)
#endif
}
+s64 mnt_iostats_counter_read(struct mount *mnt, int id)
+{
+ s64 count = 0;
+#ifdef CONFIG_FS_MOUNT_STATS
+ /*
+ * MOUNT_STATS depends on SMP.
+ * Should be trivial to implement for !SMP if anyone cares...
+ */
+ int cpu;
+
+ for_each_possible_cpu(cpu) {
+ count += per_cpu_ptr(mnt->mnt_pcp, cpu)->iostats.counter[id];
+ }
+#endif
+ return count;
+}
+
static int mnt_is_readonly(struct vfsmount *mnt)
{
if (mnt->mnt_sb->s_readonly_remount)
--
2.25.1
next prev parent reply other threads:[~2022-02-28 11:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-28 11:39 [PATCH v2 0/6] Generic per-mount io stats Amir Goldstein
2022-02-28 11:39 ` Amir Goldstein [this message]
2022-02-28 11:39 ` [PATCH v2 2/6] fs: tidy up fs_flags definitions Amir Goldstein
2022-02-28 11:39 ` [PATCH v2 3/6] fs: collect per-mount io stats Amir Goldstein
2022-02-28 11:39 ` [PATCH v2 4/6] fs: report " Amir Goldstein
2022-02-28 15:06 ` Miklos Szeredi
2022-02-28 16:18 ` Amir Goldstein
2022-02-28 16:31 ` Miklos Szeredi
2022-02-28 17:06 ` Amir Goldstein
2022-02-28 21:11 ` Dave Chinner
2022-02-28 21:57 ` Amir Goldstein
2022-03-01 9:46 ` Dave Chinner
2022-03-01 10:56 ` Amir Goldstein
2022-02-28 11:39 ` [PATCH v2 5/6] ovl: opt-in for " Amir Goldstein
2022-02-28 11:39 ` [PATCH v2 6/6] fuse: " Amir Goldstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220228113910.1727819-2-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=containers@lists.linux.dev \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).