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?
Also, what happens if it gets full? As referenced above if you've committed too much to tmpfs your machine will deadlock. Otherwise (if it's just reached its hard limit) it returns ENOSPC just like any other filesystem.
The system has around 500 GB of memory. Compute a memory limit for tmpfs. Depending on the size of the system memory, you might want to compute a memory limit of around 20 percent for large systems and around 30 percent for smaller systems. So, for a smaller system, use .
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%
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With