Skip to content

Is Swap partition necessary at present?

I have these partitions for my Linux distro: boot, root, swap

Swap partition is 2 GB while my RAM is 16 GB. I have a widget showing info in realtime about CPUs, RAM, Swap on my desk.

Recently I was playing Path of Exile and I saw my Swap partition was being used at 100% while RAM was nearly 4 GB. My question was: Should RAM not be used mainly while Swap is used just in case only? Something similar happens when using an Android emulators (Genymotion). Do I need any further configuration for my Swap? what if I don't have a SWAP partition?

UPDATE: I use SSD of 1 TB

Edited 16 Sep 2022. We only hold this version.

35 points43 comments
Open on Reddit
About this post
Posted
Archived
Edited
Score
35 · 91% up
Kind
Text
ID
xfruda

Author

1
posts
5
comments
0
media
View profile

46 comments

You need a swap space but it can be a file, im using zram, it's good and it's safer since it's inside my encrypted drive

14 points

Just to add on, swap file might be a better choice over a partition especially if you might need to resize down the road

9 points

im using zram, it's good and it's safer since it's inside my encrypted drive

zram is entirely in memory. It's definitely not inside your encrypted drive.

In any case zswap is strictly superior most of the time and is even enabled by default now.

3 points

I have 32 GB RAM and I still keep a swap partition, even though it is rarely used. I have seen it used, though, when compiling large programs (such as chromium). I have no idea how gaming might use it.

If you have plenty of drive space, why worry about it?

8 points

I've wondered the opposite. I also have 32GB of ram and I saw it wasn't paging at all really so I just disabled swap altogether. I haven't had any negative effects from this.

disk space is not really a concern, but I always wondered if swap usage just caused a lot of wear on SSDs.

4 points

Of course It does. On home or office PCs is negligible, but on servers or workstation contributes more to its wear. Also, a swap partition will always use the same drive blocks with limited rotation. A swapfile on a large partition is preferred, due to a more room to rotate used and free blocks.

5 points

Well, there's no wear and tear when it isn't used. And if it's used only rarely, it's not much wear and tear.

2 points

You can reduce your system’s swappines so it prefers ram over swap https://wiki.archlinux.org/title/Swap#Swappiness

7 points

Swappiness doesn't affect the evaluation of memory pressure, but changes linux's affinity for anonymous or file backed pages on reclaim.

Read the wiki page carefully and you'll see it's talking about the usage of swap space. It is admittedly not worded all that well, though.

2 points

I haven't set a swap in years and have never had a problem.

That's not to say that a day won't come when having a swap would save me an unscheduled boot right at that very moment I don't want one, but given my experience thinking about swap is an unnecessary step.

There is no doubt an excellent argument why everyone must set a swap and that the failure to set a swap divides good people from slobs but - no. I don't care.

6 points

I'm with ya. I haven't used a swap *anything* in about six years on my main rig. (The laptop, with far less ram, is a different story. heh.)

At the end of the day, it is the user's decision. For good or ill.

3 points

That's a bit hyperbolic don't you think?

But I mean yeah, it won't cause problems in the sense it won't break your system, just like disabling one CPU core won't break your system, but still, why would you?

1 points

Having some kind of swap is always good, mostly if using software eating a lot of RAM. Some say, when the drive is an SSD, it's better not using a swap partition in favor of a swap file or zram.

All my machines are running zram, it's working well.

4 points

Interesting about ZRAM, if I decide to use zram, what happens to my swap partition? what settings need to be made? a guide for dummies please

2 points

It's quite easy. First of all remove (or comment out) your swap partition entry from /etc/fstab to disable it from next reboot.

(optional) disable swap for your current session with swapoff /dev/<yourswappartition> where <yourswappartition> is your current active swap, you can find it with cat /proc/swaps

For zram I chose the easy way: installing zramd script from AUR which will take care of everything. Just use your favourite AUR helper (like yay or paru) to install it, eg. paru -S zramd.

After install make sure zram will be enabled at every boot and start it with sudo systemctl enable --now zramd

Reboot to verify all went well and it started automatically. If the output of swapon --show shows something like /dev/zram0 under NAME column it should be all good, with the same command you will see also the zram size and priority.

By default it dedicates to zram up to 8GB of ram. With a maximum allowed size equal to your physical memory size if lower than 8GB. Don't worry, it's ok to use all ram: it just compresses ALL memory pages, taking way less physical memory space. If your CPU isn't from ages ago it won't impact at all on overall performance. Anyway, you can change default values editing /etc/default/zramd file then reloading the service with sudo systemctl restart zramd

Further info on dev GitHub page: https://github.com/maximumadmin/zramd

7 points

Do you need a partition? No, a swapfile is also a valid option.

Do you need some form of swap space in general? Almost certainly, yes.

2 points

How did you get PoE to use so little ram? I typically see it go WAY higher lol

1 points

I just installed it by using Steam with Proton Experimental.

1 points

Sounds like adding more swap space might be a good idea. You don't even need another swap partition, Just create a swap file in whatever directory you want and add it to the end of your fstab.

1 points

Necessary? No. Useful? Yes.

Even on high-end machines, it's useful to have swap. It's more about anonymous vs file pages management, rather than using it as "emergency memory", but i don't remember much at this point.

You also need it to hibernate the PC, iirc.

1 points

You might not need a swap partition, but you want to set up a swap file

1 points

My take is that Swap is not necessary anymore (when talking about PC with common usage) but for what it takes (namely a few GB files or partition) I don't really see why you wouldn't do it.

1 points
unknown author

Deleted before we saved it.

0 points

Swap is used to keep the most frequently accessed files and program data in RAM, as I understand it. Generally on an HDD you want to avoid swapping as the disk is very, very slow at giving the data back when needed. On an SSD it's a lot more practical at extending your RAM if you don't have enough.

You also need a swap partition to hibernate.

-6 points

You're being down voted because that's not what swap is for. Swap is a way of increasing memory available to processes so that if you run out of RAM you don't have to completely purge it. You're right that this is very slow and to be avoided.

2 points

If that's not what swap is for, why does the swappiness tunable exist? When swappiness is higher Linux prioritizes keeping the page cache (which holds files) in RAM. When it's lower it prioritizes discarding the page cache to maintain more program data in RAM.

0 points

Swap is definitely not needed on modern hardware running typical home/office/gaming type applications. Modern systems do a much better job at memory management, and have a lot more memory to work with, so having free ram and unused swap is not really a big deal.

-11 points

Modern systems do a much better job at memory management

Yes, and a big part of that memory management is to move unused memory pages out of memory, so that more memory space is available for caching things (and thus improve overall system performance).

And the space where those inactive pages go is… the swap space.

5 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.