Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
(solved) swap size?
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
Spanik
l33t
l33t


Joined: 12 Dec 2003
Posts: 963
Location: Belgium

PostPosted: Sat Aug 21, 2021 12:47 pm    Post subject: (solved) swap size? Reply with quote

I just started a new install on the desktop. Reading the handbook, I still come accross:
Code:
/dev/sda2   (swap)   RAM size * 2   Swap partition


Do I really need 128GB swap? That is half of the nvme OS partition.... Maybe this needs an update.
_________________
Expert in non-working solutions


Last edited by Spanik on Sun Aug 22, 2021 2:50 pm; edited 1 time in total
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 8291
Location: Saint Amant, Acadiana

PostPosted: Sat Aug 21, 2021 12:56 pm    Post subject: Reply with quote

Use swap file(s). You can create and activate them at your will, any time. But watch out, not all filesystems support swap.
_________________
My Gentoo installation notes.
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
Ionen
Developer
Developer


Joined: 06 Dec 2018
Posts: 2732

PostPosted: Sat Aug 21, 2021 1:00 pm    Post subject: Reply with quote

It still makes some sense if you have some low'ish amount like 1-2GB, but I agree it's a bit of a crude rule by modern standards.

fwiw if you want to do suspend-to-disk you could, in theory, need up to RAM * 1 = 64GB (that's only if you're currently using as much ram, and I imagine it's gonna be pretty slow).

Doesn't hurt to have a little bit of slow swap as a buffer before the OOM killer start killing things either way (even with large amounts of RAM, it's cheap to have a some small 2-6+GB).
Back to top
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Sat Aug 21, 2021 2:26 pm    Post subject: Reply with quote

If you have 64GB of RAM, you probably won't need any swap space at all.

I haven't had swap on any of my machines for more than 10 years - and I have never missed it.

A swap partition Swap space of at least the size of your RAM is required if you want to use the sleep state 'hibernation'. Do you want to use 'hibernation'?


Last edited by mike155 on Sat Aug 21, 2021 3:36 pm; edited 1 time in total
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 8291
Location: Saint Amant, Acadiana

PostPosted: Sat Aug 21, 2021 3:00 pm    Post subject: Reply with quote

mike155 wrote:
A swap partition of at least the size of your RAM is required if you want to use the sleep state 'hibernation'. Do you want to use 'hibernation'?

Swap partition is not required for hibernation, swap space is. It can be a file. Also, some allege swap files are slower, not true. I maintain using swap file(s) is much more flexible than partition(s). With files you can change your mind any time and increase/decrease swap space. Once I saw my box running out of swap space building chromium, I managed to create and activate an additional 2 GiB of swap before OOM killer kicked in.

OTOH, having 64 GB of RAM is terribly excessive, it will never be used during normal operation of a desktop machine. To add 128 GB of swap to it is in harmony.
_________________
My Gentoo installation notes.
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Sat Aug 21, 2021 3:41 pm    Post subject: Reply with quote

Jaglover wrote:
mike155 wrote:
A swap partition of at least the size of your RAM is required if you want to use the sleep state 'hibernation'. Do you want to use 'hibernation'?

Swap partition is not required for hibernation, swap space is.

You're right. I changed my post above.

Quote:
OTOH, having 64 GB of RAM is terribly excessive, it will never be used during normal operation of a desktop machine.

Be careful! Do not make the same mistake as Bill Gates. :D :D :D
Back to top
View user's profile Send private message
steve_v
Guru
Guru


Joined: 20 Jun 2004
Posts: 399
Location: New Zealand

PostPosted: Sat Aug 21, 2021 6:32 pm    Post subject: Re: swap size? Reply with quote

