Code Monkey home page Code Monkey logo

zram-swap-manager's Introduction

zRAM Swap Manager

Foreword

This program comes with absolutely no warranty.
Use it at your own risk.
Refer to the official kernel docs, ArchWiki and/or other reputable sources for information regarding virtual memory configuration, zRAM, zswap, and swap in general.
Most users should be served by the default config.
Advanced users will probably want to tweak a thing or two.

License

Copyright (C) 2021-2023, VR25

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Generate a Magisk Module Flashable Zip

sh /path/to/zip.sh

Install/Upgrade

Android (Magisk module)
  Flash the zip or run su -c sh /path/to/install.sh [--start]

GNU/Linux
  sudo sh /path/to/install.sh [--start]

Uninstall

Android
  su -c /data/adb/modules/zram-swap-manager/uninstall.sh [[--stop] [--keep-config]]

GNU/Linux
  sudo zram-swap-manager-uninstall [[--stop] [--keep-config]]

Config

Android
  /data/adb/vr25/zram-swap-manager-data/config.txt

GNU/Linux
  /etc/zram-swap-manager.conf

Default Config

config_ver=XXXXXXXXX # used for patching; do not modify!

comp_algorithm=auto # [auto] -> zstd (288) | lz4 (210) | lzo-rle (212) | lzo (211)
comp_ratio=288 # [210], irrelevant when comp_algorithm=auto
mem_percent=33 # [33], memory limit

dynamic_swappiness=true # [true], swappiness <--> /proc/loadavg
load_sampling_rate=60 # [60] read /proc/loadavg every x seconds
high_load_threshold=90 # [90], %
high_load_swappiness=80 # [80]
medium_load_threshold=45 # [45], %
medium_load_swappiness=90 # [90]
low_load_threshold=0 # [0], %
low_load_swappiness=100 # [100]

vm="swappiness=85 page-cluster=0"

Note: One can set disksize instead of comp_ratio and mem_percent. It supports suffixes, as per the official kernel doc (e.g., disksize=1M, disksize=2G).

Terminal

Run zsm or zram-swap-manager for help.

Benchmarks

Compressor Ratio Compression Decompression
zstd 1.3.4 -1 2.877 470 MB/s 1380 MB/s
zlib 1.2.11 -1 2.743 110 MB/s 400 MB/s
brotli 1.0.2 -0 2.701 410 MB/s 430 MB/s
quicklz 1.5.0 -1 2.238 550 MB/s 710 MB/s
lzo1x 2.09 -1 2.108 650 MB/s 830 MB/s
lz4 1.8.1 2.101 750 MB/s 3700 MB/s
snappy 1.1.4 2.091 530 MB/s 1800 MB/s
lzf 3.6 -1 2.077 400 MB/s 860 MB/s

Notes/Tips

- On some Android systems, one may want to delay initialization to ensure defaults and/or third party tweaks are overridden. This can be done by adding `sleep 90` or a more elaborate logic to config.
- To disable swap on boot, add "swap_off; exit" to config, without quotes.
- To skip applying settings on boot add exit to config.

Links

zram-swap-manager's People

Contributors

mylinde avatar vr-25 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

zram-swap-manager's Issues

zsm -r being unreliable

After changing config, using zsm -r cannot apply the new config. Instead it will cycle between shrinking and growing swap. I had to reboot the phone everytime.

module got self deleted after installation

After installation (magisk --install-module //sdcard/zsm_android_2023-07-17_19.26.51.zip) module got deleted after reboot because here is a folder /data/adb/modules_update/ram-swap-manager with 3 files.

old kernels has no comp_algorithm

hammerhead:/sdcard # zsm -n

grep: /sys/block/zram0/comp_algorithm: No such file or directory
cat: can't open '/sys/block/zram0/comp_algorithm': No such file or directory
Swapspace size: 1805116k, UUID=25a4ddcd-7c67-49a9-bdc7-5f905a338a42

hammerhead:/sdcard #

defualt service arguments causing infinite boot.log

Default ./service.sh starts zram with following arguments '-dr' which causing infinite log spamming:

https://paste.debian.net/1306119/

65: '[' -x /data/adb/vr25/bin/swapoff ']'
65: >/dev/null 
65: which /data/adb/vr25/bin/swapoff
65: '[' -x /vendor/bin/swapoff ']'
66: eval /vendor/bin/swapoff /dev/block/zram0
66: /vendor/bin/swapoff /dev/block/zram0
66: echo '(i) Trying alternative: /vendor/bin/swapoff...'
(i) Trying alternative: /vendor/bin/swapoff...
65: '[' -x /system/bin/swapoff ']'
66: eval /system/bin/swapoff /dev/block/zram0
66: /system/bin/swapoff /dev/block/zram0
66: echo '(i) Trying alternative: /system/bin/swapoff...'
(i) Trying alternative: /system/bin/swapoff...
65: '[' -x /vendor/bin/swapoff ']'
66: eval /vendor/bin/swapoff /dev/block/zram0
66: /vendor/bin/swapoff /dev/block/zram0
66: echo '(i) Trying alternative: /vendor/bin/swapoff...'
(i) Trying alternative: /vendor/bin/swapoff...
65: '[' -x /sbin/swapoff ']'

'zsm -n' works tho..

EDIT: that why I recommend have 'sleep 1' in a loop scripts to prevent 100% CPU load and battery drain.

Please advise on how to write the configuration file

Is this configuration item mem_percent=33 # [33], memory limit· the option to control the size of zram?
I'm having problems modifying this option, for example, if I set 33%, the actual memory allocated is about 66% RAM.
My phone has 6G RAM, is the phone you are using for development the 12G RAM version?
Can you tell me the function of this configuration item, vm="swappiness=80 page-cluster=0· What is the function of ·vm="swappiness=80" ?

Will modifying this /sys/module/lowmemorykiller/parameters/minfree
file will change the phone's memory recycling policy?
My phone kills memory when 1GB of memory is left after zRAM is turned off, which leads to underutilized memory, I think it is more appropriate to kill memory when 256MB is left.

Applying swap parameters on Android

Hello!

Thank you for this Magisk module! I was trying to modify the ZRAM size for my device but it simply did not work, the device would freeze every time I tried to use swapoff but your module worked like a charm!

I also tried to modify some other parameters related to swap, for instance:

vm="swappiness=80 page-cluster=0 watermark_scale_factor=125"

but it did not work. I have to add this to a custom service.d script for it to work, maybe it can be used to improve the reliability of your startup scripts as well:

#!/system/bin/sh
while [ "$(getprop sys.boot_completed)" != 1 ]; do
    sleep 1
done
sysctl -w vm.watermark_scale_factor=125

Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.