小文件未提交到磁盘一分钟以上 [英] Small file not committed to disk for over a minute

查看:175
本文介绍了小文件未提交到磁盘一分钟以上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌入式的Linux应用程序以相当慢的速率写入文件( 50 bytes / s左右)。该文件在硬盘驱动器上,XFS文件系统。该文件正在通过调用 write()而不是 fwrite()



如果我重新启动系统并检查文件,则会丢失一分钟的数据。我认为默认的Linux行为是同步磁盘缓存,每个 5s (我可以容忍缺少数据的5s ,这样就没有问题)。我应该检查一下,看看为什么它不能长时间同步? / proc / sys / vm / dirty_writeback_centisecs 500 。还有其他可以改变的东西我应该检查吗?它肯定是一个磁盘缓存问题 - 如果我 ls -l <​​/ code>该文件,大小是如预期的,并且在电源循环之后它比以前少。 p>

解决方案

嗯,我不知道5s是Linux中的默认。据我所知,延迟是文件系统依赖的,尽管也许我错了。我相信XFS上的缓存同步的最大延迟是(或至少在一段时间之前)30秒。对于一些较旧的文件系统(ext2和ext3我相信),这个数字是5秒,如果我正确地记得,它不适用于ext4。



总结如果你想超越缓存,我相信你将需要使用fsync,O_SYNC或O_DIRECT。或者在安装文件系统时应用sync选项,这应该在全球解决问题。


I have an embedded Linux app that writes to a file at a fairly slow rate (50 bytes/s or so). The file is on a hard drive, XFS filesystem. The file is being written to by calling write(), not fwrite().

If I power-cycle the system and check the file, over a minute's worth of data is missing. I thought the default Linux behaviour was to sync the disk cache every 5s (I can tolerate 5s worth of missing data so they'd be no problem with this). What should I be checking to see why it isn't getting synced for a long time? /proc/sys/vm/dirty_writeback_centisecs is 500. Are there other changeable things I should be checking? It definitely looks to be a disk cache issue - if i ls -l the file, the size is as expected, and after the power cycle it is less than before.

解决方案

Mmm, I'm not sure about the 5s as "default in Linux". As far as I know the delay is filesystem dependant, although maybe I'm mistaken. I believe the maximum delay for cache sync on XFS is (or at least was a while ago) 30 seconds. That figure of 5 seconds was true for some older filesystems (ext2 and ext3 I believe) and it doesn't hold true for ext4, if I recall correctly.

In conclusion, what is happening to you is the expected behaviour.

If you want to surpass the cache, I believe you will need to use fsync, O_SYNC or O_DIRECT. Or apply the 'sync' option when mounting the filesystem, which should solve the problem globally.

这篇关于小文件未提交到磁盘一分钟以上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