init.kernel.post_boot.sh 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #=============================================================================
  2. # Copyright (c) 2019-2023 Qualcomm Technologies, Inc.
  3. # All Rights Reserved.
  4. # Confidential and Proprietary - Qualcomm Technologies, Inc.
  5. #
  6. # Copyright (c) 2009-2012, 2014-2019, The Linux Foundation. All rights reserved.
  7. #
  8. # Redistribution and use in source and binary forms, with or without
  9. # modification, are permitted provided that the following conditions are met:
  10. # * Redistributions of source code must retain the above copyright
  11. # notice, this list of conditions and the following disclaimer.
  12. # * Redistributions in binary form must reproduce the above copyright
  13. # notice, this list of conditions and the following disclaimer in the
  14. # documentation and/or other materials provided with the distribution.
  15. # * Neither the name of The Linux Foundation nor
  16. # the names of its contributors may be used to endorse or promote
  17. # products derived from this software without specific prior written
  18. # permission.
  19. #
  20. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. # IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. # NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24. # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  27. # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29. # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  30. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. #=============================================================================
  32. function configure_zram_parameters() {
  33. MemTotalStr=`cat /proc/meminfo | grep MemTotal`
  34. MemTotal=${MemTotalStr:16:8}
  35. low_ram=`getprop ro.config.low_ram`
  36. let RamSizeGB="( $MemTotal / 1048576 ) + 1"
  37. diskSizeUnit=M
  38. # Zram disk - 75%
  39. let zRamSizeMB="( $RamSizeGB * 1024 ) * 3 / 4"
  40. # use MB avoid 32 bit overflow
  41. if [ $zRamSizeMB -gt 6144 ]; then
  42. let zRamSizeMB=6144
  43. fi
  44. # And enable lz4 zram compression for Go targets.
  45. if [ "$low_ram" == "true" ]; then
  46. echo lz4 > /sys/block/zram0/comp_algorithm
  47. fi
  48. if [ -f /sys/block/zram0/disksize ]; then
  49. if [ -f /sys/block/zram0/use_dedup ]; then
  50. echo 1 > /sys/block/zram0/use_dedup
  51. fi
  52. echo "$zRamSizeMB""$diskSizeUnit" > /sys/block/zram0/disksize
  53. # ZRAM may use more memory than it saves if SLAB_STORE_USER
  54. # debug option is enabled.
  55. if [ -e /sys/kernel/slab/zs_handle ]; then
  56. echo 0 > /sys/kernel/slab/zs_handle/store_user
  57. fi
  58. if [ -e /sys/kernel/slab/zspage ]; then
  59. echo 0 > /sys/kernel/slab/zspage/store_user
  60. fi
  61. mkswap /dev/block/zram0
  62. swapon /dev/block/zram0 -p 32758
  63. fi
  64. }
  65. verify_pasr_support()
  66. {
  67. ddr_type=`od -An -tx /proc/device-tree/memory/ddr_device_type`
  68. ddr_type5="08"
  69. if [ -d /sys/kernel/mem-offline ]; then
  70. #only LPDDR5 supports PAAR
  71. if [ ${ddr_type:4:2} != $ddr_type5 ]; then
  72. setprop vendor.pasr.activemode.enabled false
  73. fi
  74. setprop vendor.pasr.enabled true
  75. echo "pasr-enabled"
  76. fi
  77. }
  78. function configure_read_ahead_kb_values() {
  79. MemTotalStr=`cat /proc/meminfo | grep MemTotal`
  80. MemTotal=${MemTotalStr:16:8}
  81. dmpts=$(ls /sys/block/*/queue/read_ahead_kb | grep -e dm -e mmc -e sd)
  82. # dmpts holds below read_ahead_kb nodes if exists:
  83. # /sys/block/dm-0/queue/read_ahead_kb to /sys/block/dm-10/queue/read_ahead_kb
  84. # /sys/block/sda/queue/read_ahead_kb to /sys/block/sdh/queue/read_ahead_kb
  85. # Set 128 for <= 4GB &
  86. # set 512 for >= 5GB targets.
  87. if [ $MemTotal -le 4194304 ]; then
  88. ra_kb=128
  89. else
  90. ra_kb=512
  91. fi
  92. if [ -f /sys/block/mmcblk0/bdi/read_ahead_kb ]; then
  93. echo $ra_kb > /sys/block/mmcblk0/bdi/read_ahead_kb
  94. fi
  95. if [ -f /sys/block/mmcblk0rpmb/bdi/read_ahead_kb ]; then
  96. echo $ra_kb > /sys/block/mmcblk0rpmb/bdi/read_ahead_kb
  97. fi
  98. for dm in $dmpts; do
  99. if [ `cat $(dirname $dm)/../removable` -eq 0 ]; then
  100. echo $ra_kb > $dm
  101. fi
  102. done
  103. }
  104. function configure_memory_parameters() {
  105. # Set Memory parameters.
  106. #
  107. # Set per_process_reclaim tuning parameters
  108. # All targets will use vmpressure range 50-70,
  109. # All targets will use 512 pages swap size.
  110. #
  111. # Set Low memory killer minfree parameters
  112. # 32 bit Non-Go, all memory configurations will use 15K series
  113. # 32 bit Go, all memory configurations will use uLMK + Memcg
  114. # 64 bit will use Google default LMK series.
  115. #
  116. # Set ALMK parameters (usually above the highest minfree values)
  117. # vmpressure_file_min threshold is always set slightly higher
  118. # than LMK minfree's last bin value for all targets. It is calculated as
  119. # vmpressure_file_min = (last bin - second last bin ) + last bin
  120. #
  121. # Set allocstall_threshold to 0 for all targets.
  122. #
  123. #configure_zram_parameters
  124. configure_read_ahead_kb_values
  125. #echo 100 > /proc/sys/vm/swappiness
  126. # Disable periodic kcompactd wakeups. We do not use THP, so having many
  127. # huge pages is not as necessary.
  128. echo 0 > /proc/sys/vm/compaction_proactiveness
  129. MemTotalStr=`cat /proc/meminfo | grep MemTotal`
  130. MemTotal=${MemTotalStr:16:8}
  131. let RamSizeGB="( $MemTotal / 1048576 ) + 1"
  132. have_pasr=$(verify_pasr_support)
  133. if [ -z $have_pasr ]; then
  134. ## Goal is to allow all allocations to use THP whilst minimizing allocaiton delays
  135. # Allow all eligibe page faults to use THP
  136. echo always > /sys/kernel/mm/transparent_hugepage/enabled
  137. # Prevent page faults on THP-elgible VMAs from causing reclaim or compaction
  138. echo never > /sys/kernel/mm/transparent_hugepage/defrag
  139. ## Goal is to make khugepaged as inert as possible using the below settings
  140. # Prevent khugepaged from doing reclaim or compaction
  141. echo 0 > /sys/kernel/mm/transparent_hugepage/khugepaged/defrag
  142. # Minimize the number of pages that khugepaged will scan
  143. echo 1 > /sys/kernel/mm/transparent_hugepage/khugepaged/pages_to_scan
  144. # Maximize the amount of time that khugepaged is asleep for
  145. echo 4294967295 > /sys/kernel/mm/transparent_hugepage/khugepaged/scan_sleep_millisecs
  146. echo 4294967295 > /sys/kernel/mm/transparent_hugepage/khugepaged/alloc_sleep_millisecs
  147. # Restrict khugepaged promotions as much as possible. Only allow khugepaged to promote
  148. # if all pages in a VMA are (1) not invalid PTEs, (2) not swapped out PTEs, (3) not
  149. # shared PTEs.
  150. echo 0 > /sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_none
  151. echo 0 > /sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_swap
  152. echo 0 > /sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_shared
  153. else
  154. # Do not enable THP is PASR is enabled
  155. echo never > /sys/kernel/mm/transparent_hugepage/enabled
  156. fi
  157. # Set the min_free_kbytes to standard kernel value
  158. if [ $RamSizeGB -ge 8 ]; then
  159. echo 11584 > /proc/sys/vm/min_free_kbytes
  160. elif [ $RamSizeGB -ge 4 ]; then
  161. echo 8192 > /proc/sys/vm/min_free_kbytes
  162. elif [ $RamSizeGB -ge 2 ]; then
  163. echo 5792 > /proc/sys/vm/min_free_kbytes
  164. else
  165. echo 4096 > /proc/sys/vm/min_free_kbytes
  166. fi
  167. #Set per-app max kgsl reclaim limit and per shrinker call limit
  168. if [ -f /sys/class/kgsl/kgsl/page_reclaim_per_call ]; then
  169. echo 38400 > /sys/class/kgsl/kgsl/page_reclaim_per_call
  170. fi
  171. # if [ -f /sys/class/kgsl/kgsl/max_reclaim_limit ]; then
  172. # echo 51200 > /sys/class/kgsl/kgsl/max_reclaim_limit
  173. # fi
  174. }
  175. configure_memory_parameters
  176. if [ -f /sys/devices/soc0/soc_id ]; then
  177. platformid=`cat /sys/devices/soc0/soc_id`
  178. fi
  179. case "$platformid" in
  180. "557"|"577")
  181. /vendor/bin/sh /vendor/bin/init.kernel.post_boot-pineapple.sh
  182. ;;
  183. "614"|"632")
  184. /vendor/bin/sh /vendor/bin/init.kernel.post_boot-cliffs.sh
  185. ;;
  186. *)
  187. echo "***WARNING***: Invalid SoC ID\n\t No postboot settings applied!!\n"
  188. ;;
  189. esac