Quoting Qu Wenruo <quwenruo.bt...@gmx.com>:
- Introduce different levels for defrag
Allow btrfs to do some calculation and space usage policy to
determine if it's a good idea to defrag some shared extents.
E.g. my extreme case, unshare the extent would make it possible to
defrag the other subvolume to free a huge amount of space.
A compromise, let user to choose if they want to sacrifice some space.
Ok, I noticed a few thing comming up frequently in this discussion, so
I thing we should clear up a meaning of a few words before continuing.
Because same words are used with two different meanings.
First, the term "defrag" can has 2 different meanings in filesystems
with shared extents
A) "plain defrag" or "unsharing-defrag"
a file is unshare-defragmented if ALL of the following are met:
1) all extents are written on disk in neighbouring sectors in the
ascending order
2) none of its extents are shared
3) it doesn't have too many small extents
B) "sharing-defrag"
a file is share-defragmented if ALL of the following are met:
1) all extents are written on disk in neighbouring sectors in the
ascending order
2) all pairs of *adjanced* extents meet ONE of the following criteria
2.1) both extents are sufficiently large
2.2) the two extents have mismatching sharing groups (they are
shared by different sets of files)
So, it might be, in some cases, a good idea to "plain defrag" some
files like databases. But, this is a completely separate concern and
completely different feature. So "plain defrag" is very different
thing from "sharing-defrag"
Why there needs to be a "sharing defrag"
- it is a defrag operation that can be run without concern
- it can be run every day
- eventually, it needs to be run to prevent degradation of performance
- all other filesystems have this kind of defrag
- the user suffers no permanent 'penalties' (like loss of free space)
The "unsharing-defrag" is something completely different, another
feature for another discussion. I don't want to discuss it, because
everything will just get confusing.
So, please, lets keep "unsharing-defrag" out of this discussion,
because it has nothing to do with the thing I'm talking about.
So the "sharing defrag" is what I mean by saying defrag. That's the
everyday defrag.