From: Ioannis Angelakopoulos <iangelak@fb.com>
To: <linux-btrfs@vger.kernel.org>, <kernel-team@fb.com>
Subject: [PATCH 2/2] btrfs: Expose the BTRFS commit stats through sysfs
Date: Fri, 10 Jun 2022 13:54:09 -0700 [thread overview]
Message-ID: <20220610205406.301397-3-iangelak@fb.com> (raw)
In-Reply-To: <20220610205406.301397-1-iangelak@fb.com>
Create a new sysfs entry named "commit_stats" for each mounted BTRFS
filesystem. The entry exposes: 1) The number of commits so far, 2) The
duration of the last commit in ms, 3) The maximum commit duration seen
so far in ms and 4) The total duration for all commits so far in ms.
The function "btrfs_commit_stats_show" is responsible for exposing the
stats to user space.
The function "btrfs_commit_stats_store" is responsible for resetting the
above values to zero.
Signed-off-by: Ioannis Angelakopoulos <iangelak@fb.com>
---
fs/btrfs/sysfs.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index b6cb5551050e..f68fc73006c0 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -991,6 +991,53 @@ static ssize_t btrfs_sectorsize_show(struct kobject *kobj,
BTRFS_ATTR(, sectorsize, btrfs_sectorsize_show);
+static ssize_t btrfs_commit_stats_show(struct kobject *kobj,
+ struct kobj_attribute *a, char *buf)
+{
+ struct btrfs_fs_info *fs_info = to_fs_info(kobj);
+
+ /*
+ * Expose the commits so far, the duration of the last commit, the
+ * maximum duration of a commit so far and the total duration of
+ * all the commits so far
+ */
+ return sysfs_emit(buf, "Commits: %llu, Last: %llu ms, Max: %llu ms, Total: %llu ms\n",
+ fs_info->commit_stats->commit_counter,
+ fs_info->commit_stats->last_commit_dur,
+ fs_info->commit_stats->max_commit_dur,
+ fs_info->commit_stats->total_commit_dur);
+}
+
+static ssize_t btrfs_commit_stats_store(struct kobject *kobj,
+ struct kobj_attribute *a,
+ const char *buf, size_t len)
+{
+ struct btrfs_fs_info *fs_info = to_fs_info(kobj);
+
+ if (!fs_info)
+ return -EPERM;
+
+ if (!capable(CAP_SYS_RESOURCE))
+ return -EPERM;
+
+ /*
+ * Just reset everything
+ * Also take the trans_lock to avoid race conditions with the udpates
+ * in btrfs_commit_transaction()
+ */
+ spin_lock(&fs_info->trans_lock);
+ fs_info->commit_stats->commit_counter = 0;
+ fs_info->commit_stats->last_commit_dur = 0;
+ fs_info->commit_stats->max_commit_dur = 0;
+ fs_info->commit_stats->total_commit_dur = 0;
+ spin_unlock(&fs_info->trans_lock);
+
+ return len;
+}
+
+BTRFS_ATTR_RW(, commit_stats, btrfs_commit_stats_show,
+ btrfs_commit_stats_store);
+
static ssize_t btrfs_clone_alignment_show(struct kobject *kobj,
struct kobj_attribute *a, char *buf)
{
@@ -1230,6 +1277,7 @@ static const struct attribute *btrfs_attrs[] = {
BTRFS_ATTR_PTR(, generation),
BTRFS_ATTR_PTR(, read_policy),
BTRFS_ATTR_PTR(, bg_reclaim_threshold),
+ BTRFS_ATTR_PTR(, commit_stats),
NULL,
};
--
2.30.2
next prev parent reply other threads:[~2022-06-10 20:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-10 20:54 [PATCH 0/2] btrfs: Expose BTRFS commit stats through sysfs Ioannis Angelakopoulos
2022-06-10 20:54 ` [PATCH 1/2] btrfs: Add the capability of getting commit stats in BTRFS Ioannis Angelakopoulos
2022-06-11 11:44 ` kernel test robot
2022-06-11 12:55 ` kernel test robot
2022-06-13 18:59 ` David Sterba
2022-06-13 21:05 ` Sweet Tea Dorminy
2022-06-14 14:15 ` David Sterba
2022-06-10 20:54 ` Ioannis Angelakopoulos [this message]
2022-06-13 19:14 ` [PATCH 2/2] btrfs: Expose the BTRFS commit stats through sysfs David Sterba
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=20220610205406.301397-3-iangelak@fb.com \
--to=iangelak@fb.com \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
/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