Skip to content
KernelSU Modules

KernelSU Tuner

Immutable release Synced

Kernel-level tuning for rooted Android. Performance profiles that switch themselves based on temperature, screen state and charging, plus charge limiting, per-app policies and a WebUI console.

Description

KernelSU Tuner

English | 简体中文

给 KernelSU 写的一个调优模块。主要想解决两件事:把散在各个 sysfs / proc 节点的性能参数集中管起来,以及让这些参数能根据实际情况自己切换。

起因是之前用过的那些"性能优化"脚本,改完之后想还原只能重刷,而且很多脚本不看机型,往同一个值上怼。所以这个模块从第一天起就定了两条规矩:写入前必须备份原值,设备不支持就跳过而不是报错。

代码全是 shell 和原生 JS,没有依赖任何第三方东西,装完断网也能用。


环境要求

项目 要求
KernelSU v0.9.0 以上(用到 ksud module config 和 initrc 注入)
Android 10 以上
内核 4.14+,我用 5.10 GKI 实测
架构 arm64-v8a / x86_64 都行,脚本层没有架构相关代码

没在 Magisk 上测过。Magisk 应该也能跑大部分功能,但 ksud 相关的那部分(动态模块描述)会直接失效。


它到底做了什么

四档预设

powersave / balanced / performance / gaming,切档会连带改动下面这些:

  • CPU 调度器 —— 从设备实际支持的 governor 列表里挑,不是硬写 performance。有的内核只有 walt 和 schedutil,那就挑得出来的那个。
  • GPU 调频 —— 高通走 kgsl-3d0,读 num_pwrlevels 算功率档位;Mali 和通用 devfreq 走 available_governors。两条路径都试,能中哪条算哪条。
  • IO 调度器 + 预读 —— read_ahead_kb 和 nr_requests 一起调,只改调度器其实意义不大。
  • VM 内存 —— swappiness、脏页回写比例、vfs_cache_pressure。
  • 网络 —— 优先开 BBR,开不了就退到 cubic;收发缓冲区、TCP Fast Open、tcp_tw_reuse 一并设。
  • DNS —— 按档位切,性能档会开加密 DNS(DoT)。
  • ZRAM 压缩算法 —— 优先 zstd,其次 lz4。已经在用的 swap 设备会跳过,不动它。

智能驾驶 AutoPilot

一个常驻循环,5 秒一轮,读温度 / 息屏状态 / 充电状态,决定该用哪一档。

温度 >= 阈值        -> 降温档
温度在降但没到位     -> 继续降温档(滞回)
屏幕关闭            -> 省电档
充电中(可选)       -> 性能档
其他                -> 基准档

滞回这块是必须的。最早我写的是"过热后强制降温 30 秒",结果温度卡在阈值附近时会反复切档,比不切还费电。现在改成状态机:只有温度掉回 AUTO_TEMP_LOW 以下才解除冷却。

温度取值会跳过 thermal_zone 里那些明显无关的传感器,优先看 type 里带 cpu / soc / gpu / tsens / battery / skin 的。有些设备 temp 单位是摄氏度而不是毫摄氏度,代码里判断了(小于 200 就当摄氏度处理)。

电池守护 BatteryGuard

充电到设定上限就断电,掉到「上限 - 3%」再恢复,来回循环。

控制节点会按顺序找这几个,找到哪个用哪个:

charging_enabled    input_suspend    batt_slate_mode
store_mode          charge_disable

高通的 charging_enabled 和 charge_disable 极性是反的,代码里分开处理了。如果这五个节点一个都没有,会直接告诉你不支持,而不是默默失败。

提示:上限设 80% 对循环寿命帮助最明显。设 100% 等于没开。

应用待机管理

直接操作 Android 的 App Standby Bucket,比"一刀切杀后台"温和很多。

档位循环:active → working → frequent → rare → restricted

可以给任意应用单独设档,也能加白名单让它不受批量操作影响。WebUI 里有搜索框,应用多了不至于翻半天。

应用性能策略 AppWatch

按前台应用自动切档。打开游戏进游戏档,切回桌面回基准档。

前台包名识别做了三级回退,因为不同 Android 版本 dumpsys 的输出差别很大:

dumpsys activity activities   (mResumedActivity / topResumedActivity)
  ↓ 没结果
dumpsys window                (mCurrentFocus / mFocusedApp)
  ↓ 没结果
dumpsys activity top          (ACTIVITY 行)

实测覆盖了 Android 11 ~ 14 的几种格式,包括多用户(u10)和包名带下划线数字的情况。

