我可以超出 tmpfs 大小吗
我正在尝试使用 /dev/shm tmpfs 来写入我的文件。默认是物理 RAM 的一半,没有交换。当我写入超出此安装大小的内容时,会出现错误“磁盘上没有剩余空间”。
我的问题是,它不应该使用交换空间而不是出错吗?有没有办法让我的应用程序使用的资源超过为 tmpfs 分配的资源,也许可以通过一个选项?
如果我的一个进程正在运行并且耗尽了 /dev/shm 中的几乎所有空间,并且我正在运行另一个进程(在 /dev/shm 之外),并且该进程也使用了超过 50% 的 RAM 空间,会发生什么情况?哪一个被换掉了?
例如,假设我的总物理内存为 40 GB,tmpfs 为 20 GB。其中一个进程正在使用 /dev/shm,大小约为 20GB。现在还有另一个进程正在运行,大约需要 30GB。哪一个进程将被换出?还是无法确定?
I'm trying to use /dev/shm tmpfs for writing my files. The default is half of the physical RAM without swap. When I write something beyond the size of this mount, it gives an error "No space left on the disk".
My question is, shouldn't it be using swap space rather than erroring out? Is there a way I can let my application use up more than what is allocated for tmpfs, maybe through an option?
What happens if one of my processes is running and has used up almost all of the space in /dev/shm and I have another process running (outside of /dev/shm) which also uses more than 50% of RAM space? Which one is swapped out?
For example, let's say my total physical memory is 40 GB and tmpfs is 20GB. One of the processes is using /dev/shm and is about 20GB. Now there is another process running which takes around 30GB. Which one of the processes will swap out? Or it cannot be determined?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
tmpfs 将在必要时使用交换空间(即使 tmpfs 大小是 RAM 大小的一半,也可能发生这种情况,因为其他东西也使用 RAM),并且“RAM 的一半”只是文件系统的默认大小(相当合理的默认值) 。您可以在使用“size”参数安装或重新安装它时将其设置为您想要的任何值:
如果您的发行版使用 fstab 来挂载 tmpfs,您可以在其中添加“size=40G”。您也可以随时使用以下命令重新安装它:
不过要小心。如果 tmpfs 上的文件占用过多的虚拟内存(RAM+交换),应用程序可能会被杀死(被 OOM 杀手),并且整个系统可能会崩溃。
回到你的问题......
我认为确定什么将被换出并不容易,因为据我所知,Linux 的所有内容(包括进程数据内存、缓存磁盘文件、映射磁盘文件、tmpfs 文件)都是相同的“虚拟内存”。 Linux 可能认为某些页面更重要(最近使用过),而其他页面则准备被换出。所以可能是tmpfs文件的一部分和其他进程的一部分换出了。
tmpfs will use swap space when neccessary (it can happen even if tmpfs size is half of the RAM size, as other things do use RAM too) and 'half of the RAM' is just the default size (quite sane defaul) of the filesystem. You may set it to whatever you want while mounting or remounting it using the 'size' argument:
If your distribution uses fstab to mount the tmpfs you may add e.g. 'size=40G' there. You can also remount it at any time using:
Be careful, though. If files on the tmpfs take too much of your virtual memory (RAM+swap) applications may get killed (byt the OOM killer) and the whole system may crash.
Back to your questions…
I don't think it is easy to determine what will be swapped out, as AFAIK at that level for Linux everything (including process data memory, cached disk files, mmaped disk files, tmpfs files) is just the same 'virtual memory'. Linux may consider some pages more important (recently used), other ready to be swapped out. So it may be a part of the tmpfs file and a part of the other process swapped out.
如果你切换到 ramfs,那么它会根据需要动态增长......直到它达到 OOM。当心!
ramfs 也不会交换。
https://www.thegeekstuff.com /2008/11/overview-of-ramfs-and-tmpfs-on-linux/
作为当前答案的附录,tmpfs 将使用交换空间,但仅限于当前的大小限制!也就是说,如果内存压力很高,一些 tmpfs 挂载将被交换到磁盘上,但这不会允许其增长超出指定的限制。
If you switch to a ramfs then it will dynamically grow as needed.... until it hits the OOM. Be careful!
ramfs will not swap either.
https://www.thegeekstuff.com/2008/11/overview-of-ramfs-and-tmpfs-on-linux/
As an addendum on the current answer, tmpfs will use swap, but only up to its current size limit!!! That is, if memory pressure is high, some of the tmpfs mount will be swapped onto disk, BUT this will not allow it to grow beyond the specified limit.