Package: e2fsprogs
Version: 1.43.4-2
Severity: minor

I have a web cache which creates and destroys new files on a regular basis.

I tried defragmenting the cache folder recently and got this result:
----
# ionice -c3 nice -n 20 e4defrag -v /cache
...
[786179/779728]/cache/94/31c16d90eb4dc4d0df8df8f3b1be7594:      100%
extents: 1 -> 1   [ OK ]
[786180/779728]/cache/94/3cfbcc37f603bb9365d48f4264eace94:      100%
extents: 1 -> 1   [ OK ]

        Success:                        [ 785923/779728 ]
        Failure:                        [ 4294961101/779728 ]
        Total extents:                  2865002->2591929
        Fragmented percentage:           18%->17%

----

Curiously, the success count is higher than the theoretical total, while
the failure count is just below MAX_INT. The running count has also
exceeded its supposed maximum.

The issue appears to be that the code is doing:
printf("\n\tSuccess:\t\t\t[ %u/%u ]\n", succeed_cnt, total_count);
printf("\tFailure:\t\t\t[ %u/%u ]\n", total_count - succeed_cnt,
total_count);

This would be fine except that:
* total_count and succeed_cnt are both unsigned integers.
* total_count is incremented via an initial call to nftw64() using
calc_entry_counts()
* succeed_cnt is incremented by a _later_ call to nftw64() using
file_defrag().
* Defragmentation occurs on a live filesystem, not a snapshot.

If enough new files are created during the defragmentation process, more
may be successfully defragged in the second walk than are initially
counted. This might not have been noticed before because defrag is often
done on a complete, mostly-static disk with several expected failures.

Probably the success/failure printf()s should use defraged_file_count
(incremented at the start of file_defrag) rather than total_count. I'm more
ambivalent about the inconsistency in the running count - it could be
argued that it merely reflects the harsh reality.
-- 
Laurence "GreenReaper" Parry
http://www.greenreaper.co.uk/

Reply via email to