sarahgad
Posts: 29
Joined: Fri Jan 20, 2017 12:07 pm

Re: Raspberry Pi 3 with 2GB RAM playing the devil's advocate

Mon Jun 19, 2017 9:39 am

Do you recommend keep on using the old Kernel prior to 3.15 for the purpose?

User avatar
ric96
Posts: 1254
Joined: Sun Mar 17, 2013 6:03 am
Location: NOIDA, India
Contact: Website

Re: Raspberry Pi 3 with 2GB RAM playing the devil's advocate

Mon Jun 19, 2017 9:57 am

sarahgad wrote:Do you recommend keep on using the old Kernel prior to 3.15 for the purpose?
absolutely NOT, the script works fine as is on any 4.x based kernel. If you want to have a single swap file just modify it, won't be necessary though.
My apologies for shameless YouTube Plugs...
youtube.com/sahajsarup
twitter @sahajsarup
skype srics1996
e-mail: sahajsarup@gmail.com
Blog: http://www.geektillithertz.com/wordpress
Web: http://www.geektillithertz.com

User avatar
PeterO
Posts: 3613
Joined: Sun Jul 22, 2012 4:14 pm

Re: Raspberry Pi 3 with 2GB RAM playing the devil's advocate

Mon Jun 19, 2017 10:31 am

ric96 wrote:https://unix.stackexchange.com/question ... m-and-swap
I'll leave this here...
PeterO wrote:"I have four cores so I need four zram devices" seems like a non sequitur.

PeterO
From that page "Interesting, and this also seems quite clear to understand by reading /etc/init/zram-config.conf "

So what is in /etc/zram-config.conf for those of us who have not installed it ?

EDIT... Google found me a version, and it contains nothing that explains the reasoning.... :roll:

Also, since all my PIs run with USB drives and no SDcards, swapping (when it happens) goes to the USB disk not the slow SDcard. Would zram still provide useful performance increase in this case ?
I'm sceptical because assigning half your ram to these devices is going to make swapping happen much sooner to start with.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),Aeromodelling,1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

pgeorges
Posts: 1
Joined: Wed Jul 19, 2017 10:21 am

Re: Raspberry Pi 3 with 2GB RAM playing the devil's advocate

Wed Jul 19, 2017 10:27 am

I discovered recently zram and it proved to be so good in terms of performance and for preserving SD Card lifetime that I wrote the script below in file /etc/init.d/zram.

IMO, swap should never be used on an SD Card because it is often so useless (when you start swapping heavily, I often unplug my Pi because it appears frozen, and multiple I/O reduces heavily SD Card's lifetime).
I even put /var/log into another zram device to perserve SD Card.

Code: Select all

#!/bin/bash
### BEGIN INIT INFO
# Provides:          zram
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     S
# Default-Stop:      0 1 6
# Short-Description: Use compressed RAM as in-memory swap
# Description:       Use compressed RAM as in-memory swap
### END INIT INFO

# Adjust the swap size in MB
SWAP_SIZE=800

CPUS=`nproc`
SIZE=$(( SWAP_SIZE * 1024 * 1024 / CPUS ))

case "$1" in
  "start")
    # if a zram swap already exists, bail out
    if [ `grep -c zram /proc/swaps` != 0 ]
      then
      echo "There is already a zram swap"
      exit 1
    fi
    modprobe zram

    for n in `seq $CPUS`; do
      i=`cat /sys/class/zram-control/hot_add`
      echo $SIZE > /sys/block/zram$i/disksize
      mkswap /dev/zram$i
      swapon /dev/zram$i -p 10
    done
    ;;
  "stop")
    readarray arr < "/proc/swaps"
    for line in "${arr[@]}" ; do
      if [ ${line:0:9} == "/dev/zram" ] ; then
          i=${line:9:1}
          echo "Removing swap zram $i"
          swapoff /dev/zram$i
          echo $i > /sys/class/zram-control/hot_remove
      fi
    done
    modprobe -r zram
    ;;
  "status")
    free -h
    cat /proc/swaps
    ;;
  *)
    echo "Usage: `basename $0` (start | stop | status)"
    exit 1
    ;;
esac

Return to “Off topic discussion”

Who is online

Users browsing this forum: No registered users and 4 guests