Script to enable zram

If you have any suggestions or ideas about improving Salix, here's the place to post them.
Post Reply
GJones
Donor
Posts: 300
Joined: 22. Jul 2011, 23:27

Script to enable zram

Post by GJones » 6. Apr 2012, 00:00

With the Thinkpad 600E I'm currently posting from, zram (compressed swap space in RAM) is a huge deal. With a 128 MB zram disk, the computer is usable with Salix, Fluxbox and a bunch of light applications; without zram, it is not usable at all, unless you use a toy OS like Puppy.

To automate things, and since zram likes having the same number of ramdisks as CPU cores, I suggest a script like this (crappy, totally unprofessional) one be included somewhere in the next Salix release...

Code: Select all

# Number of CPU cores and bytes of physical memory
num_cpus=`grep -c processor /proc/cpuinfo`
mem_bytes=`free -b | grep Mem | tr -s " " | cut -f 2 -d " "`

# individual disk size is half of MEM_BYTES, divided by NUM_CPUS
zram_size=$(($mem_bytes / $num_cpus))

# Load zram and resize the disks
modprobe zram num_devices=$num_cpus
for i in /sys/block/zram*; do
    echo $zram_size > $i/disksize
done

# Create the swap spaces and start swapping
for i in /dev/zram*; do
    mkswap $i
    swapon -p 32767 $i
done
Assuming I did it right, this would create a number of ZRAM disks equal to the number of CPU cores, adding up to a maximum total of [edit]the entirety of physical memory. This should be okay, assuming you have any real swap space to fall back on.[/edit]

NB: I certainly don't suggest that anything like this be enabled by default... Just present in the install in case someone wants to run Salix on an old machine.

(Not that old machines with multiple cores are common, but who knows.)

Edit 05/17/2012: updated the script to be less brain damaged. Also note that, for 3.x kernels, you must use zram_num_devices rather than num_devices as the module parameter.

Edit 08/05/2012: modified the script so it doesn't bail out on computers with < 1 GB of memory. Duh!
Last edited by GJones on 5. Aug 2012, 21:19, edited 5 times in total.

Shador
Posts: 1295
Joined: 11. Jun 2009, 14:04
Location: Bavaria

Re: Script to enable zram

Post by Shador » 6. Apr 2012, 01:44

I think there's more benefit from a wiki entry. First of all its easier to catch, so more peoples would know about. Who notices some file installed someplace by the setup?
Apart inclusion in the default install adds an additional maintenance burden. As it would offer little to no benefit otherwise over the wiki (copy'n pasting a script is not much work) and would be unneeded by many people, it just doesn't seem worth it.

Do you agree?
Image

GJones
Donor
Posts: 300
Joined: 22. Jul 2011, 23:27

Re: Script to enable zram

Post by GJones » 6. Apr 2012, 10:52

Mmm, I think you're right. And I'd forgotten about the wiki. Shame on me. :lol:

User avatar
JRD
Salix Warrior
Posts: 949
Joined: 7. Jun 2009, 22:52
Location: Lyon, France

Re: Script to enable zram

Post by JRD » 11. Apr 2012, 08:51

Ahhhh very interresting !
I hjave a laptop with low RAM and correct CPU, I will try this.
Image

GJones
Donor
Posts: 300
Joined: 22. Jul 2011, 23:27

Re: Script to enable zram

Post by GJones » 17. May 2012, 22:53

Updated the script above, it should actually work now. I'm rather interested in hearing how well zram works, particularly on very low-end or very high-end computers.

Post Reply