如何输出文件名义大小中实际填充了多少数据?就像vmtouch
显示当前内存中有多少文件......
我希望工作流程是这样的:
$ fallocate -l 1000000 data
$ measure_sparseness data
100%
$ fallocate -p -o 250000 -l 500000 data
$ measure_sparseness
50%
解决方法:使用du -bsh
和du -sh
并比较它们。
答案1
find
具有%S
格式说明符,甚至被称为“稀疏性”
%S File's sparseness. This is calculated as (BLOCKSIZE*st_blocks / st_size). The exact value you will get for an ordinary file of a certain length is system-dependent. However, normally sparse files will have values less than 1.0, and files which use indirect blocks may have a value which is greater than 1.0. The value used for BLOCKSIZE is system-dependent, but is usually 512 bytes. If the file size is zero, the value printed is undefined. On systems which lack support for st_blocks, a file's sparseness is assumed to be 1.0.
$ fallocate -l 1000000 data
$ find data -printf '%S\n'
1.00352
$ fallocate -p -o 250000 -l 500000 data
$ find data -printf '%S\n'
0.507904
答案2
如果您find
没有该选项,自 70 年代以来在 UNIX 上有效的方法是:
ls -ls file
这将打印实际使用的块数和曾经写入的最高字节。由此您可以轻松计算出实际有多少块尚未分配。