-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add swap space in installed system #109
Comments
Indeed the "crashes" I had experienced before had to do with the lack of swap:
Somehow we must bring messges like these to the user's attention, probably through notifications. |
Some things to note, as said by one of the comments at https://news.ycombinator.com/item?id=25789809
Personally I run both my desktop and my server without swap. Running out of memory means that either your hardware has too little RAM and you should buy more, or that your software is not tuned to the hardware that it is running on. Using swap as a band-aid for this problem is not a good solution IMO. Excessive swapping wears out your SSDs and it makes work that should be fast on a system that has enough RAM for it or with right tuning of the sotware, turns into a slow and frustrating experience. I recommend against enabling swapping by default. It's better IMO to have software that consume too much memory actually be killed, so that users will know that they either need to buy more RAM or to modify or replace the software they are using or otherwise adapting the tasks that they are trying to do by using other means of getting them done. |
Thanks for the background information @ctsrc. It seems to me that enabling swap results in a much more stable system where processes don't just get killed. Even though the swap space is almost entirely unused. So for me, adding swap greatly improved things... More opinions wanted. What is your perspective @vermaden? |
https://klarasystems.com/articles/exploring-swap-on-freebsd/
|
In the old times when 512 MB or 1 GB RAM was 'quite large' I believed in the oldschool 2*RAM rule so for 1 GB RAM I would use 2 GB of swap space. Today my laptop has 16 GB of RAM and I can upgrade it to 32 GB RAM when needed. On that 16 GB RAM system I use 1 GB of swap space (on raw GPT partition - not on ZFS) and its used 0% for most of the time. Sometimes it 'hits' 1% but nothing more. I would not waste 32 GB of SSD space for that 2*RAM rule when I have 16 GB RAM and 1 GB swap space is almost always at 0% but 512 MB to 1 GB of 'just in case' swap space should be more then enough IMHO. Hope that helps. |
Thanks @vermaden for commenting.
Please elaborate the logic behind this. During my tests I had the suspicion that swap space helps the system even though very little of it - or nothing at all - actually gets used. Is this suspicion correct? Or why else would you want to up your space from 16 to 17? |
Its 'just in case' there. I do not have anything against swap if some not now needed data can be put on swap and make RAM free. |
For privacy and security: prefer encrypted swap.
Thanks, I was previously unaware of that old-school rule. At some point, probably when I began using a more powerful notebook, I seem to have settled upon 16 GB real + 16 GB swap i.e. A few minutes ago, with around 7 GB of my 16 GB swap partition in use (internal hard disk drive, OpenZFS), whilst restoring two virtual machines from a mobile hard disk drive on USB (3 GB memory allowed for Windows, 4 GB for helloSystem) and building – and whilst those things progress, I'm typing this in Firefox with scores of extensions enabled. More useful than (simply) observing the amount of swap in use, output from:
As expected, the combined memory requirements of those two virtual machines was, on top of everything else, too much, application performance suffered, so I closed the Windows VM. Note the 'red alerts' in the gstat window: YMMV. |
/me wonders what this monstrous thing is It looks like a Hamburger menu that wants revenge for my post about hamburger menus ;-) |
Not revenge :-) but coincidentally it's no longer necessary – https://matrix.to/#/!EKNFbsWSwXpDOGLRex:matrix.org/$QvRs_gkC-1D67x1nQnfR22V-p0w6pUTDJ_QSqfOdpo8?via=matrix.org&via=fosdem.org&via=t2bot.io |
Hamburgers aside,
Thinking back … at the time I might have had only 8 GB real memory in the notebook, with a preference for 16 GB swap. At some point I doubled the amount of real memory, and either:
In any case: 16 GB swap seems good for me. I've had almost all real + all swap used on numerous occasions. Exhaustion (typically leading to an automated kill of Firefox) is extremely rare. YMMV. |
Agreed, you won't get automated kills unless you do run out of memory. This is the advantage of having swap-- you get the clue of the system slowing down hugely. I think it's madness to have windows evaporating in front of your eyes, when no other OS behaves like this by default. No operating system disables swap out of sympathy for the SSDs afaik- it's just what happens with them, and they are far cheaper than they used to be, so this is less of an issue. The performance is also much better. My suggestion would probably be a swap file, for the flexibility mentioned, and also because the user can easily see the size of the file if they were curious about it. It also has the advantage of being much easier to resize. Use truncate rather than dd to create the swapfile. In terms of size... twice the memory up to a maximum of 16 GB as a straw man. It's perfectly possible to allocate extra files if necessary. |
Thanks. Incidentally, (although I don't see any fit for this with the current design of helloSystem): sysutils/swapexd |
Full ack. It would be nice if we could give the user a notification in case RAM and/or even swap is running close to full. (On a 4GB system, having 10-20 tabs open in the Falkon browser can lead to this situation for me - is this normal? I wonder whether Falkon is smart enough to purge the RAM for the background tabs...) |
If ever you want a kernel panic in an out of memory situation, set |
Actually I'd like the largest process to get killed as it is now, but then give some information on screen about what just happened ("The application foo was closed because there is not enough memory"). I think this is how other systems do it? |
From https://lists.freebsd.org/pipermail/freebsd-questions/2014-October/261962.html
Example messages: Out of memory | The FreeBSD Forums |
So possbily we should be running a daemon that watches that file all the time and triggers a dialog box whenever a OOM event happened? I wonder whether this can be done without needing just another background process |
Received this piece of advice:
|
In context: http://freebsd.1045724.x6.nabble.com/The-out-of-swap-killer-makes-poor-choices-td6449386.html Do we need to distinguish between a swap file and a swap partition? No problems here with a GELI-encrypted swap partition. (I'll test with swap disabled … when I last did so, the experience was poor …) |
The problem is with partitioning. So if we really need a swap partition, the installer should set one up right from the start. |
👍 |
As the consensus of experts seems to be that a partition is preferable to files,
indeed.
|
On a related note, I am tempted to do enable RAM compression, something like this:
Instead of |
When might swap become a feature? It's a significant drawback.
Probably not a good idea; see for example openzfs/zfs#7734 |
Does GhostBSD use RAM compression of some sort?
|
Also pretty interesting how macOS does it. According to https://forums.macrumors.com/threads/mac-not-writing-swap-files.2219502/
and
|
Also http://newosxbook.com/MOXiI.pdf (17MB PDF), via http://newosxbook.com/1stEdIsFree.html Chapter 12 "Commit to memory: mach virtual memory" has a subsection titled "Paging Policy Management", which includes a little bit of text about dynamic_pager of macOS. However, that edition of the book came out in 2013 and I don't know how much of the book is still current. Other books which may be more up to date (idk, haven't read em) are available for purchase from the main page of the same site where the author gives the 1st edition away, linked in this comment. |
Hi @ctsrc, interesting reading. Added that book to https://github.com/helloSystem/hello/wiki#must-read. Now, do you happen to know how to achieve a similar logic on FreeBSD? |
Do you know how to do do it? Could it possibly be as easy as changing
to a reasonable value? What would be a "reasonable value"? Maybe if the target disk is larger than 32 GB and is not a removable device, then set
to prevent swap from being created on USB sticks and microSD cards. |
From top(1) DESCRIPTION OF MEMORY:
|
#109 (comment) above from @vermaden. Plus, in FreeBSD Forums:
Reading the latter for the first time, today, I see a case where 10 G swap was insufficient for large PDF files in TeXstudio on a computer with 16 G RAM. https://old.reddit.com/r/freebsd/comments/tnvkoz/-/i25hubu/?context=2 there's a more extreme example. And so on. I habitually prefer 16 G swap when installing FreeBSD. On my everyday notebook (16 G RAM + 16 G swap), I'm very frequently glad that I didn't restrict myself to less. Note:
– I would not give 16 GB of a ~33 GB device to swap. |
Maybe an option to notify, when swap capacity (e.g. as shown by swapinfo (pstat(8)) exceeds a certain percentage, however:
Alarms might create more questions than answers. Too few people are aware of relevant sysctls, and so on.
|
With export
|
Argh. There is something strange going on in When we set When we set Possibly we should disable swap on VMs by default... When we set
Need to retest with real hardware. |
Actually, the problems do not occur on real hardware with a large enough disk. Maybe the
message is totally misleading and just means "not enough space on disk"? |
Swap is working in helloSystem 0.8.1. |
Add swap in installed system
I noticed that the system can lock up in low-RAM situations, which can happen when editing video with Shotcut while running a web browser on a machine with 4 GB RAM. Hence we should add some swap space by default.
One way would be to use a swap partition/dataset. This would probably be the cleanest way.
Another way would be to add a swap file along those lines. This has the advantage that it can be done retroactively without having to repartition the disk. (But thinking about ZFS, one can probably also retroactively add a dedicated dataset for swap without having to repartition...)
What is the best practice when it comes to swap on ZFS?
Windows automatically uses dynamically growing swap files (I think).
What does the Mac do?
The text was updated successfully, but these errors were encountered: