* [PATCH] Btrfs: fix recursive auto-defrag
@ 2011-10-06 3:39 Li Zefan
2011-10-06 14:14 ` David Sterba
2011-10-06 15:53 ` Chris Mason
0 siblings, 2 replies; 3+ messages in thread
From: Li Zefan @ 2011-10-06 3:39 UTC (permalink / raw)
To: linux-btrfs@vger.kernel.org
Follow those steps:
# mount -o autodefrag /dev/sda7 /mnt
# dd if=/dev/urandom of=/mnt/tmp bs=200K count=1
# sync
# dd if=/dev/urandom of=/mnt/tmp bs=8K count=1 conv=notrunc
and then it'll go into a loop: writeback -> defrag -> writeback ...
It's because writeback writes [8K, 200K] and then writes [0, 8K].
I tried to make writeback know if the pages are dirtied by defrag,
but the patch was a bit intrusive. Here I simply set writeback_index
when we defrag a file.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
fs/btrfs/ioctl.c | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 970977a..7a10f94 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1047,6 +1047,13 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
if (!max_to_defrag)
max_to_defrag = last_index - 1;
+ /*
+ * make writeback starts from i, so the defrag range can be
+ * written sequentially.
+ */
+ if (i < inode->i_mapping->writeback_index)
+ inode->i_mapping->writeback_index = i;
+
while (i <= last_index && defrag_count < max_to_defrag) {
/*
* make sure we stop running if someone unmounts
-- 1.7.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Btrfs: fix recursive auto-defrag
2011-10-06 3:39 [PATCH] Btrfs: fix recursive auto-defrag Li Zefan
@ 2011-10-06 14:14 ` David Sterba
2011-10-06 15:53 ` Chris Mason
1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2011-10-06 14:14 UTC (permalink / raw)
To: Li Zefan; +Cc: linux-btrfs@vger.kernel.org
On Thu, Oct 06, 2011 at 11:39:54AM +0800, Li Zefan wrote:
> Follow those steps:
>
> # mount -o autodefrag /dev/sda7 /mnt
> # dd if=/dev/urandom of=/mnt/tmp bs=200K count=1
> # sync
> # dd if=/dev/urandom of=/mnt/tmp bs=8K count=1 conv=notrunc
>
> and then it'll go into a loop: writeback -> defrag -> writeback ...
>
> It's because writeback writes [8K, 200K] and then writes [0, 8K].
>
> I tried to make writeback know if the pages are dirtied by defrag,
> but the patch was a bit intrusive. Here I simply set writeback_index
> when we defrag a file.
>
> Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Tested-by: David Sterba <dsterba@suse.cz>
> ---
> fs/btrfs/ioctl.c | 7 +++++++
> 1 files changed, 7 insertions(+), 0 deletions(-)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 970977a..7a10f94 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -1047,6 +1047,13 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
> if (!max_to_defrag)
> max_to_defrag = last_index - 1;
>
> + /*
> + * make writeback starts from i, so the defrag range can be
> + * written sequentially.
> + */
> + if (i < inode->i_mapping->writeback_index)
> + inode->i_mapping->writeback_index = i;
> +
> while (i <= last_index && defrag_count < max_to_defrag) {
> /*
> * make sure we stop running if someone unmounts
> -- 1.7.3.1
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Btrfs: fix recursive auto-defrag
2011-10-06 3:39 [PATCH] Btrfs: fix recursive auto-defrag Li Zefan
2011-10-06 14:14 ` David Sterba
@ 2011-10-06 15:53 ` Chris Mason
1 sibling, 0 replies; 3+ messages in thread
From: Chris Mason @ 2011-10-06 15:53 UTC (permalink / raw)
To: Li Zefan; +Cc: linux-btrfs@vger.kernel.org
On Thu, Oct 06, 2011 at 11:39:54AM +0800, Li Zefan wrote:
> Follow those steps:
>
> # mount -o autodefrag /dev/sda7 /mnt
> # dd if=/dev/urandom of=/mnt/tmp bs=200K count=1
> # sync
> # dd if=/dev/urandom of=/mnt/tmp bs=8K count=1 conv=notrunc
>
> and then it'll go into a loop: writeback -> defrag -> writeback ...
>
> It's because writeback writes [8K, 200K] and then writes [0, 8K].
>
> I tried to make writeback know if the pages are dirtied by defrag,
> but the patch was a bit intrusive. Here I simply set writeback_index
> when we defrag a file.
Really nice and small fix. I'll definitely send this for 3.1
-chris
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-10-06 15:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-06 3:39 [PATCH] Btrfs: fix recursive auto-defrag Li Zefan
2011-10-06 14:14 ` David Sterba
2011-10-06 15:53 ` Chris Mason
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).