Commit Graph

787 Commits

Author SHA1 Message Date
Suren Baghdasaryan d0a800402c lmkd: Add support for persist.device_config.lmkd_native.* properties
Allow persist.device_config.lmkd_native.* to override ro.lmk.*
properties to enable experiments with lmkd configuration properties.
Experiments will be able to set appropriate
persist.device_config.lmkd_native.<name> property which will issue
"lmkd --reinit" command to reinitialize lmkd with new parameters.

Bug: 194316048
Test: adb shell device_config put lmkd_native thrashing_limit_critical 350
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Ia48fd51eab126d307a1604530b642e86cf250688
2021-08-31 09:20:46 -07:00
Suren Baghdasaryan 39b54809fb lmkd: Add thrashing and max_thrashing into killinfo reports
Due to the increased importance of thrashing limits, include current and
max thrashing levels into killinfo reports.

Bug: 195979894
Test: lmkd_unit_test
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I36f947e45e03a4d845d18881e137e4b242aacb65
2021-08-09 15:10:46 -07:00
George Burgess IV e849f1414e lmkd: fix potential NULL pointer dereference
`ki` appears to be potentially NULL. Output bogus values if it is.

Caught by the static analyzer:
> system/memory/lmkd/lmkd.cpp:2171:66: warning: Access to field
'kill_reason' results in a dereference of a null pointer (loaded from
variable 'ki') [clang-analyzer-core.NullDereference]

Bug: None
Test: TreeHugger
Change-Id: Iae26855528e1f7fec8f1455e06c7e813a732dc75
2021-08-05 06:59:42 +00:00
Suren Baghdasaryan 34928bb817 lmkd: Add a tracepoint for each kill with kill parameters
Add a trace for each kill that includes pid, kill reason, oom_adj_score,
min_oom_score and max_thrashing statistics at the time of the kill.

Bug: 195085238
Test: generate kills while tracing and observer the new tracepoints
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Ic2014adc08f5e5dd4aacd415970332618bd15250
2021-07-30 12:59:15 -07:00
Suren Baghdasaryan e16047516d lmkd: Add current and max thrashing levels in LMK_MEMORY_STATS reports
Thrashing threshold tuning requires collecting thrashing level data from
the field and correlating these levels with other indications of device
being non-responsive.
Include current and max thrashing levels in the lmkd kill reports. Max
thrashing level captures the highest level seen since the last kill report.

Bug: 194433891
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I8a34dc41e7f03668bfad4ac2cbcb5d2570a10752
Merged-In: I8a34dc41e7f03668bfad4ac2cbcb5d2570a10752
2021-07-23 19:11:36 +00:00
Suren Baghdasaryan 1ef4718aed Revert "lmkd: Disable critical thrashing limit by default"
This reverts commit e1ffef4e36.

Reason for revert: Restore the default thrashing limits to prevent unresponsive devices.

Bug: 194199500
Change-Id: I15be5b3d67a71b68bca6dea9c2d5b4aa54d6c260
Merged-In: I15be5b3d67a71b68bca6dea9c2d5b4aa54d6c260
2021-07-23 12:01:55 -07:00
Suren Baghdasaryan c1171394a3 lmkd: Disable critical thrashing limit by default
Critical thrashing limit determines the balance between how much
thrashing should be tolerated before killing a perceptible app.
This threshold might differ between devices, therefore we disable
critical thrashing limit by default allowing each device to set it
individually. This is done to prevent excessive kills of perceptible
apps.

Bug: 194199500
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Idd1715564c3727b09fcb0a109ab3d6bae9d0b99a
2021-07-20 18:12:22 +00:00
Suren Baghdasaryan 11221d4062 lmkd: Add ro.lmk.filecache_min_kb property for min filecache watermark
We see many cases when device keeps thrashing despite lmkd kills. This
happens because killed processes do not free enough filecache to fit
the current workingset completely.
To prevent such cases, introduce ro.lmk.filecache_min_kb property to
specify min filecache size in KB that should be reached after thrashing
is detected. Lmkd will keep killing background processes until this
filecache size limit is satisfied.

Bug: 193293513
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I49ca4cd2f33b27fdbc432d9ce6944b1a1794b749
2021-07-15 11:05:09 -07:00
Bill Yi af5221c0aa Merge RQ3A.210705.001 to aosp-master - DO NOT MERGE
Merged-In: Ie5a50c392ef5124a0c2390c8d4f902808d672739
Merged-In: I89b3edde09dfcf35b8214fecbed18ce5092701cc
Merged-In: I89b3edde09dfcf35b8214fecbed18ce5092701cc
Change-Id: I25eccb8109695125480f0da0e136ab98dabfaa0d
2021-07-12 11:08:30 -07:00
Xin Li 4571e22641 DO NOT MERGE - Mark RQ3A.210410.001 as merged
Bug: 190855093
Merged-In: Ibd98f113f81a4f699b11dbc843a95ee2e2197c92
Change-Id: Ie5a50c392ef5124a0c2390c8d4f902808d672739
2021-06-17 22:43:30 -07:00
Suren Baghdasaryan e0d6203d39 Merge "lmkd: Include total GPU memory usage in killinfo reports" am: cde0acde94
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1721873

Change-Id: Ibd98f113f81a4f699b11dbc843a95ee2e2197c92
2021-06-15 01:49:40 +00:00
Suren Baghdasaryan cde0acde94 Merge "lmkd: Include total GPU memory usage in killinfo reports" 2021-06-15 01:33:14 +00:00
Xin Li 7b42292af3 DO NOT MERGE - Merge ab/7272582 am: b494068d81
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1736156

Change-Id: I94c864786f2d51e5f265921fa1a332ba6443a9ac
2021-06-13 23:13:21 +00:00
Xin Li b494068d81 DO NOT MERGE - Merge ab/7272582
Bug: 190855093
Change-Id: I42de6c44d675f5acc076df33083f8fe87da7031a
2021-06-11 17:33:57 -07:00
Suren Baghdasaryan 940e7cf8bd lmkd: Include total GPU memory usage in killinfo reports
/sys/fs/bpf/map_gpu_mem_gpu_mem_total_map BPF map exposes total GPU
allocations size. Include this value into killinfo reports to track GPU
allocation size at the time of the kill.

Bug: 189366037
Test: lmkd_unit_test
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Icc1ed8ab2593530fa293ff9c82f6c8dc400485f5
2021-06-03 15:56:52 -07:00
android-build-team Robot 1ff19f401f Merge cherrypicks of [14651914, 14651880, 14651759, 14652210, 14651594, 14651881, 14651915, 14651882, 14651883, 14651799, 14652154, 14651595, 14651760, 14652271, 14652272, 14652273, 14652056, 14651800, 14651801, 14651802, 14651884, 14651885, 14651886, 14652274, 14652275, 14652276, 14652277, 14652278, 14651894, 14651723, 14652211, 14651895, 14651916, 14651887, 14651888, 14651596, 14651889, 14652212, 14651761, 14652310, 14652311, 14651973, 14651974, 14652312, 14652313, 14651896, 14651803] into rvc-qpr3-release
Change-Id: I559773c77635b6480d054ba0daba281eef4f84a5
2021-05-20 00:04:50 +00:00
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
Vova Sharaienko ea85216d08 lmkd: reroute atoms logging to AMS am: a92b76b54d
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1702386

Change-Id: Ibfac12827098eac2ab2789c876a688da73d0cd87
2021-05-11 17:42:46 +00:00
Vova Sharaienko a92b76b54d lmkd: reroute atoms logging to AMS
- Added new lmkd message for clients to subscribe LMK_ASYNC_EVENT_STAT
- Added support to write kill & mem stats information via data socket
  to be read & parsed on the AMS Java side for future logging to statsd

Bug: 184698933
Test: lmkd_unit_test - test check_for_oom tests lmkd message send to AMS
Test: statsd_testdrive 51 54 to inspect statsd logged atoms data
Change-Id: Id682a438c87b3e4503261d26461f6cee641d86c4
Merged-In: Id682a438c87b3e4503261d26461f6cee641d86c4
2021-05-11 00:00:56 +00:00
Suren Baghdasaryan 8aec07bbe0 lmkd: Do not treat RSS=0 as a sign of a process being dead am: 5263aa7800
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1690656

