Skip to content
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

Implement config panel for swap management #1858

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
Open

Implement config panel for swap management #1858

wants to merge 11 commits into from

Conversation

tituspijean
Copy link
Contributor

@tituspijean tituspijean commented May 30, 2024

The problem

Swap management is non existent on YunoHost, and we historically let apps set their own, which has made many core dev very angry and has been widely regarded as a bad move.

Solution

  • Shamelessly take and adapt the experimental swap helpers
  • Implement a config panel

PR Status

Tested, works for me. Please try :)

How to test

...

@tituspijean tituspijean marked this pull request as ready for review May 30, 2024 22:11
@tituspijean
Copy link
Contributor Author

Some annoying warnings appear in the logs, does anyone know how to mask them?

image

@zamentur
Copy link
Member

zamentur commented May 31, 2024

I add a swappiness configuration to avoid to write on ssd if not necessary (in order to extend its service life).

I wonder if we should adapt the code in order to support do_pre_regen and be able to --dry-run or to detect this file is managed by yunohost. However, if someone change the swappiness value, i guess it's for good reasons and we don't need to remember the user that it's configured like that.

@tituspijean tituspijean mentioned this pull request May 31, 2024
if [ -f /swap_file ] && [ $(stat -c%s /swap_file) -ne $swapfile_size ]; then
# Let's delete it first if it is not of the requested size
ynh_print_info --message="Deleting swap first..."
ynh_del_swap
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really dangerous. Let's imagine this situation:

  • RAM is 1GB, usage 900MB, Swapfile is 1GB, usage 500MB
  • you want a 2GB swap file now, so we fall into this code
  • ynh_del_swap deletes the original swap file, making the server (or services) most probably crash from OOM (1.4GB required on a 1GB available ram)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two better solutions would be :

  • just create a second swap file of size = difference (in my example, 2GB(total) - 1GB(existing) = 1GB new swap file)
  • create a second swap file of the total requested swap size, then afterwards delete the old file. The danger being the disk space but eh, i think we are okay, ram/swap is way smaller than disks usually…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good, thank you for giving some thoughts into this. :)
I had added a very lazy "Beware, if you reduce its current size, you may crash your server." in the config panel, but indeed there are other ways to crash everything.
I think your proposal is good!

helpers/helpers.v1.d/hardware Show resolved Hide resolved
#
# usage: ynh_add_swap --size=SWAP in MiB
# | arg: -s, --size= - Amount of SWAP to add in MiB.
ynh_add_swap () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need an additional helper, that would "just" call yunohost settings {get,set} 'swap.swapfile.swapfile_size' and make new_swap_size = current_swap_size + requested_app_swap_size.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yunohost settings set got me in an infinite config panel loop last night, we need to be careful with calling hooks from confif panels. ;)

@Salamandar
Copy link
Contributor

All in all… I would prefer if swap file creation was NOT linked to apps requesting swap especially, but rather to the RAM usage declared in the apps manifest.

@tituspijean
Copy link
Contributor Author

I completely agree, that's why this is a system config panel, not a general apps config panel.
Maybe we could add a warning that's displayed after we calculate the sum of all requested RAM?

@Salamandar
Copy link
Contributor

I completely agree, that's why this is a system config panel, not a general apps config panel. Maybe we could add a warning that's displayed after we calculate the sum of all requested RAM?

Yeah, something like a button on the app installation page redirecting to the swap config panel you're adding. We already have a warning if the RAM usage reported by the manifest is too high.

Co-authored-by: ljf (zamentur) <zamentur@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants