Page 4 of 4

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

Posted: Mon Jun 19, 2017 9:39 am
by sarahgad
Do you recommend keep on using the old Kernel prior to 3.15 for the purpose?

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

Posted: Mon Jun 19, 2017 9:57 am
by ric96
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.

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

Posted: Mon Jun 19, 2017 10:31 am
by PeterO
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

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

Posted: Wed Jul 19, 2017 10:27 am
by pgeorges
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

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

Posted: Thu Mar 15, 2018 9:33 am
by tkaiser
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)

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

Posted: Thu Mar 15, 2018 11:47 am
by PeterO
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

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

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

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

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

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

Posted: Wed May 23, 2018 7:47 am
by fruitoftheloom
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

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

Posted: Wed Jun 20, 2018 5:07 pm
by ejolson
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?

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

Posted: Mon Jun 25, 2018 12:10 pm
by Gavinmc42
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?

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

Posted: Wed Jul 04, 2018 1:41 am
by ejolson
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.

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

Posted: Thu Jul 05, 2018 8:19 pm
by binaryhermit
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.

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

Posted: Thu Jul 05, 2018 11:47 pm
by jahboater
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!

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

Posted: Sat Sep 29, 2018 4:11 pm
by nisses
I find Pi2/Pi3 with swap mem on USB flash memory (i use those small but fast flash drives that almost completely fit inside USB plug) and system on a decent microSD card (class 10 and faster here) pretty usable for running servers (OwnCloud for example), email clients, local files and network files management, writing Python scripts or moving files between network servers etc. but doing desktop stuff (like web browsing) or GCC recompilation and bigger things like that are very slow. Since I did not want to do cross-compilation on PC anymore, I saved lots of time by switching to 2GB platform. Some tasks (usually those big ones like IDE recompilation etc.) are 2-10 times faster. I still use my other Pis for running and testing apps. I just do development on 2GB board now. I wish there was 2GB Pi years ago. I wish there was 4GB Pi available now.