显示调优

  • 刷新率:按档位写 peak_refresh_rate / min_refresh_rate,均衡档会把设置删掉交还给系统
  • 触控采样率:扫描 9 类触控节点,游戏档拉到 300Hz

这块不是所有机器都有节点,没有就只调刷新率,不会报错。

自定义内核参数

最后加的功能,也是我觉得最实用的。填路径和值就行,模块负责备份原值。

/sys/module/xxx/parameters/yyy   ->  你想要的值

路径限 /sys 和 /proc,会拦 .. 和 |。每次写入前记录原始值,还原时只还原自己改过的那几项,不会动别的模块留下的备份。

initrc 常驻服务

用 KernelSU 的 initrc 注入,让 init 进程在 late_start 阶段直接拉起,比 service.sh 更早。

service KernelSU-Tuner_boot   /system/bin/sh .../bin/init-apply.sh
service KernelSU-Tuner_watch  /system/bin/sh .../bin/appwatch.sh run
on property:sys.boot_completed=1
    start KernelSU-Tuner_watch

改完配置想立刻生效的话,跑一下 ksud initrc refresh,下次开机用新的。

late-load 模式下 initrc 注入不可用(KernelSU 本身的限制),这种情况 service.sh 会兜底。


安装

  1. KernelSU 管理器 → 模块 → 从本地安装 → 选 zip
  2. 重启

WebUI 在模块列表里点进去就行,动作按钮会按 省电切档 → 智能驾驶 → 电池守护 → 应用追踪 → 关闭全部 循环。


命令行

不想开 WebUI 的话,脚本都能直接调。

# 主控
sh /data/adb/modules/KernelSU-Tuner/bin/tuner.sh status      # 看当前所有状态
sh /data/adb/modules/KernelSU-Tuner/bin/tuner.sh apply gaming
sh /data/adb/modules/KernelSU-Tuner/bin/tuner.sh fast gaming  # 只切 CPU/GPU/VM,快一些
sh /data/adb/modules/KernelSU-Tuner/bin/tuner.sh monitor      # 连采 3 次实时数据
sh /data/adb/modules/KernelSU-Tuner/bin/tuner.sh revert       # 回滚所有内核参数
sh /data/adb/modules/KernelSU-Tuner/bin/tuner.sh set CPU_GOV 0
sh /data/adb/modules/KernelSU-Tuner/bin/tuner.sh trim

# 智能驾驶
sh .../bin/autopilot.sh start | stop | status
sh .../bin/autopilot.sh once     # 只跑一次决策,看看现在会选哪档

# 电池守护
sh .../bin/guard.sh start | stop | status
sh .../bin/guard.sh node         # 看识别到了哪个控制节点

# 应用待机
sh .../bin/appctl.sh list
sh .../bin/appctl.sh set com.xxx.yyy rare
sh .../bin/appctl.sh optimize    # 全部设成 rare
sh .../bin/appctl.sh hibernate   # 杀掉后台(跳过前台应用)

# 应用策略
sh .../bin/appwatch.sh set com.xxx.yyy gaming
sh .../bin/appwatch.sh fg        # 看当前识别到的前台包名

# 自定义参数
sh .../bin/custom.sh add /proc/sys/vm/swappiness 100
sh .../bin/custom.sh apply
sh .../bin/custom.sh revert

# 显示
sh .../bin/display.sh status
sh .../bin/display.sh apply gaming

# 内核扩展调优
sh .../bin/kernel.sh all gaming     # 一次跑完下面全部
sh .../bin/kernel.sh devfreq        # 总线与内存控制器调频
sh .../bin/kernel.sh devfreq-list   # 看设备有哪些 devfreq 节点
sh .../bin/kernel.sh ksm            # 内存去重
sh .../bin/kernel.sh thp            # 透明大页
sh .../bin/kernel.sh schedtune      # 调度增强
sh .../bin/kernel.sh tcp            # TCP 三层缓冲
sh .../bin/kernel.sh boost          # 触控 boost
sh .../bin/kernel.sh fs             # 文件系统上限
sh .../bin/kernel.sh status         # 各开关状态

# 自定义预设
sh .../bin/presets.sh list
sh .../bin/presets.sh save night powersave
sh .../bin/presets.sh apply night

# 守护看门狗
sh .../bin/watchdog.sh start | stop | status | log

# 配置读写与迁移
sh .../bin/cfg.sh version
sh .../bin/cfg.sh migrate

status 的输出是 KEY=VALUE 格式,好解析:

