This About zram from wikipedia

zram (also called zRAM and, initially, compcache) is a Linux kernel feature that provides a form of virtual memory compression. zram increases performance by avoiding paging to disk and using a compressed block device in RAM instead, inside which paging takes place until it is necessary to use the swap space on a hard disk drive. Since using RAM is an alternative way to provide swapping on RAM, zram allows Linux to make more use of RAM when swapping/paging is required, especially on older computers with less RAM installed.

Even when the cost of RAM is low, zram still offers advantages for low-end hardware devices such as embedded devices and netbooks. Such devices usually use flash-based storage that has limited lifespan due to its nature, which is also used to provide swap space. The reduction in swap usage as a result of using zram effectively reduces the amount of wear placed on such flash-based storage, resulting in prolonging its usable life. Also, using zram results in a significantly reduced I/O for Linux systems that require swapping.

zram was merged into the Linux kernel mainline in kernel version 3.14, released on 30 March 2014. As of Linux kernel version 3.15, released on 8 June 2014, zram supports LZ4 compression algorithm, while LZO remains as the default compression backend. Changes in kernel 3.15 also provide performance improvements, as well as the ability to switch the compression algorithm via sysfs.

Google uses zram in Chrome OS and it is also available as an option for Android 4.4 devices. Also, Lubuntu started using zram with version 13.10. As of December 2012, Ubuntu has considered enabling zram by default on computers with small amounts of installed RAM.

on the first install of your linux system don’t create swap space, because swap will generate by zram after installation

if you install with minimal package, please install bc as requirement of zram

# yum install bc

zram system script (fix)

create file with name zram /etc/init.d/ and paste the script like so :

# vim /etc/init.d/zram

#!/bin/bash
### BEGIN INIT INFO
# Provides: zram
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM)
# Description: Adapted from systemd scripts at https://github.com/mystilleef/FedoraZram
### END INIT INFO
 
start() {
    # get the number of CPUs
    num_cpus=$(grep -c processor /proc/cpuinfo)
    # if something goes wrong, assume we have 1
    [ "$num_cpus" != 0 ] || num_cpus=1
 
    # set decremented number of CPUs
    decr_num_cpus=$((num_cpus - 1))
 
    # get the amount of memory in the machine
    mem_total_kb=$(grep MemTotal /proc/meminfo | grep -E --only-matching '[[:digit:]]+')
	
    #we will only assign 50% of system memory to zram
    mem_total_kb=$((mem_total_kb / 2))
 
    mem_total=$((mem_total_kb * 1024))
 
    # load dependency modules
    modprobe zram num_devices=$num_cpus
 
    # initialize the devices
    for i in $(seq 0 $decr_num_cpus); do
    echo $((mem_total / num_cpus)) > /sys/block/zram$i/disksize
    done
 
    # Creating swap filesystems
    for i in $(seq 0 $decr_num_cpus); do
    mkswap /dev/zram$i
    done
 
    # Switch the swaps on
    for i in $(seq 0 $decr_num_cpus); do
    swapon -p 100 /dev/zram$i
    done
}
 
stop() {
	for i in $(grep '^/dev/zram' /proc/swaps | awk '{ print $1 }'); do
		swapoff "$i"
	done
 
	if grep -q "^zram " /proc/modules; then
		sleep 1
		rmmod zram
	fi
}
 
status() {
        ls /sys/block/zram* > /dev/null 2>&1 || exit 0
        echo -e "-------nzram Compression Stats:n-------"
        for i in /sys/block/zram*; do
                compr=$(< $i/compr_data_size)
                orig=$( $compr)"
"
        done
        echo -e "-------nSWAP Stats:n-------"
        swapon -s | grep zram
        echo -e "-------nMemory Stats:n-------"
        free -m -l -t
}
 
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        sleep 3
        start
        ;;
	status)
		status
		;;
    *)"
	
"
      echo "Usage: $0 {start|stop|restart|status}"
        RETVAL=1

esac

save changes and give execute mode to zram

# chmod 755 /etc/init.d/zram

make zram start at boot

# chkconfig --add  zram  && chkconfig zram on

now reboot your computer/server , to check zram is running use the folowing command

# service zram status

source :
https://extremeshok.com/5094/centos-6-x-rhce-6-redhat-6-zram-compression-compressed-swap-residing-in-ram-over-allocating-memory/
https://en.wikipedia.org/wiki/Zram

Advertisements