sm7125-common : fine tuned the post boot script

- Improved the overall script behaviour
This commit is contained in:
theshaenix
2026-01-07 23:02:53 +05:30
parent 691ae80522
commit 36fc00c6f7

View File

@@ -4,15 +4,15 @@
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of The Linux Foundation nor
# the names of its contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of The Linux Foundation nor
# the names of its contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -31,62 +31,148 @@
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
function configure_zram_parameters() {
swapoff /dev/block/zram0 2>/dev/null || true
# Reset zram device
[ -w /sys/block/zram0/reset ] && echo 1 > /sys/block/zram0/reset
# Set compression algorithm (LZ4 optimized for ARM Cortex-A76/A55)
echo lz4 > /sys/block/zram0/comp_algorithm 2>/dev/null || return 1
# Optimize compression streams for 8-core big.LITTLE (2x A76 + 6x A55)
echo 4 > /sys/block/zram0/max_comp_streams 2>/dev/null || true
# Set 4GB zram size
echo 4294967296 > /sys/block/zram0/disksize 2>/dev/null || return 1
# Initialize and enable swap
mkswap /dev/block/zram0 2>/dev/null || return 1
swapon /dev/block/zram0 -p 32758 2>/dev/null || return 1
# VM tuning - Optimized for Realme 6 Pro mobile workloads
{
# Swappiness: Slightly higher for 4GB zram to utilize it effectively
echo 100 > /proc/sys/vm/swappiness
# Cache pressure: Aggressive reclaim for mobile RAM management
echo 100 > /proc/sys/vm/vfs_cache_pressure
# Page-cluster: Small reads optimal for mobile flash + zram combo
echo 1 > /proc/sys/vm/page-cluster
# Dirty ratios: Conservative for mobile storage longevity
echo 20 > /proc/sys/vm/dirty_ratio
echo 5 > /proc/sys/vm/dirty_background_ratio
echo 20 > /proc/sys/vm/dirty_ratio
echo 2000 > /proc/sys/vm/dirty_expire_centisecs
function configure_read_ahead_kb_values() {
MemTotalStr=`cat /proc/meminfo | grep MemTotal`
MemTotal=${MemTotalStr:16:8}
# Prevent early LMK: proper memory reserve
echo 15000 > /proc/sys/vm/extra_free_kbytes
echo 38000 > /proc/sys/vm/min_free_kbytes
dmpts=$(ls /sys/block/*/queue/read_ahead_kb | grep -e dm -e mmc)
# Stable overcommit
echo 0 > /proc/sys/vm/overcommit_memory
echo 50 > /proc/sys/vm/overcommit_ratio
# Additional mobile optimizations for Snapdragon 720G
echo 1 > /proc/sys/vm/compact_memory 2>/dev/null || true
echo 0 > /proc/sys/vm/oom_kill_allocating_task 2>/dev/null || true
# Optimize readahead for mobile storage patterns
echo 128 > /sys/block/*/queue/read_ahead_kb 2>/dev/null || true
} 2>/dev/null
return 0
# Set 128 for <= 3GB &
# set 512 for >= 4GB targets.
if [ $MemTotal -le 3145728 ]; then
echo 128 > /sys/block/mmcblk0/bdi/read_ahead_kb
echo 128 > /sys/block/mmcblk0rpmb/bdi/read_ahead_kb
for dm in $dmpts; do
echo 128 > $dm
done
else
echo 512 > /sys/block/mmcblk0/bdi/read_ahead_kb
echo 512 > /sys/block/mmcblk0rpmb/bdi/read_ahead_kb
for dm in $dmpts; do
echo 512 > $dm
done
fi
}
function enable_swap() {
# Enable swap if not already enabled
if [ ! -f /proc/swaps ] || [ -z "$(cat /proc/swaps | grep zram0)" ]; then
return 0
fi
}
function configure_memory_parameters() {
# Unified memory configuration for Atoll device (Realme 6 Pro: 6GB/8GB RAM)
# Combines ZRAM setup and memory management parameters
ProductName=`getprop ro.product.name`
arch_type=`uname -m`
MemTotalStr=`cat /proc/meminfo | grep MemTotal`
MemTotal=${MemTotalStr:16:8}
# Configure ZRAM parameters with LZ4 compression
echo lz4 > /sys/block/zram0/comp_algorithm
echo 100 > /proc/sys/vm/swappiness
echo 60 > /proc/sys/vm/direct_swappiness
echo 0 > /proc/sys/vm/page-cluster
if [ -f /sys/block/zram0/disksize ]; then
# Enable deduplication if available
if [ -f /sys/block/zram0/use_dedup ]; then
echo 1 > /sys/block/zram0/use_dedup
fi
# Configure ZRAM size based on total RAM
if [ $MemTotal -le 4194304 ]; then
# 4GB RAM: 2.5GB ZRAM
echo 2684354560 > /sys/block/zram0/disksize
echo 4 > /sys/module/lowmemorykiller/parameters/almk_totalram_ratio
elif [ $MemTotal -le 6291456 ]; then
# 6GB RAM: 3GB ZRAM
echo 3221225472 > /sys/block/zram0/disksize
echo 6 > /sys/module/lowmemorykiller/parameters/almk_totalram_ratio
elif [ $MemTotal -le 8388608 ]; then
# 8GB RAM: 4GB ZRAM
echo 4294967296 > /sys/block/zram0/disksize
echo 8 > /sys/module/lowmemorykiller/parameters/almk_totalram_ratio
else
# 12GB+ RAM: 5GB ZRAM
echo 5368709120 > /sys/block/zram0/disksize
echo 10 > /sys/module/lowmemorykiller/parameters/almk_totalram_ratio
fi
# Initialize and enable ZRAM swap
mkswap /dev/block/zram0
swapon /dev/block/zram0 -p 32758
fi
# Configure Low Memory Killer parameters
# Read adj series and set adj threshold for PPR and ALMK
adj_series=`cat /sys/module/lowmemorykiller/parameters/adj`
adj_1="${adj_series#*,}"
set_almk_ppr_adj="${adj_1%%,*}"
# Calculate PPR adj threshold (HOME adj and below should not be affected)
set_almk_ppr_adj=$(((set_almk_ppr_adj * 6) + 6))
echo $set_almk_ppr_adj > /sys/module/lowmemorykiller/parameters/adj_max_shift
# Calculate vmpressure_file_min for 64-bit architecture
if [ "$arch_type" == "aarch64" ]; then
minfree_series=`cat /sys/module/lowmemorykiller/parameters/minfree`
minfree_1="${minfree_series#*,}"
rem_minfree_1="${minfree_1%%,*}"
minfree_2="${minfree_1#*,}"
rem_minfree_2="${minfree_2%%,*}"
minfree_3="${minfree_2#*,}"
rem_minfree_3="${minfree_3%%,*}"
minfree_4="${minfree_3#*,}"
rem_minfree_4="${minfree_4%%,*}"
minfree_5="${minfree_4#*,}"
vmpres_file_min=$((minfree_5 + (minfree_5 - rem_minfree_4)))
echo $vmpres_file_min > /sys/module/lowmemorykiller/parameters/vmpressure_file_min
fi
# Enable Adaptive LMK
echo 1 > /sys/module/lowmemorykiller/parameters/enable_adaptive_lmk
# Enable OOM reaper
if [ -f /sys/module/lowmemorykiller/parameters/oom_reaper ]; then
echo 1 > /sys/module/lowmemorykiller/parameters/oom_reaper
fi
# Configure Process Reclaim parameters
if [ -f /sys/devices/soc0/soc_id ]; then
soc_id=`cat /sys/devices/soc0/soc_id`
else
soc_id=`cat /sys/devices/system/soc/soc0/id`
fi
# Set PPR parameters (excluding premium SoCs)
case "$soc_id" in
"321" | "341" | "292" | "319" | "246" | "291" | "305" | "312")
# Skip PPR for premium targets
;;
*)
echo $set_almk_ppr_adj > /sys/module/process_reclaim/parameters/min_score_adj
echo 1 > /sys/module/process_reclaim/parameters/enable_process_reclaim
echo 50 > /sys/module/process_reclaim/parameters/pressure_min
echo 70 > /sys/module/process_reclaim/parameters/pressure_max
echo 30 > /sys/module/process_reclaim/parameters/swap_opt_eff
echo 512 > /sys/module/process_reclaim/parameters/per_swap_size
;;
esac
# Set global VM parameters
echo 0 > /sys/module/vmpressure/parameters/allocstall_threshold
echo 1 > /proc/sys/vm/watermark_scale_factor
# Configure read-ahead values
configure_read_ahead_kb_values
# Enable swap
enable_swap
}
# Core control parameters on silver
echo 0 0 0 0 1 1 > /sys/devices/system/cpu/cpu0/core_ctl/not_preferred
@@ -106,109 +192,94 @@ echo 85 > /proc/sys/kernel/sched_group_downmigrate
echo 100 > /proc/sys/kernel/sched_group_upmigrate
echo 1 > /proc/sys/kernel/sched_walt_rotate_big_tasks
#colocation v3 settings
# Colocation v3 settings
echo 740000 > /proc/sys/kernel/sched_little_cluster_coloc_fmin_khz
# configure governor settings for little cluster
# Configure governor settings for little cluster
echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/up_rate_limit_us
echo 0 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/down_rate_limit_us
echo 500 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/up_rate_limit_us
echo 20000 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/down_rate_limit_us
echo 1248000 > /sys/devices/system/cpu/cpu0/cpufreq/schedutil/hispeed_freq
echo 576000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
# configure governor settings for big cluster
# Configure governor settings for big cluster
echo "schedutil" > /sys/devices/system/cpu/cpu6/cpufreq/scaling_governor
echo 0 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/up_rate_limit_us
echo 0 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/down_rate_limit_us
echo 500 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/up_rate_limit_us
echo 20000 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/down_rate_limit_us
echo 1267200 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/hispeed_freq
echo 652800 > /sys/devices/system/cpu/cpu6/cpufreq/scaling_min_freq
# sched_load_boost as -6 is equivalent to target load as 85. It is per cpu tunable.
echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost
echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost
echo -6 > /sys/devices/system/cpu/cpu6/sched_load_boost
echo -6 > /sys/devices/system/cpu/cpu7/sched_load_boost
echo 85 > /sys/devices/system/cpu/cpu6/cpufreq/schedutil/hispeed_load
# Enable conservative pl for power save
echo 1 > /proc/sys/kernel/sched_conservative_pl
echo "0:1248000" > /sys/module/cpu_boost/parameters/input_boost_freq
echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms
# Set Memory parameters
configure_memory_parameters
# Enable bus-dcvs
for device in /sys/devices/platform/soc
do
for cpubw in $device/*cpu-cpu-llcc-bw/devfreq/*cpu-cpu-llcc-bw
do
echo "bw_hwmon" > $cpubw/governor
echo "2288 4577 7110 9155 12298 14236" > $cpubw/bw_hwmon/mbps_zones
echo 4 > $cpubw/bw_hwmon/sample_ms
echo 68 > $cpubw/bw_hwmon/io_percent
echo 20 > $cpubw/bw_hwmon/hist_memory
echo 0 > $cpubw/bw_hwmon/hyst_length
echo 80 > $cpubw/bw_hwmon/down_thres
echo 0 > $cpubw/bw_hwmon/guard_band_mbps
echo 250 > $cpubw/bw_hwmon/up_scale
echo 1600 > $cpubw/bw_hwmon/idle_mbps
echo 50 > $cpubw/polling_interval
done
for cpubw in $device/*cpu-cpu-llcc-bw/devfreq/*cpu-cpu-llcc-bw
do
echo "bw_hwmon" > $cpubw/governor
echo "2288 4577 7110 9155 12298 14236" > $cpubw/bw_hwmon/mbps_zones
echo 4 > $cpubw/bw_hwmon/sample_ms
echo 68 > $cpubw/bw_hwmon/io_percent
echo 20 > $cpubw/bw_hwmon/hist_memory
echo 0 > $cpubw/bw_hwmon/hyst_length
echo 80 > $cpubw/bw_hwmon/down_thres
echo 0 > $cpubw/bw_hwmon/guard_band_mbps
echo 250 > $cpubw/bw_hwmon/up_scale
echo 1600 > $cpubw/bw_hwmon/idle_mbps
echo 50 > $cpubw/polling_interval
done
for llccbw in $device/*cpu-llcc-ddr-bw/devfreq/*cpu-llcc-ddr-bw
do
echo "bw_hwmon" > $llccbw/governor
echo "1144 1720 2086 2929 3879 5931 6881 8137" > $llccbw/bw_hwmon/mbps_zones
echo 4 > $llccbw/bw_hwmon/sample_ms
echo 68 > $llccbw/bw_hwmon/io_percent
echo 20 > $llccbw/bw_hwmon/hist_memory
echo 0 > $llccbw/bw_hwmon/hyst_length
echo 80 > $llccbw/bw_hwmon/down_thres
echo 0 > $llccbw/bw_hwmon/guard_band_mbps
echo 250 > $llccbw/bw_hwmon/up_scale
echo 1600 > $llccbw/bw_hwmon/idle_mbps
echo 40 > $llccbw/polling_interval
done
for npubw in $device/*npu*-npu-ddr-bw/devfreq/*npu*-npu-ddr-bw
do
echo 1 > /sys/devices/virtual/npu/msm_npu/pwr
echo "bw_hwmon" > $npubw/governor
echo "1144 1720 2086 2929 3879 5931 6881 8137" > $npubw/bw_hwmon/mbps_zones
echo 4 > $npubw/bw_hwmon/sample_ms
echo 80 > $npubw/bw_hwmon/io_percent
echo 20 > $npubw/bw_hwmon/hist_memory
echo 10 > $npubw/bw_hwmon/hyst_length
echo 30 > $npubw/bw_hwmon/down_thres
echo 0 > $npubw/bw_hwmon/guard_band_mbps
echo 250 > $npubw/bw_hwmon/up_scale
echo 0 > $npubw/bw_hwmon/idle_mbps
echo 40 > $npubw/polling_interval
echo 0 > /sys/devices/virtual/npu/msm_npu/pwr
done
#Enable mem_latency governor for L3, LLCC, and DDR scaling
for memlat in $device/*cpu*-lat/devfreq/*cpu*-lat
do
echo "mem_latency" > $memlat/governor
echo 10 > $memlat/polling_interval
echo 400 > $memlat/mem_latency/ratio_ceil
done
#Enable cdspl3 governor for L3 cdsp nodes
for l3cdsp in $device/*cdsp-cdsp-l3-lat/devfreq/*cdsp-cdsp-l3-lat
do
echo "cdspl3" > $l3cdsp/governor
done
#Gold L3 ratio ceil
echo 4000 > /sys/class/devfreq/soc:qcom,cpu6-cpu-l3-lat/mem_latency/ratio_ceil
#Enable compute governor for gold latfloor
for latfloor in $device/*cpu*-ddr-latfloor*/devfreq/*cpu-ddr-latfloor*
do
echo "compute" > $latfloor/governor
echo 10 > $latfloor/polling_interval
done
for llccbw in $device/*cpu-llcc-ddr-bw/devfreq/*cpu-llcc-ddr-bw
do
echo "bw_hwmon" > $llccbw/governor
echo "1144 1720 2086 2929 3879 5931 6881 8137" > $llccbw/bw_hwmon/mbps_zones
echo 4 > $llccbw/bw_hwmon/sample_ms
echo 68 > $llccbw/bw_hwmon/io_percent
echo 20 > $llccbw/bw_hwmon/hist_memory
echo 0 > $llccbw/bw_hwmon/hyst_length
echo 80 > $llccbw/bw_hwmon/down_thres
echo 0 > $llccbw/bw_hwmon/guard_band_mbps
echo 250 > $llccbw/bw_hwmon/up_scale
echo 1600 > $llccbw/bw_hwmon/idle_mbps
echo 40 > $llccbw/polling_interval
done
for npubw in $device/*npu*-npu-ddr-bw/devfreq/*npu*-npu-ddr-bw
do
echo 1 > /sys/devices/virtual/npu/msm_npu/pwr
echo "bw_hwmon" > $npubw/governor
echo "1144 1720 2086 2929 3879 5931 6881 8137" > $npubw/bw_hwmon/mbps_zones
echo 4 > $npubw/bw_hwmon/sample_ms
echo 80 > $npubw/bw_hwmon/io_percent
echo 20 > $npubw/bw_hwmon/hist_memory
echo 10 > $npubw/bw_hwmon/hyst_length
echo 30 > $npubw/bw_hwmon/down_thres
echo 0 > $npubw/bw_hwmon/guard_band_mbps
echo 250 > $npubw/bw_hwmon/up_scale
echo 0 > $npubw/bw_hwmon/idle_mbps
echo 40 > $npubw/polling_interval
echo 0 > /sys/devices/virtual/npu/msm_npu/pwr
done
done
# cpuset parameters
echo 0-5 > /dev/cpuset/background/cpus
# memlat specific settings are moved to separate file under
# device/target specific folder
setprop vendor.dcvs.prop 1
# cpuset parameters for power save
echo 0-3 > /dev/cpuset/background/cpus
echo 0-5 > /dev/cpuset/system-background/cpus
# Turn off scheduler boost at the end
@@ -217,8 +288,8 @@ echo 0 > /proc/sys/kernel/sched_boost
# Turn on sleep modes
echo 0 > /sys/module/lpm_levels/parameters/sleep_disabled
# configure zram
configure_zram_parameters
# Change IO scheduler to noop for better performance
echo noop > /sys/block/sda/queue/scheduler
# Post-setup services
setprop vendor.post_boot.parsed 1
# Create 1 kswapd thread
echo 1 > /proc/sys/vm/kswapd_threads