CFG_PROFILE=balanced
LIVE_GOVERNOR=walt
LIVE_CUR_FREQ=1286400
LIVE_GPUFREQ=490
...

配置文件

/data/adb/ksu_tuner/config.conf,KEY=VALUE 一行一条。重复的键以最后一条为准。

主要几个:

键 说明
PROFILE 当前预设
CPU_GOV GPU_TUNE IO_SCHED READ_AHEAD VM_TUNE NET_TUNE DNS_TUNE ZRAM_TUNE 各子系统开关,1 开 0 关
THERMAL_OPEN 温控解锁,默认关
SELINUX_PERM SELinux 宽容,默认关
AUTOPILOT AUTO_BASE AUTO_COOL AUTO_TEMP_HIGH AUTO_TEMP_LOW AUTO_SCREEN AUTO_CHARGE 智能驾驶
BATT_GUARD CHARGE_LIMIT 电池守护
APPWATCH WATCH_BASE 应用策略
DISP_TUNE 显示调优

温度阈值单位是毫摄氏度,45000 = 45°C。

改完不用重启,跑一次 tuner.sh apply 就生效。


目录结构

/data/adb/modules/KernelSU-Tuner/
├── module.prop
├── customize.sh           安装时初始化配置、设权限
├── post-fs-data.sh        建目录、校验配置、识别 late-load
├── service.sh             开机应用预设、拉起守护进程
├── boot-completed.sh      动画缩放、自动 fstrim、刷新模块描述
├── action.sh              动作按钮
├── uninstall.sh           卸载时完整还原
├── initrc/
│   └── KernelSU-Tuner.rc  init 常驻服务
├── bin/
│   ├── tuner.sh           主控,预设应用与状态查询
│   ├── autopilot.sh       温度/息屏/充电自适应
│   ├── guard.sh           充电上限
│   ├── appctl.sh          Standby Bucket 管理
│   ├── appwatch.sh        前台应用追踪
│   ├── custom.sh          自定义参数
│   ├── display.sh         刷新率与触控
│   ├── kernel.sh          devfreq/KSM/THP/schedtune/TCP/boost/fs
│   ├── presets.sh         自定义预设
│   ├── backup.sh          配置导出导入
│   ├── wipeshield.sh      防格机
│   ├── watchdog.sh        守护进程看门狗
│   ├── cfg.sh             配置原子读写与版本迁移
│   └── init-apply.sh      initrc 调用的入口
├── sepolicy.rule          SELinux 规则
└── webroot/
    └── index.html         WebUI(单文件,无外部依赖)

运行时数据在 /data/adb/ksu_tuner/(与模块 id 解耦,升级不丢配置):config.conf 配置、backup.conf 原始值备份、tuner.log 日志、各守护进程的 .pid 和 .log。


几个坑

温度阈值别设太低。 设 40°C 的话日常刷个网页都会触发降温,得不偿失。45~50 比较合理。

温控解锁和 SELinux 宽容默认关着是有原因的。 前者会让机身明显更热,长期高温反而伤电池;后者降低安全强度,调试完就该关掉。这俩我不建议长期开着。

自定义参数改之前先确认节点含义。 虽然能还原,但写错值可能当场就卡住,得进 recovery 删文件。不确定的先 cat 一下看看当前值和取值范围。

AppWatch 和 AutoPilot 别同时开。 两个都在抢着切预设,会打架。动作按钮的循环顺序已经考虑到了这点,但手动配置时容易踩。

revert 之后记得重新 apply。 回滚是把值恢复成模块第一次写入前的样子,此时配置里的开关还是开的,不重新应用的话状态和配置就对不上了。

WebUI 首次打开会读一圈状态,大概 1~2 秒。 标签页是懒加载的,切到「应用管理」才开始拉应用列表,应用多的话会再等一会儿。


卸载

直接在管理器里删就行,uninstall.sh 会:

  1. 杀掉所有守护进程
  2. 还原自定义参数和内核参数
  3. 恢复应用待机档位到 frequent
  4. 恢复刷新率和触控设置
  5. 清掉 /data/adb/ksu_tuner/

如果哪个环节没跑成功,backup.conf 里还有原始值,手动写回去就行。


测试情况

主控和守护进程都留了注入点,方便不刷机验证逻辑:

  • KSU_SYS=<路径> 把 /sys、/proc 的读取重定向到别处
  • autopilot.sh once 只跑一次决策
  • appwatch.sh fg / once 单独看前台识别结果

