Posts: 75
tradetaxfree
Joined: 18 Jan 2012
#31
For anyone using systemd or sysvinit (as systemd also supports init scripts) - I've updated the init script to include a Factor % I noticed today in the latest version which can be set in the script itself or by creating /etc/default/zram & setting the value there (see lines 26-28):

Code: Select all

#!/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
# Included as part of antix-goodies package by anticapitalista <antiX@operamail.com>
# This script was written by tradetaxfree and is found at http://crunchbanglinux.org/forums/topic/15344/zram-a-good-idea/
# Copy this script (as root) from /usr/local/bin to /etc/init.d and then #update-rc.d zram defaults
# After booting verify the module is loaded with: lsmod | grep zram
### END INIT INFO
set -e

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
    last_cpu=$((num_cpus - 1))
    
    #default Factor % = 90 change this value here or create /etc/default/zram
    FACTOR=90
    #& put the above single line in /etc/default/zram with the value you want
     [ -f /etc/default/zram ] && source /etc/default/zram || true
     factor=$FACTOR # percentage

    # get the amount of memory in the machine
    memtotal=$(grep MemTotal /proc/meminfo | awk ' { print $2 } ')
    mem_by_cpu=$(($memtotal/$num_cpus*$factor/100*1024))

    # load dependency modules
    modprobe zram num_devices=$num_cpus
    echo"zram devices probed successfully"
    
    # initialize the devices
    for i in $(seq 0 $last_cpu); do
    echo $mem_by_cpu > /sys/block/zram$i/disksize
    # Creating swap filesystems
    mkswap /dev/zram$i
    # Switch the swaps on
    swapon -p 100 /dev/zram$i
    done
}

stop() {
    # get the number of CPUs
    num_cpus=$(grep -c processor /proc/cpuinfo)

    # set decremented number of CPUs
    last_cpu=$((num_cpus - 1))

    # Switching off swap
    for i in $(seq 0 $last_cpu); do
    if ["$(grep /dev/zram$i /proc/swaps)" !="" ]; then
    swapoff /dev/zram$i
    sleep 1
    fi
    done

    sleep 1
    rmmod zram
}

case"$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        sleep 3
        start
        ;;
    *)
        echo"Usage: $0 {start|stop|restart}"
        RETVAL=1
esac
exit $RETVAL
Last edited by tradetaxfree on 24 Jun 2012, 22:50, edited 1 time in total.
Posts: 765
rust collector
Joined: 27 Dec 2011
#32
anticapitalista wrote: /usr/local/sbin/ doesn't exist on antiX.

zram is in /usr/local/bin.

But it says:

Code: Select all

# Short-Description: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM)
# Description: Adapted from systemd scripts at https://github.com/mystilleef/FedoraZram
# Included as part of antix-goodies package by anticapitalista <antiX@operamail.com>
# This script was written by tradetaxfree and is found at http://crunchbanglinux.org/forums/topic/15344/zram-a-good-idea/
# Copy this script (as root) from /usr/local/bin to /etc/init.d and then #update-rc.d zram defaults
# After booting verify the module is loaded with: lsmod | grep zram
### END INIT INFO
Have you done that?
I must say that I was wondering about that bit..
No, I didn't, as I can not find it anywhere in /usr/local/bin...
All I did was the steps listed here:
========= SCRAPER REMOVED AN EMBEDDED LINK HERE ===========
url was:"https://github.com/mystilleef/FedoraZram"
linktext was:"https://github.com/mystilleef/FedoraZram"
====================================

I was a bit worried about the missing sbin, as I mentioned on the last post in the first page... but I just made an sbin file...

Ok, so, I have to get rid of the sbin, and copy that script into /usr/local/bin, and from there to /etc/init.d?
That script is the antix version of the
zramstart and zramstop files from fedora? and it should be named"zram"?

