Commit Graph

1572 Commits

Author SHA1 Message Date
Suren Baghdasaryan ee6412ebf0 Revert "lmkd: change default lowmem_min_oom_score for low-RAM devices"
This reverts commit 686abc4e2b.

Reason for revert: regressing wear device tests
Bug: 349256852

Change-Id: I6c38c11dcad38bfba93609f476745513798c8e0b
2024-06-25 20:13:06 +00:00
Suren Baghdasaryan 686abc4e2b lmkd: change default lowmem_min_oom_score for low-RAM devices
Experiments on low-RAM devices indicate regressions due to the new low
memory kill reason which cause LMKD to kill too many processes. Change
ro.lmk.lowmem_min_oom_score to disable kills for this reason by default.

Bug: 341257415
Change-Id: Id7137c4c8d888061353b253dc6906d2854e31b1d
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2024-06-24 16:14:27 +00:00
Treehugger Robot e4d7e850a5 Merge "Fix format warning in direct reclaim length kill strategy" into main am: 3641d12083
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3101418

Change-Id: Ica2395ad87f98446c3c90aca8d31d11bde63c6f0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-06-01 00:35:09 +00:00
Carlos Galo a11f18de9f Adding io_uring for batching PROCS_PRIO cmd am: af79337d51
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3081144

Change-Id: I7f8fe3846c8c7a59abec83666108c161044b1102
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-06-01 00:19:14 +00:00
Carlos Galo dc126e3c57 Integration PROCS_PRIO cmd in lmkd am: 2f00c03379
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3056977

Change-Id: Id86823f585927ab8955613769790a543bd640219
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-06-01 00:19:11 +00:00
Carlos Galo baad4601eb Splitting logic from cmd PROC_PRIO am: 19b5892ba8
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3077890

Change-Id: I61bbe3fd7c7f6ed5c2273c6c0ffdbf796f630fdf
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-06-01 00:19:03 +00:00
Carlos Galo 3cd5c9cc3f liblmkd_utils: Adding get kill count interface am: 05e8c7bbda
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3086709

Change-Id: I680a62c5cfb274b6a0dec1f49edf6fa41ff4580d
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-06-01 00:18:59 +00:00
Treehugger Robot 3641d12083 Merge "Fix format warning in direct reclaim length kill strategy" into main 2024-06-01 00:14:46 +00:00
Carlos Galo af79337d51 Adding io_uring for batching PROCS_PRIO cmd
Integrate io_uring within LMKD to batch the read, and write, system
calls needed to process, and register, processes and adjust their OOM
scores.

Test: atest lmkd_tests
Bug: 325525024
Change-Id: I339be2b6f569189519e0e11d07cd6d7d1cf2566d
Signed-off-by: Carlos Galo <carlosgalo@google.com>
2024-05-31 22:56:10 +00:00
Carlos Galo 2be06f4c78 Fix format warning in direct reclaim length kill strategy
Adjusting the string copy message to utiilize the correct format for
direct_reclaim_duration_ms.

Test: m
Bug: 244232958
Change-Id: I3fbfc33e2520ef38b829db67ddb59c636a2bc3e1
Signed-off-by: Carlos Galo <carlosgalo@google.com>
2024-05-23 19:41:55 +00:00
Carlos Galo 2f00c03379 Integration PROCS_PRIO cmd in lmkd
Creating new cmd in LMKD to batch PROCPRIO requests.

Test: atest lmkd_tests
Bug: 325525024
Change-Id: I5460446d4e968e80263aa25298e2a893863eece4
Signed-off-by: Carlos Galo <carlosgalo@google.com>
2024-05-23 17:42:38 +00:00
Carlos Galo 19b5892ba8 Splitting logic from cmd PROC_PRIO
Refactor cmd_procprio() to reuse its main functionality for bulk updates
later on.

Test: m
Bug: 295231583
Change-Id: Ic42de6e256b813349530f19a20e3ef9d484b20cf
Signed-off-by: Carlos Galo <carlosgalo@google.com>
2024-05-21 23:05:28 +00:00
Carlos Galo 05e8c7bbda liblmkd_utils: Adding get kill count interface
Add new API to fetch the current kill count from lmkd.

Test: m
Bug: 325525024
Change-Id: I9289be653444c8641cd5a698049835c3ac271b56
Signed-off-by: Carlos Galo <carlosgalo@google.com>
2024-05-21 23:03:04 +00:00
Carlos Galo a0e25cea31 Applying clang-format suggestions in PROCPRIO cmd am: 8b5a67d35a
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3073186

Change-Id: I6fa4416ef3df2d7c05abe12a9867994f9cf6adf7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-05-03 17:31:45 +00:00
Carlos Galo 4e801dde74 Move register proc logic to prepare for new PROCS_PRIO cmd am: 7da353fb00
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3068766

Change-Id: I51557dc843ecb7b2518049d5afa17a07e244c821
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-05-03 17:31:41 +00:00
Carlos Galo 8b5a67d35a Applying clang-format suggestions in PROCPRIO cmd
Updating the cmd_procprio function with the clang-format suggestions. No logic changes.

Test: m
Bug: 325525024
Change-Id: Id6c1feb717259406d953e5e2a174398bccf65d23
Signed-off-by: Carlos Galo <carlosgalo@google.com>
2024-05-03 17:02:10 +00:00
Carlos Galo 7da353fb00 Move register proc logic to prepare for new PROCS_PRIO cmd
Moving logic for registering proc, after oom adjustment, to its
own function. This work is for the introduction of the new
PROCS_PRIO cmd. This logic will be shared between the current PROCPRIO
and PROCS_PRIO cmd.

Test: m
Bug: 325525024
Change-Id: I0683f63faa3dfa2e4534cdfb8935b4d2f83a6af9
Signed-off-by: Carlos Galo <carlosgalo@google.com>
2024-05-03 17:01:09 +00:00
Treehugger Robot 79b31d8bd1 Merge "Replace PATH_MAX usages with smaller size" into main am: e1eb315723
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3072843

Change-Id: I213c3f0ef714c337032d418d24b0b4811cfb0ef1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-05-03 00:47:25 +00:00
Treehugger Robot e1eb315723 Merge "Replace PATH_MAX usages with smaller size" into main 2024-05-03 00:29:11 +00:00
Carlos Galo eccbfe3256 Replace PATH_MAX usages with smaller size
All the PATH_MAX usages are used to store proc/<pid>/filename
information in lmkd. PATH_MAX is 4096, which is an overkill
of buffer sizes for their usage. Replace PATH_MAX with a smaller size.

Test: m
Bug: 325525024
Change-Id: If6d500102fca532a8afc331d0c847675d6e9e96f
Signed-off-by: Carlos Galo <carlosgalo@google.com>
2024-05-03 00:28:02 +00:00
Suren Baghdasaryan f7436e9054 Merge "lmkd: introduce lowmem_min_oom_score tunable" into main am: fcb1b8a339
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3061523

Change-Id: I915bb63cbd4d99b41d8ff752f9bbfb9378cd6930
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-04-30 20:26:54 +00:00
Suren Baghdasaryan fcb1b8a339 Merge "lmkd: introduce lowmem_min_oom_score tunable" into main 2024-04-30 20:08:35 +00:00
Suren Baghdasaryan 3dc50798a3 lmkd: introduce lowmem_min_oom_score tunable
Current lmkd behavior to kill cached apps when free memory hits low
watermark threshold does not work well on certain devices where more
or less aggressive behavior would yield better results. Introduce a
tunable to control the min oom_score_adj level at which lmkd considers
to kill processes when the system gets into this state. The default
value is set to 701 which preserves the current behavior of killing
cached apps except for the last active one. Setting it to lower values
will make more processes eligible to be killed, setting it to higher
values will limit the kills to a smaller set of processes. Setting it
to 1001 will prevent any process from being killed for this reason.

Bug: 334867461
Bug: 337063274
Change-Id: I1447436e0a0cd1e696b34d2c06b92ff73a5100a9
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2024-04-30 12:05:14 -07:00
Lakshman Annadorai 1868632e37 Update init_psi_monitor to include MEMORY/IO/CPU resources. am: d872253483
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3050182

Change-Id: I86b3f3c4c1fc7aa4acdeb0fe3afb4797d2f88795
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-04-30 19:01:20 +00:00
Lakshman Annadorai d872253483 Update init_psi_monitor to include MEMORY/IO/CPU resources.
Update the init_psi_monitor API to monitor MEMORY, IO, and CPU
resources.

Test: m libpsi
Bug: 335872571
Change-Id: Ieae8c98be0e6353a1d0ca0728c84bcf1897b259c
2024-04-29 13:25:50 -07:00
Treehugger Robot 91aeaf6284 Merge "Migrate Test Targets to New Android Ownership Model" into main am: 02de7905e5
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/2946238

Change-Id: Ia27c91f14b0fb2faffa5ef3f614b284f534a3478
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-04-22 16:47:37 +00:00
Treehugger Robot 02de7905e5 Merge "Migrate Test Targets to New Android Ownership Model" into main 2024-04-22 16:20:30 +00:00
Elliott Hughes e2e125a69f Don't define LINE_MAX. am: c2d8bfdf59
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3034232

