简体   繁体   English

文件系统块大小如何工作?

[英]How file system block size works?

All Linux file systems have 4kb block size.所有 Linux 文件系统都有 4kb 块大小。 Let's say I have 10mb of hard disk storage.假设我有 10mb 的硬盘存储空间。 That means I have 2560 blocks available and let's say I copied 2560 files each having 1kb of size.这意味着我有 2560 个块可用,假设我复制了 2560 个文件,每个文件的大小为 1kb。 Each 1 kb block will occupy 1 block though it is not filling entire block.每个 1 kb 块将占用 1 个块,尽管它没有填满整个块。

So my entire disk is now filled but still I have 2560x3kb of free space.所以我的整个磁盘现在已满,但我仍然有 2560x3kb 的可用空间。 If I want to store another file of say 1mb will the file system allow me to store?如果我想存储另一个 1mb 的文件,文件系统是否允许我存储? Will it write in the free space left in the individual blocks?它会写入单个块中剩余的可用空间吗? Is there any concept addressing this problem?有没有解决这个问题的概念?

I would appreciate some clarification.我希望得到一些澄清。 Thanks in advance.提前致谢。

It is true, you are in a way wasting disk space if you are storing a lot of files which are much smaller than the smallest block size of the file system.确实,如果您存储的文件远小于文件系统的最小块大小,那么您在某种程度上浪费了磁盘空间。

The reason why the block size is around 4kb is the amount of metadata associated with blocks.块大小约为 4kb 的原因是与块关联的元数据量。 Smaller the block size, more there is metadata about the locations of the blocks compared to the actual data and more fragmented is the worst case scenario.与实际数据相比,块大小越小,关于块位置的元数据就越多,而且越碎片化是最坏的情况。

However, there are filesystems with different block sizes, most filesystems let you define the block size, typically the minimum block size is 512 bytes.然而,有不同块大小的文件系统,大多数文件系统允许您定义块大小,通常最小块大小为 512 字节。 If you are storing a lot of very small files having a small block size might make sense.如果您要存储大量具有小块大小的非常小的文件,则可能是有意义的。

http://www.tldp.org/LDP/sag/html/filesystems.html http://www.tldp.org/LDP/sag/html/filesystems.html

XFS Filesystem documentation has some comments on how to select filesystem block size - it is also possible to defined the directory block size: XFS 文件系统文档对如何选择文件系统块大小有一些评论——也可以定义目录块大小:

http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=linux&db=bks&srch=&fname=/SGI_Admin/LX_XFS_AG/sgi_html/ch02.html http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=linux&db=bks&srch=&fname=/SGI_Admin/LX_XFS_AG/sgi_html/ch02.html

You should consider setting a logical block size for a filesystem directory that is greater than the logical block size for the filesystem if you are supporting an application that reads directories (with the readdir(3C) or getdents(2) system calls) many times in relation to how much it creates and removes files.如果您支持的应用程序会多次读取目录(使用 readdir(3C) 或 getdents(2) 系统调用),则应考虑为文件系统目录设置一个大于文件系统逻辑块大小的逻辑块大小与它创建和删除文件的数量有关。 Using a small filesystem block size saves on disk space and on I/O throughput for the small files.使用小的文件系统块大小可以节省磁盘空间和小文件的 I/O 吞吐量。

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

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