文件系统开发
当设计一个使用inode结构指向文件/块的文件系统时,实际需要的inode数量是如何确定的?
When designing a file system that uses an inode structure to point to files/blocks, how is the number of inodes needed actually determined?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一些现代文件系统(其中之一是 XFS)根据需要动态分配 inode。没有该功能的文件系统会选择一个与磁盘大小相关的基于经验的值(例如,ext2/3/4 每 4KB 磁盘空间创建 1 个索引节点 IIRC),并且在创建文件系统时通常有一种方法可以调整该值。
Some modern filesystems (XFS for one) allocate inodes dynamically as needed. Filesystems without that feature choose an experience-based value relative to disk size (e.g. ext2/3/4 creates 1 inode per 4KB disk space IIRC) and there's usually a way to tune this value when creating a filesystem.
在某些 Unix 文件系统(例如 ext*fs)中,这实际上取决于系统管理员,系统管理员在创建文件系统时设置相对参数。
如果文件系统将托管大量小文件(新闻和邮件服务器是典型的示例),则需要大量 inode,因为每个对象(文件或目录)都需要一个 inode。
另一方面,如果文件系统将托管较大的文件(例如视频服务器),则您不需要那么多的索引节点。
由于索引节点会占用空间,因此在性能/效率和拥有足够的索引节点以满足您的目的之间实现平衡非常重要。一种简单的方法是计算具有类似使用模式的活动文件系统上的平均文件大小,并使用该数字作为新 FS 上字节/索引节点比率的基值。只要使用模式不发生剧烈变化,这将允许 FS 在卷填满时保持功能。
如果您实际上正在设计一个新的文件系统,而不仅仅是创建一个卷,您应该考虑像其他一些常见的 Unix 文件系统(例如 JFS、XFS、Reiserfs)一样动态分配 inode 的想法。这将使您的文件系统更加灵活,尽管人们普遍认为动态文件系统结构使得从损坏问题中恢复变得更加困难。
In some Unix filesystems (e.g. ext*fs) that is actually up to the system administrator, who sets a relative parameter while creating the filesystem.
If the filesystem will host lots of small files (news and mail servers are a typical example) you need a large number of inodes, since you need an inode for each object (file or directory).
If, on the other hand, the filesystem will host larger files (e.g. a video server) you don't need as many inodes.
Since inodes take up space, it's important to achieve a balance between performance/efficiency and having enough inodes for your purpose. A simple method is to compute the average file size on an active filesystem with similar usage patterns and use that number as a base value for the bytes/inode ratio on the new FS. That would allow the FS to remain functional while the volume fills up, as long as the usage patterns don't change drastically.
If you are actually designing a new filesystem, rather than just creating a volume, you should consider the idea of allocating inodes dynamically like some other common Unix filesystems (e.g. JFS, XFS, Reiserfs). That would make your filesystem slightly more flexible, although it is generally thought that dynamic FS structures make recovery from corruption problems significantly harder.