Does anyone tried zRam?

  • Thread starter Thread starter cirroz
  • Start date Start date
C

cirroz

Guest
Gentoo Wiki

What it does is create a compressed block device in ram. That block device can then be used for swap or general purpose ram disk. The two most popular uses for it are swap to extend the available amount of ram to processes and /tmp. The ram used for the block device is dynamicaly obtained and released up to it's predefined uncompressed maximum size. The way it extends the amount of available ram to a system is by using a portion of the ram as compressed swap. It can therefore hold more pages of memory in the compressed swap than the amount of actual memory used. Typically it compresses to a 3:1 ratio. So, 1G of swap uses only 333MB of ram on average. The compression ratio including memory used for disk overhead varies depending on the % maximum space used. I found it to vary from 1.5:1 for a 1.5G disk with only 5% space used, to over 3:1 when nearly full. It also is much faster at swapping pages than typical hard disk swap.
My experience with using it, my system is still fully functional, with only slight slow downs at times. This is for a Xfce4 desktop with several apps and emerge running with PORTAGE_NICENESS=10. The memory and swap spaces were nearly maxed out. Intel Core2 Quad core 2.6Ghz, 4G ram. I had 4 - 1.5G zram disks for swap, plus 1G partition of hard drive swap as backup. At one point during linking chromium, I saw the system using just over 5G of zram swap, while using about 1.2G of ram, about 100MB of hard disk swap. The desktop was still responsive :)
 
Yep, I'm using ZRAM on my Debian Proxmox installation and it works great, I've got mine setup to create a ZRAM swap 50% of the size of the physical memory, steps and script below:

In terminal on the host:

1) nano /etc/init.d/zram

2) Paste this:

Code:
#!/bin/sh
### BEGIN INIT INFO
# Provides: zram
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 5
# Default-Stop:
# Description:
### END INIT INFO

case "$1" in
'start')
        dphys-swapfile swapoff
        modprobe zram
        totalram=$(free -m | grep 'Mem:' | awk '{ print $2 }')
        zramsize=$(echo $(($totalram/2)))
        echo $(($zramsize * 1024*1024)) > /sys/block/zram0/disksize
        mkswap /dev/zram0
        swapon -p 10 /dev/zram0
        sysctl vm.swappiness=10
        ;;
'stop')
        ;;
*)
        echo "Usage: $0 { start | stop }"
        ;;
esac
exit 0

3) chmod 755 /etc/init.d/zram

4) update-rc.d zram defaults

5) reboot

6) Check you have swap half the size of installed physical ram in the Proxmox GUI.

Note this guide assumes you have disabled the standard swap file by commenting it out in /etc/fstab

I'd really like to see a "compress memory" option built into Proxmox GUI. For small hobby / home installations with limited memory it can be very beneficial.
 
Last edited:
init.d? That's kinda oldschool. You should migrate that to systemd - e.g. just use the package from Ubuntu, which works great on Jessie and Stretch:

https://packages.ubuntu.com/xenial/zram-config

This line "sysctl vm.swappiness=100" tells the kernel not to use swap unless absolutely necessary.

Sorry, that's wrong. Please check with
https://www.kernel.org/doc/Documentation/sysctl/vm.txt and https://en.wikipedia.org/wiki/Swappiness

I'd really like to see a "compress memory" option built into Proxmox GUI. For small hobby / home installations with limited memory it can be very beneficial.

Nice idea, but it can only be fast if it is incorporated into the MMU like it is on sparc.
 
Nice catch RE swappiness, I copy this script between machines frequently and pulled this from one of my Raspberry Pi's.

A value of about 10 is more suitable for Proxmox I think (if you want the kernel not to use swap unless absolutely nessesary, then value should be 1).

I've changed the script to 10.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!