简体   繁体   English

Linux中的I / O性能

[英]I/O Performance in Linux

File A in a directory which have 10000 files, and file B in a directory which have 10 files, Would read/write file A slower than file B? 目录中有10000个文件的文件A,目录中有10个文件的文件B,读/写文件A的速度是否比文件B慢? Would it be affected by different journaling file system? 是否会受到其他日记文件系统的影响?

No. 没有。

Browsing the directory and opening a file will be slower (whether or not that's noticeable in practice depends on the filesystem). 浏览目录和打开文件会比较慢(实际上是否值得注意,取决于文件系统)。 Input/output on the file is exactly the same. 文件上的输入/输出完全相同。

EDIT: 编辑:
To clarify, the "file" in the directory is not really the file, but a link ("hard link", as opposed to symbolic link), which is merely a kind of name with some metadata, but otherwise unrelated to what you'd consider "the file". 为了澄清,“文件”目录中的是不是真正的文件,而是一个链接 (“硬链接”,而不是符号链接),它仅仅是一个样的名字以及一些元数据,但在其他方面无关的你” d考虑“文件”。 That's also the historical reason why deleting a file is done via the unlink syscall, not via a hypothetical deletefile call. 这也是历史原因,为什么要通过unlink syscall而不是通过假定的deletefile调用来删除文件。 unlink removes the link, and if that was the last link (but only then!), the file. unlink删除链接,如果那是最后一个链接(但只有这样!),则删除文件。

It is perfectly legal for one file to have a hundred links in different directories, and it is perfectly legal to open a file and then move it to a different place or even unlink it (while it remains open!). 一个文件在不同目录中具有一百个链接是完全合法的,打开一个文件然后将其移动到另一个位置甚至取消链接(保持打开状态)是完全合法的。 It does not affect your ability to read/write on the file descriptor in any way, even when a file (to your knowledge) does not even exist any more. 即使文件(据您所知)不再存在,它也不会以任何方式影响您在文件描述符上进行读/写的能力。

In general, once a file has been opened and you have a handle to it, the performance of accessing that file will be the same no matter how many other files are in the same directory. 通常,一旦打开了文件并具有该文件的句柄,无论同一目录中有多少其他文件,访问该文件的性能将相同。 You may be able to detect a small difference in the time it takes to open the file, as the OS will have to search for the file name in the directory. 可能能够检测到打开文件所花费时间的微小差异,因为操作系统将不得不在目录中搜索文件名。

Journaling aims to reduce the recover time from file system crashes, IMHO, it will not affect the read/write speed of files. 日记功能旨在减少文件系统崩溃的恢复时间,恕我直言,它不会影响文件的读写速度。 Journaling ext2 日记ext2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM