Android go 低内存配置--简介

adtxl
2022-02-23 / 0 评论 / 1,766 阅读 / 正在检测是否收录...

1. 打开

可以直接在device配置中,直接include Android默认的Android go配置:

(call inherit-product, build/target/product/go_defaults.mk)

然后,正常的编译,烧写,即打开了Android go.

打开Android go会设置ro.config.low_ram属性为true,可通过此来验证是否打开成功。

console:/ # getprop | grep low
[ro.allow.mock.location]: [0]
[ro.config.low_ram]: [true]

2. Android go做的一些修改

首先看下go_defaults.mk文件(Android12中)的内容,其中build/make/target/board/go_defaults.prop文件中什么都没有,关于属性的更改会在go_defaults_common.prop中做,该文件主要就是include go_defaults_common.mk文件中的内容。

# Inherit common Android Go defaults.
$(call inherit-product, build/make/target/product/go_defaults_common.mk)

# Add the system properties.
TARGET_SYSTEM_PROP += \
    build/make/target/board/go_defaults.prop

下面看下go_defaults_common.mk中的文件内容。

2.1 go_defaults_common.mk

go_defaults_common.mk文件内容如下:

# Sets Android Go recommended default product options..

# Set lowram options and enable traced by default
PRODUCT_VENDOR_PROPERTIES += \
     ro.config.low_ram=true \

# Speed profile services and wifi-service to reduce RAM and storage.
PRODUCT_SYSTEM_SERVER_COMPILER_FILTER := speed-profile

# Always preopt extracted APKs to prevent extracting out of the APK for gms
# modules.
PRODUCT_ALWAYS_PREOPT_EXTRACTED_APK := true

# Use a profile based boot image for this device. Note that this is currently a
# generic profile and not Android Go optimized.
PRODUCT_USE_PROFILE_FOR_BOOT_IMAGE := true
PRODUCT_DEX_PREOPT_BOOT_IMAGE_PROFILE_LOCATION := frameworks/base/config/boot-image-profile.txt

# Do not generate libartd.
PRODUCT_ART_TARGET_INCLUDE_DEBUG_BUILD := false

# Do not spin up a separate process for the network stack on go devices, use an in-process APK.
PRODUCT_PACKAGES += InProcessNetworkStack
PRODUCT_PACKAGES += CellBroadcastAppPlatform
PRODUCT_PACKAGES += CellBroadcastServiceModulePlatform
PRODUCT_PACKAGES += com.android.tethering.inprocess

# Strip the local variable table and the local variable type table to reduce
# the size of the system image. This has no bearing on stack traces, but will
# leave less information available via JDWP.
PRODUCT_MINIMIZE_JAVA_DEBUG_INFO := true

# Disable Scudo outside of eng builds to save RAM.
ifneq (,$(filter eng, $(TARGET_BUILD_VARIANT)))
  PRODUCT_DISABLE_SCUDO := true
endif

# Add the system properties.
TARGET_SYSTEM_PROP += \
    build/make/target/board/go_defaults_common.prop

# use the go specific handheld_core_hardware.xml from frameworks
PRODUCT_COPY_FILES += \
    frameworks/native/data/etc/go_handheld_core_hardware.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/handheld_core_hardware.xml

# Dedupe VNDK libraries with identical core variants.
TARGET_VNDK_USE_CORE_VARIANT := true

go_defaults_common.mk中会include build/make/target/board/go_defaults_common.prop属性文件。

2.2 go_defaults_common.prop

# Sets Android Go recommended default values for propreties.

# Set lowram options
ro.lmk.critical_upgrade=true
ro.lmk.upgrade_pressure=40
ro.lmk.downgrade_pressure=60
ro.lmk.kill_heaviest_task=false

# set threshold to filter unused apps
pm.dexopt.downgrade_after_inactive_days=10

# set the compiler filter for shared apks to quicken.
# Rationale: speed has a lot of dex code expansion, it uses more ram and space
# compared to quicken. Using quicken for shared APKs on Go devices may save RAM.
# Note that this is a trade-off: here we trade clean pages for dirty pages,
# extra cpu and battery. That's because the quicken files will be jit-ed in all
# the processes that load of shared apk and the code cache is not shared.
# Some notable apps that will be affected by this are gms and chrome.
# b/65591595.
pm.dexopt.shared=quicken

# Default heap sizes. Allow up to 256m for large heaps to make sure a single app
# doesn't take all of the RAM.
dalvik.vm.heapgrowthlimit=128m
dalvik.vm.heapsize=256m

3. 使用Android go对系统造成的一些影响

3.1 对logcat的影响

当属性ro.config.low_ram=true时,logd会被影响:

根据文件system/logging/logd/README.property,

ro.config.low_ram          bool   false  if true, logd.statistics,
                                         ro.logd.kernel default false,
                                         logd.size 64K instead of 256K.
  1. logd.statistics为false,"logd.statistics"默认为svelte+,功能为Enable logcat -S statistics,统计log信息。
  2. ro.logd.kernel为false,不能使用logcat看kernel的log
  3. 将logd的size默认改小为64K

打开android go,部分logd属性如下,这里ro.logd.size为1M是因为我们在device里把大小进行了重新设置。

init.svc.logd]: [running]
[init.svc.logd-auditctl]: [stopped]
[init.svc.logd-reinit]: [stopped]
[init.svc_debug_pid.logd]: [1523]
[init.svc_debug_pid.logd-auditctl]: []
[init.svc_debug_pid.logd-reinit]: []
[logd.logpersistd.enable]: [true]
[ro.boottime.logd]: [6978878640]
[ro.boottime.logd-auditctl]: [45475594640]
[ro.boottime.logd-reinit]: [14782816960]
[ro.logd.size]: [1M]
[ro.logd.size.stats]: [64K]

下面是不打开Android go时的属性:

[init.svc.logd]: [running]
[init.svc.logd-reinit]: [stopped]
[init.svc_debug_pid.logd]: [1546]
[init.svc_debug_pid.logd-reinit]: []
[logd.logpersistd.enable]: [true]
[ro.boottime.logd]: [8855586180]
[ro.boottime.logd-reinit]: [18629724820]
[ro.logd.kernel]: [true]
[ro.logd.size]: [1M]
[ro.logd.size.stats]: [64K]
0

评论

博主关闭了当前页面的评论