通常在几秒钟后会刷新文件系统写缓冲区? [英] After how many seconds are file system write buffers typically flushed?

查看:91
本文介绍了通常在几秒钟后会刷新文件系统写缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在覆盖文件中的数据之前,我想确定旧数据已存储在磁盘上.这可能是一个很大的文件(多个GB),因此需要就地更新.通常,写操作将为2 MB或更大(我的计划是使用4 KB的块大小).

Before overwriting data in a file, I would like to be pretty sure the old data is stored on disk. It's potentially a very big file (multiple GB), so in-place updates are needed. Usually writes will be 2 MB or larger (my plan is to use a block size of 4 KB).

除了(或除了)调用fsync()外,我想在磁盘上保留(而不是覆盖)旧数据,直到文件系统写入新数据为止.我不想依赖fsync()的主要原因是:

Instead of (or in addition to) calling fsync(), I would like to retain (not overwrite) old data on disk until the file system has written the new data. The main reasons why I don't want to rely on fsync() is: most hard disks lie to you about doing an fsync.

所以我要寻找的是文件系统,操作系统(例如Windows),硬盘驱动器直到不使用fsync或类似方法将数据写入磁盘之前的典型最大延迟是多少.如果可能的话,我想提供真实的数字.我不是在寻找使用fsync的建议.

So what I'm looking for is what is the typical maximum delay for a file system, operating system (for example Windows), hard drive until data is written to disk, without using fsync or similar methods. I would like to have real-world numbers if possible. I'm not looking for advice to use fsync.

我知道没有100%可靠的方法可以做到这一点,但是我想更好地了解操作系统和文件系统在这方面的工作方式.

I know there is no 100% reliable way to do it, but I would like to better understand how operating systems and file systems work in this regard.

到目前为止,我发现的是: 30秒是//proc/sys/vm/dirty_expire_centiseconds .然后将"脏页刷新(写入)到磁盘上...( (自何时开始)自页面变脏以来已经花费了太多时间(但我找不到默认时间).因此,对于Linux而言,40秒似乎是安全的.但这是否适用于所有文件系统/磁盘? Windows,Android等呢?我想得到一个适用于所有常见操作系统/文件系统/磁盘类型的答案,包括Windows,Android,常规硬盘,SSD等.

What I found so far is: 30 seconds is / was the default for /proc/sys/vm/dirty_expire_centiseconds. Then "dirty pages are flushed (written) to disk ... (when) too much time has elapsed since a page has stayed dirty" (but there I couldn't find the default time). So for Linux, 40 seconds seems to be on the safe side. But is this true for all file systems / disks? What about Windows, Android, and so on? I would like to get an answer that applies to all common operating systems / file system / disk types, including Windows, Android, regular hard disks, SSDs, and so on.

推荐答案

让我仅用一些不太友好的术语来重述此问题:您试图控制物理设备的行为,而该设备的操作系统中的驱动程序无法控制.如果您想要的是实际的保证,而不是一个很好的猜测,那么您试图做的事情似乎是不可能的.如果您只想作一个很好的猜测,那很好,但是要当心,并据此进行记录.

Let me restate this your problem in only slightly-uncharitable terms: You're trying to control the behavior of a physical device which its driver in the operating system cannot control. What you're trying to do seems impossible, if what you want is an actual guarantee, rather than a pretty good guess. If all you want is a pretty good guess, fine, but beware of this and document accordingly.

您也许可以使用正确的设备驱动程序解决此问题.例如,SCSI协议在其READWRITE命令中具有一个Force Unit Access (FUA)位,该位指示设备绕过任何内部缓存.即使最初以缓冲方式写入数据,但以无缓冲方式读取数据也应能够验证其实际位置.

You might be able to solve this with the right device driver. The SCSI protocol, for example, has a Force Unit Access (FUA) bit in its READ and WRITE commands that instructs the device to bypass any internal cache. Even if the data were originally written buffered, reading unbuffered should be able to verify that it was actually there.

这篇关于通常在几秒钟后会刷新文件系统写缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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