Commit Graph

515 Commits

Author SHA1 Message Date
Suren Baghdasaryan ffce101d86 lmkd: Handle cases when proc_get_name() might return NULL
proc_get_name() can return NULL if the corresponding process has died
or open fails with ENOMEM due to memory shortages.
Ensure such cases are handled without NULL pointer access.

Bug: 186157675
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I05b288e3808bec0bdb73db32de02ba3a322ca6e1
(cherry picked from commit e5995b8269)
2021-05-20 00:02:07 +00:00
android-build-team Robot 547707cc2e Snap for 7269201 from e68bfe9a73 to rvc-qpr3-release
Change-Id: I4121184ff7bb28e9ee2d7e029d6d875833c46504
2021-04-08 22:07:02 +00:00
Suren Baghdasaryan e68bfe9a73 lmkd: Allow lmkd to kill perceptible apps during heavy thrashing
Occasionally a system can get into heavy file cache thrashing situation
and become unresponsive. In these situations we observe lmkd wakeups,
however it does not kill because all non-perceptible apps are already
killed and the system manages to reclaim enough memory to stay above
min watermark.
Add ro.lmk.thrashing_limit_critical property which when breached will
allow lmkd to kill perceptible apps. The property represents the
percentage of refaulted workingset pages as a fraction of overall file
cache size. By default it is disabled.

Bug: 181778155
Test: thrashing.py 500 10 200
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Merged-In: Icb38ef6c90adaa4f5c956593b6ea0c4febc91dc0
Change-Id: Icb38ef6c90adaa4f5c956593b6ea0c4febc91dc0
2021-04-07 11:55:04 +08:00
Suren Baghdasaryan 720abce177 lmkd: choose the heaviest task when killing perceptible processes
When killing a task at or lower than oom_score_adj PERCEPTIBLE_APP_ADJ
choose the heaviest task among the ones at that level to try minimizing
the number of required kills. Because killing a perceptible app will
affect user experience anyway, it makes sense to choose the one that
will release the most memory and therefore no more kills might be
necessary.

Bug: 181778155
Test: running thrashing.py script
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Merged-In: I775ff774430b6fde4d619ede794825dbae59fd8e
Change-Id: I775ff774430b6fde4d619ede794825dbae59fd8e
2021-04-07 11:50:57 +08:00
Suren Baghdasaryan 140385d3a0 lmkd: report kill reason, and meminfo details to statsd for each kill
Information like free memory and swap as well as kill reason would be
useful for understanding regressions in the number of lmk kills in the
field.

Bug: 168117803
Test: statsd_testdrive 51, load with lmk_unit_test
Merged-In: Ic46aed3c85b880b32ac5ad61b55f90e0d33517c7
Change-Id: Ic46aed3c85b880b32ac5ad61b55f90e0d33517c7
2020-09-15 11:34:27 -07:00
Martin Liu d816ab7c54 lmkd: fix possible long stall state
If the first PSI event triggers a kill, lmkd won't resume polling
immediately after the process has died. Instead, it will wait until the
next PSI event to resume the polling which is too late when the device
is under memory pressure. This happens if data communication with AMS
happens after previous polling window expired, in which case paused
handler gets reset and polling does not resume after the kill.
Fix this by changing pause handler reset logic.

Bug: 167562248
Test: memory pressure test
Signed-off-by: Martin Liu <liumartin@google.com>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Merged-In: I10c65c85b718a656e3d8991bf09948b96da895cb
Change-Id: I10c65c85b718a656e3d8991bf09948b96da895cb
2020-09-07 10:46:16 +08:00
Martin Liu 91bf598282 lmkd: avoid division by zero because of file_base_lru
It seems we have chance that file_base_lru is zero.
Avoid it by adding 1.

Bug: 167660459
Bug: 163134367
Test: boot
Signed-off-by: Martin Liu <liumartin@google.com>
Merged-In: If19dbbaafe6cd28a9d5b7f8a002f3cd33daab5e7
Change-Id: If19dbbaafe6cd28a9d5b7f8a002f3cd33daab5e7
2020-09-07 10:43:24 +08:00
Martin Liu 94d99a7bc8 lmkd: adjust thrashing dection strategy
When a device is thrashing the file cache, workingset refaults can
grow slowly because of variant reasons. Current thrashing detection
mechanism could reset the thrashing counter frequently as it relies
on presence of reclaim activity, however refaults can keep increasing
even when the device is not actively reclaiming. In addition, the
thrashing counter gets reset when conditions require a kill but lmkd
could not find an eligible process to be killed. This is problematic
because when this happens thrashing is being ignored.