Change-Id: I785575f6428b89bb59df690828fb60dc73f7d6e7
2021-04-30 00:35:22 +00:00
Suren Baghdasaryan 5263aa7800 lmkd: Do not treat RSS=0 as a sign of a process being dead
With kernel SPLIT_RSS_COUNTING feature it is possible for a valid
process to report RSS of 0 size when reading /proc/pid/statm. This
happens because split RSS accounting aggregates per-thread counters
asynchronously and depending on the timing of the read, reported
value can be inaccurate and occasionally be 0.
lmkd currently treats processes reporting RSS of 0 as dead and
removes them from the list of processes being tracked. This might
lead to a valid process becoming unkillable.
Change lmkd to stop treating RSS of 0 as a sign of a dead process.

Bug: 160199622
Test: set ro.lmk.kill_heaviest_task=true and hack kernel to report RSS=0
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Ia311d2f98649c92d1a487657f94ea51f57813b73
2021-04-29 15:33:06 -07:00
Suren Baghdasaryan d7838b8e06 lmkd: Handle cases when proc_get_name() might return NULL am: 9f1be12b9a
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1685347

Change-Id: I048051fbbcf880642206e0a219171e7474fc677d
2021-04-23 23:04:06 +00:00
Suren Baghdasaryan 9f1be12b9a 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
2021-04-23 21:18:18 +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 0107f3c655 [automerger skipped] lmkd: Allow lmkd to kill perceptible apps during heavy thrashing am: e68bfe9a73 -s ours
am skip reason: skip tag Change-Id Icb38ef6c90adaa4f5c956593b6ea0c4febc91dc0 with SHA-1 0142b3c166 is already in history

Original change: https://googleplex-android-review.googlesource.com/c/platform/system/memory/lmkd/+/14108657

Change-Id: Ic33eb574acd23965cb6f7742ccc2093b3e0033b3
2021-04-08 05:52:00 +00:00
Suren Baghdasaryan c5bc8cb7fa [automerger skipped] lmkd: choose the heaviest task when killing perceptible processes am: 720abce177 -s ours
am skip reason: skip tag Change-Id I775ff774430b6fde4d619ede794825dbae59fd8e with SHA-1 858e8c6373 is already in history

Original change: https://googleplex-android-review.googlesource.com/c/platform/system/memory/lmkd/+/14108656

Change-Id: I38ceae15c85ab3e02f4bb3e25d88729ed779406e
2021-04-08 05:51:59 +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 eb09287574 lmkd: Allow lmkd to kill perceptible apps during heavy thrashing am: 0142b3c166 am: 7ccd2c10ee
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1653491

Change-Id: I3bd353b448a3a6f886805704d64ffd23bc8f46a4
2021-03-31 20:32:29 +00:00
Suren Baghdasaryan 7ccd2c10ee lmkd: Allow lmkd to kill perceptible apps during heavy thrashing am: 0142b3c166
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1653491

Change-Id: I1e014a9ccf2b1d6db1407c01feb3bc9794243c05
2021-03-31 19:56:50 +00:00
Suren Baghdasaryan 0142b3c166 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>
Change-Id: Icb38ef6c90adaa4f5c956593b6ea0c4febc91dc0
2021-03-25 17:00:09 -07:00
Josh Gao 46b431749e Switch to Bionic's pidfd wrappers. am: 84623bef7b am: 7e7793b48d
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1646355

Change-Id: Ib9c7982acf005a17d113bd36d96635884d531bde
2021-03-19 18:58:24 +00:00
Josh Gao 7e7793b48d Switch to Bionic's pidfd wrappers. am: 84623bef7b
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1646355

