Unverified Commit 09e52842 authored by Alexander Koskovich's avatar Alexander Koskovich
Browse files

common: init: Add kernel scripts from LAHAINA (15500).

Change-Id: I13eb7859b26cc9aa0ee3cff1c71b1f60d9739cd0
parent 07fb532f
......@@ -29,6 +29,13 @@ prebuilt_etc {
vendor: true,
}
prebuilt_etc {
name: "init.qti.kernel.rc",
src: "init.qti.kernel.rc",
sub_dir: "init/hw",
vendor: true,
}
prebuilt_etc {
name: "ueventd.qcom.rc",
src: "ueventd.qcom.rc",
......@@ -102,6 +109,12 @@ sh_binary {
vendor: true,
}
sh_binary {
name: "init.qti.kernel.sh",
src: "init.qti.kernel.sh",
vendor: true,
}
sh_binary {
name: "init.veth_ipa_config.sh",
src: "init.veth_ipa_config.sh",
......@@ -113,3 +126,9 @@ sh_binary {
src: "qca6234-service.sh",
vendor: true,
}
sh_binary {
name: "vendor_modprobe.sh",
src: "vendor_modprobe.sh",
vendor: true,
}
#=============================================================================
# Copyright (c) 2020 Qualcomm Technologies, Inc.
# All Rights Reserved.
# Confidential and Proprietary - Qualcomm Technologies, Inc.
#
# Copyright (c) 2012-2013, 2016-2020, The Linux Foundation. All rights reserved.
#
# 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.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#=============================================================================
function configure_zram_parameters() {
MemTotalStr=`cat /proc/meminfo | grep MemTotal`
MemTotal=${MemTotalStr:16:8}
# Zram disk - 75% for < 2GB devices .
# For >2GB devices, size = 50% of RAM size. Limit the size to 4GB.
let RamSizeGB="( $MemTotal / 1048576 ) + 1"
diskSizeUnit=M
if [ $RamSizeGB -le 2 ]; then
let zRamSizeMB="( $RamSizeGB * 1024 ) * 3 / 4"
else
let zRamSizeMB="( $RamSizeGB * 1024 ) / 2"
fi
# use MB avoid 32 bit overflow
if [ $zRamSizeMB -gt 4096 ]; then
let zRamSizeMB=4096
fi
if [ -f /sys/block/zram0/disksize ]; then
if [ -f /sys/block/zram0/use_dedup ]; then
echo 1 > /sys/block/zram0/use_dedup
fi
echo "$zRamSizeMB""$diskSizeUnit" > /sys/block/zram0/disksize
# ZRAM may use more memory than it saves if SLAB_STORE_USER
# debug option is enabled.
if [ -e /sys/kernel/slab/zs_handle ]; then
echo 0 > /sys/kernel/slab/zs_handle/store_user
fi
if [ -e /sys/kernel/slab/zspage ]; then
echo 0 > /sys/kernel/slab/zspage/store_user
fi
mkswap /dev/block/zram0
swapon /dev/block/zram0 -p 32758
fi
}
function configure_read_ahead_kb_values() {
MemTotalStr=`cat /proc/meminfo | grep MemTotal`
MemTotal=${MemTotalStr:16:8}
dmpts=$(ls /sys/block/*/queue/read_ahead_kb | grep -e dm -e mmc)
# Set 128 for <= 3GB &
# set 512 for >= 4GB targets.
if [ $MemTotal -le 3145728 ]; then
ra_kb=128
else
ra_kb=512
fi
if [ -f /sys/block/mmcblk0/bdi/read_ahead_kb ]; then
echo $ra_kb > /sys/block/mmcblk0/bdi/read_ahead_kb
fi
if [ -f /sys/block/mmcblk0rpmb/bdi/read_ahead_kb ]; then
echo $ra_kb > /sys/block/mmcblk0rpmb/bdi/read_ahead_kb
fi
for dm in $dmpts; do
echo $ra_kb > $dm
done
}
function configure_memory_parameters() {
# Set Memory parameters.
# Set swappiness to 100 for all targets
echo 100 > /proc/sys/vm/swappiness
# Disable wsf for all targets beacause we are using efk.
# wsf Range : 1..1000 So set to bare minimum value 1.
echo 1 > /proc/sys/vm/watermark_scale_factor
configure_zram_parameters
configure_read_ahead_kb_values
echo 0 > /proc/sys/vm/page-cluster
#Spawn 2 kswapd threads which can help in fast reclaiming of pages
echo 2 > /proc/sys/vm/kswapd_threads
}
# Core control parameters for silver
echo 0 0 0 0 1 1 > /sys/devices/system/cpu/cpu0/core_ctl/not_preferred
echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/min_cpus
echo 60 > /sys/devices/system/cpu/cpu0/core_ctl/busy_up_thres
echo 40 > /sys/devices/system/cpu/cpu0/core_ctl/busy_down_thres
echo 100 > /sys/devices/system/cpu/cpu0/core_ctl/offline_delay_ms
echo 8 > /sys/devices/system/cpu/cpu0/core_ctl/task_thres
# Enable Core control for Silver
echo 1 > /sys/devices/system/cpu/cpu0/core_ctl/enable
# Disable Core control on gold
echo 0 > /sys/devices/system/cpu/cpu6/core_ctl/enable
# Setting b.L scheduler parameters
echo 65 > /proc/sys/kernel/sched_downmigrate
echo 71 > /proc/sys/kernel/sched_upmigrate
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
echo 0 > /proc/sys/kernel/sched_coloc_busy_hysteresis_enable_cpus
echo 0 > /proc/sys/kernel/sched_busy_hysteresis_enable_cpus
echo 5 > /proc/sys/kernel/sched_ravg_window_nr_ticks
# disable unfiltering
echo 20000000 > /proc/sys/kernel/sched_task_unfilter_period
# cpuset parameters
echo 0-5 > /dev/cpuset/background/cpus
echo 0-5 > /dev/cpuset/system-background/cpus
# Turn off scheduler boost at the end
echo 0 > /proc/sys/kernel/sched_boost
# configure governor settings for silver cluster
echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/down_rate_limit_us
echo 0 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/up_rate_limit_us
echo 1190400 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/hispeed_freq
echo 576000 > /sys/devices/system/cpu/cpufreq/policy0/scaling_min_freq
# configure governor settings for gold cluster
echo "schedutil" > /sys/devices/system/cpu/cpufreq/policy6/scaling_governor
echo 0 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/down_rate_limit_us
echo 0 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/up_rate_limit_us
echo 1248000 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/hispeed_freq
echo 768000 > /sys/devices/system/cpu/cpufreq/policy6/scaling_min_freq
# Colocation V3 settings
echo 680000 > /sys/devices/system/cpu/cpufreq/policy0/schedutil/rtg_boost_freq
echo 0 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/rtg_boost_freq
echo 51 > /proc/sys/kernel/sched_min_task_util_for_boost
echo 35 > /proc/sys/kernel/sched_min_task_util_for_colocation
# 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 85 > /sys/devices/system/cpu/cpufreq/policy6/schedutil/hispeed_load
# configure input boost settings
echo "0:1190400" > /sys/devices/system/cpu/cpu_boost/input_boost_freq
echo 120 > /sys/devices/system/cpu/cpu_boost/input_boost_ms
# Enable bus-dcvs
for device in /sys/devices/platform/soc
do
for cpubw in $device/*cpu-cpu-ddr-bw/devfreq/*cpu-cpu-ddr-bw
do
cat $cpubw/available_frequencies | cut -d " " -f 1 > $cpubw/min_freq
echo "bw_hwmon" > $cpubw/governor
echo "1144 1720 2086 2929 3879 5931 6881 8137" > $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 40 > $cpubw/polling_interval
done
# configure compute settings for silver latfloor
for latfloor in $device/*cpu0-cpu*latfloor/devfreq/*cpu0-cpu*latfloor
do
cat $latfloor/available_frequencies | cut -d " " -f 1 > $latfloor/min_freq
echo 8 > $latfloor/polling_interval
done
# configure compute settings for gold latfloor
for latfloor in $device/*cpu6-cpu*latfloor/devfreq/*cpu6-cpu*latfloor
do
cat $latfloor/available_frequencies | cut -d " " -f 1 > $latfloor/min_freq
echo 8 > $latfloor/polling_interval
done
# configure mem_latency settings for DDR scaling
for memlat in $device/*lat/devfreq/*lat
do
cat $memlat/available_frequencies | cut -d " " -f 1 > $memlat/min_freq
echo 8 > $memlat/polling_interval
echo 400 > $memlat/mem_latency/ratio_ceil
done
#Gold CPU6 L3 ratio ceil
for l3gold in $device/*cpu6-cpu-l3-lat/devfreq/*cpu6-cpu-l3-lat
do
echo 4000 > $l3gold/mem_latency/ratio_ceil
echo 25000 > $l3gold/mem_latency/wb_filter_ratio
echo 60 > $l3gold/mem_latency/wb_pct_thres
done
#Gold CPU7 L3 ratio ceil
for l3gold in $device/*cpu7-cpu-l3-lat/devfreq/*cpu7-cpu-l3-lat
do
echo 4000 > $l3gold/mem_latency/ratio_ceil
echo 25000 > $l3gold/mem_latency/wb_filter_ratio
echo 60 > $l3gold/mem_latency/wb_pct_thres
done
done
echo N > /sys/module/lpm_levels/parameters/sleep_disabled
configure_memory_parameters
setprop vendor.post_boot.parsed 1
#=============================================================================
# Copyright (c) 2019-2021 Qualcomm Technologies, Inc.
# All Rights Reserved.
# Confidential and Proprietary - Qualcomm Technologies, Inc.
#
# Copyright (c) 2009-2012, 2014-2019, The Linux Foundation. All rights reserved.
#
# 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.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#=============================================================================
import /vendor/etc/init/hw/init.qti.kernel.test.rc
on early-init
mount debugfs debugfs /sys/kernel/debug
chmod 0755 /sys/kernel/debug
# Mount tracefs in /sys/kernel/tracing as CONFIG_DEBUG_FS might be
# disabled and /sys/kernel/debug/tracing might not be available
mount tracefs tracefs /sys/kernel/tracing
chmod 0755 /sys/kernel/tracing
chown root system /dev/kmsg
chmod 0620 /dev/kmsg
write /proc/sys/kernel/sched_boost 1
write /proc/sys/kernel/firmware_config/force_sysfs_fallback 1
on init
# Create cgroup mount point for memory
mkdir /sys/fs/cgroup/memory/bg 0750 root system
write /sys/fs/cgroup/memory/bg/memory.swappiness 140
write /sys/fs/cgroup/memory/bg/memory.move_charge_at_immigrate 1
chown root system /sys/fs/cgroup/memory/bg/tasks
chmod 0660 /sys/fs/cgroup/memory/bg/tasks
# update scheduler tunables
write /dev/cpuctl/foreground/cpu.uclamp.sched_boost_no_override 1
write /dev/cpuctl/top-app/cpu.uclamp.sched_boost_no_override 1
write /dev/cpuctl/background/cpu.uclamp.colocate 0
write /dev/cpuctl/foreground/cpu.uclamp.colocate 0
write /dev/cpuctl/top-app/cpu.uclamp.colocate 1
on post-fs
chmod 0755 /sys/kernel/debug/tracing
# set aggressive read ahead for dm-0 and dm-1 during boot up
write /sys/block/dm-0/queue/read_ahead_kb 2048
write /sys/block/dm-1/queue/read_ahead_kb 2048
write /sys/block/dm-2/queue/read_ahead_kb 2048
on early-boot
# Allow subsystem (modem etc) debugging
write /sys/kernel/boot_adsp/boot 1
write /sys/kernel/boot_cdsp/boot 1
write /sys/kernel/boot_slpi/boot 1
write /sys/devices/virtual/cvp/cvp/boot 1
on boot
# Set the console loglevel to < KERN_WARN
# Set the default message loglevel to KERN_INFO
write /proc/sys/kernel/printk "4 6 1 7"
# Allow access to emmc rawdump block partition and dload sysfs node
chown root system /dev/block/bootdevice/by-name/rawdump
chmod 0660 /dev/block/bootdevice/by-name/rawdump
chown root system /sys/kernel/dload/emmc_dload
chmod 0660 /sys/kernel/dload/emmc_dload
chown root system /dev/block/bootdevice/by-name/ramdump
chmod 0660 /dev/block/bootdevice/by-name/ramdump
chown root system /sys/kernel/dload/dload_mode
chmod 0660 /sys/kernel/dload/dload_mode
# set the io-scheduler to bfq on all mq support devices
write /sys/block/sda/queue/scheduler bfq
write /sys/block/sdb/queue/scheduler bfq
write /sys/block/sdc/queue/scheduler bfq
write /sys/block/sdd/queue/scheduler bfq
write /sys/block/sde/queue/scheduler bfq
write /sys/block/sdf/queue/scheduler bfq
write /sys/block/sdg/queue/scheduler bfq
write /sys/block/sdh/queue/scheduler bfq
write /sys/class/block/mmcblk0/queue/scheduler bfq
write /sys/class/block/mmcblk1/queue/scheduler bfq
# update io-scheduler tunables
write /sys/block/sda/queue/iosched/slice_idle 0
write /sys/block/sdb/queue/iosched/slice_idle 0
write /sys/block/sdc/queue/iosched/slice_idle 0
write /sys/block/sdd/queue/iosched/slice_idle 0
write /sys/block/sde/queue/iosched/slice_idle 0
write /sys/block/sdf/queue/iosched/slice_idle 0
write /sys/block/sdg/queue/iosched/slice_idle 0
write /sys/block/sdh/queue/iosched/slice_idle 0
write /sys/class/block/mmcblk0/queue/iosched/slice_idle 0
write /sys/class/block/mmcblk1/queue/iosched/slice_idle 0
on post-fs-data
# Create directory used for dump collection
mkdir /data/vendor/ssrdump 0770 root system
on property:persist.sys.ssr.enable_debug=*
write /sys/module/subsys_pil_tz/parameters/enable_debug ${persist.sys.ssr.enable_debug}
on property:persist.sys.mba_boot_timeout=*
write /sys/module/pil_msa/parameters/pbl_mba_boot_timeout_ms ${persist.sys.mba_boot_timeout}
on property:persist.sys.modem_auth_timeout=*
write /sys/module/pil_msa/parameters/modem_auth_timeout_ms ${persist.sys.modem_auth_timeout}
on property:persist.sys.pil_proxy_timeout=*
write /sys/module/peripheral_loader/parameters/proxy_timeout_ms ${persist.sys.pil_proxy_timeout}
on property:persist.vendor.ssr.enable_ramdumps=1
write /sys/module/subsystem_restart/parameters/enable_ramdumps 1
on property:persist.vendor.ssr.enable_ramdumps=0
write /sys/module/subsystem_restart/parameters/enable_ramdumps 0
on property:persist.vendor.sys.rawdump_copy=1
write /sys/kernel/dload/emmc_dload 1
on property:persist.vendor.sys.rawdump_copy=0
write /sys/kernel/dload/emmc_dload 0
service kernel-boot /vendor/bin/sh /vendor/bin/init.qti.kernel.sh
class core
user root
group root
disabled
oneshot
service kernel-post-boot /vendor/bin/sh /vendor/bin/init.kernel.post_boot.sh
class core
user root
group root system wakelock graphics
disabled
oneshot
on property:sys.boot_completed=1
write /dev/kmsg "Boot completed "
#Reset read ahead for dm-0, dm-1 and dm-2 to 512kb
write /sys/block/dm-0/queue/read_ahead_kb 512
write /sys/block/dm-1/queue/read_ahead_kb 512
write /sys/block/dm-2/queue/read_ahead_kb 512
write /proc/sys/vm/page-cluster 0
start kernel-boot
start kernel-post-boot
service vendor.msm_irqbalance /vendor/bin/msm_irqbalance -f /system/vendor/etc/msm_irqbalance.conf
class core
user root
group root
disabled
#! /vendor/bin/sh
#=============================================================================
# Copyright (c) 2019-2020 Qualcomm Technologies, Inc.
# All Rights Reserved.
# Confidential and Proprietary - Qualcomm Technologies, Inc.
#
# Copyright (c) 2009-2012, 2014-2019, The Linux Foundation. All rights reserved.
#
# 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.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#=============================================================================
verify_pasr_support()
{
ddr_type=`od -An -tx /proc/device-tree/memory/ddr_device_type`
ddr_type5="08"
if [ -d /sys/kernel/mem-offline ]; then
#only LPDDR5 supports PAAR
if [ ${ddr_type:4:2} != $ddr_type5 ]; then
setprop vendor.pasr.activemode.enabled false
fi
setprop vendor.pasr.enabled true
fi
}
start_msm_irqbalance()
{
if [ -f /vendor/bin/msm_irqbalance ]; then
start vendor.msm_irqbalance
fi
}
start_msm_irqbalance
verify_pasr_support
#=============================================================================
# Copyright (c) 2020 Qualcomm Technologies, Inc.
# All Rights Reserved.
# Confidential and Proprietary - Qualcomm Technologies, Inc.
#
# Copyright (c) 2009-2012, 2014-2019, The Linux Foundation. All rights reserved.
#
# 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.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#=============================================================================
function configure_zram_parameters() {
MemTotalStr=`cat /proc/meminfo | grep MemTotal`
MemTotal=${MemTotalStr:16:8}
low_ram=`getprop ro.config.low_ram`
# Zram disk - 75% for Go and < 2GB devices .
# For >2GB Non-Go devices, size = 50% of RAM size. Limit the size to 4GB.
# And enable lz4 zram compression for Go targets.
let RamSizeGB="( $MemTotal / 1048576 ) + 1"
diskSizeUnit=M
if [ $RamSizeGB -le 2 ]; then
let zRamSizeMB="( $RamSizeGB * 1024 ) * 3 / 4"
else
let zRamSizeMB="( $RamSizeGB * 1024 ) / 2"
fi
# use MB avoid 32 bit overflow
if [ $zRamSizeMB -gt 4096 ]; then
let zRamSizeMB=4096
fi
if [ "$low_ram" == "true" ]; then
echo lz4 > /sys/block/zram0/comp_algorithm
fi
if [ -f /sys/block/zram0/disksize ]; then
if [ -f /sys/block/zram0/use_dedup ]; then
echo 1 > /sys/block/zram0/use_dedup
fi
echo "$zRamSizeMB""$diskSizeUnit" > /sys/block/zram0/disksize
# ZRAM may use more memory than it saves if SLAB_STORE_USER
# debug option is enabled.
if [ -e /sys/kernel/slab/zs_handle ]; then
echo 0 > /sys/kernel/slab/zs_handle/store_user
fi
if [ -e /sys/kernel/slab/zspage ]; then
echo 0 > /sys/kernel/slab/zspage/store_user
fi
mkswap /dev/block/zram0
swapon /dev/block/zram0 -p 32758
fi
}
function configure_read_ahead_kb_values() {
MemTotalStr=`cat /proc/meminfo | grep MemTotal`
MemTotal=${MemTotalStr:16:8}
dmpts=$(ls /sys/block/*/queue/read_ahead_kb | grep -e dm -e mmc)
# Set 128 for <= 3GB &
# set 512 for >= 4GB targets.
if [ $MemTotal -le 3145728 ]; then
ra_kb=128
else
ra_kb=512
fi
if [ -f /sys/block/mmcblk0/bdi/read_ahead_kb ]; then
echo $ra_kb > /sys/block/mmcblk0/bdi/read_ahead_kb
fi
if [ -f /sys/block/mmcblk0rpmb/bdi/read_ahead_kb ]; then
echo $ra_kb > /sys/block/mmcblk0rpmb/bdi/read_ahead_kb
fi
for dm in $dmpts; do
echo $ra_kb > $dm
done
}
function configure_memory_parameters() {
# Set Memory parameters.
#
# Set per_process_reclaim tuning parameters
# All targets will use vmpressure range 50-70,
# All targets will use 512 pages swap size.
#
# Set Low memory killer minfree parameters
# 32 bit Non-Go, all memory configurations will use 15K series
# 32 bit Go, all memory configurations will use uLMK + Memcg
# 64 bit will use Google default LMK series.
#
# Set ALMK parameters (usually above the highest minfree values)
# vmpressure_file_min threshold is always set slightly higher
# than LMK minfree's last bin value for all targets. It is calculated as
# vmpressure_file_min = (last bin - second last bin ) + last bin
#