0

This question already has an answer here:

I want to install Ubuntu on my machine by allocating 400 GB for the / partition and 50 GB for the /home folder and 16GB RAM. Does it make sense, in this case, to create a swap partition or is it useless?

marked as duplicate by Thomas Dickey, Community Jan 13 '18 at 17:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    Swap space doesn't relate directly to hard drive space, except for the fact that it takes up a part of the hard drive space. – Mukesh Sai Kumar Jan 13 '18 at 17:42
  • 2
    Wow; duplicate in hot questions. – Kyslik Jan 13 '18 at 19:14
  • 1
    Whether it's useful depends entirely on how the machine is used. e.g. for a server where memory usage is not likely to exceed available RAM, it's not very useful (but it doesn't hurt to have some, just in case), while a desktop machine running programs that use lots of RAM (e.g. chromium or firefox with lots of tabs/windows open), it can be very useful. BTW Linux has zram (uses RAM only) and zswap (uses RAM with block device) which use compression algorithms to increase virtual memory size. compression ratio can be very impressive but depends, of course, on what is being compressed. – cas Jan 14 '18 at 3:43
  • Very insightful feedback, thank you very much @cas – Billal Begueradj Jan 14 '18 at 6:00
2

As @francois says, it is always a good idea to have a partition, mainly because you might have a contingency situation someday, and it will keep the kernel happy.

Modern kernels are however not that much dependent on having swap as in the past.

However, having a large enough root partition, more than enough RAM, and swap being rarely used, it does not need to be a partition. Create a 51MB/1G swap file inside the root partition if you want a simpler configuration.

You will only need larger swap files in production servers like application servers, databases or large web servers.

see Creating a Swap File

3

Swap partition doesn't have links to partition size or partition use but linked to memory & some I/O usage...

Swap is needed only to manage on this. It's always a good Idea to have e little swap even when it seems to be useless just in case... it should be needed ... someday....

Even with a 64Gb ram machine I Use some swap if it is an important machine like production server or backup machine for example.

  • It also depend on the type of production servers, their loads and how much RAM you allocated for them. As a rule of thumb, DHCP/DNS servers wont need it much, Java-based application servers or MySQL server might need a larger swap often in a while. – Rui F Ribeiro Jan 13 '18 at 17:26
3

Swap is just like an extension to your physical RAM, and it caches unused data from your RAM, freeing critical RAM space, and speeding some of your operations up. It doesn't have any direct relation to how much space you allocate for each partition. If you're sure that you have plenty of RAM, then you may simply give a lesser amount of swap. But just in case, using a large and generous swap partition ( >= 1 GB) is all good and fine.

There used to be an old rule: Swap = RAM * 2, but this doesn't apply to modern systems.

For more information about what swap is, refer here. Or better, google it out.

  • 1
    I also agree that nowadays a 1-2G partition should be enough for most common servers. – Rui F Ribeiro Jan 13 '18 at 17:10
1

Swap needs will depend on how much RAM you have and what your system will be used for. I give my machine with 16gb of RAM 4gb of swap, it very rarely gets used. My linode.com VPS with 1gb of ram has 256mb swap and even acting as mail/web/etc for a private domain it rarely uses swap.

Depending on what the machine will be used for I'd reconsider that space allocation - my /home takes much more space than the rest of the filesystem, except for one spot that I store ISO and OVA files on (which is actually yet another disk on a different mount point).

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