Swap or not swap on an SDcard?

Hi,

There are a lot of yunohost instance without swapfile, it could be dangerous during installation/remove operation (or simply could create service instability).

Swapfile of 1GB can be added really simply:

dd if=/dev/zero of=/swapfile bs=1024 count=1048576
mkswap /swapfile
swapon /swapfile
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab

On hard drive disk no doubt you should add it, but on SDcard (like in the internetcube) the swapfile could accelerates the end of life of your SDcard.

Any idea how we should properly manage this in YunoHost ?

I suggest to add it automatically (during the yunohost upgrade) if it’s an hard drive or if the device has less than 1GB RAM. What’s your point of view.

Note: if your / is on a sdcard the better will be to put your swap file on a small usb disk (1GB)

3 Likes

I think on SDcard we can reduce the swappiness of swap. Lesser the value,system will put less data on swam and use up the ram first.

I think setting swappiness to 10 is ok.

Edit /etc/sysctl.conf
nano /etc/sysctl.conf

and add this in the last line of /etc/sysctl.conf
vm.swappiness=10

3 Likes

for the first 3 commands I can (have to) use sudo, but the last command didn’t work with sudo for me ("permission denied).
So I’ve added this at the end of /etc/fstab with sudo nano …

/swapfile swap swap defaults 0 0

It’s also important to do chmod 600 /swapfile

La regrettée solution zRam

Fondamentalement, zRam permet au système d’utiliser la RAM comme espace d’échange, mais dans un mode compressé qui lui permet d’apparaître comme un ensemble RAM + Swap plus grand que la mémoire présente sur le système…

zRam était compilé dans le noyau Raspbian à ses débuts mais… en est à présent absent (trop peu utilisé…?)

256 mo suffirait Ă  mon sens
pour de l auto-hebergement sur RaspberryPi qui à mon sens est le principal matériel utilisé (Selon moi :slight_smile: et quasi inutile sur ce type de support carte SD ( pas de moi cette fois )
je rejoins @kanhu sur l’idee de diminuer la partition mais seulement sur l image Yunohost pour RaspberryPi

Ah ça expliquerait pourquoi j’ai pu l’installer sur un de mes raspberry et pas l’autre ? :thinking:

En tout cas c’est très efficace pour palier aux pointes de consommation en RAM qui sinon ferait planter le système et/ou ralentiraient considérablement les performances.

1 Like