Swap or no swap? #X

After reading this forum post...
and this....

It's still unclear for me which is the best practice. So for a system with 16G ram and 2T nvme ssd (where the few gigs used for swap isn't going to be really felt), should I create swap "just in case some program wants to use it" or not? Or should I use zram? Or neither?

remains unclear what you wanted to say here and what was "the crime":
a) removing the swap partition
b) to have the swap partition on SSD in the first place?

It's entirely use and system dependent.

You simply have to try each option and see which works best for you.

Normal desktop usage. FF with 100 tabs; gaming while not closing sayd FF before. maybe some torrent and spotify or something else also in background...

OK, so... I don't know what your current system is, whether it has swap, how much RAM you have in use, whether you're having any issues, etc. etc. etc.

You'll have to try it yourself.

1 Like

In my case,
I have 8 GB RAM..
Screenshot_20190605_095607
Swap = 1.9 GB :smile:
When I install packages/build from source code or when I open so much tab on browser..
..the number swap file is rising up even higher..

I have 8 GB of RAM, 8.8GB of Swap.
As far as I know my system has never userd swap, period. It's always at 0.

But I have a 1TB drive so 9GB is nothing, it might as well be there.

If you use Suspend To Disc, then you need a swap partition, which is bigger than the size of the RAM.

If you have no swap and the RAM is completely used, the computer will freeze.

So it is a good idea to have a swap partition on the disc.

2 Likes

You can start with a swap file. You don't need a special partition just for the swap.

Then you can log your swap usage (add this to Cron to repeat every minute)

free -wh | grep Swap | awk '{ print ""$3""}' >> ~/swap_used.log

If after a few weeks/months all you can see is 0B in the log then you will not need the swap in my oppinion.

But a special case still apply for example if you want to use hibernation then you will need it.

From the end of this thread : /swapfile : fstab | SOLUTION : systemd-swap ! Thank You all!

I only install systemd-swap.

Even with 12Go RAM, I see some use, I don't have to think : it sets whatever is needed for me.

1 Like

just some clarification:

you can use suspend even is more ram is used than swap available (or no swap available at all)

mv@mv-pc:~$ free
              total        used        free      shared  buff/cache   available
Mem:        8017068     4968356     2019428      118836     1029284     2661688
Swap:       1048572           0     1048572

##############################
mv@mv-pc:~$ systemctl suspend
##############################

mv@mv-pc:~$ 
mv@mv-pc:~$ free
              total        used        free      shared  buff/cache   available
Mem:        8017068     4975916     2011716      118836     1029436     2654128
Swap:       1048572           0     1048572
mv@mv-pc:~$

hibernation wouldn't work. Altough you dont need swap = ram size necessarily (lower swap should also work in most cases)

Also your computer usually wouldn't freeze if you fill ram completely. It should (try to) kill application(s) and free ram

(edit: it depends, if your lucky segfault occurs and applications gets killed. But "freeze" can also happen. You can test easily if you use a lot of ram, e.g. 7.7 gb of 8 gb and try to open chromium, pc "freezes". If you have chromium already open (lets say ram usage is about 3 gb) and a application tries to use e.g. 6 gb mem segfault may occur)

This is all about personal use cases and preferences.

On my desktop PC I have 32 GB RAM. It hardly swaps so I moved regular swap to zram and that is fine.

On my laptop I want to hibernate. So I use regular swap. And I prefer a swapfile over a swap partition. A swapfile is more flexible. It can be resized or even removed without touching the partition layout. And because I am using a LUKS encrypted filesystem the swapfile is encrypted as well.

Just my 2 cent.

Swapping is not a bad thing per se.
Zram is a viable alternative for both low-mem and high-mem systems. I use it on all my computers ranging from 4 GB RAM to 32 GB RAM.
It is (or was) also used on some Android phones with 2 GB RAM btw.

But a real swap partition doesn't hurt either.
In contrast to mbod, I prefer a swap partition in order to keep the filesystem clean.

In the end it depends on what you do with your computer, though I cannot imagine how one could possibly manage a 100-tab Firefox... I already lose the plot with 10 :slight_smile:

If you want to be able to hibernate your system a swap file or partition is required for that, otherwise a token small swap file for legacy programs is probably all you require.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

Forum kindly sponsored by