Shmem vs tmpfs vs mmap [英] Shmem vs tmpfs vs mmap

查看:406
本文介绍了Shmem vs tmpfs vs mmap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道以下3个速度的比较:

Does someone know how well the following 3 compare in terms of speed:


  • 共享内存

  • shared memory

tmpfs(/ dev / shm)

tmpfs (/dev/shm)

li>

mmap (/dev/shm)

谢谢!

推荐答案

tmpfs 这里。下面是从那篇文章复制的,特别解释了共享内存和 tmpfs 之间的关系。

Read about tmpfs here. The following is copied from that article, explaining the relation between shared memory and tmpfs in particular.

1) There is always a kernel internal mount which you will not see at
   all. This is used for shared anonymous mappings and SYSV shared
   memory. 

   This mount does not depend on CONFIG_TMPFS. If CONFIG_TMPFS is not
   set the user visible part of tmpfs is not build, but the internal
   mechanisms are always present.

2) glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for
   POSIX shared memory (shm_open, shm_unlink). Adding the following
   line to /etc/fstab should take care of this:

    tmpfs	/dev/shm	tmpfs	defaults	0 0

   Remember to create the directory that you intend to mount tmpfs on
   if necessary (/dev/shm is automagically created if you use devfs).

   This mount is _not_ needed for SYSV shared memory. The internal
   mount is used for that. (In the 2.3 kernel versions it was
   necessary to mount the predecessor of tmpfs (shm fs) to use SYSV
   shared memory)

所以,当你实际使用POSIX共享内存(我以前使用过),然后 glibc 将创建一个文件 / dev / shm ,用于在应用程序之间共享数据。它返回的文件描述符将引用那个文件,你可以传递到 mmap 来告诉它把这个文件映射到内存,就像它可以做任何真正的文件。因此,您列出的技术是互补的。他们不是竞争。 Tmpfs 只是提供内存文件作为 glibc 实现技术的文件系统。

So, when you actually use POSIX shared memory (which i used before, too), then glibc will create a file at /dev/shm, which is used to share data between the applications. The file-descriptor it returns will refer to that file, which you can pass to mmap to tell it to map that file into memory, like it can do with any "real" file either. The techniques you listed are thus complementary. They are not competing. Tmpfs is just the file-system that provides in-memory files as an implementation technique for glibc.

例如,在我的盒子上运行了一个进程,目前已经注册了这样一个共享内存对象:

As an example, there is a process running on my box currently having registered such a shared memory object:

# pwd
/dev/shm
# ls -lh
insgesamt 76K
-r-------- 1 js js 65M 24. Mai 16:37 pulse-shm-1802989683
#

这篇关于Shmem vs tmpfs vs mmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