Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Swap & How Big?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
OldTango
l33t
l33t


Joined: 21 Feb 2004
Posts: 630

PostPosted: Sat Nov 30, 2019 9:45 pm    Post subject: [SOLVED] Swap & How Big? Reply with quote

How do I best determine how big a SWAP DRIVE/(PARTITION) needs to be and is there a point when it becomes completely unnecessary?
Is there some application or script I can use to log the use of swap over time to see how often and how much swap the system has used?

I have read several posts and seen many recommendations over the years on how big a SWAP DRIVE/(PARTITION) should be. However most recommendations like (2 times the system ram or 1GB for each CPU Core) seem excessive and a waste of disk space for a basic desktop (user) on many of today's modern systems.

From the current Gentoo Handbook
Quote:
What about swap space?

There is no perfect value for the swap partition. The purpose of swap space is to provide disk storage to the kernel when internal memory (RAM) is under pressure. A swap space allows for the kernel to move memory pages that are not likely to be accessed soon to disk (swap or page-out), freeing memory. Of course, if that memory is suddenly needed, these pages need to be put back in memory (page-in) which will take a while (as disks are very slow compared to internal memory).

When the system is not going to run memory intensive applications or the system has lots of memory available, then it probably does not need much swap space. However, swap space is also used to store the entire memory in case of hibernation. If the system is going to need hibernation, then a bigger swap space is necessary, often at least the amount of memory installed in the system.


The reason I ask is two fold:

One: In the next few months I will be converting to High Speed NVme drives which are more costly and typically smaller than HDD's. So it seems configuring swap space will be more critical (space wise) on these drives.

Two: It appears that my main system which is a AMD 1950x (16core/32thread) Threadripper with 128GB of ram using a 1TB HDD configured with a 2GB swap partition has never touched the swap partition even under heavy workloads.

TIA..... :)


Last edited by OldTango on Mon Dec 02, 2019 12:19 am; edited 1 time in total
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 45383
Location: 56N 3W

PostPosted: Sat Nov 30, 2019 10:07 pm    Post subject: Reply with quote

OldTango,

With 96 cores (single threaded) I can't get the system to use more than 80G of RAM and I've tried.
I had the load average up to 300 building firefox, chromium and libreoffice concurrently.

Swap is used for two things, swapping and hibernating.
For hibernate, swap = RAM is plenty as hibernate images are compressed.
If you don't us hibernate, swap is used as a home for pages of dynamically allocated RAM in times of memory pressure.

Not having swap space does not prevent the kernel swapping. It removes one of its options.
The kernel can still drop any read only memory it wants to, including code.
It can still write 'dirty' buffers out and drop them from RAM.

Consider using a swap file rather than a swap partition. You can always add that later.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3768
Location: Hamburg

PostPosted: Sat Nov 30, 2019 10:40 pm    Post subject: Re: Swap & How Big? Reply with quote

OldTango wrote:
with 128GB of ram using a 1TB HDD configured with a 2GB swap partition
Well, at my server (Xeon, 6 core, 128 GB RAM) I do have a swap file of 32 GB which is almost empty except for few dozen ore hundreds of MB. I like to have such a fall back.
But in your case 2 GB seems IMO way too small compared to 128 GB. So either do not have swap at all or have a bigger one.
Back to top
View user's profile Send private message
Makersmarx
n00b
n00b


Joined: 16 Feb 2019
Posts: 39
Location: Costa Rica

PostPosted: Sun Dec 01, 2019 12:40 am    Post subject: Reply with quote

Ive always just figured, why not if I have the space. Is swap needed in 99% of the use cases with my lesser Ryzen system...nope, but in case it is needed I have it available.
_________________
Pura Vida
Back to top
View user's profile Send private message
Ionen
l33t
l33t


Joined: 06 Dec 2018
Posts: 691

PostPosted: Sun Dec 01, 2019 3:22 am    Post subject: Reply with quote