Use a fixed 1 sec periods to aggregate the thrashing counter. Also we
need to keep monitoring thrashing counter while retrying as someone
could release the memory to mitigate the thrashing. If thrashing
counter is greater than the limit at the end of the 1 sec period this
means lmkd failed to find an eligible process to kill. In this case
we store accumulated thrashing in case a new eligible process appears
until accumulated thrashing is less that the limit or we miss an
entire 1 sec window.

Bug: 163134367
Test: heavy loading launch
Signed-off-by: Martin Liu <liumartin@google.com>
Merged-In: Ie9f4121ea604179c0ad510cc8430e7a6aec6e6b2
Change-Id: Ie9f4121ea604179c0ad510cc8430e7a6aec6e6b2
2020-09-07 10:42:51 +08:00
Martin Liu cd5f08d8ee Revert "lmkd: Add a margin for watermark when swap free is low"
This reverts commit 95551f816a.

Reason to revert: don't need this change.
Bug: 163134367

Signed-off-by: Martin Liu <liumartin@google.com>
Change-Id: I8b209b054b6caec553bce13cd51f931401c1e42a
2020-09-07 10:42:40 +08:00
Martin Liu 07c9ed14e3 lmkd: Add a margin for watermark when swap free is low am: 95551f816a
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/memory/lmkd/+/12361021

Change-Id: Iadbc1b44c4699b9a0a1f74edce25eb5817615f5c
2020-08-14 14:15:32 +00:00
Martin Liu 95551f816a lmkd: Add a margin for watermark when swap free is low
When swap is depleted file cache thrashing might result in allocations
quickly pushing memory below low watermark and kswapd quickly pushing
it back above high watermark. In this situation free memory stays above
high watermark most of the time and lmkd during its periodic wake-ups
has low chance of detecting low memory conditions. Add a 15% margin
for high watermark which would allow lmkd to kill if swap is low,some
memory was reclaimed since the last wakeup and free memory is just
above the high watermark limit.

Bug: 163134367
Test: heavy loading launch
Signed-off-by: Martin Liu <liumartin@google.com>
Change-Id: I5694736b04bafcd13c01f4b51e242e2ac4ff55a8
2020-08-14 04:29:48 +00:00
Suren Baghdasaryan 2c509d9073 lmkd: Add lmkd wakeup information into killinfo logs am: fa667edb56
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/memory/lmkd/+/12245884

Change-Id: I0e84d86642df4dc4097f01ab7f6f94ba441f3692
2020-07-30 01:43:30 +00:00
Suren Baghdasaryan 504a7cafc5 lmkd: Set default kill timeout to limit waits for uninterruptible processes am: dd8c2c181b
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/memory/lmkd/+/12245883

Change-Id: I65c4ef026b2118d09fd3d3cdd2ff5aab2bf66cd2
2020-07-30 01:43:29 +00:00
Suren Baghdasaryan fa667edb56 lmkd: Add lmkd wakeup information into killinfo logs
Oftentimes while investigating bugreports it's unclear whether lmkd
was active between kills. To provide visibility into lmkd activity
adding the following fields into killinfo reports:
MsSinceEvent - number of msecs since the last PSI/vmpressure event
MsSincePrevWakeup - number of msecs since the previous wakeup
WakeupsSinceEvent - number of wakeups since the last PSI/vmpressure
event
SkippedWakeups - number of wakeups that were skipped due to an
incomplete kill

Bug: 162034541
Bug: 161955028
Bug: 162297751
Test: lmkd_unit_test
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I0356c27515132ff0dd309b59a8bf907acbd67cd8
(cherry picked from commit d7b4fcb8a5)
Signed-off-by: Martin Liu <liumartin@google.com>
Merged-In: I0356c27515132ff0dd309b59a8bf907acbd67cd8
2020-07-30 01:33:27 +00:00
Suren Baghdasaryan dd8c2c181b lmkd: Set default kill timeout to limit waits for uninterruptible processes
When lmkd tries to kill a process in uninterruptible sleep state, it may
need to wait for a long time. To prevent this set the default kill timeout
to 100ms which should work for majority of the devices.

