Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Are there any conventions on where to put swap files on Linux?

I usually just create them in /var/swapfile, but that seems a bit too high up in the hierarchy.

share|improve this question
up vote 6 down vote accepted

AFAIK there is no location defined in the File System Hierarchy Standard.

Because /var is for often-changed files, I would say it is okay to place it here. But remember that if you use a flat-file swap instead of a partition, consider to use a fast file system for /var.

share|improve this answer
According to this: You don't have to worry at all about the filesystem! – Paul Nov 24 '15 at 6:05

The conventional way is to have a partition dedicated to swap. If you use a file it's at your own discretion, but Malte's suggestion of the file system being important is a good one.

share|improve this answer
+1 for it's own partition. I usually have swap as a partition at the beginning of the drive. /boot then swap is my general approach. – egorgry Jun 10 '11 at 18:30
I personally don't really care about the last few percentage points of swap performance enough to take the extra complexity of a separate partition. If my server starts seriously swapping, I have a problem anyway. The swap space is more of a last-resort safety net in case some process starts gobbling up memory. – Jo Liss Jun 11 '11 at 14:10
That's fine, you're welcome to use a file. I find partitions quite easy to manage but I see your reasoning. You just asked what the convention was and that's pretty much the default scenario. – Caleb Jun 11 '11 at 14:18
@egorgry - Didn't BSD historically try and always put swap on the 2nd partition to be in the middle? – Xepoch Mar 1 '12 at 17:52
I find it quite useful to put swap space on a file in /var, because it makes a little easier to move system to new storage (one thing less to care about). I don't care about performance, since I almost don't use swap any more. Maybe its main use today is for laptop hibernation, and obviously as "safety net". – gerlos Dec 15 '14 at 15:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.