Yeah, even if not using hibernation, a small swap file is always handy as a bit of a buffer for rare cases or if something just went wrong (could be unintended) and gives you time before processes start being killed for running out of memory which could be something important to you. I do set vm.swappiness = 1 (sysctl) to prevent its usage unless necessary though (aka I typically have 0 swap usage, prevents drives from working / using write cycles for nothing).

Edit: To explain, it's the % before it activates (or so I've read anyway), borderline 1% is good enough for me as a last resort, the default is when down to 60% free memory (this is better for low memory systems that need to manage this a lot, but if being halfway full means you still have a whole lot of ram then 10-20% or less makes more sense, I typically fill that much from heavy tmpfs usage but I'm not exactly in RAM troubles).
Back to top
View user's profile Send private message
OldTango
l33t
l33t


Joined: 21 Feb 2004
Posts: 630

PostPosted: Sun Dec 01, 2019 10:08 pm    Post subject: Reply with quote

NeddySeagoon wrote:
OldTango,

Consider using a swap file rather than a swap partition. You can always add that later.

Thank you this is very helpful. It seems a swap file may be more useful than an actual drive partition.

Dose the swap file need to be on the root partition or could it be on a partition of a different drive?
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 45383
Location: 56N 3W

PostPosted: Sun Dec 01, 2019 10:40 pm    Post subject: Reply with quote

OldTango,

Its wherever you say it is in /etc/fstab.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
OldTango
l33t
l33t


Joined: 21 Feb 2004
Posts: 630

PostPosted: Sun Dec 01, 2019 11:39 pm    Post subject: Reply with quote

NeddySeagoon wrote:
OldTango,

Its wherever you say it is in /etc/fstab.
I thought so but wasn't sure. I have always followed the Handbook's advise concerning swap and using HDD's >=1TB, space wasn't an issue. Never gave it much thought after that. Now that high speed SSD's are more advanced with more and more vendors building products supporting them it seems like a good time to give them a go. The research I've done so far into how flash memory works and wears makes me think that an actual swap partition on such a device would be far less advantageous than a swap file. Please correct me if my thinking hear is wrong but dosen't creating a swap partition make that portion of a drive unusable for anything but swapping. If so and swapping rarely if ever occurs will it have any effect on how the device wears?

Again Thanks
Best Tango
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 45383
Location: 56N 3W

PostPosted: Mon Dec 02, 2019 12:01 am    Post subject: Reply with quote

OldTango,

Modern SSDs have a layer of indirection at the erase block level, so the concept of a partition consisting of a contiguous range of physical blocks on a drive does not exist for SSDs.
Its an illusion preserved by the SSD moving things around to perform wear levelling.
That's not under user control.

Even things that do not change are wear levelled. That is, the drive copies the data to another block and swaps the old and new block out.

Swap partitions on an SSD are trimmed on mount. A swap file is a part of the filesystem, so won't be trimmed. It depends on the filesystem for that.
Both reserve space, Both will be considered for wear levelling, used or not.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
OldTango
l33t
l33t


Joined: 21 Feb 2004
Posts: 630

PostPosted: Mon Dec 02, 2019 12:18 am    Post subject: Reply with quote

NeddySeagoon wrote:
OldTango,

Modern SSDs have a layer of indirection at the erase block level, so the concept of a partition consisting of a contiguous range of physical blocks on a drive does not exist for SSDs.
Its an illusion preserved by the SSD moving things around to perform wear levelling.
That's not under user control.

Even things that do not change are wear levelled. That is, the drive copies the data to another block and swaps the old and new block out.

Swap partitions on an SSD are trimmed on mount. A swap file is a part of the filesystem, so won't be trimmed. It depends on the filesystem for that.
Both reserve space, Both will be considered for wear levelling, used or not.
WOW thanks you just answered all of my questions in a very clear and understandable way.

Have a beer on me..... :wink:
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum