How to increase the swap file size on Home Assistant OS

Anyone noticed increased swap and memory use after upgrade to HAOS 10.
My RAM use jumps to 97% after upgrade to HAOS 10 and even 10.1 doesn’t solve it.

image

even @falstaff321 suggestion doesn’t solve the issue `

swapoff /mnt/data/swapfile
dd if=/dev/zero of="/mnt/data/swapfile" bs=1M count=2048
mkswap /mnt/data/swapfile
chmod 600 /mnt/data/swapfile
swapon /mnt/data/swapfile

update:
Swap use also in over drive

image

I’ve upgraded and don’t have that issue. It kinda suggests that one of your add-ons or a device integration is the cause. I would try disabling some temporarily and enabling one at a time while watching swap use.

Thanks a lot for your feedback!

I just integrated in the last update this which corrects the behavior of the addon:

  • Support for resizing the swap file when the configuration changes.
  • Automatically remove old swap file when changing the swap location in the configuration.

I hope you like it :slight_smile:

1 Like

Nice work @TazzerMAN !!!

Minor inconvenience… I started the container after upgrading and had the default swap of like 800MB. Then I restarted, still 800. I then changed my 3072 back to 2048 and started, got my 2048. Then went to 3GB and restarted the container/add-on again and got my 3GB of swap. Works with minor quirks but no complaints, I like it :slight_smile:

1 Like

Hello,

Did anyone else have the issue that the default swapfile that HAOS created after first installation is huge (11GB), leaving only 500mb left in a 16gb ssd, causing to not restore a backup and continue?

So I want to reduce the swapfile but I can’t install any addons. I created a new topic, and because this is the most related topic that I found, I hope it’s ok to share my weird problem here.

Thanks very much for the Add-On. I can finally apply ESPHome updates without my Raspberry Pi 4 2GB locking up.

1 Like

Thanks! Works perfect :+1:
However, first install gave an error. After reboot, I was surprised to see addon was installed and working. :grin:

1 Like

Hi @TazzerMAN , or somebody else,

I’m using the addon but like to go back to default, so back to standard.
The reason why is because (I’m not 100% sure) my RPi powers off after x-hours after using the addon.
Can you let me know how to do that??

Thanks! Everything worked as advertised. Made my day. My RPi 3B will live another day.

1 Like

Uninstall and reboot.
Should be enough.

Brilliant, this should be an official addon! @frenck

1 Like

Does this mean its successful? How do I check?

You can check by typing htop and looking in the top for the swap size and usage.

But to answer your question, no, you are doing it wrong. You are not typing the command into the terminal window. You are adding that command to the settings of the Terminal addon.

So on boot the SWAP is recreated?

image

No, on start of the addon is recreated to the size that you set (2GB in your example)

Yes, that is how it supposed to be, but if not working, then there is a line to enter init_commands, paste it there without the beginning and it will take care of it.

You need to save the settings and restart the addon. Look at the log then and you will see how the command was activated during the start of the addon.

So I want terminal to start on boot of HA so this command will run right?

Yep, but follow the instructions from the first post, and change the username and password, because it allows ssh access to your HA, being Terminal and SSH addon.

1 Like

Just came to say that this still works in 2024-05 :grimacing:

1 Like

@mararn1618 which did you use? Whats in my original post?

I used it on my system today:
Core 2024.5.5
Supervisor 2024.05.1
Operating System 12.3
Userinterface 20240501.1

Worked fine - I am running Advanced SSH & Web Terminal (version: 18.0.0)

I used this under init_commands in the settings:

if [ ! -f /backup/_swap.swap ]; then fallocate -l 2G /backup/_swap.swap && mkswap /backup/_swap.swap && chmod 0600 /backup/_swap.swap && swapon  /backup/_swap.swap ; elif [[ ! $(dmesg|grep _swap.swap) = *swap\ on* ]] ; then swapon /backup/_swap.swap ; else swapon /backup/_swap.swap ; fi
1 Like