Zram: Difference between revisions

From Alpine Linux
m (fixed typo)
(changed introduction paragraph, fixed wikitags, cleaned up categories, rephrased sentence, added links)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
This page documents how to set up [https://docs.kernel.org/admin-guide/blockdev/zram.html ZRAM] in Alpine.  
This page documents how to set up [https://docs.kernel.org/admin-guide/blockdev/zram.html ZRAM] in Alpine Linux. Zram can be used as an alternative to [[Swap]] partition.


== Installation ==  
== Installation ==  
Install the neccessary packages.
 
{{Cmd|# apk add {{pkg|zram-init}}}}
Install the neccessary packages:{{Cmd|# apk add {{pkg|zram-init}}}}


== Configuration ==  
== Configuration ==  
Make service start during next reboot.
{{Cmd|# rc-update add zram-init}}


Configure ZRAM SWAP:
For a basic ZRAM swap, configure ZRAM by editing the file {{path|/etc/conf.d/zram-init}} as follows:{{Cat|/etc/conf.d/zram-init|<nowiki>num_devices=1
{{Cmd|# vi /etc/conf.d/zram-init}}
size0=8000 </nowiki>}}


For basic ZRAM swap:  
Start services:{{Cmd|# rc-service zram-init start}}
# Update from num_devices=3 to num_devices=1
# Change the size0=512 to the desired megabytes (same as available RAM or 8GB, whichever is less)
# Change the default algorithm from zstd to lzo-rle


{{warning| The default algorithm zstd does not work with Alpine Linux.[https://gitlab.alpinelinux.org/alpine/aports/-/issues/10044 10044]}}
View the ZRAM drive:{{Cmd|# cat /proc/swaps}}


Start services:
Check Algorithms:{{Cmd|# cat /sys/block/zram0/comp_algorithm}}
{{Cmd|# rc-service zram-init start}}


View the ZRAM drive
Advanced setups may also add these parameters to {{path|/etc/sysctl.conf}} as follows:{{Cat|/etc/sysctl.conf|<nowiki>vm.page-cluster=0
{{Cmd|# cat /proc/swaps}}
vm.extfrag_threshold=0
vm.swappiness=100</nowiki>}}


Check Algorithms:
To ensure that service starts during next reboot: {{Cmd|# rc-update add zram-init}}
{{Cmd|# cat /sys/block/zram0/comp_algorithm}}


Advanced setups may also add these parameters to /etc/sysctl.conf:
* vm.page-cluster=0
* vm.extfrag_threshold=0
* vm.swappiness=100
<!--
Remove the remarks once content is added
== Troubleshooting ==  
== Troubleshooting ==  
-->
 
== See Also ==
== See also ==
 
* [https://github.com/vaeth/zram-init/blob/main/openrc/conf.d/zram-init sample zram-init file on official website]
* [https://wiki.archlinux.org/title/Zram Zram in Arch Wiki]
* [https://wiki.archlinux.org/title/Zram Zram in Arch Wiki]
* [https://en.wikipedia.org/wiki/zram Zram in Wikipedia]
* [https://en.wikipedia.org/wiki/zram Zram in Wikipedia]


[[Category:System Administration‏‎]]
[[Category:System Administration‏‎]]
[[Category:Storage‏‎‏‎]]
[[Category:Storage‏‎‏‎]]
[[Category:Storage‏‎‏‎]]
[[Category:Kernel]]
[[Category:Kernel]]
[[Category:Filesystems‎]]

Latest revision as of 11:45, 3 April 2025

This page documents how to set up ZRAM in Alpine Linux. Zram can be used as an alternative to Swap partition.

Installation

Install the neccessary packages:

# apk add zram-init

Configuration

For a basic ZRAM swap, configure ZRAM by editing the file /etc/conf.d/zram-init as follows:

Contents of /etc/conf.d/zram-init

num_devices=1 size0=8000

Start services:

# rc-service zram-init start

View the ZRAM drive:

# cat /proc/swaps

Check Algorithms:

# cat /sys/block/zram0/comp_algorithm

Advanced setups may also add these parameters to /etc/sysctl.conf as follows:

Contents of /etc/sysctl.conf

vm.page-cluster=0 vm.extfrag_threshold=0 vm.swappiness=100

To ensure that service starts during next reboot:

# rc-update add zram-init

Troubleshooting

See also