Linux Performance: Why You Should Almost Always Add Swap Space

Originally published at: https://haydenjames.io/linux-performance-almost-always-add-swap-space/

We know that using Linux swap space instead of RAM (memory) can severely slow down performance. So, one might ask, since I have more than enough memory available, wouldn’t it better to delete swap space? The short answer is, No. There are performance benefits when swap space is enabled, even when you have more than…

I think swap space is usually only recommended when you don’t have much ram. If you have 8 gigs or more, I wouldn’t say it is necessary for a home user. Most computers these days have plenty out the box, even more if you build one yourself.

1 Like

I think it depends more on the CPU really, I have 8GB RAM and 15 GB of swap but my processor is only a dual core so it helps out alot to have that. Guess I’ll find out for sure when I get my 12 core AMD with 128 GB of RAM when I get all growed up :stuck_out_tongue_closed_eyes:

I thought similar. I don’t really setup swap unless I have a 4gb machine. Otherwise, for standard usage, never had an issue. :+1:

I have this set up on my laptop and the main reason is that it is only 6gb. I can probably do without it but I like to maintain a certain speed when using it. It is an older laptop and I plan to get a new one soon anyway.

The article addresses this. Even on a healthy system its useful to encourage opportunistic swapping. The longer your uptime will be, the more important opportunistic swapping becomes. On a system you shut down every day, not so much.

Generally unless the ram we install or configure comes free of cost, we should only install just a tad more than the system needs to run. Anything more is a waste of :moneybag:.

Overabundance of RAM is about the the only time opportunistic swap isn’t useful. For example if one has 64GB of RAM on a server or desktop and after days or weeks of uptime only half of it is used, then its literally wasted hardware and thus no need for opportunistic swapping to move the LFU or rather LRU data to the disk in order to ensure ram is being used just for the most active stuff.

Swap is kinda like those couple of boxes we have sent to storage because we never open or use the items inside. But if the # of boxes continues to grown, then it becomes obvious we may need a bigger house.

But living without swap is like living without storage and just stepping over very old and seldomly accessed data, because there’s no storage unit to put them in.

Or, a family of 3 living in a 8 bedroom house, yup, definitely may not need a storage room. At least with a mansion we can make use of all of it if we choose to. But with RAM if you can only make use 3GB and you have 8GB it just sits there, never used.

2 Likes

I have 16GB on my laptop,but sometimes i use swap on my systems depending on what my use case will be,might however not be needed,but what if i suddenly need it someday…so better safe than sorry maybe?:slight_smile:

Loved this read (and Part 2).

It was very interesting reading about ZRAM–particularly (like you mentioned) with the memory-saving benefits it comes with–and a good refresh on how the Linux kernel manages memory pages to optimize memory performance and availability.

The advantage of allowing enough response time for admins is huge (especially with a monitoring/alert system that may or may not be in place), conceptually at least.

Will be taking note of the memory management commands, thanks again @hydn :+1:

2 Likes

Thanks for taking a moment to leave this feedback. It makes me realize what’s been lacking for the past ten years; being able to mingle, share, learn and understand the different perspectives of peers.

I’ll post up part 2 to the Blog articles forum.

This week I gutted the blog menu to focus more on allowing readers to find the articles which interest them. You can view that here:

2 Likes