All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH RFC] btrfs: sysfs: introduce <uuid>/debug/cleaner_trigger
Date: Fri, 21 Jan 2022 15:13:28 +0800	[thread overview]
Message-ID: <20220121071328.47060-1-wqu@suse.com> (raw)

Since there is no existing quick way to trigger cleaner to do
cleanup/autodefrag, here we introduce a new sysfs file at:

  /sys/fs/btrfs/<uuid>/debug/cleaner_trigger

Any write into that file will wake up cleaner_kthread.

This allows us to have a fast and relieable way to trigger cleaner to
test autodefrag.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
There seems to be no way to initiate the cleaner thread to run.

With this patch and previous io_accounting patch, I can now trigger an
autodefrag run and compare io_accounting to get how many bytes are
re-written (aka, defragged).

Although so far I still can't craft a minimal script to trigger more IO
than expected.
---
 fs/btrfs/sysfs.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index dfdef93bdeab..a20e6bd82d8d 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -577,6 +577,17 @@ static ssize_t btrfs_discard_max_discard_size_store(struct kobject *kobj,
 BTRFS_ATTR_RW(discard, max_discard_size, btrfs_discard_max_discard_size_show,
 	      btrfs_discard_max_discard_size_store);
 
+static ssize_t wake_up_cleaner(struct kobject *kobj, struct kobj_attribute *a,
+			       const char *buf, size_t count)
+{
+	struct btrfs_fs_info *fs_info = to_fs_info(kobj->parent);
+
+	wake_up_process(fs_info->cleaner_kthread);
+	return count;
+}
+
+BTRFS_ATTR_RW(debug_mount, cleaner_trigger, NULL, wake_up_cleaner);
+
 /*
  * Per-filesystem debugging of discard (when mounted with discard=async).
  *
@@ -600,6 +611,7 @@ static const struct attribute *discard_debug_attrs[] = {
  * Path: /sys/fs/btrfs/UUID/debug/
  */
 static const struct attribute *btrfs_debug_mount_attrs[] = {
+	BTRFS_ATTR_PTR(debug_mount, cleaner_trigger),
 	NULL,
 };
 
-- 
2.34.1


                 reply	other threads:[~2022-01-21  7:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220121071328.47060-1-wqu@suse.com \
    --to=wqu@suse.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.