... | @@ -931,20 +931,72 @@ If you find that the swap file is too large or too small, you can resize it. |
... | @@ -931,20 +931,72 @@ If you find that the swap file is too large or too small, you can resize it. |
|
|
|
|
|
1. Before you resize the swap file, you should turn the swap off. You should also make sure that you have enough free RAM available to take the data from swap file. Otherwise, create a temporary swap file.
|
|
1. Before you resize the swap file, you should turn the swap off. You should also make sure that you have enough free RAM available to take the data from swap file. Otherwise, create a temporary swap file.
|
|
|
|
|
|
```sh
|
|
```sh
|
|
sudo swapoff /dev/zram0
|
|
sudo swapoff /dev/zram0
|
|
```
|
|
```
|
|
|
|
|
|
2. Reset and resize the ZRAM.
|
|
2. Reset and resize the ZRAM.
|
|
|
|
|
|
```sh
|
|
```sh
|
|
sudo zramctl --reset /dev/zram0
|
|
sudo zramctl --reset /dev/zram0
|
|
sudo zramctl --find --size 5G
|
|
sudo zramctl --find --size 5G
|
|
```
|
|
```
|
|
|
|
|
|
3. Mark and enable the ZRAM.
|
|
3. Mark and enable the ZRAM.
|
|
|
|
|
|
```sh
|
|
```sh
|
|
sudo mkswap /dev/zram0
|
|
sudo mkswap /dev/zram0
|
|
sudo swapon /dev/zram0
|
|
sudo swapon /dev/zram0
|
|
``` |
|
```
|
|
\ No newline at end of file |
|
|
|
|
|
To make the changes persist between reboots, create a service that executes the commands on boot.
|
|
|
|
|
|
|
|
1. Add the commands of this post in a script that will be run at boot through a systemd service; and make it executable (`chmod +x`).
|
|
|
|
|
|
|
|
2. Create a service “at boot”, with this script (just complete the ExecStart variable):
|
|
|
|
|
|
|
|
```sh
|
|
|
|
#!/bin/sh
|
|
|
|
serviceName=run_at_boot
|
|
|
|
sudo tee /etc/systemd/system/$serviceName > /dev/null <<EOT
|
|
|
|
[Unit]
|
|
|
|
Description=run_at_boot
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
ExecStart=<YOUR_SCRIPT_IN_ABSOLUTE_PATH>
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
EOT
|
|
|
|
sudo chmod +x /etc/systemd/system/$serviceName
|
|
|
|
sudo systemctl enable $serviceName
|
|
|
|
sudo systemctl status $serviceName
|
|
|
|
```
|
|
|
|
|
|
|
|
Alternatively, the [systemd zram-generator service can be configured]() (zram-generator systemd manual page: <https://raw.githubusercontent.com/systemd/zram-generator/master/man/zram-generator.conf.md>).
|
|
|
|
|
|
|
|
- `zram-fraction` - Defines the scaling factor of the zram device's size with relation to the total usable RAM. Defaulted to *0.5*.
|
|
|
|
- `max-zram-size` - Sets the limit on the zram device's size obtained by `zram-fraction`. Defaulted to *4096*.
|
|
|
|
|
|
|
|
1. In `/usr/lib/systemd/zram-generator.conf.d/librem5.conf`:
|
|
|
|
|
|
|
|
```conf
|
|
|
|
zram-fraction=2.0
|
|
|
|
max-zram-size=none
|
|
|
|
```
|
|
|
|
|
|
|
|
2. Run the command `systemctl restart systemd-zram-setup@zram0` to recreate the ZRAM device without rebooting.
|
|
|
|
|
|
|
|
Alternative instructions to configure the systemd zram-generator service (Source: <https://www.ctrl.blog/entry/how-to-systemd-zram-generator.html>):
|
|
|
|
|
|
|
|
1. Create the file `/etc/systemd/zram-generator.conf` and include the below configuration example. (You can also leave an empty file in this path to disable ZRAM).
|
|
|
|
|
|
|
|
```conf
|
|
|
|
[zram0]
|
|
|
|
zram-fraction=0.5
|
|
|
|
max-zram-size=4096
|
|
|
|
```
|
|
|
|
|
|
|
|
> The limits given above matches the default limits (50 % of available memory or 8 GB in MB). Change the limits to your preference. Keep in mind that the system can become unstable if you set it too high. I suggest staying with the default factor of 0.5 and increasing the max size to match your available system memory. For example, set `max-zram-size=8192` if you have 16 GB of RAM.
|
|
|
|
|
|
|
|
2. > You can recreate the ZRAM device immediately without a reboot if you have enough physical memory to hold an uncompressed copy of all your currently compressed memory. The commands `free` and `zramctl` can help you determine the current memory pressure and compression ratio. Run the command `systemctl restart systemd-zram-setup@zram0.service` to recreate the ZRAM device without rebooting. However, the safest and quickest option is probably to save your work and reboot. |
|
|
|
\ No newline at end of file |