By Alan Hargreaves-Oracle on Feb 28, 2013
That title may sound a little self explanatory and obvious, but over the last two weeks I have had two customers tell me flat out that /tmp uses swap and that I should still continue to investigate where their memory is being used.
This is likely because when you define /tmp in /etc/vfstab, you list the device being used as swap.
In the context of a tmpfs, swap means physical memory + physical swap. A tmpfs uses pageable kernel memory. This means that it will use kernel memory, but if required these pages can be paged to the swap device. Indeed if you put more data onto a tmpfs than you have physical memory, this is pretty much guaranteed.
If you are still not convinced try the following.
- In one window start up the command
$ vmstat 2
- In another window make a 1gb file in /tmp.
$ mkfile 1g /tmp/testfile
- Watch what happens in the free memory column in the vmstat.
There seems to be a misconception amongst some that a tmpfs is a way of stealing some of the disk we have allocated as swap to use as a filesystem without impacting memory. I'm sorry, this is not the case.