Commit Graph

1579 Commits

Author SHA1 Message Date
Suren Baghdasaryan 753642e31a lmkd/tests: add 200ms wait for reaper to output its logs
Occasionally the test reads logcat before lmkd reaper had a chance to
write into it, resulting in the expected report messages being missed.
Add a 200ms delay after lmkd kills the process to give lmkd reper thread
more time to write its reports.

Bug: 347296675
Bug: 358830454
Test: atest lmkd_tests
Change-Id: I2549e37f25c81c9add91f7ee450c4a96c8cf18e4
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2024-08-12 19:03:09 +00:00
Suren Baghdasaryan 13b5b0ce06 lmkd/tests: handle kill reports being confused with reap reports
The starting line for kill and reap reports are the same. Add additional
logic in the test to distinguish between them and retry if a kill report
is found.

Bug: 347296675
Bug: 358830454
Test: mock the input data where lmkd_tests failed
Change-Id: Idf83831e45e6682c1dfb6cde258d4ec631a5eb32
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2024-08-12 19:02:49 +00:00
Christopher Ferris b1d5c43490 Remove unused variable.
Test: treehugger
Change-Id: I07fe4a36004bdb12e80990f9d9c61a051140e263
2024-08-04 03:39:29 +00:00
Carlos Galo 1e50c6ecc4 Report up-to-date RSS in LMK_PROCKILL cmd
Add RSS field, in LMK_PROCKILL cmd, to report the latest memory usage of
the killed process.

Test: Verified RSS field is captured in ApplicationExitInfo
Bug: 322549716
Change-Id: Ic1788e8121da97cd879bd7e9d685c7b879ea5475
Signed-off-by: Carlos Galo <carlosgalo@google.com>
2024-07-22 20:42:22 +00:00
Treehugger Robot 0aeff477af Merge "Remove usage of BPF_FD_JUST_USE_INT in favor of unique_fd" into main 2024-07-12 20:56:03 +00:00
Martin Liu d10742025b lmkd: handle missing process' information case
When we get nothing from /proc/<PID>/status and /proc/<PID>/cmdline,
we should return NULL or False because this usually indicates the
process has already terminated. We should avoid attempting
to kill a non-existent process, as it's an unnecessary waste
of kill timeout.

Bug: 331612600
Test: give memory pressure to trigger LMKD
Change-Id: I468ff25012f9bb6fc842a7fad268ebcad0de4690
Signed-off-by: Martin Liu <liumartin@google.com>
2024-06-27 15:17:05 +00:00
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
Patrick Rohr e15214ea24 Remove usage of BPF_FD_JUST_USE_INT in favor of unique_fd
We are trying to remove BPF_FD_JUST_USE_INT since we now have access to
libbase everywhere.

Test: builds
Change-Id: Ie9445d3d648e6837deb718aa38ebef3c936653d6
2024-06-14 14:55:36 -07: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