gpt4 book ai didi

linux - 写入文件非常快,覆盖文件需要更长的时间

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:41:12 25 4
gpt4 key购买 nike

我发现 Linux 上的 PHP 脚本存在一些性能问题 Fedora Core 11框,所以我正在运行一些命令来寻找瓶颈。我注意到的一件事是写文件非常快:

[root@localhost ~]# dd if=/dev/zero of=/root/myGfile bs=1024K count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 1.0817 s, 969 MB/s

但是覆盖它需要更长的时间;

[root@localhost ~]# dd if=/dev/zero of=/root/myGfile bs=1024K count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 23.0658 s, 45.5 MB/s

这是为什么呢? (我可以重复这些结果。)

最佳答案

第一次写入文件时,它会缓冲在系统内存中。

第二次写入文件时,文件被截断,由于某种原因导致所有脏页被写出到磁盘。是的,这看起来很愚蠢:为什么在文件刚刚被截断为零长度时写出文件数据?

您可以通过让第二个 dd 仅写入 4k 数据来证明这一点。它需要同样长的时间。

您还可以使用 conv=notrunc 强制 dd 不截断。

关于linux - 写入文件非常快,覆盖文件需要更长的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2183400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com