0

TLDR; If /tmp in mounted as tmpfs, in the presence of swap, is there any kind of priority when swapping ? Does tmpfs start to swap before applications ?

FULL STORY

I have a laptop with 32G of RAM (Debian), and 32G of swap. I plan to mount /tmp with tmpfs.

But I am concerned with the behavior if the system needs to swap : what will swap first ? I guess (and I hope) that applications will have priority for RAM usage over tmpfs (e.g., I guess tmpfs will swap first). But I couldn't find any confirmation for this.

More broadly, are there any scenarios where mounting /tmp as tmpfs can slow down the system ?

1 Answer 1

2

I’m not aware of any priority applied here. Pages will be swapped out based on their level of use — pages which haven’t been used recently will be swapped out first. If that happens to be pages used in a tmpfs, or pages used by applications, doesn’t make any difference. See How does the kernel decide between disk-cache vs swap? for details of the process.

So you’ll generally see applications which don’t run much swapped out first, then tmpfs content which hasn’t been touched in a while.

In my experience using a tmpfs for /tmp increases system responsiveness overall, for /tmp-intensive workloads, and the improvement is greater than potential slowdown caused by increased memory use. It is however important to keep track of /tmp use — it’s easy to end up with obsolete files there which take up room in memory and/or swap without actually being necessary.

1
  • I probably also have to increase swap space, if I want to keep hibernation working. 32G RAM + 32G swap is fine if the system is not swapping, but if it swaps there won't be enough space to hibernate
    – ChennyStar
    Feb 19 at 10:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .