For Low-RAM Devices, Include Memory Cgroups
Leonor Gosse 于 6 天之前 修改了此页面


Starting March 27, 2025, we advocate using android-newest-release as an alternative of aosp-principal to build and contribute to AOSP. For extra data, see Changes to AOSP. Low memory killer daemon Keep organized with collections Save and categorize content material primarily based in your preferences. The Android low memory killer daemon (lmkd) course of displays the memory state of a running Android system and reacts to excessive memory pressure by killing the least important processes to maintain the system performing at acceptable levels. An Android system operating multiple processes in parallel might encounter conditions when system memory is exhausted and processes that require more memory experience noticeable delays. Memory stress, a state wherein the system is operating brief on memory, requires Android to free memory (to alleviate the strain) by throttling or killing unimportant processes, requesting processes to free noncritical cached assets, and so on. Traditionally, Android monitored system memory stress using an in-kernel low memory killer (LMK) driver, a inflexible mechanism that depends upon exhausting-coded values.


As of kernel 4.12, the LMK driver is faraway from the upstream kernel and MemoryWave Official the userspace lmkd performs memory monitoring and process killing duties. Android 10 and better assist a brand new lmkd mode that makes use of kernel pressure stall info (PSI) displays for memory strain detection. The PSI patchset within the upstream kernel (backported to 4.9 and 4.14 kernels) measures the amount of time that tasks are delayed as a result of memory shortages. As these delays directly have an effect on user experience, they characterize a convenient metric for determining memory pressure severity. The upstream kernel additionally contains PSI screens that enable privileged userspace processes (such as lmkd) to specify thresholds for these delays and to subscribe to occasions from the kernel when a threshold is breached. Because the vmpressure indicators (generated by the kernel for memory pressure detection and utilized by lmkd) usually embody numerous false positives, lmkd should carry out filtering to find out if the memory is beneath actual strain.
broadcom.com


This results in unnecessary lmkd wakeups and the usage of additional computational sources. Utilizing PSI displays outcomes in more accurate memory strain detection and minimizes filtering overhead. The default is true, making PSI monitors the default mechanism of memory pressure detection for lmkd. Low-RAM gadgets needed to be tuned aggressively, and even then would perform poorly on workloads with giant file-backed energetic pagecache. The poor performance resulted in thrashing and no kills. The LMK kernel driver relied on free-memory limits, with no scaling based on the memory pressure. Due to the rigidity of the design, companions often custom-made the driver so that it could work on their devices. The LMK driver hooked into the slab shrinker API, which wasn't designed for heavy operations corresponding to trying to find targets and killing them, which slowed down the vmscan process. The userspace lmkd implements the same performance because the in-kernel driver but makes use of existing kernel mechanisms to detect and estimate memory pressure. Such mechanisms include using kernel-generated vmpressure occasions or pressure stall data (PSI) screens to get notifications about memory stress levels, and using memory cgroup options to restrict the memory resources allotted to each course of based on course of importance.


In Android 9 and higher, userspace lmkd activates if an in-kernel LMK driver is not detected. Userspace lmkd supports kill methods based mostly on vmpressure events or PSI monitors, their severity, and different hints such as swap utilization. On low-memory units, the system ought to tolerate higher memory strain as a normal mode of operation. On excessive-performance devices, Memory Wave memory stress must be considered as an abnormal scenario and fixed earlier than it impacts total performance. Userspace lmkd additionally supports a legacy mode wherein it makes kill selections using the same methods because the in-kernel LMK driver (that's, free memory and file cache thresholds). Configure lmkd for a particular device utilizing the following properties. Android 11 improves the lmkd by introducing a new killing technique. The killing strategy uses a PSI mechanism for memory strain detection launched in Android 10. lmkd in Android 11 accounts for memory resource use ranges and thrashing to prevent memory starvation and efficiency degradation. This killing technique replaces earlier methods and MemoryWave Official can be used on each high-efficiency and low-RAM (Android Go) gadgets. For low-RAM devices, embrace memory cgroups. The memory killing strategy in Android 11 helps the tuning knobs and defaults listed below. These options work on each excessive-performance and low-RAM devices.