我用这套跑了这些场景:

  • AutoPilot 决策矩阵 12 组(常规 / 息屏 / 过热 / 临界 45°C / 充电提速 / 改基准档 / 关息屏省电 / 动态改阈值)
  • 冷却滞回时序(46°C 触发 → 43°C 保持 → 39°C 解除)
  • BatteryGuard 充放电循环 5 组(85% 断电 / 79% 保持 / 76% 恢复 / 再次断电 / 停止时恢复充电)
  • 前台识别 7 组(含 3 级回退链、多用户、特殊包名)
  • 自定义参数增删改查、非法路径拦截、节点缺失降级

在骁龙 8 Gen 2 / 内核 5.10.236 的机器上实机验证通过。


许可

GPL-3.0

Releases

v3.4.0

Latest

Version code 30040 v3.4.0

Download

Install through the KernelSU manager under Modules - Install from storage, then reboot.

Kernel extensions. A new kernel.sh covers the areas this module had not touched: devfreq bus and memory-controller clocks, KSM deduplication, transparent hugepages, schedtune boost, the full three-value TCP buffers, touch boost, and the filesystem ceilings (inotify, file-max, nr_open). Each section has its own switch and all of them are off by default.

Config versioning. Config writes now go through a temp file and an atomic rename rather than sed -i, so an interrupted write can no longer leave a half-written file. There is a SCHEMA field and a migration path that fills in new keys on existing installs without disturbing what is already set.

SELinux. The module now ships sepolicy.rule with 184 rules covering the nodes it writes. Previously some writes could be silently blocked on enforcing devices.

Watchdog. watchdog.sh checks autopilot, guard, appwatch and wipeshield every five minutes and restarts anything that died. They used to fail silently.

Also

  • periodic TRIM, interval in days
  • switch to powersave automatically below a battery level you choose
  • dry run now reports what the kernel extensions would change
  • WebUI: kernel extension switches, watchdog controls, devfreq listing

Fixed

  • safe mode appended SAFEGUARD=0 to the config, creating a duplicate key. It rewrites in place now
  • the boot-failure counter was left as an empty file when cleared

Everything from earlier versions is unchanged.

Assets 1

KernelSU-Tuner-30040-v3.4.0.zip 51.9 KiB

SHA-256 31c534b53951743834bc408f0c1cb787d3170937f2a7ecad45d481d9c23881fc · Attestations

Version code 30030 v3.3.0

Download

Install through the KernelSU manager under Modules - Install from storage, then reboot.

License - the repo now carries the GPL-3.0 text that module.yaml was already claiming.

Custom presets - save your own named profile on top of one of the four built-ins. Names are validated, and you cannot shadow a built-in.

Per-app parameters - a node and value can be bound to a package and written only while that package is in the foreground. Range checking applies. Useful for capping one game's clocks without slowing everything else.

Dry-run preview - before applying anything, ask what would change. It prints every node with its current and target value and writes nothing at all.

Also in this build

  • CHANGELOG.md covering every release so far
  • English readme, linked from the Chinese one
  • a tools tab in the WebUI for backup, presets, per-app parameters and the preview, 9 tabs total

Fixed

  • app-revert silently restored nothing: it looked up backups by the unprefixed path while the writer stored them with the KSU_SYS prefix
  • the per-app code was initially inserted inside another function and broke the script; custom.sh was rewritten with all functions at top level

Everything from earlier versions is unchanged: four profiles, adaptive switching, charge limiting, app standby management, custom parameters, display tuning, boot-failure rollback, wipe protection and config export/import.

Assets 1

KernelSU-Tuner-30030-v3.3.0.zip 43.3 KiB

SHA-256 8a2bbfc40f2dbecd1ce4aef32398f4e6c3939f3ef2f31ffe8378942f0f9c5a17 · Attestations

Version code 30020 v3.2.0

Download

Install through the KernelSU manager under Modules - Install from storage, then reboot.

This build is mostly about the things that were missing rather than new switches on top of old ones.

Config export and import - everything you have configured (options, per-app rules, custom parameters, whitelist) goes into one JSON file on your storage. Import merges rather than replaces, so keys the backup does not contain are left alone. Useful when moving to a new device or sharing a setup.

CPU frequency limits - the profiles used to change the governor and nothing else. They now set scaling_max_freq and scaling_min_freq too, snapped to frequencies your kernel actually advertises. Ranges are 10-45 percent for powersave up to 60-100 for gaming.

Range checking for custom parameters - if a node has min and max files next to it, a value outside that range is refused before it is ever written. There is a force option if you know what you are doing.

