xfs - 写入文件时如何不修改mtime? [英] xfs - how to not modify mtime when writing to file?

查看:238
本文介绍了xfs - 写入文件时如何不修改mtime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件, a.dat ,它是1GB,驻留在磁盘上。出于性能原因,我重复使用这个文件,并根据需要简单地覆盖它的内容,而不是创建一个新的文件,并让它增长(每个增长的操作必须更新inode的大小)。

我试图挤出更多的表现,并搜索了手册装载,以试图找出文件的mtime和ctime被更新。根据我的理解,每次更改文件内容时,都会更新mtime和/或ctime。这是如何xfs工作?

如果是这样,有没有办法在Linux上禁用此?我不关心mtime和ctime,宁可不花费每个写入操作更新它们的成本。最后,我将完全摆脱文件系统,并直接写入设备,但同时我希望有一种方法可以用文件系统来做到这一点。

编辑回应回答



澄清,我写信给固态硬盘和挤出每一个我可以摆脱SSD的操作是非常重要的。 SSD理论上可以处理每秒25K的操作,而这些对我来说都很重要。除了写入我的文件之外,我不希望他们中的任何一个被浪费掉。在这个笔记上,实际上我在我的磁盘上有200个1GB的文件。我试图简化上面的问题。



此外,每个写入必须是同步的,我的程序将不会继续,直到我确信这些位在磁盘上( 是可能的)。但是我认为这个提示是切题的。 $ c>用于mtime和ctime的语义。实际上,mtime和ctime将在inode的内存副本中更新,并异步刷新到磁盘。

你不能跳过inode中的mtime更新,而没有主要的内核hackery,如果你真的认为从一个32位计数器到另一个存储器位置的副本正在减慢你的速度,您错误地试图优化 write(2)的快速部分。

想要提高文件写入性能在1GB的文件?为块缓存添加更多的内存使用,并忘记了时间。



在评论中添加



同步写入将不会提供任何有意义的安全性,因为在磁盘写入过程中拉动的电源线不受同步的帮助;这就是使用像xfs和ext3 +这样的日志文件系统的原因。面对失败,最好的希望是一致的。

您似乎希望确定所记录的数据是完全不可能的,即使您使用电池供电的SRAM写入缓冲区构建RAID,总是在提交位之前失败。写入原始卷可以减少对日志文件系统的保护。



如果您在问题中阐明了您的设计意图,那么可能会有更好的答案。从内心上看,尽管写入时间较长,但对于一个小巧的1GB文件来说,闪存对我来说是一个比旋转氧化物更少的故障,但这不是一个正式的声明。


I have a file, a.dat that is 1GB and resides on disk. For performance reasons, I reuse this file and simply overwrite its contents as needed, rather than creating a new file and letting it grow (each grow operation has to update its size in the inodes).

I am trying to squeeze even more performance out, and have searched the man pages for open and mount to try to figure out when the mtime and ctime for a file are updated. From my understanding, each time you change a file's contents, the mtime and/or ctime are updated. Is this how xfs works?

If so, is there a way to disable this on linux? I don't care about the mtime and ctime and would rather not incur the cost of updating them with each write operation.

Eventually, I will get rid of the filesystem completely and write directly to the device, but for the meantime I am hoping there is a way to do this with the filesystem.

EDIT IN RESPONSE TO ANSWER

For clarification, I am writing to an SSD and squeezing every operation I can out of the SSD is extremely important. The SSD can theoretically handle on the order of 25K operations per second, and each of these is important to me. I don't want any of them to be wasted on anything other than writing to my files. On that note, in reality I have 200 1GB files on my disk that I'm writing to. I was trying to simplify the problem with my question above.

Additionally, each write must be synchronous and my program will not continue until I am sure that the bits are on disk (which is possible). But I think this note is tangential to the question.

解决方案

See man 2 stat for the semantics of mtime and ctime. In practice, the mtime and ctime will be updated in the in-memory copy of the inode and flushed out to disk asynchronously.

You can't skip the mtime update in the inode without major kernel hackery and if you really think that a copy from one 32bit counter to another memory location is slowing you down, you are mistakenly trying to optimize the fast part of write(2).

Want to increase file write performance on a 1GB file? Add more memory for the block cache to use and forget about the mtime.

added in response to comment

Synchronous writes will not provide safety in any meaningful sense as a pulled power cord in the middle of a disk write is not helped by sync; this is why journaled filesystems like xfs and ext3+ are used. The best you can hope for is consistency in the face of failure.

You appear to desire certainty that the data recorded are cast in stone which is fundamentally impossible even if you build a RAID with battery backed SRAM write buffers as something can always fail before the bits are committed. Writing the raw volume gives you even less protection than a journaled filesystem.

If you clarify your design intention in your question, a better answer might be possible. On a gut level, even though the write times are longer, for a piddling little 1GB file, flash memory strikes me as less failure prone than spinning oxides, but this is not a formal declaration.

这篇关于xfs - 写入文件时如何不修改mtime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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