/tmp与/dev/shm在Linux上用于临时文件存储? [英] /tmp vs. /dev/shm for temp file storage on Linux?
问题描述
我有一些脚本,它们需要创建数百个快速连续的小型临时文件,并很快将其读回,然后取消链接.
I have scripts that make hundreds of quick succession, small, temp files needing to be created and very soon read back in, then unlinked.
即使在中等负载下,通过将上述文件放在Linux上的/tmp
(到磁盘)或/dev/shm
(文件系统级共享内存)中,我的测试也没有表现出任何性能差异.我将此归因于文件系统缓存.
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.
授予磁盘最终会 被fileystem操作击中,但是在多个小的读写临时文件上,为什么您(不)在磁盘支持的目录中推荐/dev/shm
呢?您是否注意到缓存的VFS上的共享内存目录显着提高了性能?
Granted the disk will eventually get 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
用于非常特殊的目的,而不是用于由任意程序放入的文件.
/dev/shm
is intended for a very special purpose, not for files to be put to by arbitrary programs.
相反,/tmp
是专门为此制作的.在我的系统上,/tmp
也是tmpfs
,而/var/tmp
则是设计用于放置较大的文件,可能会保留更长的时间.
In contrast, /tmp
is exactly made for this. On my systems, /tmp
is a tmpfs
as well, in contrast to /var/tmp
which is designed for putting larger files, potentially staying longer.
这篇关于/tmp与/dev/shm在Linux上用于临时文件存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!