Spanik wrote:
Do I really need 128GB swap?
Lol. No, no you do not. At least not for any sane desktop configuration.
To quote the RHEL manual (yes, blasphemy I know, but them's reasonable numbers):
Code:

Amount of RAM in the system    Recommended swap space       Recommended swap space if allowing for hibernation

⩽ 2 GB                        2 times the amount of RAM     3 times the amount of RAM
2 GB – 8 GB                   Equal to the amount of RAM    2 times the amount of RAM
8 GB – 64 GB                  At least 4 GB                 1.5 times the amount of RAM
> 64 GB                       At least 4 GB                 Hibernation not recommended


Jaglover wrote:
some allege swap files are slower, not true.

It kinda was true, once. It really doesn't matter on solid-state storage though.
_________________
Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.
Back to top
View user's profile Send private message
Spanik
l33t
l33t


Joined: 12 Dec 2003
Posts: 963
Location: Belgium

PostPosted: Sat Aug 21, 2021 6:40 pm    Post subject: Reply with quote

Jaglover wrote:

OTOH, having 64 GB of RAM is terribly excessive, it will never be used during normal operation of a desktop machine. To add 128 GB of swap to it is in harmony.

Having 8 ram slots on the motherboard that needs 4 of them populated and then finding only 16GB supported ram modules... you end up with 64GB. And now I even have only half the memory bandwidth!

steve_v wrote:
To quote the RHEL manual (yes, blasphemy I know, but them's reasonable numbers):

Looks more reasonable. I do not need hibernation. This is a desktop that is regulary shut down and powered down.
_________________
Expert in non-working solutions
Back to top
View user's profile Send private message
CooSee
Veteran
Veteran


Joined: 20 Nov 2004
Posts: 1456
Location: Earth

PostPosted: Sat Aug 21, 2021 6:49 pm    Post subject: Reply with quote

i never used 'swap' since i have 32GB RAM and no problems at all, even with big compiles like 'ungoogled-chromium', while watching stream and browsing through web.

suspend on a desktop system never made sense to me - if i don't use the computer i just shut down.

suspend only makes sense on a notebook.

just my two cents :)
_________________
" Die Realität ist eine Illusion, die durch Mangel an ehrlicher Kommunikation entsteht "
---
" Der Mensch ist von Natur aus neugierig, was am Ende übrig bleibt ist die Gier "
Back to top
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Sat Aug 21, 2021 7:00 pm    Post subject: Reply with quote

I added a comment on the discussion page of our handbook. See: https://wiki.gentoo.org/wiki/Handbook_Talk:AMD64/Installation/Disks, last paragraph.
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 21849

PostPosted: Sat Aug 21, 2021 7:12 pm    Post subject: Reply with quote

Both suspend and hibernate make great sense to me. When I don't need my system, I suspend it, so that everything is where I left it when I return. This is more convenient than trying to get every program I use to correctly remember its state and reopen itself on next boot, each with all their interactive per-instance history.

Hibernate is nice for cases where I would suspend, but I expect a thunderstorm to knock out power. Once hibernated, the system can survive a complete loss of wall power during the storm. After the storm passes, I can turn back on and again be where I was.
Back to top
View user's profile Send private message
CooSee
Veteran
Veteran


Joined: 20 Nov 2004
Posts: 1456
Location: Earth

PostPosted: Sat Aug 21, 2021 7:16 pm    Post subject: Reply with quote

thanks @mike155
--

i hope it's ok to ask, but how Apple is handling or using 'suspend', because imho they do it perfectly on their devices.
_________________
" Die Realität ist eine Illusion, die durch Mangel an ehrlicher Kommunikation entsteht "
---
" Der Mensch ist von Natur aus neugierig, was am Ende übrig bleibt ist die Gier "
Back to top
View user's profile Send private message
steve_v
Guru
Guru


Joined: 20 Jun 2004
Posts: 399
Location: New Zealand

PostPosted: Sat Aug 21, 2021 7:43 pm    Post subject: Reply with quote

CooSee wrote:
i never used 'swap' since i have 32GB RAM and no problems at all

It's not really needed on a machine with plenty of RAM, but it's still potentially beneficial if the kernel can page out cruft that hasn't been used in forever to free up RAM for cache and buffers.
Anecdotally, I've also found that having at least a little swap makes the system more likely to deal with an OOM situation gracefully if it ever does arise.

CooSee wrote:
suspend on a desktop system never made sense to me - if i don't use the computer i just shut down.

suspend only makes sense on a notebook.

I just never shut anything down. :lol: That and I've had an UPS (the same UPS even) since 1996.
Power saving modes I get, and maybe even suspend... But yeah, hibernation is for laptops IMO. It's certainly not something I'm going to reserve a significant fraction of an SSD for in any case.


CooSee wrote:
just my two cents :)

Four cents is better than two, right? :P
_________________
Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.
Back to top
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2023

PostPosted: Sun Aug 22, 2021 10:20 am    Post subject: Reply with quote

Hu wrote:
Both suspend and hibernate make great sense to me. When I don't need my system, I suspend it, so that everything is where I left it when I return. This is more convenient than trying to get every program I use to correctly remember its state and reopen itself on next boot, each with all their interactive per-instance history.

Hibernate is nice for cases where I would suspend, but I expect a thunderstorm to knock out power. Once hibernated, the system can survive a complete loss of wall power during the storm. After the storm passes, I can turn back on and again be where I was.