Change-Id: I722fe4ed08a9e451be95620c86a364794388435a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-04-15 23:32:22 +00:00
Elliott Hughes c2d8bfdf59 Don't define LINE_MAX.
It's a POSIX mistake we'd been avoiding, but finally added to
bionic.

It's unclear to me that this code shouldn't just be using fscanf()
and getline() to simplify the code and avoid arbitrary hard-coded
limits -- since the code does do some allocation already -- but
that's a bigger cleanup for a code owner.

Change-Id: Ibab28f082a084c1f933ee6a39aa4ee3fa7868e5a
2024-04-09 16:16:03 +00:00
Suren Baghdasaryan af9d7fe055 lmkd: update watermarks before the first kill am: 20de82dde2
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3028841

Change-Id: Ib79f1d3fbcb08cb2b15e3861006e9806e5d94c52
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-04-08 15:53:56 +00:00
Suren Baghdasaryan 20de82dde2 lmkd: update watermarks before the first kill
Change-Id: Ie8080fd8995c54fc8c1f5b94e77dbf32e33783fe
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2024-04-05 17:58:41 -07:00
Suren Baghdasaryan 42dba7a8e0 lmkd: introduce swap_compression_ratio tunable am: 63dd69984d
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/2620611

Change-Id: I8676ede74373fefa0f51896e8b31cedf7da88337
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-04-05 05:05:02 +00:00
Suren Baghdasaryan 63dd69984d lmkd: introduce swap_compression_ratio tunable
Free swap is calculated using the min of free swap that kernel would
consider using and easily available memory which can be used by ZRAM
for swapping purposes. However calculation does not consider the
average data compression ratio of ZRAM. Introduce a tunable to set
the average swap compression ratio used when evaluating the amount
of data which can be swapped. Default is set to 1 (no compression)
to keep current behavior. Setting it to 0 will ignore available memory
and assume that configured swap size can be always utilized fully.

Bug: 285854307
Bug: 327561101
Change-Id: I6b0f93ce24179ebf7365a3dbcd52c6e4a52ac200
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2024-04-04 23:28:04 +00:00
Carlos Galo 49fa9d895e Adding kswapd state monitoring with memevent_listener am: 6593e2cee6
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3025666

Change-Id: Id00cd93937e4c53128265e4171ccb361e156f66c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-04-04 20:33:50 +00:00
Carlos Galo 6593e2cee6 Adding kswapd state monitoring with memevent_listener
Replacing mechanism of reading vmstats to detect kswapd with
memevents instead. Maintain vmstats mechanism if bpf is not supported by
current kernel.

Test: Verified lmkd receives kswapd state changes
Test: m
Bug: 330606003
Change-Id: I9b980a8b94e015d1b8e0986fff9113890420d102
Signed-off-by: Carlos Galo <carlosgalo@google.com>
2024-04-03 15:38:07 -07:00
Carlos Galo f806a7d6a4 Renaming direct reclaim monitoring to memevent monitoring am: f9dfb20456
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3022599

Change-Id: I77d2a7370cf0cf2d48ad6544cfb6ca3b8da332f9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-04-03 18:45:11 +00:00
Carlos Galo f9dfb20456 Renaming direct reclaim monitoring to memevent monitoring
This monitoring will no longer only track direct reclaim state changes.
Adjusting naming to reflect the broader utilization.

Test: m
Bug: 330606003
Change-Id: Ib77b8b58cd6e8ce1296ffa14481018c29e979754
Signed-off-by: Carlos Galo <carlosgalo@google.com>
2024-04-03 00:19:26 -07:00
Carlos Galo 6a9574526a Add boot completed cmd to LMKD am: 65c1b5dcc5
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3017682

Change-Id: I357c44a68f97608d7f9be1d567a417315209430b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-04-03 00:15:41 +00:00
Carlos Galo 65c1b5dcc5 Add boot completed cmd to LMKD
Add new command to allow for post-boot actions to occur. This
will allow for the MemEventListener to start after the BPF files are
loaded, removing the need to stall during boot-up until they are loaded
in the device.

Test: Verified memevent listener initialized post-boot
Test: Verified LMKD no longer stalls until BPF progs are loaded
Bug: 331008250
Bug: 244232958
Change-Id: I55f97b41349ea7693cff81b1170d33712b820292
Signed-off-by: Carlos Galo <carlosgalo@google.com>
2024-04-02 22:25:36 +00:00
Carlos Galo ed5f6f9c6b lmkd: Introduce kill strategy based on direct reclaim length am: 81a7c21087
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/2959942

Change-Id: Ic643aaf44e45f21b941deeebdcf674c2591e88c2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-26 20:33:12 +00:00
Carlos Galo 81a7c21087 lmkd: Introduce kill strategy based on direct reclaim length
Add kill reason for when the device is stuck in direct reclaim for
longer than the configurable threshold. Only allow configurable
threshold, and direct reclaim stuck detection, if memevents direct
reclaim monitoring is enabled.

Test: Verified direct reclaim stuck kill log with memory pressure test
Test: m
Bug: 244232958
Change-Id: I1156899874d2eb7e0f4b61597741087c110b3414
Signed-off-by: Carlos Galo <carlosgalo@google.com>
2024-03-22 16:21:30 -07:00
Carlos Galo 696456889a Adding direct reclaim state monitoring am: 9e136285a6
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/3001286

Change-Id: Ifcf98d8422445dab92b1e24be004056e6871bcb5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2024-03-21 06:25:30 +00:00
Carlos Galo 9e136285a6 Adding direct reclaim state monitoring
Replacing mechanism of reading vmstats to detect direct reclaim with
memevents instead. Maintain vmstats mechanism if bpf ring buffer is not
supported by current kernel.

Test: Verified lmkd receives direct reclaim state changes
Test: m
Bug: 244232958
Change-Id: I59ee7657da1240355d611dfa129c4d50bed2c330
Signed-off-by: Carlos Galo <carlosgalo@google.com>
2024-03-20 06:46:04 +00:00
Aditya Choudhary b749603ac4 Migrate Test Targets to New Android Ownership Model
This CL is created as a best effort to migrate test targets to the new Android ownership model.
It is based on historical data from repository history and insights from git blame.
Given the nature of this effort, there may be instances of incorrect attribution. If you find incorrect or unnecessary
attribution in this CL, please create a new CL to fix that.

For detailed guidelines and further information on the migration please refer to the link below,
go/new-android-ownership-model

Bug: 304529413
Test: N/A
Change-Id: I6f597ed681e95367a641a69ff2ec4b69c5087f18
2024-02-02 13:59:15 +00:00
Suren Baghdasaryan f8bae6fed3 [automerger skipped] lmkd: Kill cached apps when thrashing or below low watermark am: d1968032a2 -s ours am: 3fff5c5850 -s ours
am skip reason: Merged-In I356eac1fe6d44dad292a7ea2fadee69a5be61479 with SHA-1 0ac96fcb1a is already in history

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

Change-Id: Ia2bd9c7e9d32405ef7bce6ede4d6a6f4169ff269
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-12-19 04:40:53 +00:00
Suren Baghdasaryan 3fff5c5850 [automerger skipped] lmkd: Kill cached apps when thrashing or below low watermark am: d1968032a2 -s ours
am skip reason: Merged-In I356eac1fe6d44dad292a7ea2fadee69a5be61479 with SHA-1 0ac96fcb1a is already in history

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

Change-Id: I541d20e637cb1b9bd242c029dd31b8f18677e3e4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-12-19 04:10:13 +00:00
Suren Baghdasaryan d1968032a2 lmkd: Kill cached apps when thrashing or below low watermark
With Android U removing AMS kills, lmkd has additional duty to kill
cached apps which previously were killed by AMS. The former logic is
not proactive enough and leads to too many cached apps contributing
to memory pressure.
Implement additional logic to kill cached apps (excluding previous
foreground apps) when low watermark is breached or when device is
thrashing.

Bug: 300660611
Change-Id: I356eac1fe6d44dad292a7ea2fadee69a5be61479
Merged-In: I356eac1fe6d44dad292a7ea2fadee69a5be61479
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2023-12-18 10:28:54 +00:00
Matt Stephenson d537478999 add min score option to PRESSURE_AFTER_KILL am: 18578a55d0 am: 3fe819c85f am: 9ae8f1fd20
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/2868426

Change-Id: I4872f7576447a460737107e9cebf5c131dff4a40
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-12-12 02:07:48 +00:00
Matt Stephenson 9ae8f1fd20 add min score option to PRESSURE_AFTER_KILL am: 18578a55d0 am: 3fe819c85f
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/2868426

Change-Id: I843f99dc21bc34e719a979b2b616a54ab6dba1c6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-12-12 01:35:21 +00:00
Matt Stephenson 3fe819c85f add min score option to PRESSURE_AFTER_KILL am: 18578a55d0
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/2868426

Change-Id: I4784e9fd8ebec9c72ceb7d642ca5aba0ff16dc5b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-12-12 01:03:37 +00:00