On Thu, Aug 17, 2023 at 02:13:17PM +0900, Naohiro Aota wrote: > Currently, we use "ls ... | sort -R | head -n1" to choose a removing > victim. It sorts the files with "ls", sort it randomly and pick the first > line, which wastes the "ls" sort. > > Also, using "sort -R | head -n1" is inefficient. For example, in a > directory with 1000000 files, it takes more than 15 seconds to pick a file. > > $ time bash -c "ls -U | sort -R | head -n 1 >/dev/null" > bash -c "ls -U | sort -R | head -n 1 >/dev/null" 15.38s user 0.14s system 99% cpu 15.536 total > > $ time bash -c "ls -U | shuf -n 1 >/dev/null" > bash -c "ls -U | shuf -n 1 >/dev/null" 0.30s user 0.12s system 138% cpu 0.306 total > > So, just use "ls -U" and "shuf -n 1" to choose a victim. > > Signed-off-by: Naohiro Aota <naohiro.aota@xxxxxxx> Reviewed-by: Josef Bacik <josef@xxxxxxxxxxxxxx> Thanks, Josef