1 |
On Fri, Oct 22, 2021 at 7:36 AM Helmut Jarausch <jarausch@××××××.be> wrote: |
2 |
> |
3 |
> |
4 |
> There are more than 55,000 files on some <PREVBackUp> which is located |
5 |
> on a BTRFS file system. |
6 |
> Standard 'rm -rf' is really slow. |
7 |
> |
8 |
> Is there anything I can do about this? |
9 |
> |
10 |
|
11 |
I don't have any solid suggestions as I haven't used btrfs in a while. |
12 |
File deletion speed is something that is very filesystem specific, but |
13 |
on most it tends to be slow. |
14 |
|
15 |
An obvious solution would be garbage collection, which is something |
16 |
used by some filesystems but I'm not aware of any mainstream ones. |
17 |
You can sort-of get that behavior by renaming a directory before |
18 |
deleting it. Suppose you have a directory created by a build system |
19 |
and you want to do a new build. Deleting the directory takes a long |
20 |
time. So, first you rename it to something else (or move it someplace |
21 |
on the same filesystem which is fast), then you kick off your build |
22 |
which no longer sees the old directory, and then you can delete the |
23 |
old directory slowly at your leisure. Of course, as with all garbage |
24 |
collection, you need to have the spare space to hold the data while it |
25 |
gets cleaned up. |
26 |
|
27 |
I'm not sure if btffs is any faster at deleting snapshots/reflinks |
28 |
than hard links. I suspect it wouldn't be, but you could test that. |
29 |
Instead of populating a directory with hard links, create a snapshot |
30 |
of the directory tree, and then rsync over it/etc. The result looks |
31 |
the same but is COW copies. Again, I'm not sure that btrfs will be |
32 |
any faster at deleting reflinks than hard links though - they're both |
33 |
similar metadata operations. I see there is a patch in the works for |
34 |
rsync that uses reflinks instead of hard links to do it all in one |
35 |
command. That has a lot of benefits, but again I'm not sure if it |
36 |
will help with deletion. |
37 |
|
38 |
You could also explore other filesystems that may or may not have |
39 |
faster deletion, or look to see if there is any way to optimize it on |
40 |
btrfs. |
41 |
|
42 |
If you can spare the space, the option of moving the directory to make |
43 |
it look like it was deleted will work on basically any filesystem. If |
44 |
you want to further automate it you could move it to a tmp directory |
45 |
on the same filesystem and have tmpreaper do your garbage collection. |
46 |
Consider using ionice to run it at a lower priority, but I'm not sure |
47 |
how much impact that has on metadata operations like deletion. |
48 |
|
49 |
-- |
50 |
Rich |