init.kernel.post_boot.sh 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #=============================================================================
  2. # Copyright (c) 2019-2022 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. # Zram disk - 75% for Go and < 2GB devices .
  37. # For >2GB Non-Go devices, size = 50% of RAM size. Limit the size to 4GB.
  38. # And enable lz4 zram compression for Go targets.
  39. let RamSizeGB="( $MemTotal / 1048576 ) + 1"
  40. diskSizeUnit=M
  41. if [ $RamSizeGB -le 2 ]; then
  42. let zRamSizeMB="( $RamSizeGB * 1024 ) * 3 / 4"
  43. else
  44. let zRamSizeMB="( $RamSizeGB * 1024 ) / 2"
  45. fi
  46. # use MB avoid 32 bit overflow
  47. if [ $zRamSizeMB -gt 4096 ]; then
  48. let zRamSizeMB=4096
  49. fi
  50. if [ "$low_ram" == "true" ]; then
  51. echo lz4 > /sys/block/zram0/comp_algorithm
  52. fi
  53. if [ -f /sys/block/zram0/disksize ]; then
  54. if [ -f /sys/block/zram0/use_dedup ]; then
  55. echo 1 > /sys/block/zram0/use_dedup
  56. fi
  57. echo "$zRamSizeMB""$diskSizeUnit" > /sys/block/zram0/disksize
  58. # ZRAM may use more memory than it saves if SLAB_STORE_USER
  59. # debug option is enabled.
  60. if [ -e /sys/kernel/slab/zs_handle ]; then
  61. echo 0 > /sys/kernel/slab/zs_handle/store_user
  62. fi
  63. if [ -e /sys/kernel/slab/zspage ]; then
  64. echo 0 > /sys/kernel/slab/zspage/store_user
  65. fi
  66. mkswap /dev/block/zram0
  67. swapon /dev/block/zram0 -p 32758
  68. fi
  69. }
  70. function configure_read_ahead_kb_values() {
  71. MemTotalStr=`cat /proc/meminfo | grep MemTotal`
  72. MemTotal=${MemTotalStr:16:8}
  73. dmpts=$(ls /sys/block/*/queue/read_ahead_kb | grep -e dm -e mmc -e sd)
  74. # dmpts holds below read_ahead_kb nodes if exists:
  75. # /sys/block/dm-0/queue/read_ahead_kb to /sys/block/dm-10/queue/read_ahead_kb
  76. # /sys/block/sda/queue/read_ahead_kb to /sys/block/sdh/queue/read_ahead_kb
  77. # Set 128 for <= 4GB &
  78. # set 512 for >= 5GB targets.
  79. if [ $MemTotal -le 4194304 ]; then
  80. ra_kb=128
  81. else
  82. ra_kb=512
  83. fi
  84. if [ -f /sys/block/mmcblk0/bdi/read_ahead_kb ]; then
  85. echo $ra_kb > /sys/block/mmcblk0/bdi/read_ahead_kb
  86. fi
  87. if [ -f /sys/block/mmcblk0rpmb/bdi/read_ahead_kb ]; then
  88. echo $ra_kb > /sys/block/mmcblk0rpmb/bdi/read_ahead_kb
  89. fi
  90. for dm in $dmpts; do
  91. if [ `cat $(dirname $dm)/../removable` -eq 0 ]; then
  92. echo $ra_kb > $dm
  93. fi
  94. done
  95. }
  96. function configure_memory_parameters() {
  97. # Set Memory parameters.
  98. #
  99. # Set per_process_reclaim tuning parameters
  100. # All targets will use vmpressure range 50-70,
  101. # All targets will use 512 pages swap size.
  102. #
  103. # Set Low memory killer minfree parameters
  104. # 32 bit Non-Go, all memory configurations will use 15K series
  105. # 32 bit Go, all memory configurations will use uLMK + Memcg
  106. # 64 bit will use Google default LMK series.
  107. #
  108. # Set ALMK parameters (usually above the highest minfree values)
  109. # vmpressure_file_min threshold is always set slightly higher
  110. # than LMK minfree's last bin value for all targets. It is calculated as
  111. # vmpressure_file_min = (last bin - second last bin ) + last bin
  112. #
  113. # Set allocstall_threshold to 0 for all targets.
  114. #
  115. configure_zram_parameters
  116. configure_read_ahead_kb_values
  117. echo 100 > /proc/sys/vm/swappiness
  118. # Disable periodic kcompactd wakeups. We do not use THP, so having many
  119. # huge pages is not as necessary.
  120. echo 0 > /proc/sys/vm/compaction_proactiveness
  121. # With THP enabled, the kernel greatly increases min_free_kbytes over its
  122. # default value. Disable THP to prevent resetting of min_free_kbytes
  123. # value during online/offline pages.
  124. if [ -f /sys/kernel/mm/transparent_hugepage/enabled ]; then
  125. echo never > /sys/kernel/mm/transparent_hugepage/enabled
  126. fi
  127. MemTotalStr=`cat /proc/meminfo | grep MemTotal`
  128. MemTotal=${MemTotalStr:16:8}
  129. let RamSizeGB="( $MemTotal / 1048576 ) + 1"
  130. # Set the min_free_kbytes to standard kernel value
  131. if [ $RamSizeGB -ge 8 ]; then
  132. echo 11584 > /proc/sys/vm/min_free_kbytes
  133. elif [ $RamSizeGB -ge 4 ]; then
  134. echo 8192 > /proc/sys/vm/min_free_kbytes
  135. elif [ $RamSizeGB -ge 2 ]; then
  136. echo 5792 > /proc/sys/vm/min_free_kbytes
  137. else
  138. echo 4096 > /proc/sys/vm/min_free_kbytes
  139. fi
  140. }
  141. configure_memory_parameters
  142. if [ -f /sys/devices/soc0/chip_family ]; then
  143. chipfamily=`cat /sys/devices/soc0/chip_family`
  144. fi
  145. case "$chipfamily" in
  146. "0x74")
  147. /vendor/bin/sh /vendor/bin/init.kernel.post_boot-taro.sh
  148. ;;
  149. "0x7B"|"0x7b")
  150. /vendor/bin/sh /vendor/bin/init.kernel.post_boot-diwali.sh
  151. ;;
  152. "0x82")
  153. /vendor/bin/sh /vendor/bin/init.kernel.post_boot-cape.sh
  154. ;;
  155. *)
  156. echo "***WARNING***: Invalid chip family\n\t No postboot settings applied!!\n"
  157. ;;
  158. esac