can I over run the tmpfs size

user900563 picture user900563 · Aug 30, 2011 · Viewed 22.4k times · Source

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?

Answer

Jacek Konieczny picture Jacek Konieczny · Aug 30, 2011

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.