[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: swap and /tmp



Digby Tarvin wrote:

> I am thinking of using a tmpfs for /tmp, and would be interested
> to hear any thoughts that others have on this issue.

I use tmpfs for /tmp on all of my machines and have so far not found
a good reason why I should not.
 
> Obviously it would mean that /tmp would be volatile, which sames
> having to clean it up, but is sometimes annoying if you have grown
> used to being able to leave things there...

/tmp is volatile by definition.  See /etc/init.d/bootclean.sh on your
Debian system.  Other distributions have similar mechanisms.
 
> I don't know if the competition for memory is any different if done
> through tmpfs vs the buffer pool for a disk backed filesystem.

If you don't use the tmpfs excessively you won't notice the extra
competition.

The kernel has (or had?) problems, if you put several gigabytes of
data into your tmpfs, though.  Some time ago, when I was trying to
build a complete KDE from sources in /tmp, the OOM killer triggered,
although there was still a lot of swap available.

> I suspect it would be more efficient to have a tmpfs /tmp on an
> system with an encrypted swap partition than separately
> encrypted swap and /tmp partitions, because the encrypt/decrypt
> would only be done on the former if the temporary file lives
> long enough to be swapped out of memory..

I guess the much bigger advantage results from the reduced disk io.
If you're swapping out pages, the encryption overhead is negligible on
a modern system.  If you're going to encrypt your swap, have a look at
loop-aes.

> The main advantage I see is that instead of having to have a
> separate swap and tmp filesystem, I can have one combined
> partition serving both purposes, and can change the size of the
> tmp filesystem by a simple edit of fstab and a reboot.

You don't need a reboot to change the size of a tmpfs.  
You can just say "mount -o remount,size=XXXm /tmp"

> The only guidance I have seen on acceptible sizes for swap partitions
> has been:
> 	a. a rule of thumb suggesting it should be the same size as physical
>        memory.

In my opinion this is not a good rule of thumb.  The required amount
of swap depends entirely on your workload. 

>     b. I think I read somewhere that Linux cannot use more than 2GB.

This is no longer true.  I'm using a 4 GB swap partition without
problems here.

> So I was thinking a swap partition equal to memory (1GB in this case)
> plus the size of a modest /tmp partition (about 0.5GB) would be a
> good compromise.

Disk space is cheap.  When in doubt, unused swap will hurt less than
the OOM killer.

Regards,
Dennis



Reply to: