linux删除磁盘后刷新,linux – 短暂的文件是否刷新到磁盘?
我的程序創(chuàng)建了許多小的短期文件.它們通常在創(chuàng)建后的一秒內(nèi)被刪除.這些文件位于由真實(shí)硬盤支持的ext4文件系統(tǒng)中.我知道Linux會(huì)定期將(pdflush)臟頁(yè)刷新到磁盤.由于我的文件是短暫的,很可能它們不是由pdflush緩存的.我的問(wèn)題是,我的程序是否會(huì)導(dǎo)致大量磁盤寫入?我擔(dān)心的是我硬盤的生命.
由于文件很小,我們假設(shè)它們的大小總和小于dirty_bytes和dirty_background_bytes.
Ext4打開了默認(rèn)日志,即元數(shù)據(jù)日志.我還想知道元數(shù)據(jù)或數(shù)據(jù)是否寫入磁盤.
解決方法:
使用ext4的簡(jiǎn)單實(shí)驗(yàn):
創(chuàng)建一個(gè)100MB的圖像……
# dd if=/dev/zero of=image bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.0533049 s, 2.0 GB/s
使它成為一個(gè)循環(huán)設(shè)備……
# losetup -f --show image
/dev/loop0
制作文件系統(tǒng)并掛載……
# mkfs.ext4 /dev/loop0
# mount /dev/loop0 /mnt/tmp
使用短期文件進(jìn)行某種運(yùn)行. (將此更改為您喜歡的任何方法.)
for ((x=0; x<1000; x++))
do
(echo short-lived-content-$x > /mnt/tmp/short-lived-file-$x
sleep 1
rm /mnt/tmp/short-lived-file-$x ) &
done
Umount,sync,unloop.
# umount /mnt/tmp
# sync
# losetup -d /dev/loop0
檢查圖像內(nèi)容.
# strings image | grep short-lived-file | tail -n 3
short-lived-file-266
short-lived-file-895
short-lived-file-909
# strings image | grep short-lived-content | tail -n 3
在我的例子中,它列出了所有文件名,但沒有列出文件內(nèi)容.所以只寫了內(nèi)容.
標(biāo)簽:disk,linux,ext4
來(lái)源: https://codeday.me/bug/20190809/1630806.html
總結(jié)
以上是生活随笔為你收集整理的linux删除磁盘后刷新,linux – 短暂的文件是否刷新到磁盘?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java访问其它服务器,一个Java W
- 下一篇: c++如何显示图片_Vue+larave