免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2334 | 回复: 3
打印 上一主题 下一主题

很奇怪的问题,df -h /var和du -hd0 /var的结果差别很大 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-07-25 12:07 |只看该作者 |倒序浏览
df -h
Filesystem     Size    Used   Avail Capacity  Mounted on
/dev/ad6s1a    248M     45M    183M    20%    /
devfs          1.0K    1.0K      0B   100%    /dev
/dev/ad6s1e    248M    3.9M    224M     2%    /tmp
/dev/ad6s1f    221G     68G    135G    34%    /usr
/dev/ad6s1d    248M    247M    -19M   109%    /var

du -hd0 /var
var
9.7M    /var

为什么/var的大小用df和du的结果不同呢?
top时发现snmpd进程的cpu使用率有点高,近8%,
于是把snmpd干掉,
df -h
Filesystem     Size    Used   Avail Capacity  Mounted on
/dev/ad6s1a    248M     45M    183M    20%    /
devfs          1.0K    1.0K      0B   100%    /dev
/dev/ad6s1e    248M    3.9M    224M     2%    /tmp
/dev/ad6s1f    221G     68G    135G    34%    /usr
/dev/ad6s1d    248M    9.7M    218M     4%    /var
就正常了,是什么原因呢?

论坛徽章:
0
2 [报告]
发表于 2007-07-25 22:16 |只看该作者

quite comon

sorry, my IME sucks.

du and df are different.
du calculates file by file, that means, it will scan every file in the specific directory. so it is slow, most of the time.
df calculates via a smarter way, by the blocks in the block_image_zone in a filesystem, so beside the space recorgnized by du, df will also count such situations in:
1. super blocks, various zones to record the fs informations.
2. blocks which are not full, if 3K of the 4K block is taken by a file, du counts 3K in, but 4K for df.
3. a unlinked file, but still hold by some processes, like yours, you know, it only release the blocks until related processes get quit.

So, du always show you a smaller disk usage than df. but i trust df, which is even faster.

论坛徽章:
0
3 [报告]
发表于 2007-07-26 09:35 |只看该作者
yeah,that's it,thanks.

论坛徽章:
0
4 [报告]
发表于 2007-07-26 19:58 |只看该作者
怎么收藏按钮没了,看来只好回帖做记号了,讲的很明白。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP