rm -r is expected to be slow as its recursive. A depth first traversal has to be made on the directory structure.
Now how did you create 10 million files ? did u use some script which loops on some order ? 1.txt,2.txt,3.txt... if yes then those files may too be allocated on same order in contigous blocks in hdd.so deleting on same order will be faster.
"ls -f" will enable -aU which lists in directory order which is again recursive.
In principle, I don't see why strict ring-buffer writes would pose any challenge regarding fragmentation. It seems like it would be straightforward. The quote sounds to me like it is based on advice from more general write workloads. But looking at the linked SO question I see you have a real problem...
Since you are concerned about fragmentation, you should consider how to measure it! e4defrag
exists. It has only two options. -c
only shows the current state and does not defrag. -v
shows per-file statistics. All combinations of options are valid (including no options). Although it does not provide any explicit method to limit the performance impact on a running system, e4defrag
supports being run on individual files, so you can rate-limit it yourself.
(XFS also has a defrag tool, though I haven't used it.)
e2freefrag
can show free space fragmentation. If you use the CFQ IO scheduler, then you can run it with a reduced IO priority using ionice
.
The quote guesses wrong, the reply by Stephen Kitt is correct. ext4 does not perform any automatic defragmentation. It does not try to "shuffle around" data which has already been written.
Discarding this strange misconception leaves no reason to suggest "ext2/ext3". Apart from anything else, the ext3 code does not exist in current kernels. The ext4 code is used to mount ext3. ext3 is a subset of ext4. In particular when you are creating relatively large files, it just seems silly not to use extents, and those are an ext4-specific feature.
I believe "hanging" is more often associated with the journal. See e.g. comments from (the in-progress filesystem) bcachefs -
Tail latency has been the bane of ext4 users for many years - dependencies in the journalling code and elsewhere can lead to 30+ second latencies on simple operations (e.g. unlinks) on multithreaded workloads. No one seems to know how to fix them.
In bcachefs, the only reason a thread blocks on IO is because it explicitly asked to (an uncached read or an fsync operation), or resource exhaustion - full stop. Locks that would block foreground operations are never held while doing IO. While bcachefs isn't a realtime filesystem today (it lacks e.g. realtime scheduling for IO), it very conceivably could be one day.
Don't ask me to interpret the extent to which using XFS can avoid the above problem. I don't know. But if you were considering testing an alternative filesystem setup, XFS is the first thing I would try.
I'm struggling to find much information about the effects of disabling journalling on ext4. At least it doesn't seem to be one of the common options considered when tuning performance.
I'm not sure why you're using sys_sync(). It's usually better avoided (see e.g. here). I'm not sure that really explains your problem, but it seems an unfortunate thing to come across when trying to narrow this down.
Best Answer
When you run the
find
command like you posted, it will do arm
for each file that it finds. This isn't a good way to do it, in terms of performance.For improve this task, you can use the
-exec
option in find for process the output to arm
command:It's very important the use of the
+
termination instead the alternate\;
. With+
, find will only make arm
command for the maximum number of files it can process on a simple execution. With the\;
termination,find
will do arm
command for each file, so you would have the same problem.For a better performance, you can join it to the
ionice
command like you mentioned. If you don't notice that it improves the system performance, most possible is that it is consuming other resources more than I/O, like CPU. For this, you can userenice
command to decrease the priority in CPU usage of the process.I would use the following:
Now, in another shell, you need to find the PID of the find command:
ps -ef | grep find
And finally run the renice command:
renice +19 -p <PID_find_command>