创建/删除许多硬链接的缺点?

发布于 2024-10-15 17:58:59 字数 589 浏览 9 评论 0原文

我需要创建数百到数千个临时硬链接或符号链接,这些链接将在创建后不久被删除。就我的目的而言,两种类型的链接都可以工作(即目标不是目录,它始终存在于同一文件系统上)

据我了解,符号链接创建一个包含原始文件路径的小文件。而硬链接创建对同一索引节点中数据的引用。因此,如果我要创建/删除数千个这样的链接,那么创建和删除数千个小文件(符号链接)或数千个这样的引用(硬链接)是否更好?似乎一个对硬盘驱动器征税(可能是碎片),而另一个可能对文件系统本身征税? inode 引用存储在哪里。建立如此多的硬链接是否有损坏文件系统的风险?速度怎么样?

感谢您的专业知识!

这是一种解决方法,能够使用 ffmpeg 从目录中的任意图像子集中编码电影。由于 ffmpeg 要求正确命名文件(例如,frame%04d.jpg),我意识到我可以创建指向文件子集的硬/符号链接,并适当地命名链接。这避免了重命名原始文件并必须实际复制数据。它效果很好,但需要重复创建和删除数千个链接。

我相信也解决了这个问题: 使用 ffmpeg 转换图像序列

I need to create hundreds to thousands of temporary hard or symbolic links that will be deleted shortly after creation. For my purposes both types of links will work (i.e. the target is not a directory and it always exists on the same file system)

As I understand it, symbolic links create a small file that contains the path to the original file. Whereas a hardlink creates a reference to the data in the same inode. So maybe if I am going to be creating/deleting thousands of these links is it better to be creating and deleting thousands of tiny files (symlinks) or thousands of these references (hardlinks)? It seems like one taxes the hard drive (maybe fragmentation) while the other might tax the file system itself? Where are inode references stored. Do I risk corrupting the file system by making so many hard links? What about speed?

Thanks for your expertise!

This a work around to be able to use ffmpeg to encode a movie out of an arbitrary subset of images from a directory. Since ffmpeg requires that the files be named properly (e.g. frame%04d.jpg) I realized I can just create hard/sym links to the subset of files and just name the links appropriately. This avoids renaming the original files and having to actually copy the data. It works great but it requires creating and deleting many thousands of links, repeatedly.

Sort of addresses this problem too I believe:
convert image sequence using ffmpeg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萧瑟寒风 2024-10-22 17:58:59

如果此活动破坏了您的文件系统,那么问题出在您的文件系统上,而不是您。文件系统通常非常可靠,因此不必担心。

这两个选项都需要在目录中添加一个条目。符号链接还需要创建一个文件。当您访问文件时,硬链接会直接跳转到内容,而访问符号链接则需要找到符号链接文件,读取它,找到包含内容的目录,找到内容所在的位置,然后访问它。因此,符号链接对于文件系统来说是更多的工作。

但与实际读取文件中的数据的工作相比,差异很小。因此,我不会担心它,只需选择最能提供您想要的语义的那个即可。

If this activity breaks your file system, then your file system is at fault, not you. File systems are generally pretty reliable, so don't worry about that.

Both options require adding an entry in the directory. The symbolic link requires creating a file as well. When you access the file the hard link jumps directly to the content, while accessing a symlink requires finding the symlink file, reading it, finding the directory with the content, finding where the content is, and then accessing that. Therefore symlinks are more work for the filesystem all around.

But the difference is minute when compared to the work of actually reading the data in the files. Therefore I would not worry about it, and just go with whichever one best gives you the semantics you want.

一曲琵琶半遮面シ 2024-10-22 17:58:59

由于您不尝试为同一个文件创建数十万个文件,因此硬链接的性能稍好一些。

但是,如果 /tmp 是 tmpfs,则 /tmp 中的符号链接的性能甚至更好。

哦,符号链接太小,不会导致碎片问题。

Since you are not trying to create hundreds of thousands to the same file, hard links are marginally better performing.

However, symbolic links in /tmp if /tmp is tmpfs is even better performing yet.

Oh, and symlinks are too small to cause fragmentation issues.

浮萍、无处依 2024-10-22 17:58:59

这两个选项都需要在目录 inode 中添加文件条目,目录结构可能会通过分配新块来增长。

但是符号链接需要分配 inode,并且文件系统对 inode 有限制。您的数十万符号链接可能会达到该限制,并且即使有千兆字节的可用空间,您也可能会收到“文件空间不足”错误消息。

默认情况下,文件系统创建工具根据物理分区大小选择最大 inode 数量。例如,对于 Linux ext2/3/4,mkfs.ext3 使用 bytes-per-inode 比率,您可以在 /etc/mke2fs.conf< 中找到/代码>。

对于现有文件系统,以下是获取有关 inode 信息的命令:

# dumpe2fs /dev/sda1 | grep -i inode | less

Inode count:              979200
Free inodes:              742304
Inodes per group:         16320
Inode blocks per group:   510
First inode:              11
Inode size:               128
Journal inode:            8
First orphan inode:       441066
Journal backup:           inode blocks

作为结论,您应该首选硬链接,主要用于磁盘和内存(缓存中的 VFS 结构)上的资源消耗。

另一个建议:不要在同一目录中创建太多文件,2'000 个文件是避免性能问题的合理限制。

Both options require the addition of a file entry in the directory inode, the directory structure may grow by allocating new blocks.

But a symbolic link requires the allocation of an inode and the filesystem has a limit for inodes. Your hundreds of thousands symlinks may hit that limit and you may get the "Not enough space for file" error message even with gigabytes free.

By default, the file system creation tool choose the maximum number of inodes according to the physical partition size. For instance for Linux ext2/3/4, mkfs.ext3 uses a bytes-per-inode ratio you can find in your /etc/mke2fs.conf.

For an existing filesystem, here is a command to get information about inodes:

# dumpe2fs /dev/sda1 | grep -i inode | less

Inode count:              979200
Free inodes:              742304
Inodes per group:         16320
Inode blocks per group:   510
First inode:              11
Inode size:               128
Journal inode:            8
First orphan inode:       441066
Journal backup:           inode blocks

As a conclusion, you should prefer hard links mainly for resource consumption on disk and in memory (VFS structures in caches).

Another advice: do not create too many files in the same directory, 2'000 files is a reasonable limit to avoid performance issues.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文