Bug: 160295034
Bug: 161955028
Bug: 162297751
Test: lmkd_unit_test
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Ia280dc095df9ca8494278e0a75b976ed93fc04ae
(cherry picked from commit 7d1f4f0047)
Signed-off-by: Martin Liu <liumartin@google.com>
Merged-In: Ia280dc095df9ca8494278e0a75b976ed93fc04ae
2020-07-28 09:13:44 +00:00
Martin Liu 8087e1104c lmkd: Fix do not kill perceptible apps due to low swap if above min wmark am: dfc73bc2fe am: 62f4f4262e
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/memory/lmkd/+/11699841

Change-Id: I3213442a2628581dedb0ccf753c70643d55acce0
2020-06-02 21:11:17 +00:00
Martin Liu 62f4f4262e lmkd: Fix do not kill perceptible apps due to low swap if above min wmark am: dfc73bc2fe
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/memory/lmkd/+/11699841

Change-Id: Iee2254c3047d939a82bbaf7de9e350ea1df4ea20
2020-06-02 20:55:29 +00:00
Martin Liu dfc73bc2fe lmkd: Fix do not kill perceptible apps due to low swap if above min wmark
Fix code logic to obey our intetion of not killing perceptible apps
due to low swap if above min wmark.

Bug: 155709603
Test: boot
Signed-off-by: Martin Liu <liumartin@google.com>
Merged-In: Ifc09c2a1fe7e21faa096988f471644f63951d81c
Change-Id: Ifc09c2a1fe7e21faa096988f471644f63951d81c
2020-06-02 23:47:01 +08:00
Suren Baghdasaryan 0a55215fbe lmkd: Do not kill perceptible apps due to low swap if above min wmark am: 7afa463978 am: 747c846a5a
Change-Id: I546012e24b96df68eb303e3c940d2b8fc596c62b
2020-05-21 00:35:46 +00:00
Suren Baghdasaryan 747c846a5a lmkd: Do not kill perceptible apps due to low swap if above min wmark am: 7afa463978
Change-Id: Ib75f23cdd2fc21a32c8e2f6c303ad59ca531b026
2020-05-21 00:09:51 +00:00
Suren Baghdasaryan 7afa463978 lmkd: Do not kill perceptible apps due to low swap if above min wmark
Prevent kills of perceptible apps due to swap shortages unless system
free memory is below the min watermark. This prevents kills of important
apps when the system is recovering from the memory pressure.

Bug: 155709603
Test: memory stress test with multiple foreground apps
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Merged-In: I6beb4b55f8b4f7bc22818b5a7bdfa3adc6cd31c1
Change-Id: I6beb4b55f8b4f7bc22818b5a7bdfa3adc6cd31c1
2020-05-20 20:48:06 +00:00
Suren Baghdasaryan 10be4c368e lmkd: Set the default free swap threshold to 10% for all devices am: c2b228e498 am: b0027daa8a
Change-Id: I6e2a4793cf262628a6788d5c0ecae1b30919ec61
2020-05-20 19:16:03 +00:00
Suren Baghdasaryan 0b210fe185 lmkd: Fix min_score_adj to exclude killing foreground processes am: 0e589f61ba am: 3125ebc794
Change-Id: I2c718dfb23f06010ce56c7bb9f8fdc346523494e
2020-05-20 19:15:57 +00:00
Suren Baghdasaryan b0027daa8a lmkd: Set the default free swap threshold to 10% for all devices am: c2b228e498
Change-Id: I750cb3aa52c7341374ed692040d9ff88b5ae907c
2020-05-20 18:59:48 +00:00
Suren Baghdasaryan 3125ebc794 lmkd: Fix min_score_adj to exclude killing foreground processes am: 0e589f61ba
Change-Id: I1d8d38af4a50239721428bd2bff008cf1b00e198
2020-05-20 18:59:19 +00:00
Suren Baghdasaryan 15b83b66d1 lmkd: Enable stricter compiler checks am: 5096d16091 am: 2b90436606
Change-Id: If46294fade5d9c122e78e65d359aec784f3e052e
2020-05-20 00:54:07 +00:00
Suren Baghdasaryan aabfa71492 lmkd: Remove unused variables and fix type mismatches am: dd7ec447ab am: 9cc5e9624f
Change-Id: I811f18d5574be6a09045d4e8d5d15b4d33166612
2020-05-20 00:54:05 +00:00
Suren Baghdasaryan de6c2612e2 lmkd: enable ro.lmk.kill_timeout_ms to be used with kill notifications am: c7e51b7b2a am: c5969c34b2
Change-Id: I09b3b29ac5e3cbd37ed4c0d72c1061ae79fbc540
2020-05-20 00:54:03 +00:00
Suren Baghdasaryan 0425267bf2 lmkd: polling code cleanup am: 3f84a211e5 am: 8a6cf251b8
Change-Id: I1b7e6c55b8a188b7a40cb618bb0c1b7a1fef0e5b
2020-05-20 00:54:01 +00:00
Suren Baghdasaryan 2b90436606 lmkd: Enable stricter compiler checks am: 5096d16091
Change-Id: I36d6b5276ac8cc8012c584069fe546584a592fb8
2020-05-20 00:28:32 +00:00
Suren Baghdasaryan 9cc5e9624f lmkd: Remove unused variables and fix type mismatches am: dd7ec447ab
Change-Id: I7703e61d915ba89190030e2f1e302b17b749369c
2020-05-20 00:28:30 +00:00
Suren Baghdasaryan c5969c34b2 lmkd: enable ro.lmk.kill_timeout_ms to be used with kill notifications am: c7e51b7b2a
Change-Id: Ica5909a02fd969771df38b37b85dd9e768c8b430
2020-05-20 00:28:29 +00:00
Suren Baghdasaryan 8a6cf251b8 lmkd: polling code cleanup am: 3f84a211e5
Change-Id: I5265d3370371ea5b4c07dce31af732f6d4f29c71
2020-05-20 00:28:27 +00:00
Suren Baghdasaryan c2b228e498 lmkd: Set the default free swap threshold to 10% for all devices
Lower the min swap threshold to 10% for all devices to limit kills while
swap still has enough space.

Bug: 155709603
Test: memory stress test with multiple foreground apps
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I443486763c034ed0603ea52b81c060c3969af9a5
2020-05-20 00:20:40 +00:00
Suren Baghdasaryan 0e589f61ba lmkd: Fix min_score_adj to exclude killing foreground processes
In the cases when foreground processes should not be killed
min_score_adjust should be set above PERCEPTIBLE_APP_ADJ to prevent such
kills.

Bug: 155709603
Test: memory stress test with multiple foreground apps
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: If187654b8001ce843ec6085ccd2042d75a986dae
2020-05-20 00:20:14 +00:00
Suren Baghdasaryan 5096d16091 lmkd: Enable stricter compiler checks
Enable -Wall and -Wextra compiler flags to catch compilation warnings.

Bug: 147315292
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Merged-In: Ia802dbd7abb167d66b76390e269e4a4418ca5def
Change-Id: Ia802dbd7abb167d66b76390e269e4a4418ca5def
2020-05-19 15:53:36 -07:00
Suren Baghdasaryan dd7ec447ab lmkd: Remove unused variables and fix type mismatches
Fix compilation warnings by removing unused variables and add typecasting
whenever mixed type comparisons are performed.

Bug: 147315292
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Merged-In: I7f0839d803a6bf6532f077208ce54aba761dc9fe
Change-Id: I7f0839d803a6bf6532f077208ce54aba761dc9fe
2020-05-19 15:52:19 -07:00
Suren Baghdasaryan c7e51b7b2a lmkd: enable ro.lmk.kill_timeout_ms to be used with kill notifications
Allow lmkd to stop waiting for a kill notification if a kill takes longer
than ro.lmk.kill_timeout_ms.

Bug: 147315292
Test: lmkd_unit_test with ro.lmk.kill_timeout_ms set to 100
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Merged-In: Ia3eed3448fd6928a5e634c2737044722048b3578
Change-Id: Ia3eed3448fd6928a5e634c2737044722048b3578
2020-05-19 15:51:27 -07:00
Suren Baghdasaryan 3f84a211e5 lmkd: polling code cleanup
- Remove unused POLLING_STOP state
- Simplify POLLING_DO_NOT_CHANGE state handling
- Correct last_poll_tm assignment logic

Bug: 147315292
Test: lmkd_unit_test
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Merged-In: If0674eda954a25f0f6c9188501ff77db8ba0813b
Change-Id: If0674eda954a25f0f6c9188501ff77db8ba0813b
2020-05-19 15:50:18 -07:00
Suren Baghdasaryan f8ea710bef lmkd: Add property re-initialization support am: c4081918a7 am: a84a5e5801
Change-Id: Id3001f3ea024c9bf30ae919949c709f2776923e5
2020-05-08 22:40:41 +00:00
Suren Baghdasaryan a84a5e5801 lmkd: Add property re-initialization support am: c4081918a7
Change-Id: I538cee8d0825d61ad5283e8a504e8cc74e5aa69a
2020-05-08 22:24:38 +00:00
Suren Baghdasaryan c4081918a7 lmkd: Add property re-initialization support
Add --reinit command-line option to allow updating lmkd properties. For
example to enable debug logging in the running lmkd process user should
issue:

setprop ro.lmk.debug true
lmkd --reinit

Bug: 155149944
Test: lmkd_unit_test after resetting lmkd properties
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Merged-In: Ic60331f3368f5a7fdfe09ad7d47c7ccf0a497685
Change-Id: Ic60331f3368f5a7fdfe09ad7d47c7ccf0a497685
2020-05-07 09:46:42 -07:00
Muhammad Qureshi 0eefbff7b9 Link libstatssocket as a shared library. am: 87168c0e26 am: 2171a0c2f4 am: e18b6d0b90
Change-Id: I3c9c5d48f57fc57e34c059a4863856a90607ae03
2020-02-14 22:37:37 +00:00
Muhammad Qureshi e18b6d0b90 Link libstatssocket as a shared library. am: 87168c0e26 am: 2171a0c2f4
Change-Id: Idb85f7875499f727744bd7b6cbe2f40ff7991efe
2020-02-14 22:19:30 +00:00
Muhammad Qureshi 2171a0c2f4 Link libstatssocket as a shared library. am: 87168c0e26
Change-Id: I02b53349508cfead1d6a43704b39ad648bf8e3f0
2020-02-14 22:00:51 +00:00
Muhammad Qureshi 87168c0e26 Link libstatssocket as a shared library.
As part of moving libstatssocket into statsd apex, libstatssocket will
only be available as a shared library.

Bug: 145923416
Test: m
Change-Id: Ia6b13dcd378011c201b2595d2b3f3fc14213011b
2020-02-12 16:42:53 -08:00
Automerger Merge Worker 5ce5183e22 [automerger skipped] DO NOT MERGE - Empty merge qt-qpr1-dev-plus-aosp-without-vendor (6129114) into stage-aosp-master am: 45cb77c5bc am: 5759b94152 -s ours
am skip reason: subject contains skip directive

Change-Id: Id1f72e87196c7e6e20c65a3110f2719c8adf373a
2020-01-16 01:58:50 +00:00
Automerger Merge Worker 5759b94152 DO NOT MERGE - Empty merge qt-qpr1-dev-plus-aosp-without-vendor (6129114) into stage-aosp-master am: 45cb77c5bc
Change-Id: Id74bdff1f30e8a1a6da7ddd6c2c989eb1e0f889e
2020-01-16 01:46:18 +00:00
Xin Li 45cb77c5bc DO NOT MERGE - Empty merge qt-qpr1-dev-plus-aosp-without-vendor (6129114) into stage-aosp-master
Bug: 146167222
Change-Id: I0adb962a42c190f863a301731f8cf53237821555
2020-01-15 15:59:17 -08:00
Automerger Merge Worker 80db5e76e1 Use generated code for logging events to statsd am: ed8fe8465a am: 0ecafff527 am: 08a1f55b5c
Change-Id: Ia4cfd02666dbd8269f4dcde0fec6309e00dd9069
2020-01-15 23:32:46 +00:00