Hibernate is, of course, also very useful for portable devices to save battery during travel. Or so I've heard - I can't get it to work on mine! (AMD no longer bother to test if their drivers will hibernate, and mine definitely doesn't.)

Don't forget there's the hybrid sleep (don't remember its real name) that does the IO to create a hibernate image, but then sleeps. If you open the box before the power goes off, it wakes from suspend. If the power goes off, when you reconnect it resumes from hibernate.
_________________
Greybeard
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 21849

PostPosted: Sun Aug 22, 2021 4:26 pm    Post subject: Reply with quote

Agreed, power-saving states (both suspend-to-ram and suspend-to-disk) are great for mobile devices, and suspend-to-disk is nice for any device where you know it will be off wall power for long enough that the extra seconds of resuming from disk are worth the battery time saved by not using suspend-to-ram. I was focusing on CooSee's comment that suspend didn't make sense on a desktop, but only made sense on a notebook. I wanted to present cases where suspend makes sense for any device that cannot, on its own, readily restore its state.

I've sometimes seen the hybrid mode referred to as suspend-to-both. That's how sys-power/suspend describes it (via the utility s2both).
Back to top
View user's profile Send private message
Maffblaster
Developer
Developer


Joined: 01 May 2007
Posts: 70
Location: Spokane, Washington, USA

PostPosted: Sun Feb 18, 2024 1:43 am    Post subject: Reply with quote

I have implemented a table to help readers make a more reasonable choice for swap size:

https://wiki.gentoo.org/index.php?title=Handbook%3AParts%2FBlocks%2FDesigningPartitionScheme&type=revision&diff=1282171&oldid=1214646

Thanks to Mike155 for raising to my attention in the discussion here :arrow: https://wiki.gentoo.org/wiki/Handbook_Talk:AMD64/Installation/Disks#Recommendation_on_swap_scape_is_outdated
_________________
Lets make Gentoo better together!
wiki: https://wiki.gentoo.org/wiki/User:Maffblaster
blog: http://dev.gentoo.org/~maffblaster/
Back to top
View user's profile Send private message
figueroa
Advocate
Advocate


Joined: 14 Aug 2005
Posts: 2971
Location: Edge of marsh USA

PostPosted: Sun Feb 18, 2024 5:53 am    Post subject: Reply with quote

I've been working my way down to setting aside less swap. My desktop has 16 GB or RAM and I currently set aside an 8 GB partition for swap on a secondary hard drive. I never see swap actively used, but the system currently has @ 32 MB or swap in -use. There are three large, internal hard drives, all spinning rust, so the disk space isn't much of a consideration.

My home server and home desktop both run 24/7. At night, they do housekeeping chores, including (most importantly) backups. These two computers only get turned off for hardware repair or changing of UPS batteries. However, I do normally shut down all application programs and log off at the end of each day. This leaves my system, the GUI in particular, in a sound, idle state for sane backups. Obviously I don't suspend or hibernate these two machines.

My old and humble notebook, when in use, just gets turned off when not in use, and I have to run backups manually. It only has 4 GB or RAM and a 4 GB swap partition. On the other hand, my wife's main computer is a laptop with 8 GB or RAM. She closes the lid when not in use, which eventually causes it to suspend but not hibernate. She finds it very handy that way. She has a small swap partition just for assurance that it's there when needed. Her backups are triggered by anacron, and she tells me that she doesn't really notice the extra load when backups are taking place. Backups are initially made to an always installed SD card, and then archived to the home server over NFS.

If one does suspend or hibernate (or turn off) their computer, extra consideration should be given to when and how backups are to be made, preferably automatically in some manner.
_________________
Andy Figueroa
hp pavilion hpe h8-1260t/2AB5; spinning rust x3
i7-2600 @ 3.40GHz; 16 gb; Radeon HD 7570
amd64/23.0/split-usr/desktop (stable), OpenRC, -systemd -pulseaudio -uefi
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Sun Feb 18, 2024 10:11 am    Post subject: Reply with quote

Swap space is not the kernels only mechanism for swapping.

The swap partition/file is only used as a temporary home for dynamically allocated RAM. That is, things that have no permanent home on storage.
Things like executable code, input data and even output data, can be dropped and reloaded.
Dirty (output) buffers must be flushed before they can be dropped.

This has some interesting side effects.
Programs that cannot be fitted into available RAM cam still be executed. Its OK to mmap the same pages of physical RAM to two (or more) pages of code.
They will be swapped as required. This is slow due the the page faults. But it works.

The same is true with input and output buffers, with the rider that data that is only in RAM must be flushed to disk first.

From the above it follows that not having a swap partition/file only puts pressure on the other 'swapping' mechanisms.

That does not mean that a swap partition/file is required but its a useful diagnostic tool.
_________________
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
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3403
Location: Rasi, Finland

PostPosted: Sun Feb 18, 2024 10:40 am    Post subject: Reply with quote

Jaglover wrote:
Use swap file(s). You can create and activate them at your will, any time. But watch out, not all filesystems support swap.
Or if lvm is being used, swap partition (logical volume) can be added, removed and/or resized easily.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
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