I am easily confused these days... __{{emoticon}}__
Posts: 765
rust collector
Joined: 27 Dec 2011
#33
ok, so I went back and removed all zram stuff... I will try again!
I still wonder where that script is, as I can not find it...
anticapitalista
Posts: 5,955
Site Admin
Joined: 11 Sep 2007
#34
Ok, maybe it isn't uploaded yet __{{emoticon}}__

Copy paste what tradtaxfree posted above into a text file, name it zram, make it executable and place it in /etc/init.d
Posts: 765
rust collector
Joined: 27 Dec 2011
#35
Ok!
I did, and the module is loaded.
Is there an antix version of the

Code: Select all

/usr/local/sbin/zramstart 
command?

/usr/local/bin/zram start
Or
/usr/local/bin/zram restart
Maybe?
anticapitalista
Posts: 5,955
Site Admin
Joined: 11 Sep 2007
#36
No. forget the fedora instructions.

Code: Select all

# Copy this script (as root) from /usr/local/bin to /etc/init.d (you have this in /etc/init.d already) and then run 
#update-rc.d zram defaults
# After booting verify the module is loaded with: lsmod | grep zram
Posts: 765
rust collector
Joined: 27 Dec 2011
#37
Ok,

Code: Select all

root@antiberg:/home/kberg
# lsmod | grep zram
zram                    8658  2 
So it is loaded...

And that is all???
anticapitalista
Posts: 5,955
Site Admin
Joined: 11 Sep 2007
#38
Yes, unless tradetaxfree knows more.
Posts: 765
rust collector
Joined: 27 Dec 2011
#39
Wow! that might have been easy! if that is all.
Dave
Posts: 1,062
Dave
Joined: 20 Jan 2010
#40
Simply a great piece,
Been following this thread, decided to enable zram and after a reboot ram usage went from 90 % to 23 % according to conky.
Posts: 765
rust collector
Joined: 27 Dec 2011
#41
Hmm, I can not say I notice a difference... still at 5%...
Posts: 765
rust collector
Joined: 27 Dec 2011
#42
For some reason, I tried: dmesg zram

And I got

Code: Select all

kernelXXXXX
blablabla

umpteen lines of stuff...

zram: module is from the staging directory, the quality is unknown, you have been warned.
zram: Creating 2 devices ...
Adding 693084k swap on /dev/zram0.  Priority:100 extents:1 across:693084k SS
Adding 693084k swap on /dev/zram1.  Priority:100 extents:1 across:693084k SS

More lines, wlan, etc.

zram: module is from the staging directory, the quality is unknown, you have been warned.
zram: Unknown parameter `zram_num_devices'
So, it seems to me that it has made a pair of"swap areas"?
But I am not sure I like that last line???

Just to ask a related question...
Should I play with the % setting in zram? I noticed it was at 90%
Posts: 75
tradetaxfree
Joined: 18 Jan 2012
#43
@rust collector - change the modprobe module parameter zram_num_devices to num_devices (as shown in the updated
========= SCRAPER REMOVED AN EMBEDDED LINK HERE ===========
url was:"antix.freeforu ms.org/post25137.html#p25137"
linktext was:"zram init script"
====================================
) so it reads as:

Code: Select all

modprobe zram num_devices=$num_cpus
& then run:

Code: Select all

sudo update-rc.d zram defaults
sudo service zram restart
Posts: 765
rust collector
Joined: 27 Dec 2011
#44
I did, but nah...

Sooooo.... I messed it up again... it works with the liqourix kernel...but I was booted into the antix one, which don't seem to like zram...sorry...

Anyway, it creates 2 swap areas now, and probably works... in liqourix

I would like it to work with the antix kernel too, but it is ok, I guess
Posts: 75
tradetaxfree
Joined: 18 Jan 2012
#45
I've been playing around with grsecurity & building custom kernels - note for Anti to compile the kernels with ZRAM support:

device drivers ----> staging drivers ----> Compressed RAM block device support (M)

device drivers ----> staging drivers ----> Dynamic compression of swap pages and clean pagecache pages (*)