sarahgad
Posts: 30
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: [email protected]
Blog: http://www.geektillithertz.com/wordpress
Web: http://www.geektillithertz.com

User avatar
PeterO
Posts: 4237
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

tkaiser
Posts: 103
Joined: Fri Aug 05, 2016 1:28 pm

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

Thu Mar 15, 2018 9:33 am

PeterO wrote:
Mon Jun 19, 2017 10:31 am
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.
There's no need to use slow SD cards other than people being not aware of random IO being the most important performance metric while everywhere only sequential performance is measured. A is the problem but users are only told to look at B (A is random IO, B sequential performance).

In the meantime SD cards do exist that are optimized for exactly this: https://forum.armbian.com/topic/954-sd- ... ment-49811

Those A1 rated cards are at least 3 times faster than spinning rust (HDDs) as long as we're talking about random IO which pretty much is exactly what's happening when running Linux.
PeterO wrote:
Mon Jun 19, 2017 10:31 am
I'm sceptical because assigning half your ram to these devices is going to make swapping happen much sooner to start with.
Nope, this is a misunderstanding. You are not 'assigning half your ram' to zram that's just the amount of memory that will be used once zram would be used and the system starts to run out of memory. If you have 1 GB physical DRAM and activate zram with defaults (configured to use half the size of physical DRAM as maximum size) the sum is 1.5GB and not 1GB.

Still the full 1 GB are available. Only if the kernel is running out of physical memory it starts to send pages to one of the zram devices which then start to slowly use physical RAM. Now the amount of available RAM of course decreases since used by zram but since compression is applied (LZ4 being the default AFAIK) the zram devices do NOT allocate the same amount of physical RAM as would be needed to move pages into.

So a lot more paging activity has to happen since the amount of available physical RAM gets further reduced once data arrives at the zram devices but if the data is highly compressable then you end up with a lot more data fitting into same amount of physical RAM. BTW: since the kernel is not an idiot it takes care that stuff gets pushed into zram that is least frequently accessed (just like with traditional swapping) so with a somewhat decent host (excluding the single core Raspberries) you end up with more available DRAM anyway.

And of course zram is magnitudes faster than swapping especially compared to slow spinning rust (again: there's no need to use slow SD cards since ultra fast ones exist)

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

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

Thu Mar 15, 2018 11:47 am

It still makes no sense to me. It's still using memory to hold stuff that the kernel has decided isn't needed at the moment.
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

User avatar
Nick_Hudson
Posts: 9
Joined: Mon May 21, 2018 10:13 am

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

Wed May 23, 2018 6:45 am

And I'm thinking to run SNES games on Raspberry Pi. :lol:

User avatar
rpdom
Posts: 12754
Joined: Sun May 06, 2012 5:17 am
Location: Ankh-Morpork

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

Wed May 23, 2018 6:54 am

Nick_Hudson wrote:
Wed May 23, 2018 6:45 am
And I'm thinking to run SNES games on Raspberry Pi. :lol:
Retropi

fruitoftheloom
Posts: 17300
Joined: Tue Mar 25, 2014 12:40 pm

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

Wed May 23, 2018 7:47 am

Nick_Hudson wrote:
Wed May 23, 2018 6:45 am
And I'm thinking to run SNES games on Raspberry Pi. :lol:

https://retropie.org.uk
Adieu

ejolson
Posts: 1842
Joined: Tue Mar 18, 2014 11:47 am

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

Wed Jun 20, 2018 5:07 pm

tkaiser wrote:
Thu Mar 15, 2018 9:33 am
Nope, this is a misunderstanding. You are not 'assigning half your ram' to zram that's just the amount of memory that will be used once zram would be used and the system starts to run out of memory.
I know this is an old thread, but thanks for clarifying.

Does anyone know whether zRAM eliminates the need for swap when compiling a new version of gcc?

User avatar
Gavinmc42
Posts: 2099
Joined: Wed Aug 28, 2013 3:31 am

Re: Raspberry Pi 3 with 2GB RAM playing the devil's advocate [result: 1GIG is enough!]

Mon Jun 25, 2018 12:10 pm

Does anyone know whether zRAM eliminates the need for swap when compiling a new version of gcc?
Good question which no one seems to have noticed.

I use Gentoo64 these days which uses the OpenGL driver,
config.txt sets GPU at the 16MB minimum, extra is requested on demand from the VC4?
Sakaki showed me how to go headless and get back the X11 memory, which made compiling the Arm Compute Library possible.

Using zram on the DDR2 and swapfile on a USB stick should free up more memory.
Not sure but I think GCC might still need to be cross compiled.

Pi4 of course with have to have 2 x 1GB DDR4 memory for 64bit wide, faster memory to improve performance :D
Perhaps 4GB will be cheaper then, 8GB memory?
Will that be enough to compile GCC?
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

ejolson
Posts: 1842
Joined: Tue Mar 18, 2014 11:47 am

Re: Raspberry Pi 3 with 2GB RAM playing the devil's advocate [result: 1GIG is enough!]

Wed Jul 04, 2018 1:41 am

Gavinmc42 wrote:
Mon Jun 25, 2018 12:10 pm
Perhaps 4GB will be cheaper then, 8GB memory?
Will that be enough to compile GCC?
My experience indicates that gcc will build using a -j4 parallel make on a Pi 2B with a 1GB swap file. Likely less would also work; however, I usually use a 2GB swap file residing on an external HD--far more than necessary.

When running a serial make the actual memory requirements are less, but still more than the 1GB memory available. Therefore, it seems likely that zRAM would be sufficient for a serial make.

binaryhermit
Posts: 20
Joined: Sun Apr 13, 2014 1:26 am
Location: Lockport, Illinois
Contact: Website

Re: Raspberry Pi 3 with 2GB RAM playing the devil's advocate [result: 1GIG is enough!]

Thu Jul 05, 2018 8:19 pm

Honestly, I can see the use case for more than 1 GB of RAM on a rpi.

Any time I try to browse the web in Firefox or Chromium on my pi in the default LXDE-based desktop while running deluge, my pi locks up for several minutes, and the OOM killer does its thing.

If you need to do desktop things, there are probably better choices out there. But that doesn't make the pi useless.

jahboater
Posts: 2857
Joined: Wed Feb 04, 2015 6:38 pm

Re: Raspberry Pi 3 with 2GB RAM playing the devil's advocate [result: 1GIG is enough!]

Thu Jul 05, 2018 11:47 pm

ejolson wrote:
Wed Jul 04, 2018 1:41 am
My experience indicates that gcc will build using a -j4 parallel make on a Pi 2B with a 1GB swap file. Likely less would also work; however, I usually use a 2GB swap file residing on an external HD--far more than necessary.
I believe the gcc build with make -j4 on the Pi requires swap for only a small amount of time. The rest of the time, the Pi is perfectly usable. Its one of those cases where the swap enables the program to continue, rather than being continually reliant on it.

I don't really care if the machine gets slow during those few minutes, and the SD card swapfile is good enough.

I thought make -j2 or less did not require swap at all, but I have not tried that recently - takes too long!

Return to “Off topic discussion”

Who is online

Users browsing this forum: No registered users and 10 guests