回答
阅读tmpfs
here。以下内容是从该文章中复制的,特别解释了共享内存与tmpfs
之间的关系。
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
的实现技术。
举个例子,对我目前已经注册了这种共享内存对象箱中运行的进程:
# pwd
/dev/shm
# ls -lh
insgesamt 76K
-r-------- 1 js js 65M 24. Mai 16:37 pulse-shm-1802989683
#
tmpfs是最慢的。共享内存和mmap的速度相同。
“这取决于”。一般来说,它们都是内存中的,并且依赖于系统实现,所以性能将可以忽略不计,并且可用于大多数平台。如果你真的关心绩效,你应该分析和确定你的要求。将这些方法中的任何一种替换为另一种方法都很简单。这就是说,共享内存是最不密集的,因为没有涉及任何文件操作(但又是非常依赖实现的)。如果您需要反复打开和关闭(map/unmap),则可能会产生大量开销。
干杯!
肖恩
通过“共享内存”你的意思是系统V共享内存,对不对?
我觉得Linux mmap是一个隐藏的tmpfs,当你使用这个,所以它实际上和mmpping一个tmpfs是一样的。
做文件I /在tmpfs上O时将有一个点球......大部分(有特殊情况下,它可能是有意义的,比如> 4G在32位进程)
如何?如果mmap使用共享内存,那么性能应该是相同的? – SyRenity 2009-05-25 09:19:02
- 1. mmap(2)vs mmap(3)
- 2. malloc vs mmap C
- 3. 'Flash Vs tmpfs'哪一个是首选的
- 4. mmap vs fileinput的优点
- 5. mmap vs sbrk,性能对比
- 6. mmap()vs malloc()返回地址
- 7. 做tmpfs和mmap在xen上玩不错?
- 8. Nginx的Fastcgi_cache性能 - 磁盘缓存VS tmpfs缓存VS静态文件
- 9. APC vs自定义Mmap扩展
- 10. 内存分配阈值(mmap vs malloc)
- 11. Linux共享内存:shmget()vs mmap()?
- 12. 在内存中创建一个SQLite数据库vs使用tmpfs
- 13. Exec的VS ExecWait VS ExecShell VS nsExec :: Exec的VS nsExec :: ExecToLog VS nsExec :: ExecToStack VS ExecDos VS ExeCmd
- 14. VS VS VS VS 11中的MVC测试
- 15. vs vs 2008 vs vs 2010
- 16. FTP vs SFTP vs HDFS vs NTFS vs EXT2,EXT3
- 17. CGL vs AGL vs OpenGL vs NSOpenGL vs CoreAnimation(CALayer)
- 18. MobileNet VS SqueezeNet VS ResNet50 VS启V3 VS VGG16
- 19. NTOSKRNL.EXE VS NTKRNLMP.EXE VS NTKRNLPA.EXE VS NTKRPAMP.EXE
- 20. VS 2008 vs VS 2008 Express
- 21. RailwayJS vs Geddy vs Express vs Socket.IO
- 22. .NET vs ASP.NET vs CLR vs ASP
- 23. DynamicProperty vs MutableProperty vs AnyProperty vs ConstantsProperty
- 24. codendi vs redmine vs Retrospectiva vs trac
- 25. body.scrollTop VS documentElement.scrollTop VS window.pagYOffset VS window.scrollY
- 26. Asp.net vs Html5 vs xml vs xhtml
- 27. Sleep VS alarmManager.set VS alarmManager.setRepeat VS Handler
- 28. Atomikos vs JOTM vs Bitronix vs?
- 29. inline vs __inline vs __inline__ vs __forceinline?
- 30. JRuby:import vs include vs java_import vs include_class
请你解释一下......谢谢 – hhafez 2009-05-24 21:17:03
事实上,似乎tmpfs的实际权力共享记忆?而且我认为,使用tmpfs作为底层传输时,mmap速度很快? – SyRenity 2009-05-25 09:19:11