Enhanced heuristics for determining the swap file size in swap-file-creator?

I just finished installing Debian 12 onto a USB flash drive, then distro-morphing it to Kicksecure on my primary development laptop. The laptop has 32 GB RAM, while the flash drive is about 128 GB. I noticed swap-file-creator report it was creating a swapfile that was around 45 GB in size. I can see how this probably happened (I’m guessing it’s making a file equal to RAM size plus 50%), but two things come to mind:

  • Creating a 45GB swap file is almost certainly overkill.
  • Creating a swapfile that takes up over 35% of available disk space is almost certainly overkill.

By default, Debian chose to give me a swap partition that was only 1 GB in size, which seems much more reasonable for systems that have lots of RAM like mine. Then again, for someone with very little RAM, 1 GB of swap probably doesn’t make much sense and creating a swapfile equal to 1.5x RAM size would be helpful.

Should we change the algorithm used for determining swap file size? Perhaps 1.5x RAM is fine in general, but we should cap the maximum size to 8 GB or so. Taking into account the size of the storage device would probably also be a good idea.

1 Like

Yes, please.

calculate-swap-size and/or swap-file-creator/usr/share/swap-file-creator/swap-file-creator at master · Kicksecure/swap-file-creator · GitHub improvements are most welcome.

1 Like

I realize now after reading the code that I shouldn’t have assumed my particular Kicksecure installation had all of the latest changes. I see now that the reason I ended up with a 45 GB or so swapfile was because hibernation was being taken into account, whereas the most recent code in Git appears to have hibernation not taken into account unless explicitly configured otherwise. I didn’t realize I was working on outdated packages, though I see it now.

Looking at the heuristics, I think the only change I want to make outside of general code quality improvements is that I’d like to cap the swapfile size to no more than 10% of the size of the disk. That way if someone boots up a powerful machine from a tiny drive like I did, the swapfile doesn’t end up taking too much space, and it doesn’t end up not being created at all. I’ll implement that.

1 Like

This is done in Kicksecure 17.2.7.8 - Point Release! and above.