All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] btrfs: defrag: rework to support sector perfect defrag
@ 2021-05-28  2:28 Qu Wenruo
  2021-05-28  2:28 ` [PATCH 1/7] btrfs: defrag: pass file_ra_state instead of file for btrfs_defrag_file() Qu Wenruo
                   ` (6 more replies)
  0 siblings, 7 replies; 14+ messages in thread
From: Qu Wenruo @ 2021-05-28  2:28 UTC (permalink / raw)
  To: linux-btrfs

This branch is based on subpage RW branch, as the 4th patch needs to use
subpage helpers to support sector perfect defrag for subpage.

But the core rework should be applied for all cases.

[BACKGROUND]
In subpage rw branch, although we implemented defrag support for
subpage, but it's still doing defrag in full page size.

This means, if we want to defrag a 64K page which contains one 4K sector
and 60K holes, we will re-write the full page back to disk, causing
extra space usage.

This is far from ideal, and will cause generic/018 to fail due to above
reason.

[SOLUTION]
To defrag a file range, what we do is pretty much like buffered write,
except we don't really write any new data to page cache, but just mark
the range dirty.

Then let later writeback to merge the range into a larger extent.

But current defrag code is working on per-page basis, not per-sector,
thus we have to refactor it a little to make it to work properly for
subpage.

This patch will separate the code into 3 layers:
Layer 0:	btrfs_defrag_file()
		The defrag entrace
		Just do proper inode lock and split the file into
		page aligned 256K clusters to defrag

Layer 1:	defrag_one_cluster()
		Will collect the targets file extents, and pass each
		continuous target to defrag_one_range()

Layer 2:	defrag_one_range()
		The real work.
		Do almost all the same work as btrfs_buffered_write(),
		except we don't copy any content into page cache, but
		just mark the range dirty, defrag and delalloc.

[BEHAVIOR CHANGE]
In the refactor, there is one behavior change:

- It's no longer ensured we won't defrag holes
  This is caused by the timing when targets are collected.
  At that time, we don't have page/extent/inode locked, thus
  the result got can be volatile.

  But considering this greatly simplify the workflow, and sane users
  should never run defrag on files under heavy IO, I think it's worthy
  to change the behavior a little for a more readable code.

[PATCH STRUTURE]
Patch 01~02:	Small independent refactor to improve readability
Patch 03~06:	Implement the more readable and subpage friendly defrag
Patch 07:	Cleanup of old infrastruture

Qu Wenruo (7):
  btrfs: defrag: pass file_ra_state instead of file for
    btrfs_defrag_file()
  btrfs: defrag: extract the page preparation code into one helper
  btrfs: defrag: introduce a new helper to collect target file extents
  btrfs: defrag: introduce a helper to defrag a continuous range
  btrfs: defrag: introduce a new helper to defrag one cluster
  btrfs: defrag: use defrag_one_cluster() to implement
    btrfs_defrag_file()
  btrfs: defrag: remove the old infrastructure

 fs/btrfs/ctree.h |   4 +-
 fs/btrfs/ioctl.c | 815 ++++++++++++++++++++---------------------------
 2 files changed, 342 insertions(+), 477 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-05-28 10:39 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-28  2:28 [PATCH 0/7] btrfs: defrag: rework to support sector perfect defrag Qu Wenruo
2021-05-28  2:28 ` [PATCH 1/7] btrfs: defrag: pass file_ra_state instead of file for btrfs_defrag_file() Qu Wenruo
2021-05-28  9:46   ` Johannes Thumshirn
2021-05-28  2:28 ` [PATCH 2/7] btrfs: defrag: extract the page preparation code into one helper Qu Wenruo
2021-05-28 10:23   ` Johannes Thumshirn
2021-05-28 10:36     ` Qu Wenruo
2021-05-28 10:38       ` Johannes Thumshirn
2021-05-28  2:28 ` [PATCH 3/7] btrfs: defrag: introduce a new helper to collect target file extents Qu Wenruo
2021-05-28  2:28 ` [PATCH 4/7] btrfs: defrag: introduce a helper to defrag a continuous range Qu Wenruo
2021-05-28  9:07   ` Filipe Manana
2021-05-28 10:27     ` Qu Wenruo
2021-05-28  2:28 ` [PATCH 5/7] btrfs: defrag: introduce a new helper to defrag one cluster Qu Wenruo
2021-05-28  2:28 ` [PATCH 6/7] btrfs: defrag: use defrag_one_cluster() to implement btrfs_defrag_file() Qu Wenruo
2021-05-28  2:28 ` [PATCH 7/7] btrfs: defrag: remove the old infrastructure Qu Wenruo

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.