zram swap support for the PBP; aka: "how to download more RAM"
#1
Hey all,

Last month I posted a simple zram-swap script that I wrote for my PBP on IRC for people to use. I took some time to package it and make it "release worthy" and pushed it to github with updates today: https://github.com/foundObjects/zram-swap

This makes a huge difference if you're memory constrained on your PBP, and even if you aren't I encourage you to check it out simply to avoid the NAND wear of swapping to your eMMC when you eventually do need to swap.

I also added a fixed-size swap feature for people who know ahead of time exactly how much swap they want, so if you're doing something like building GCC with -lto on the PBP and need 10+G swap I've got you covered: just set "_zram_fixed_size=10G" in the /etc/default/zram-swap config file along with your prefered swap algorithm and you're good to go. Yes, you can use lzo-rle.

README.md:
Code:
# zram-swap
Simple zram swap setup + teardown script for modern systemd Linux systems

https://github.com/foundObjects/zram-swap

### Why?

There are dozens of zram swap scripts out there, but most of them are overly
complicated and do things that haven't been neccessary since linux 3.X or have
massive logic errors in their swap size calculations. This script is simple and
reliable, modern and easy to configure.

### Installation

```
git clone https://github.com/foundObjects/zram-swap.git
cd zram-swap && sudo ./install.sh
```

### Usage

zram-swap.service will be started automatically after installation and during
each subsequent boot. The default allocation creates a zram device that should
use around half of physical memory when completely full.

The default configuration using lz4 should work well for most people. lzo may
provide slightly better RAM utilization at a cost of slightly more expensive
decompression. zstd should provide better compression than lz* and still be
moderately fast on most machines. On very modern kernels the best overall
choice is probably lzo-rle.

Edit `/etc/default/zram-swap` if you'd like to change compression algorithms or
swap allocation and then restart zram-swap with `systemctl restart
zram-swap.service`.

Run `zramctl` during use to monitor swap compression and real memory usage.

### Debugging

Start zram-swap.sh with `zram-swap.sh -x (start|stop)` to view the debug trace
and determine what's going wrong.

To dump the full execution trace during service start/stop edit
`/etc/systemd/systemd/zram-swap.service` and add -x to the following two lines:

```
ExecStart=/usr/local/sbin/zram-swap.sh -x init
ExecStop=/usr/local/sbin/zram-swap.sh -x  end
```

### Compatibility

This should run on pretty much any recent (4.0+? kernel) Linux system using
systemd. If anyone wants to try it on something really old and let me know how
far back compatibility goes I'm interested, but I don't have any legacy systems
to test on at the moment.

The script will also work on non-systemd Linux without issue and I welcome PRs
supporting SysVinit.
#2
Nice!!!
#3
Thank you. I find it very useful for Gnome. I thought I'd use it too.
#4
@Arglebargle thanks. Just great.
#5
Thanks. I've applied this. I had a bad day yesterday after about 10 tabs in chrome and swapping while syncing about 1GB to my storage at the same time.

Looking forward to see how it works.
#6
Copying your question from PM here so everyone can benefit from the answer-

james64 Wrote:I just installed zram yesterday. Thanks!

Question: Should the 500M default swap be removed?

Will swap happen to zram first? then zram?

That'll depend on the swap priority set on the default swapfile. Swaps with a higher priority are used first, when the high priority swap is full then lower priority swap will be used. Check your existing swaps by running `swapon` with no arguments or `cat /proc/swaps` to see the priorities:

Code:
root@pinebookpro:~/work/zram-swap# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/zram0                              partition       6291452 0       5

I'm pretty sure the default swapfile has a priority of 1, 0 or -1; I can't remember which. The zram-swap script sets priority 5 which should be higher.

You can safely disable the default swapfile and remove it.
#7
ah. i didn't see you post since my previous post here so pm'd. Cool. I confirmed it was working yesterday once I got back to the pinebook. thanks
#8
I've made a quick PKGBUILD for it, if anyone else has some use for it.


Code:
pkgname=zram-swap-git
_pkgname=zram-swap
pkgver=01a.r0.gd70751d
pkgrel=1
pkgdesc="A simple zram swap service for modern systemd Linux"
arch=('any')
url="https://github.com/foundObjects/zram-swap.git"
license=('MIT')
depends=('systemd' 'bash')
backup=('etc/default/zram-swap')
source=('git+https://github.com/foundObjects/zram-swap.git')
sha512sums=('SKIP')

pkgver() {
cd ${_pkgname}
git describe --long | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
cd ${_pkgname}
sed -i 's/local\/sbin/bin/g' ./service/zram-swap.service
}

package() {
cd ${_pkgname}
install -Dm0644 "$srcdir/${_pkgname}"/service/zram-swap.service "$pkgdir"/usr/lib/systemd/system/zram-swap.service
install -Dm0644 "$srcdir/${_pkgname}"/service/zram-swap.config "$pkgdir"/etc/default/zram-swap
install -Dm0755 "$srcdir/${_pkgname}"/zram-swap.sh "$pkgdir"/usr/bin/zram-swap.sh
}
#9
I use zram with zstd, and it usually compresses RAM to better than half the size.

For kernel compiling, I resize /tmp to 8G (sudo mount -o remount,size=8G /tmp) then do an overlay mount over the kernel source, so that all the build files are in RAM.
#10
(01-21-2020, 11:39 PM)Arglebarg Wrote:
Code:
root@pinebookpro:~/work/zram-swap# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/zram0                              partition       6291452 0       5

I'm pretty sure the default swapfile has a priority of 1, 0 or -1; I can't remember which. The zram-swap script sets priority 5 which should be higher.

You can safely disable the default swapfile and remove it.

What size of zram do you recommend?
PBP ISO / Debian Bullseye (unofficial installer)


Possibly Related Threads…
Thread Author Replies Views Last Post
  Official Debian support moonwalkers 64 64,793 07-08-2024, 01:40 PM
Last Post: Humid Stylus
  Armbian is [edit: no longer] dropping support for Pinebook Pro TRS-80 4 4,822 12-23-2022, 12:01 AM
Last Post: TRS-80
  Armbian VPU decoding support coming soon LivingLinux 0 1,064 11-13-2022, 02:32 PM
Last Post: LivingLinux
  Kernel 5.17 will improve VP9 support? jiyong 1 2,558 01-16-2022, 08:26 PM
Last Post: xmixahlx
  Debian GPU Support Atton 5 6,602 12-02-2021, 05:37 PM
Last Post: cobratbq
  PostmarketOS - Why swap file not on at boot? stozi 3 4,715 06-24-2021, 12:27 AM
Last Post: craftyguy
  [LibreOffice & Gimp] ARM support: no hardware acceleration on [Manjaro] Pinebook Pro regivanx 0 2,108 06-15-2021, 04:04 AM
Last Post: regivanx
  [Panfrost] now support stable OpenGL ES 3.1 rimaille 0 2,290 06-10-2021, 11:23 PM
Last Post: rimaille
  Better rkvdec support in 5.11? ShootTheMoon2 2 4,210 02-28-2021, 07:10 PM
Last Post: ShootTheMoon2
  Question about graphics support mcc 11 17,459 10-10-2020, 06:43 AM
Last Post: sigmaris

Forum Jump:


Users browsing this thread: 2 Guest(s)