Change-Id: I14598a17121770a9175b3ac1e6f46c31b21751de
2021-03-19 18:38:42 +00:00
Josh Gao 84623bef7b Switch to Bionic's pidfd wrappers.
Bug: http://b/172518739
Test: treehugger
Change-Id: Ib6cac8f31ec64343c6eec6b82dac52888890c688
2021-03-18 17:16:08 -07:00
Suren Baghdasaryan e1bfcc3cac lmkd: choose the heaviest task when killing perceptible processes am: 858e8c6373 am: c71ce3fed4
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1619563

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I95dc9527835a28e38feb689ba872ee1101eb5a1a
2021-03-05 19:10:12 +00:00
Suren Baghdasaryan 4847bb51f5 lmkd: fix log message reporting the breached watermark am: 236781873f am: e452c6be98
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1619562

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I32a69fc6bcb77d5adfc426455e945c9bb047f9d5
2021-03-05 19:10:06 +00:00
Suren Baghdasaryan c71ce3fed4 lmkd: choose the heaviest task when killing perceptible processes am: 858e8c6373
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1619563

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ib919f6de91c1634dd7c6cff70a23d17ac52b91e7
2021-03-05 18:27:14 +00:00
Suren Baghdasaryan e452c6be98 lmkd: fix log message reporting the breached watermark am: 236781873f
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1619562

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I9e7f62d919466d83d5c3bf085f0b70b6c690cec5
2021-03-05 18:27:10 +00:00
Suren Baghdasaryan 858e8c6373 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>
Change-Id: I775ff774430b6fde4d619ede794825dbae59fd8e
2021-03-05 17:45:30 +00:00
Suren Baghdasaryan 236781873f lmkd: fix log message reporting the breached watermark
Wrong condition causes reporting low watermark breach when min watermark
is breached and visa versa. Fix the condition to make reporting correct.

Bug: 181778155
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I684141c38f961fce99d17cfb3a83706fcd84ea10
2021-03-05 17:45:10 +00:00
Ioannis Ilkos 76b91a1a15 Reorder swap field in killinfo am: 282437fbbe am: b26c239bd9
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1619719

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ic4923c5e286c873dcfcba276440f6aeb1e819b9a
2021-03-05 05:42:29 +00:00
Ioannis Ilkos b26c239bd9 Reorder swap field in killinfo am: 282437fbbe
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1619719

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I0fc10cfb4dfcee922cb43a11660538b974b9e2b9
2021-03-05 04:53:55 +00:00
Ioannis Ilkos 282437fbbe Reorder swap field in killinfo
Some tools might parse killinfo entries based on the field order. Move
the newly added swap field to the end to ensure compatibility.

Test: build
Change-Id: Id6dad850beba6835f061da95e84190d00a1b26a0
2021-03-04 17:50:05 +00:00
Ioannis Ilkos f69765b15a Log killed process swap size am: 4884890305 am: bd6991af02
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1595271

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Iedf9e57c6cfb1f55665b7e648e9ba5e691017374
2021-02-26 20:29:28 +00:00
Ioannis Ilkos bd6991af02 Log killed process swap size am: 4884890305
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1595271

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I57719767560f040d95508b86719ab4ee92cde599
2021-02-26 19:11:07 +00:00
Chris Morin 8ae13ca324 Replace mentions of "oom_adj" with "oom_score_adj" am: 74b4df95b4 am: 2c432eaf62
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1607288

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I0f3dc88df88e2166c6e801ab66b7c1b1c095718b
2021-02-26 18:16:15 +00:00
Chris Morin 2c432eaf62 Replace mentions of "oom_adj" with "oom_score_adj" am: 74b4df95b4
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1607288

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I25d37095e413f5e62f327f0275ae888ac7a1be41
2021-02-26 17:15:37 +00:00
Ioannis Ilkos 4884890305 Log killed process swap size
We already log the rss size for the process. Given lmkd strategies also consider low swap, it will be beneficial to record the swap size too.

Test: build, manual test
Change-Id: I923f733f7a3aa77fc5968827693b0fc085819174
2021-02-26 17:05:35 +00:00
Chris Morin 74b4df95b4 Replace mentions of "oom_adj" with "oom_score_adj"
Some log messages mention "oom_adj" instead of "oom_score_adj" when
referring to oom_score_adj. This is confusing because "oom_adj" is a
separate value which was supplanted by oom_score_adj, but can still be
used.

Test: trigger memory pressure and view logs
Change-Id: I23825083cecfff6bd32bfb39c6dac1f2b17a72a7
2021-02-26 00:07:16 -08:00
Xin Li 93f513941c [automerger skipped] Mark ab/7061308 as merged in stage. am: b88ab3d63f -s ours
am skip reason: Change-Id Iaf7197de5b8b1632357d239aedc58589dfa01ca8 with SHA-1 019502f8ff is in history

Original change: undetermined

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I6d3d72caea3176493f55efa85c643e0e12b796ad
2021-02-20 09:30:00 +00:00