Hi all,
I have a question regarding zram
.
Reading up on the subject on https://discourse.lubuntu.me/t/enabling-ram-compression-on-lubuntu/3323/1 I found out that it might make sense to enable RAM compression (especially on a 4 GB RAM system, as is the case with me).
I don´t want to have it enabled at all times but want to experiment with it first.
Therefore I created the following script (rampak.sh
) and made it executable:
#! /bin/bash
modprobe zram
sleep 1
zramctl --find --size=400M
mkswap /dev/zram0
swapon /dev/zram0
So this would create a 400 MB compressed RAM disk, which then acts as a swapfile.
I first tried it out on my Debian system (vm).
On this system there´s already a swap partition (/dev/vda5):
rosika2@debian ~> sudo swapon -s
Filename Type Size Used Priority
/dev/vda5 partition 999420 0 -2
Now I ran rampaks.sh
:
rosika2@debian ~> sudo /home/rosika2/Dokumente/Ergänzungen_zu_Programmen/zu_RAM-compression/rampak.sh
/dev/zram0
Setting up swapspace version 1, size = 400 MiB (419426304 bytes)
no label, UUID=72b75a83-3f2a-4bf4-b84f-6ca74f88be0a
I checked again:
rosika2@debian ~> sudo swapon -s
Filename Type Size Used Priority
/dev/vda5 partition 999420 0 -2
/dev/zram0 partition 409596 0 -3
So now there are two swap devices active at the same time. Indeed both seem to be in use as I looked it up in top
and realized the size-values were added.
Hmm, now I´m a bit confused :
How does the system know what device to use if it needs swapping
On my host Lubuntu it´s a bit different:
Here I have no swap partition but a swapfile enabled:
swapon -s
Dateiname Typ Größe Benutzt Priorität
/swapfile file 1048572 0 -2
Now I tried running rampak.sh
, which curiously enough failed:
sudo /media/rosika/f14a27c2-0b49-4607-94ea-2e56bbf76fe1/DATEN-PARTITION/Dokumente/Ergänzungen_zu_Programmen/zu_zram/rampak.sh
zramctl: /dev/zram0: Zurücksetzen fehlgeschlagen: Das Gerät oder die Ressource ist belegt
mkswap: Fehler: der Auslagerungsbereich muss mindestens 40 KiB groß sein
swapon: /dev/zram0: Swap-Header konnte nicht gelesen werden
Sorry, that´s in German.
Rough translation:
zramctl: Reset failed: The device or resource is busy
mkswap: Error: the swap space must be at least 40 KiB
swapon: Swap header could not be read
O.K.
Then I turned off the use of the existing swap file: sudo swapoff -a
and after that running rampak.sh
worked.
To experiment a bit further:
I deactivated zram:
sudo swapoff /dev/zram0
sudo zramctl --reset /dev/zram0
and re-activated the use of my original swapfile: sudo swapon -a
Now everything was back to its original state.
Out of curiosity I attempted to run rampak.sh
again and this time it worked immediately - without having to de-activate my swap partition first.
No idea why this couldn´t be achieved the first time but now it worked:
sudo /media/rosika/f14a27c2-0b49-4607-94ea-2e56bbf76fe1/DATEN-PARTITION/Dokumente/Ergänzungen_zu_Programmen/zu_zram/rampak.sh
/dev/zram0
Auslagerungsbereich Version 1 wird angelegt, Größe = 400 MiB (419426304 Bytes)
keine Bezeichnung, UUID=c327f91e-007f-45f0-9e60-050149fd7482
rough translation again:
Swap space version 1 is created, size u003d 400 MiB (419426304 bytes)
no label, UUIDu003dc327f91e-007f-45f0-9e60-050149fd7482
This is the state in Lubuntu now:
swapon -s
Dateiname Typ Größe Benutzt Priorität
/swapfile file 1048572 0 -2
/dev/zram0 partition 409596 0 -3
So basically the same as in Debian aside from the fact in Debian there are two swap partitions whereas in Lubuntu there´s a swap file and a swap partition.
So to ask my original question again:
How does the system know what device to use if it needs swapping
The last entry in swapon-s
is priority? May this be a clue ?
Thanks a lot for your help.
Many greetings
Rosika