LMK and memory pressure - min_free_kbytes scaled by installed RAM, lowmemorykiller minfree per profile, watermark tuning. This is usually the real reason background apps get killed, and it was not covered before.

ZRAM sizing - if zram0 has no size yet it gets 75 percent of RAM, with mkswap and swapon. Existing sizes are left alone.

Thermal zone selection - unlocking thermal no longer disables every zone blindly. You choose which ones, cpu and gpu by default. A new zones command lists every zone with its type, mode and temperature.

Autopilot - follows the system battery saver and can force a profile during a time window, including windows that cross midnight.

Everything from earlier versions is still there: four profiles, adaptive switching, charge limiting, app standby management, per-app policies, display tuning, boot-failure rollback, wipe protection and the WebUI, now with 8 tabs.

Assets 1

KernelSU-Tuner-30020-v3.2.0.zip 40.2 KiB

SHA-256 2fc35935b2d3f56b3c0295d1e9f2abf54ab8553d55d13df1e43d2d66f0d9bb0b · Attestations

Version code 30010 v3.1.0

Download

Drop the zip into the KernelSU manager under Modules - Install from storage, then reboot.

New in this build:

CPU frequency limits - profiles now set scaling_max_freq and scaling_min_freq, not just the governor. The range is picked from the frequencies your kernel actually exposes, so nothing is hardcoded. Toggle with the CPU 频率上下限 switch.

Boot-failure rollback - the module counts boots. If the system does not come up three times in a row, it rolls back every kernel and custom parameter it changed, writes the disable flag and turns itself off. This is what protects you when a custom parameter turns out to be wrong.

Wipe protection - a new guard with three modes:

  • 增强模式: kills the process the moment a wipe command is seen
  • 普通模式: pauses and asks you first, through the WebUI
  • 不防护: logs only

It watches running processes and boot scripts for rm -rf on system paths, mkfs, dd to block devices, fastboot wipe/erase/format and shred. Temporary paths such as /tmp, /cache and /data/local/tmp are deliberately left alone.

Also: updateJson is now set, so the manager can tell you about new versions.

Everything from before is unchanged: four profiles, adaptive switching, charge limiting, app standby management, per-app policies, custom parameters, display tuning, initrc services and the WebUI.

Assets 1

KernelSU-Tuner-30010-v3.1.0.zip 35.2 KiB

SHA-256 d6af54c9eecf77ca5e604a8dce8cef732af2644f4578647def369f7689a8539c · Attestations

Version code 30003 v3.0.3

Download

Drop the zip into the KernelSU manager under Modules - Install from storage, then reboot.

If you had v3.0.2 installed, uninstall it first. The module id changed from ksu_tuner to
KernelSU-Tuner to match the registered id, so the manager treats them as two different modules.

What changed in this build:

  • module.prop and module.yaml now use id=KernelSU-Tuner, matching the registered id
  • module paths follow the id, so the module now lives at /data/adb/modules/KernelSU-Tuner
  • the initrc file and its service names were renamed to match
  • the runtime data directory intentionally stays at /data/adb/ksu_tuner so existing configuration survives

Everything else is unchanged from v3.0.2:

  • Four profiles (powersave / balanced / performance / gaming) driving CPU governor, GPU levels, IO scheduler and readahead, VM tunables, network stack, DNS and ZRAM compression
  • Adaptive switching based on temperature, screen state and charging, with hysteresis
  • Charge limiting with automatic resume
  • App Standby Bucket management with a per-app whitelist
  • Per-app profiles driven by whichever app is in the foreground
  • Custom sysfs and proc parameter editor, every change backed up first
  • Refresh rate and touch sampling tuning
  • initrc services
  • WebUI console, no external dependencies

Assets 1

KernelSU-Tuner-30003-v3.0.3.zip 30.6 KiB

SHA-256 858c59ee201a7899689e597f9c367d6deff026c9232b556c52a66be23c3658a1 · Attestations

Transparency

Tag
v3.4.0 Immutable release
Tag commit
12dc3479d773
Content commit
12dc3479d773
SHA-256
31c534b53951743834bc408f0c1cb787d3170937f2a7ecad45d481d9c23881fc
Last change synced

Verify it yourself

KernelSU Modules does not sign or audit modules. The SHA-256 only proves the download matches this index. Verify the release yourself with the GitHub CLI:

gh release verify v3.4.0 -R ylh440104/KernelSU-Tuner
gh release verify-asset v3.4.0 KernelSU-Tuner-30040-v3.4.0.zip -R ylh440104/KernelSU-Tuner