summaryrefslogtreecommitdiffstats
path: root/lmkd
Commit message (Collapse)AuthorAgeFilesLines
* lmkd: Do not set soft_limit_in_bytes on high-end devicesSuren Baghdasaryan2018-05-211-31/+40
| | | | | | | | | | | | | | | Setting memory.soft_limit_in_bytes on high-end devices with large memory reserves affects performance of memory-hungry applications that have large workingsets and keep thrashing because of the memory limits imposed. Limit the usage of memory.soft_limit_in_bytes to low-memory devices only. Add debug messages for future troubleshooting to capture cases when vmpressure events are being ignored. Bug: 78916015 Test: collect vmstat while running a heavy app Change-Id: Ib4434b96d2be802ef89960b573486eae8d12f198 Merged-In: Ib4434b96d2be802ef89960b573486eae8d12f198 Signed-off-by: Suren Baghdasaryan <surenb@google.com>
* Only log the lmkd state change when the killing really happened.Yang Lu2018-05-151-5/+11
| | | | | | | | BUG: b/78603347 Test: statsd test Change-Id: I0345a47e1cd1c79a67103e401a2eb0a7fbe0631b
* Revert "Only log the lmkd state change when the killing really happened."Dan Willemsen2018-05-151-10/+5
| | | | | | | | | This reverts commit 5e60f88cab8a22d88d76f7fd49f5a6e9cc0d931b. Reason for revert: broke some builds Bug: 78603347 Change-Id: I46bf6face35f5399d7d43146b360c0703eedfb1a
* Only log the lmkd state change when the killing really happened.Yangster-mac2018-05-141-5/+10
| | | | | | Test: statsd test BUG: b/78603347 Change-Id: Ie08b0c3260f2f96b48e9e12c2c88208a3613042d
* lmkd: Enable more logs during a killSuren Baghdasaryan2018-05-111-18/+15
| | | | | | | | | | | | | Logs that provide information about memory conditions during a process kill event contain useful information and do not affect device performance because these events are rare. Enabling them even when ro.config.debug flag is not set will help in understanding low memory conditions. Bug: 79572814 Change-Id: Iae6e9bb612b9a7904ca491de3f1ddc727f24c7e0 Signed-off-by: Suren Baghdasaryan <surenb@google.com>
* Fix the stats log in lmkdYao Chen2018-05-034-8/+27
| | | | | | | | | | | | | | | | | | | 1. let logs be written to statsd directly like all other stats logs. + stats log should not write to logd anymore(b/78239479) 2. fixed the log format + need to embed the elapsed real time in the log 3. fixed the log context reuse problem +reset the log context buffer and internal state before reuse Bug: 78603347 Bug: 78239479 Test: tested with alloc_stress, and saw logs written to statsd performance measurement (memory & cpu): https://paste.googleplex.com/5508158646648832 Change-Id: I345f0eace8ba1687ff480fb88e9abba1d8533f76
* lmkd: Introduce support for legacy kill algorithm that uses minfree levelsSuren Baghdasaryan2018-04-172-25/+85
| | | | | | | | | | | | | | | | | Add ability to switch to the algorithm used by lowmemorykiller driver for determining when to kill. It uses minfree levels to decide at which levels of free memory and file cache to kill a process. oom_adj_score is also determined by comparing current memory resources against minfree levels. ro.lmk.use_minfree_levels property is introduces for switching into this mode. By default it is disabled. Bug: 77299493 Bug: 75322373 Change-Id: I6b51972951026854a079fcda33d6786b7ed035e4 Merged-In: I6b51972951026854a079fcda33d6786b7ed035e4 Signed-off-by: Suren Baghdasaryan <surenb@google.com> (cherry picked from commit d273b6630d47d6bb32996bcc87e01a73240cb228)
* lmkd: Switch to using /proc/meminfo to have access to file cache sizeSuren Baghdasaryan2018-04-171-49/+30
| | | | | | | | | | | | | | | Current mechanism of getting system memory state by using sysinfo() is not enough because it does not provide information about file cache size which is needed to correctly assess memory state. Switch to using data from /proc/meminfo that includes information provided by sysinfo() and file cache size in addition to that. Bug: 77299493 Bug: 75322373 Change-Id: I16106fc4f9254f17f776803e60502b7b6474e1b7 Merged-In: I16106fc4f9254f17f776803e60502b7b6474e1b7 Signed-off-by: Suren Baghdasaryan <surenb@google.com> (cherry picked from commit 9ac54eb2f88a4a8fc84d1da307be93f99573ead4)
* lmkd: Add zoneinfo and meminfo parsing routinesSuren Baghdasaryan2018-04-171-1/+237
| | | | | | | | | | | | /proc/zoneinfo and /proc/meminfo contain information necessary for lmkd to assess system memory state. Add routines to parse these files. Bug: 77299493 Bug: 75322373 Change-Id: Ie7d80bbb81fd0d2fc0629f6f678e6afc97fed1f6 Merged-In: Ie7d80bbb81fd0d2fc0629f6f678e6afc97fed1f6 Signed-off-by: Suren Baghdasaryan <surenb@google.com> (cherry picked from commit da0bc05b2293095c4e1153268ae7b53773f8f5ed)
* lmkd: Optimize frequent file reads by keeping file descriptors openSuren Baghdasaryan2018-04-161-15/+73
| | | | | | | | | | | | | | To check system memory state lmkd is using same files every time vmpressure event is received. Instead of opening and closing these files every time we store the file descriptor and use pread() to reread the file from the beginning. Bug: 77299493 Bug: 75322373 Change-Id: I8e27f8b9526e82e3cc313a02fce215c2e4dd3d29 Merged-In: I8e27f8b9526e82e3cc313a02fce215c2e4dd3d29 Signed-off-by: Suren Baghdasaryan <surenb@google.com> (cherry picked from commit d716fe3610aae8cefcc676ade00c7bfd2b823c20)
* lmkd: Fix usage of ro.lmk.kill_heaviest_task propertySuren Baghdasaryan2018-04-161-5/+3
| | | | | | | | | | | | | | lmkd should use ro.lmk.kill_heaviest_task property to select between algorithms for victim selection. Set ro.lmk.kill_heaviest_task default value to false in order to keep it compatible with previous versions of lmkd (killing the heaviest task is a new mechanism). Bug: 77299493 Bug: 75322373 Change-Id: I78d2dc79d9c54e636c26665605518d9c87b535b3 Merged-In: I78d2dc79d9c54e636c26665605518d9c87b535b3 Signed-off-by: Suren Baghdasaryan <surenb@google.com> (cherry picked from commit 818b59b2292f87c3781a6f7a288d10e2453b0d13)
* lmkd: Rename is_go_device variable to better reflect its functionSuren Baghdasaryan2018-04-161-4/+4
| | | | | | | | | | | | Rename is_go_device variable to low_ram_device to better reflect its meaning and relation to ro.config.low_ram variable. Bug: 77299493 Bug: 75322373 Change-Id: I6e2eaebe79cf2e6edf861f7c602e52a5b573ad0a Merged-In: I6e2eaebe79cf2e6edf861f7c602e52a5b573ad0a Signed-off-by: Suren Baghdasaryan <surenb@google.com> (cherry picked from commit fe2be6cc44073b7ef09ca849004e5072bdf18857)
* lmkd: Add lmkd README fileSuren Baghdasaryan2018-04-161-0/+60
| | | | | | | | | | | | Add README file providing lmkd overview and description for its properties. Bug: 77299493 Bug: 75322373 Change-Id: I30236dd4ccaa2b48c31dfb80b63f0b82b49b5744 Merged-In: I30236dd4ccaa2b48c31dfb80b63f0b82b49b5744 Signed-off-by: Suren Baghdasaryan <surenb@google.com> (cherry picked from commit 7e5dea82a5a2f86117722ff11c93bc672ffb7903)
* lmkd: Protect against buffer overflowGreg Kaiser2018-03-271-2/+5
| | | | | | | | | | | | We're passing a 'line' whose backing buffer is PAGE_MAX in size into memory_stat_parse_line(). We protect overflowing the smaller LINE_MAX 'key' buffer via some C preprocessing macros to assure we limit the size. Test: Local build with LMKD_LOG_STATS set for this file. Bug: 76220622 Merged-In: I9e50d4270f7099e37a9bfc7fb9b9b95cc7adb086 Change-Id: I9e50d4270f7099e37a9bfc7fb9b9b95cc7adb086
* Merge "Use usel_mkd_stats_log build variable while compiling lmkd with stats ↵TreeHugger Robot2018-03-261-0/+7
|\ | | | | | | logging feature." into pi-dev
| * Use usel_mkd_stats_log build variable while compiling lmkd with stats ↵Rajeev Kumar2018-03-231-0/+7
| | | | | | | | | | | | | | | | | | | | logging feature. Bug: 74443701 Test: Tested manually Merged-In: Ifa13cc7d1c3ff3ac71a16cf55be5a48ce808ef59 Change-Id: Ifa13cc7d1c3ff3ac71a16cf55be5a48ce808ef59 (cherry picked from commit 083be30783870ce4093d1d5f040f42f9f3c27510)
* | Fix compilation issue when LMKD_LOG_STATS is defined.Rajeev Kumar2018-03-262-15/+19
|/ | | | | | | | | Note: The breakage was caused by http://ag/3621623 Test: mmma system/core/lmkd/ Change-Id: I17033aeedb3183d4777dacb89ec84430ff061b3c Bug: 74443701 (cherry picked from commit fb25ddd9c9004de9a9ebb1175a6ceaf7aeec0673)
* lmkd: move sundry pieces to statslog.hMark Salyzyn2018-02-282-29/+45
| | | | | | | | | | | | Pragma once is not part of the standard, and is actually a gnu C++ addition. Android coding standard requires the #ifndef header wrappers. Moved things that belong in statslog.h from the lmkd files. SideEffects: None Test: lmkd_unit_tests Bug: 33808187 Bug: 72838192 Change-Id: I9686b1a0791ee2b723d05b91905eda0bb64a1156
* Fix variable name in log statement and initialize memory_stat before using it.Rajeev Kumar2018-02-221-2/+2
| | | | | | Bug: 72177881 Test: Tested manually Change-Id: Icbf948dd0e40eaa6c660d55f5cd72182436da086
* Enable lmkd kill tracing everywhereDaniel Colascione2018-02-122-12/+3
| | | | | | Test: asdf Exempt-From-Owner-Approval: vacation Change-Id: If6af7df74d303466aac4a69cdfe558e9748f72b9
* Implement stats logging in LMKD.Rajeev Kumar2018-02-093-1/+138
| | | | | | | | | | | | | | | | | | It implements logging of following atoms: -- LMK_STATE_CHANGED -- LMK_KILL_OCCURRED We would like to gather memory metrics of the process killed by LMKD because by gathering this info we would be able to analyze and improve system health by potentially reducing memory footprint of the process. This feature would be available on production builds. To know more about this see: http://go/android-p-memory-metrics Bug: 65738734 Test: Tested manually Change-Id: I064e0cdcb47c3b4c95d8b8d5654050c9812008d8
* Merge "lmkd: use after free" am: 7c3c8c27e1 am: c95fb64f0fMark Salyzyn2018-02-071-3/+3
|\ | | | | | | | | | | am: 9e11bb0cdb Change-Id: I2ee21f9d995b588a2a08eeaf9366dcfce4354e63
| * lmkd: use after freeMark Salyzyn2018-02-051-3/+3
| | | | | | | | | | | | | | | | | | Remove a use-after free reference of procp->pid, using the already captured pid variable. Test: lmkd_unit_tests Bug: 33808187 Change-Id: I3f5f8dd9acab2e28c81465d6195b73ae47e0a3c4
* | Cleanup zoneinfo parsing function.Rajeev Kumar2018-01-311-71/+0
| | | | | | | | | | | | | | | | Usage of this function was removed in http://ag/2402070 Bug: 62626918 Test: Manual Change-Id: Ib6af945d1005062d4219deae078a415bb7369261
* | lmkd: Implement lmkd-testSuren Baghdasaryan2018-01-312-0/+413
| | | | | | | | | | | | | | | | | | | | lmkd-test executes alloc-stress native application and monitors kernel logs for OOM kills. Bug: 63631020 Change-Id: Ia9441cc5f8e283131f0bc839cb808a911bcdb168 Signed-off-by: Suren Baghdasaryan <surenb@google.com>
* | lmkd: Introduce liblmkd_utils for communicating with lmkd processSuren Baghdasaryan2018-01-315-49/+343
| | | | | | | | | | | | | | | | | | | | | | | | A number of tools and tests require communication with lmkd. In order to avoid code duplication liblmkd_utils implements functions commonly used when interacting with lmkd process. Isolate communication protocol details into lmkd.h Bug: 63631020 Change-Id: Id840983d55b7db60013d52dee0c3187943811822 Signed-off-by: Suren Baghdasaryan <surenb@google.com>
* | lmkd: Add support for multiple lmkd client connectionsSuren Baghdasaryan2018-01-311-65/+128
| | | | | | | | | | | | | | | | | | | | | | | | lmkd testing requires communication with lmkd daemon to register new native processes. New implementation allows more than one communication channel to lmkd. Current max number of communication channels is set to two - one for ActivityManager and another one for a test process. Bug: 63631020 Change-Id: I736115938a3c5ad9253bce29a17cd5349af190eb Signed-off-by: Suren Baghdasaryan <surenb@google.com>
* | Functions to log stats log from LMKD.Rajeev Kumar2018-01-293-0/+151
| | | | | | | | | | | | Bug: 72177881 Test: Manual Change-Id: I0f618013e242fabae785b62eb39f9bfbcaac16da
* | Merge "Add MCL_ONFAULT to mlockall" am: ccb9960beb am: 179c81f733Daniel Colascione2018-01-241-1/+10
|\| | | | | | | | | | | am: 1592d9b458 Change-Id: I55420b49d0902dc00b5741294c05a1320bf13325
| * Add MCL_ONFAULT to mlockallDaniel Colascione2018-01-241-1/+10
| | | | | | | | | | | | | | | | | | | | | | This way, we don't fault in the entirety of our DSOs immediately; instead, used pages are "sticky" in memory. Works only on kernel 4.4 and up: downlevel, we ignore the mlockall failure. Once we get statically-linked lmkd in better shape, we'll just switch to that. Change-Id: I07a75ee3bc1264a1db41635c2acf611fede99b91
* | lmkd: Select in-kernel vs userspace lmk based on kernel driver presenceSuren Baghdasaryan2018-01-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Currently selection criteria for in-kernel vs userspace lmk is kernel driver presence and device not being a Go device. This change removes Go device check leaving kernel driver presence to be the only selection criteria. Bug: 71502948 Change-Id: I394a7920433a8d090e207ea86296356413a63fe7 Signed-off-by: Suren Baghdasaryan <surenb@google.com>
* | lmkd: Implement kill timeoutSuren Baghdasaryan2018-01-201-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | New ro.lmk.kill_timeout_ms property defines timeout in ms after a successful kill cycle for more kills to be considered. This is necessary because memory pressure after a kill does not go down instantly and system needs time to reflect new memory state. This timeout prevents extra kills in the period immediately after a kill cycle. By default it is set to 0 which disables this feature. Bug: 63631020 Test: alloc-stress Change-Id: Ia847118c8c4a659a7fc38cd5cd0042acb514ae28 Signed-off-by: Suren Baghdasaryan <surenb@google.com>
* | lmkd: Allow killing multiple processes to downgrade memory pressureSuren Baghdasaryan2018-01-171-23/+114
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Record free memory at low vmpressure levels and whenever pressure increases beyond low free up enough memory to downgrade memory pressure to low. This is done by freeing enough memory to get to the max free memory levels seen during low vmpressure. The kill logic for Go devices is not changed as these devices are designed to operate under high memory pressure. Bug: 63631020 Test: alloc-stress Change-Id: Ic8396eee08013b1c709072a13525601d5c8bf1f1 Signed-off-by: Suren Baghdasaryan <surenb@google.com>
* | lmkd: Detect the highest level of vmpressure when event is detectedSuren Baghdasaryan2018-01-171-6/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | lmkd checks for vmpressure events using epoll_wait() with eventfds of all registered events. It's possible that multiple events of different priorities happen before epoll_wait() returns. For these cases we use conservative approach by assuming that the system is under the highest registered vmpressure levels. This speeds up lmkd response time to high memory pressure by not responding to possibly stale low pressure levels when vmpressure rises quickly. Bug: 63631020 Test: alloc-stress Change-Id: I79a85c3342e7e1b3a3be82945266b2cc60b437cf Signed-off-by: Suren Baghdasaryan <surenb@google.com>
* | lmkd: Close cgroup.event_control file when done writingSuren Baghdasaryan2018-01-171-0/+1
| | | | | | | | | | | | | | | | After events are specified by writing into cgroup.event_control file the file should be closed. Change-Id: Id015e6a7bac2b74bbc8d8793c85f529ee00bdf55 Signed-off-by: Suren Baghdasaryan <surenb@google.com>
* | lmkd: Remove stale dependency on libprocessgroupSuren Baghdasaryan2018-01-172-3/+0
| | | | | | | | | | | | | | Remove stale dependencies and header file inclusions Change-Id: Ic0e7adb5bd2a0832937a831b6918e52ace4ad46a Signed-off-by: Suren Baghdasaryan <surenb@google.com>
* | lmkd: Add ability to trace lmkd killsSuren Baghdasaryan2018-01-172-0/+31
| | | | | | | | | | | | | | | | | | | | | | | | For tracing lmkd kills inside kernel it is useful to have traces indicating when and which process lmkd is killing. By default the tracing is disabled. Bug: 63631020 Test: alloc-stress Change-Id: I3ceb2bde0c292eec55855cb4535927f3b4c5d08b Signed-off-by: Suren Baghdasaryan <surenb@google.com>
* | lmkd: add logic to kill the heaviest of the eligible processesSuren Baghdasaryan2018-01-161-1/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | Killing the most memory-demanding process from the set of eligible processes yields better results on high-performance devices than killing the first one we could find. This is in line with how in-kernel lowmemorykiller driver chooses its victims. Bug: 63631020 Test: alloc-stress Change-Id: Ie1ef7f33f3e79698a9b4120c14490386d6129f9b Signed-off-by: Suren Baghdasaryan <surenb@google.com>
* | lmkd: change defaults to disable event upgrade/downgrade logicSuren Baghdasaryan2018-01-161-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | vmpressure upgrade/downgrade logic based on swap utilization works well for low memory devices because of a small swap size, however for high performance devices this measure is not a good indication of the memory pressure because of large swap resources. This change sets the default levels to disable upgrade/downgrade logic by default and each device can set these properties appropriately. Bug: 63631020 Test: alloc-stress Change-Id: Ifd4fbd4d6bb3e82f0f87b029df94934f1e7b1c9c Signed-off-by: Suren Baghdasaryan <surenb@google.com>
* | Merge "lmkd: add ability to monitor all vmpressure events"TreeHugger Robot2018-01-051-55/+81
|\ \ | |/ |/|
| * lmkd: add ability to monitor all vmpressure eventsSuren Baghdasaryan2018-01-041-55/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Ability to monitor all available vmpressure event levels is needed to accommodate systems with different memory resources. Low memory systems can rely on medium and critical level events because working under memory pressure is usual mode of operation. High performance systems with more memory need to react earlier using also low vmpressure level events to free memory early and prevent low memory condition affecting its performance. Bug: 63631020 Test: alloc-stress Change-Id: I0cef1bd4c97d32c005045ae47f0ce3464ed98899 Signed-off-by: Suren Baghdasaryan <surenb@google.com>
* | Pin lmkd for realDaniel Colascione2018-01-031-1/+3
|/ | | | | | | | | | | | | | | | | We pin lmkd in memory so that we don't take page faults (and thus requisition memory) while we're in the process of responding to a low-memory condition. mlockall(2) is the right primitive for this pinning. Previously, we used the MCL_FUTURE flag to mlockall: used this way, mlockall doesn't actually pin all pages in memory, since MCL_FUTURE affects only the default flags for future mappings and doesn't affect mapping already in existence at the time of the mlockall call --- like the lmkd executable itself. This patch adds the MCL_CURRENT flag, which also pins all pages already mapped. Test: code inspection Change-Id: I4563959367a2f0a9cadc3ea41731b7f311326685
* Merge "Add lmkd/OWNERS."Elliott Hughes2017-12-091-0/+1
|\
| * Add lmkd/OWNERS.Elliott Hughes2017-12-081-0/+1
| | | | | | | | | | | | Bug: N/A Test: N/A Change-Id: Ic4970a95d799c16ffe06bc94a85adabc18d6cc0b
* | Simplify lmkd functionalityRobert Benea2017-09-171-5/+4
| | | | | | | | | | | | | | | | Get min adj score when needed, instead to propagate from caller funct. Bug:65642829 Test: tested on gobo_512 Change-Id: I87f15c5c6206d471002828a24d0462b0abb0d196
* | Downgrade memory pressure eventsRobert Benea2017-09-141-9/+30
| | | | | | | | | | | | | | | | | | If the system has enough memory the pressure events are ignored or downgraded from critical to medium. Bug: 65642829 Test: tested on gobo Change-Id: I44e66d2e35508aceee5c1719313db217b80d582e
* | Allow ANDROID_LOW_MEMORY_KILLER to coexist with lmkdRobert Benea2017-09-111-4/+8
| | | | | | | | | | | | | | | | | | | | For Go devices fallback to memcg/memory pressure events for LMK. Go devices will use memcg pressure events while inkernel module is disabled. Bug: 64852905 Test: tested on gobo Change-Id: I267ab00be85e324331f6c91551ba013184de817e
* | Detect critical preassureRobert Benea2017-08-251-2/+50
| | | | | | | | | | | | | | | | | | | | | | When close to oom the system tend to become very thrashy and keeps paging. This change looks at the current working sent and checks it against swap. Test: tested on gobo Bug: 64721547 Change-Id: I93d42def93cbc03a01a54988fd5286ec9f124e36
* | Improvements to lmkdRobert Benea2017-08-111-18/+17
| | | | | | | | | | | | | | | | | | | | | | - Don't show misleading messages, add the correct description for the reason of process killing - Don't kill Launcher3 upgrade the score to perceptible (200) - Limit the verbose logging Test: tested on gobo Bug: 64316273 Change-Id: Ic7c13853d939afe4f20cdaa5b488b6e1810f5ddf
* | Make lmkd memory pressure levels configurable.Robert Benea2017-08-021-1/+8
| | | | | | | | | | | | | | | | | | | | | | By doing so different platforms can customize them accordingly. For instance a low mem, 512MB device can do ro.lmk.medium=400, while a device with more memory can keep the default(800). Test: tested on gobo. Bug: 64316084 Change-Id: Ifc4f3853bc06f30488adb25883ccd9aaf683ba9b