For Low-RAM Units, Embody Memory Cgroups
Faustino Landrum edited this page 1 month ago


Beginning March 27, 2025, we recommend utilizing android-latest-launch as a substitute of aosp-fundamental to construct and contribute to AOSP. For more 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 monitors the memory state of a operating Android system and reacts to high memory stress by killing the least important processes to keep the system performing at acceptable ranges. An Android system running multiple processes in parallel might encounter situations when system memory is exhausted and processes that require extra memory experience noticeable delays. Memory stress, a state through which the system is operating brief on memory, requires Android to free memory (to alleviate the stress) by throttling or killing unimportant processes, requesting processes to free noncritical cached sources, and so forth. Historically, Android monitored system memory strain using an in-kernel low memory killer (LMK) driver, a rigid mechanism that depends upon arduous-coded values.


As of kernel 4.12, the LMK driver is faraway from the upstream kernel and the userspace lmkd performs memory monitoring and course of killing tasks. Android 10 and higher support a new lmkd mode that makes use of kernel stress stall data (PSI) screens for memory pressure detection. The PSI patchset in the upstream kernel (backported to 4.9 and 4.14 kernels) measures the amount of time that duties are delayed because of memory shortages. As these delays instantly have an effect on consumer expertise, they characterize a convenient metric for determining memory pressure severity. The upstream kernel additionally consists of PSI screens that allow privileged userspace processes (akin to lmkd) to specify thresholds for these delays and to subscribe to events from the kernel when a threshold is breached. As a result of the vmpressure alerts (generated by the kernel for memory strain detection and utilized by lmkd) typically embrace numerous false positives, lmkd should perform filtering to find out if the memory is below actual pressure.


This leads to unnecessary lmkd wakeups and using further computational assets. Utilizing PSI screens results in additional accurate memory strain detection and minimizes filtering overhead. The default is true, making PSI displays the default mechanism of memory stress detection for lmkd. Low-RAM devices had to be tuned aggressively, and even then would perform poorly on workloads with large file-backed active pagecache. The poor performance resulted in thrashing and no kills. The LMK kernel driver relied on free-memory limits, with no scaling based mostly on the memory strain. Due to the rigidity of the design, partners often custom-made the driver so that it will work on their devices. The LMK driver hooked into the slab shrinker API, which wasn't designed for heavy operations resembling searching for Memory Wave focus enhancer targets and killing them, which slowed down the vmscan course of. The userspace lmkd implements the identical performance because the in-kernel driver but uses current kernel mechanisms to detect and estimate memory pressure. Such mechanisms embody using kernel-generated vmpressure events or strain stall info (PSI) monitors to get notifications about memory pressure levels, and using memory cgroup features to restrict the memory resources allotted to each course of based mostly on course of importance.


In Android 9 and better, userspace lmkd activates if an in-kernel LMK driver isn't detected. Userspace lmkd supports kill strategies based mostly on vmpressure occasions or PSI monitors, their severity, and different hints comparable to swap utilization. On low-memory gadgets, the system ought to tolerate higher memory stress as a traditional mode of operation. On excessive-efficiency units, memory strain needs to be viewed as an abnormal situation and fixed before it affects overall performance. Userspace lmkd also supports a legacy mode by which it makes kill selections utilizing the same strategies as the in-kernel LMK driver (that is, free memory and file cache thresholds). Configure lmkd for a particular machine utilizing the next properties. Android eleven improves the lmkd by introducing a brand new killing technique. The killing technique makes use of a PSI mechanism for memory stress detection introduced in Android 10. lmkd in Android 11 accounts for memory resource use ranges and thrashing to prevent Memory Wave focus enhancer starvation and efficiency degradation. This killing strategy replaces earlier methods and can be utilized on each high-efficiency and low-RAM (Android Go) gadgets. For low-RAM gadgets, include memory cgroups. The memory killing strategy in Android eleven helps the tuning knobs and defaults listed beneath. These features work on both excessive-efficiency and low-RAM units.