Linux can I over run the tmpfs size
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7242484/
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
can I over run the tmpfs size
提问by user900563
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".
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?
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?
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?
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?
回答by Jacek Konieczny
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:
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:
Mount options for tmpfs
size=nbytes Override default maximum size of the filesystem. The size is given in bytes, and rounded up to entire pages. The default is half of the memory. The size parameter also accepts a suffix % to limit this tmpfs instance to that percentage of your physical RAM: the default, when neither size nor nr_blocks is specified, is size=50%
Mount options for tmpfs
size=nbytes Override default maximum size of the filesystem. The size is given in bytes, and rounded up to entire pages. The default is half of the memory. The size parameter also accepts a suffix % to limit this tmpfs instance to that percentage of your physical RAM: the default, when neither size nor nr_blocks is specified, is size=50%
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:
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:
mount -o remount,size=40G /dev/shm
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.
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…
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.
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.
回答by DylanYoung
If you switch to a ramfs then it will dynamically grow as needed.... until it hits the OOM. Be careful!
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.
ramfs will not swap either.
https://www.thegeekstuff.com/2008/11/overview-of-ramfs-and-tmpfs-on-linux/
https://www.thegeekstuff.com/2008/11/overview-of-ramfs-and-tmpfs-on-linux/
As an addendum on the current answer, tmpfs willuse 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.
As an addendum on the current answer, tmpfs willuse 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.