/tmp 与 /dev/shm 用于 Linux 上的临时文件存储?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9745281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
/tmp vs. /dev/shm for temp file storage on Linux?
提问by Jé Queue
I have scripts that make hundreds of quick succession, small, temp files needing to be created and very soon read back in, then unlinked.
我有脚本可以制作数百个快速连续的小型临时文件,需要创建并很快读回,然后取消链接。
My testing shows little if any performance difference by putting said files in /tmp
(to disk) or into /dev/shm
(filesystem-level shared memory) on Linux even under moderate load. I attribute this to the filesystem cache.
我的测试表明,即使在中等负载下,将所述文件放入/tmp
(到磁盘)或放入/dev/shm
(文件系统级共享内存)在 Linux 上的性能差异也很小。我将此归因于文件系统缓存。
Granted the disk will eventuallyget hit with the fileystem actions, but on multiple small write-read temp files, why would you (not) recommend /dev/shm
over disk-backed directory? Have you noticed big performance increases with shared memory directory over a cached VFS?
授予磁盘最终会受到文件系统操作的影响,但是在多个小的写-读临时文件上,您为什么(不)推荐使用/dev/shm
磁盘支持的目录?您是否注意到共享内存目录在缓存 VFS 上的性能显着提高?
采纳答案by glglgl
/dev/shm
is intended for a very special purpose, not for files to be put to by arbitrary programs.
/dev/shm
用于非常特殊的目的,而不是用于由任意程序放入的文件。
In contrast, /tmp
is exactly made for this. On my systems, /tmp
is a tmpfs
as well, in contrast to /var/tmp
which is designedfor putting larger files, potentially staying longer.
与此相反,/tmp
在此做出准确。在我的系统上,/tmp
也是tmpfs
,相比之下,/var/tmp
它旨在放置更大的文件,可能会停留更长时间。
回答by ???
It is essentially the same (shm is also backed implicitly by the disk when you have a swapfile).
它本质上是相同的(当您有交换文件时,shm 也由磁盘隐式支持)。
/tmp has the advantage that it fills up harder (considering your hard disk is likely larger than your swapfile). And also it is more widely supported.
/tmp 的优点是它更难填满(考虑到您的硬盘可能比您的交换文件大)。而且它得到了更广泛的支持。