How to use compcache for Linux 3.2 (Debian Wheezy)

3

1

How do I set up and configure compcache for Debian Wheezy (3.2 kernel). As far as I can understand compcache is now in the kernel and is not to be found in the debian repo either. Compcache should be accessible thorugh a /sys or /proc interface to my best knowledge but I can't figure out where it is / what it is called in Debian.

Waxhead

Posted 2012-04-23T22:44:39.513

Reputation: 1 092

Answers

1

After some searching I found a script that explains fairly well how to turn on zram who replaces compcache. Edit: I also changed the script a bit - this is the updated version.

Edit: 2016. below I also added a systemd service example for zram (which is the same as compcache)

#! /bin/sh
### BEGIN INIT INFO
# Provides:          zramstuff
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     2
# Default-Stop:      0 6
# Short-Description: Enable swap to compressed ram
# Description:       Enables swapping to compressed ram
### END INIT INFO

case "$1" in
  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:]]+')
       mem_total=$((mem_total_kb * 1024))

       # load dependency modules
       modprobe zram 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)
       # get the number of CPUs
       num_cpus=$(grep -c processor /proc/cpuinfo)

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

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

       rmmod zram
       ;;
esac

Systemd service example: (tested on Debian)

[Unit]
Description=Set up zram
Conflicts=hibernate.service

[Service]
Environment=ZRAM_MEM=1G
Environment=ZRAM_CMPALGO=lz4
Environment=ZRAM_CMPSTREAMS=2

Type=oneshot
User=root
ExecStartPre=/bin/sh -c "/sbin/modprobe zram num_devices=1"
ExecStartPre=/bin/sh -c "echo $ZRAM_CMPALGO >/sys/block/zram0/comp_algorithm"
ExecStartPre=/bin/sh -c "echo $ZRAM_CMPSTREAMS >/sys/block/zram0/max_comp_streams"
ExecStartPre=/bin/sh -c "echo $ZRAM_MEM > /sys/block/zram0/disksize"
ExecStartPre=/bin/sh -c "/sbin/mkswap /dev/zram0"
ExecStart=/sbin/swapon /dev/zram0 -p 10

ExecStop=/sbin/swapoff /dev/zram0
ExecStop=/bin/echo 1 > /sys/block/zram0/reset
ExecStop=/sbin/rmmod zram

RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Waxhead

Posted 2012-04-23T22:44:39.513

Reputation: 1 092

0

I believe compcache will be visible as a device called /dev/ramzswap0 of type SWAP. You should be able to see it listed using blkid.

ckhan

Posted 2012-04-23T22:44:39.513

Reputation: 5 689

Nope, ramzswap0 does not exists nor anything else that looks like that in /dev/ – Waxhead – 2012-04-24T19:03:21.150