Commit Graph

976 Commits

Author SHA1 Message Date
Yi Kong edd3325830 Turn on AFDO for lmkd
Enable PGO (profile guided optimisation) for better performance.

Bug: 195134194
Bug: 175205560
Test: presubmit
Change-Id: I97fb9945bfe9afa3396b850518fadaf7b9f38eaa
2022-01-17 07:36:59 +00:00
Suren Baghdasaryan af1b0e0627 lmkd: Implement watchdog thread
To detect lmkd being stuck on a syscall for prolonged period of time,
introduce a watchdog thread which gets set when lmkd starts handling of
events and is reset after handling is done. If it takes more than the
timeout period (2 sec) to handle an event, watchdog wakes up and kills
the least important process to prevent mounting memory pressure caused
by lmkd lockup. After a kill, watchdog will wait for the reset for
another timeout period and kill again. This repeats until lmkd unlocks
and resets the watchdog.

Bug: 201671997
Test: induce random sleep in lmkd main handler and observe watchdog kills
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I56a55834582e11c06cc6cf9da3bc7380e634b301
2022-01-06 18:14:25 +00:00
Suren Baghdasaryan 7c3addb2a1 lmkd: Use process_mrelease to reap the target process from a thread
process_mrelease syscall can be used to expedite memory release of
a process after it was killed. This allows memory to be released
without the target process being scheduled, therefore does not depend
on target's priority or the CPU it's running on.
However process_mrelease syscall can take considerable time. Blocking
lmkd main thread during that time can cause memory pressure events
being missed while lmkd is busy reaping previous target's memory.
For this reason reaping should be done in a separate thread. This way
lmkd main thread can keep monitoring memory pressure while memory is
being released.
Introduce Reaper class which maintains a pool of threads to perform
process killing and reaping. The main thread submits a request to the
Reaper to kill and reap the process without blocking. If all the threads
in the pool are busy at the time the next kill is needed, the kill is
performed by the main thread without reaping.

Bug: 130172058
Bug: 189803002
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: If7b10fdd1838bdfeea3fed3031565feffe0b52be
2022-01-06 18:14:14 +00:00
liuhailong 53df06cdf1 lmkd: Fix lowmem_minfree out of bounds am: cf8af501dc
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1908669

Change-Id: Ie928b2d3c3882dafcf591a0487eb73c0d3b0b73a
2021-12-07 02:52:13 +00:00
liuhailong cf8af501dc lmkd: Fix lowmem_minfree out of bounds
lmkd daemon launches before system_server. If lowmem_targets_size
does not initialize by system_server, the value will be zero.
Before system_server starts lmkd receives a psi event
and debug_process_killing on, the lmkd crashes here.

Bug: 209090314
Signed-off-by: liuhailong <liuhailong@oppo.com>
Change-Id: I0736a882ed1ff5eee2b07676ae590a2cb2a7721c
2021-12-04 17:59:24 +08:00
Suren Baghdasaryan ac36e3a50a lmkd: fix low swap threshold failing to update after reinit am: 6e6d14b387 am: 07de899509 am: 6d2d6d4d62
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1874517

Change-Id: I5efeb150d303d81fbd3575171bb6cef40a278505
2021-10-28 23:30:18 +00:00
Suren Baghdasaryan 6d2d6d4d62 lmkd: fix low swap threshold failing to update after reinit am: 6e6d14b387 am: 07de899509
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1874517

Change-Id: I1527091b5889d57c237cbaccea373effc2ee94a6
2021-10-28 23:18:38 +00:00
Suren Baghdasaryan 07de899509 lmkd: fix low swap threshold failing to update after reinit am: 6e6d14b387
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1874517

Change-Id: I2d5854cca756b90ac16b941628b35fe2a32ec802
2021-10-28 23:00:59 +00:00
Suren Baghdasaryan 6e6d14b387 lmkd: fix low swap threshold failing to update after reinit
lmkd calculates low swap threshold using total available swap and
ro.lmk.swap_free_low_percentage property. A wrong assumption is made that
both these values are constant and therefore the threshold can be
calculated once and reused later. However ro.lmk.swap_free_low_percentage
can be changed by the user and lmkd --reinit issued to reapply new
configuration. If that happens low swap threshold will not be updated.
Fix this by calculating the threshold whenever it is used. The overhead
of that calculation is negligible.

Bug: 203161607
Test: setprop ro.lmk.swap_free_low_percentage <new value>; lmkd --reinit
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Idff50655a75d006ea86d9ab10ca54c375c4bea46
2021-10-28 13:30:08 -07:00
Suren Baghdasaryan f269e20364 Replace writepid with task_profiles command for cgroup migration am: 1938f90eb8 am: 95b23108fa am: 9e0fe78675
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1740140

Change-Id: I72c4b517729b76c66090c86f2824773055036118
2021-10-15 18:44:28 +00:00
Suren Baghdasaryan 9e0fe78675 Replace writepid with task_profiles command for cgroup migration am: 1938f90eb8 am: 95b23108fa
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1740140

Change-Id: I0b4f462cc61e8c4b6388edd239ab417a86ca8921
2021-10-15 18:30:04 +00:00
Suren Baghdasaryan 95b23108fa Replace writepid with task_profiles command for cgroup migration am: 1938f90eb8
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1740140

Change-Id: I0762beb6cf6e7a081956938335f85c91f4716bac
2021-10-15 18:18:07 +00:00
Suren Baghdasaryan 1938f90eb8 Replace writepid with task_profiles command for cgroup migration
writepid command usage to join a cgroup has been deprecated in favor
of a more flexible approach using task_profiles. This way cgroup path
is not hardcoded and cgroup changes can be easily made. Replace
writepid with task_profiles command to migrate between cgroups.

Bug: 191283136
Test: build and boot
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: I594a5fc5e988f812237bd226aaecefa5f1159d2d
2021-10-15 16:40:18 +00:00
Wei Wang cdfda035f2 [automerger skipped] lmkd: move to foreground cpuset before killing am: e80774f4b7 -s ours
am skip reason: Merged-In Id475625e0d892fb7111a2cf054d1b57d17003d5a with SHA-1 730e7a9248 is already in history

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

Change-Id: I56b16242e84de7041d06fca9f434e9765b828e5f
2021-10-01 20:34:31 +00:00
Wei Wang efff2cd14b lmkd: move to foreground cpuset before killing am: 730e7a9248 am: c2fdae89e4 am: 7cc53280b3
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1842588

Change-Id: Ieee9b828bd2bf1b754a039284db6775fe8f9c9c5
2021-10-01 18:15:26 +00:00
Wei Wang 7cc53280b3 lmkd: move to foreground cpuset before killing am: 730e7a9248 am: c2fdae89e4
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1842588

Change-Id: Ibbc084bafb4b4cbc5ec870076d2aa35238af799d
2021-10-01 18:06:29 +00:00
Wei Wang c2fdae89e4 lmkd: move to foreground cpuset before killing am: 730e7a9248
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1842588

Change-Id: I167412b9121920a1efea698a45447c1bd507f671
2021-10-01 17:58:01 +00:00
Wei Wang e80774f4b7 lmkd: move to foreground cpuset before killing
Test: Build and boot
Bug: 199797672
Signed-off-by: Wei Wang <wvw@google.com>
Merged-In: Id475625e0d892fb7111a2cf054d1b57d17003d5a
Change-Id: Id475625e0d892fb7111a2cf054d1b57d17003d5a
(cherry picked from commit 730e7a9248)
2021-09-30 23:25:34 -07:00
Wei Wang 730e7a9248 lmkd: move to foreground cpuset before killing
Test: Build and boot
Bug: 199797672
Signed-off-by: Wei Wang <wvw@google.com>
Change-Id: Id475625e0d892fb7111a2cf054d1b57d17003d5a
2021-09-30 23:24:11 -07:00
Wei Wang f59352a4d3 [automerger skipped] lmkd: use fd cache for cgroup migration am: 328e612f1b -s ours
am skip reason: Merged-In Ie7a9eb9676c58309f1407c5f8cc59b302f107d38 with SHA-1 0162e0361f is already in history

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

Change-Id: I46b16bb312656e4c4f30d700f4ec4ff53cd0898e
2021-09-22 22:19:41 +00:00
Wei Wang d1165a4975 [automerger skipped] lmkd: migrate process to FOREGROUND sched group before kill am: 90f3c9e5c6 -s ours
am skip reason: skipped by user wvw

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

Change-Id: I315aeaecde8646dbcb7e5ee13e919ccdc0bcc331
2021-09-22 22:19:39 +00:00
Wei Wang 7bfd31e6e3 lmkd: use fd cache for cgroup migration am: 0162e0361f am: dbb9a69dc6 am: 022fa421c6
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1833054

Change-Id: I0405e4cf84706d15bf97fda53e8f5711943ca9f5
2021-09-22 18:59:48 +00:00
Wei Wang 022fa421c6 lmkd: use fd cache for cgroup migration am: 0162e0361f am: dbb9a69dc6
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1833054

Change-Id: I6e90cb69fb9e446239212737f8ef2643699b1360
2021-09-22 18:38:47 +00:00
Wei Wang 328e612f1b lmkd: use fd cache for cgroup migration
Test: Build
Bug: 199797672
Signed-off-by: Wei Wang <wvw@google.com>
Change-Id: Ie7a9eb9676c58309f1407c5f8cc59b302f107d38
Merged-In: Ie7a9eb9676c58309f1407c5f8cc59b302f107d38
(cherry picked from commit 0162e0361f)
2021-09-22 18:35:19 +00:00
Wei Wang dbb9a69dc6 lmkd: use fd cache for cgroup migration am: 0162e0361f
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1833054

Change-Id: Ie70f8800acdef24ccf8731215ce1b1cae8e01539
2021-09-22 18:27:25 +00:00
Wei Wang 90f3c9e5c6 lmkd: migrate process to FOREGROUND sched group before kill
BG group may have settings such as cpu.shares impacting reclaim
performance. Let us migrate task to foreground sched group similarly to
cpuset group.

Test: Build
Bug: 199797672
Signed-off-by: Wei Wang <wvw@google.com>
Change-Id: I75ee9f3486a2c76e65267a98e39edff96a5e1673
(cherry picked from commit 0195bcdba7)
2021-09-21 14:54:44 -07:00
Wei Wang 0162e0361f lmkd: use fd cache for cgroup migration
Test: Build
Bug: 199797672
Signed-off-by: Wei Wang <wvw@google.com>
Change-Id: Ie7a9eb9676c58309f1407c5f8cc59b302f107d38
2021-09-21 14:38:49 -07:00
Suren Baghdasaryan d31d0d1eb2 [automerger skipped] lmkd: Do not re-initialize lmkd when persistent properties are loaded am: fcb9cb6de4 -s ours
am skip reason: Merged-In Iba34fc719a18d58b890549c7415bec869d471901 with SHA-1 0e64eadc21 is already in history

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

Change-Id: I414d3c898dd7503119e37f9e7ad2a601c51cbbba
2021-09-15 23:18:00 +00:00
Suren Baghdasaryan d941a3e7bb [automerger skipped] lmkd: Add support for persist.device_config.lmkd_native.* properties am: e7d82ee7e7 -s ours
am skip reason: Merged-In Ia48fd51eab126d307a1604530b642e86cf250688 with SHA-1 d0a800402c is already in history

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

Change-Id: Ice7ea4aac70782659cc2009cea1e6614b13d85a9
2021-09-15 23:17:59 +00:00
Wei Wang 193b84cd38 lmkd: migrate process to FOREGROUND sched group before kill am: 0195bcdba7 am: a95efc0941 am: 50bf1dc40c
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1825954

Change-Id: I73a62f67750c64f87739d64ea0ba3f9010b94f70
2021-09-14 15:13:34 +00:00
Wei Wang 50bf1dc40c lmkd: migrate process to FOREGROUND sched group before kill am: 0195bcdba7 am: a95efc0941
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1825954

Change-Id: I675954885ae62c41b441865dffc8ce9e65529146
2021-09-14 15:03:43 +00:00
Wei Wang a95efc0941 lmkd: migrate process to FOREGROUND sched group before kill am: 0195bcdba7
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1825954

Change-Id: I9b572a9786cf5b7a583730654facca0e30bf57bb
2021-09-14 14:48:51 +00:00
Wei Wang 0195bcdba7 lmkd: migrate process to FOREGROUND sched group before kill
BG group may have settings such as cpu.shares impacting reclaim
performance. Let us migrate task to foreground sched group similarly to
cpuset group.

Test: Build
Bug: 199797672
Signed-off-by: Wei Wang <wvw@google.com>
Change-Id: I75ee9f3486a2c76e65267a98e39edff96a5e1673
2021-09-13 19:07:26 -07:00
Suren Baghdasaryan fcb9cb6de4 lmkd: Do not re-initialize lmkd when persistent properties are loaded
When a device boots, lmkd starts before persistent properties are loaded,
therefore if experiments set any flags, the corresponding persistent
properties will trigger change notifications when they are first loaded
during boot.
In order to prevent lmkd from re-initializing on every property load,
mark persistent property change by setting lmkd.reinit to 0 and delay
lmkd re-initialization until sys.boot_completed=1 when all properties
are set and only one re-initialization will capture them all. On devices
with no experiment flags being set lmkd.reinit will be undefined at the
boot completion time and re-initialization will not be triggered at all.

Bug: 194316048
Test: adb shell device_config put lmkd_native thrashing_limit_critical 350
Test: adb shell device_config put lmkd_native thrashing_limit 100
Test: adb reboot; adb -b all logcat | grep lmkd
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Iba34fc719a18d58b890549c7415bec869d471901
Merged-In: Iba34fc719a18d58b890549c7415bec869d471901
2021-09-09 15:11:08 -07:00
Suren Baghdasaryan e7d82ee7e7 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
Merged-In: Ia48fd51eab126d307a1604530b642e86cf250688
2021-09-09 15:09:45 -07:00
Suren Baghdasaryan ca40541bfc lmkd: Do not re-initialize lmkd when persistent properties are loaded am: 0e64eadc21 am: e87dd04e20 am: 6ea9d83ddd
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1815756

Change-Id: Ic7fc8573cfa282340d19c5430b18ca0333628309
2021-09-02 00:33:32 +00:00
Suren Baghdasaryan 6ea9d83ddd lmkd: Do not re-initialize lmkd when persistent properties are loaded am: 0e64eadc21 am: e87dd04e20
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1815756

Change-Id: I275bb50a28e949971d44b36c4133763200acce73
2021-09-02 00:18:56 +00:00
Suren Baghdasaryan e87dd04e20 lmkd: Do not re-initialize lmkd when persistent properties are loaded am: 0e64eadc21
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1815756

Change-Id: I9862d501675abeec5f4306e111d148bcc7ae8fb9
2021-09-01 23:58:43 +00:00
Suren Baghdasaryan 0e64eadc21 lmkd: Do not re-initialize lmkd when persistent properties are loaded
When a device boots, lmkd starts before persistent properties are loaded,
therefore if experiments set any flags, the corresponding persistent
properties will trigger change notifications when they are first loaded
during boot.
In order to prevent lmkd from re-initializing on every property load,
mark persistent property change by setting lmkd.reinit to 0 and delay
lmkd re-initialization until sys.boot_completed=1 when all properties
are set and only one re-initialization will capture them all. On devices
with no experiment flags being set lmkd.reinit will be undefined at the
boot completion time and re-initialization will not be triggered at all.

Bug: 194316048
Test: adb shell device_config put lmkd_native thrashing_limit_critical 350
Test: adb shell device_config put lmkd_native thrashing_limit 100
Test: adb reboot; adb -b all logcat | grep lmkd
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Iba34fc719a18d58b890549c7415bec869d471901
2021-09-01 00:56:35 -07:00
Suren Baghdasaryan deb55f8395 lmkd: Add support for persist.device_config.lmkd_native.* properties am: d0a800402c am: c51f018a6d am: 345fb264a4
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1785437

Change-Id: Ib92c5fa0fb55359762419021c1de551b68ffdc55
2021-08-31 20:12:10 +00:00
Suren Baghdasaryan 345fb264a4 lmkd: Add support for persist.device_config.lmkd_native.* properties am: d0a800402c am: c51f018a6d
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1785437

Change-Id: I370b9988d5d94b56069c59656dd47e9f96c0546b
2021-08-31 20:03:28 +00:00
Suren Baghdasaryan c51f018a6d lmkd: Add support for persist.device_config.lmkd_native.* properties am: d0a800402c
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1785437

Change-Id: Ib77d4ce588ec31631e6721130ea0a163afe83bed
2021-08-31 19:52:44 +00:00
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
Xin Li 6ef245e3f1 [automerger skipped] Mark sc-dev-plus-aosp-without-vendor@7634622 as merged am: 597d5d2b61 -s ours am: 18ecbf78ce -s ours
am skip reason: Merged-In I905d1733efec72c8e2745cff51cec0547ea57fea with SHA-1 e4689257db is already in history

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

Change-Id: Id107b539c97dad962d78aaecb833474975a74f4e
2021-08-14 06:42:20 +00:00
Xin Li 18ecbf78ce [automerger skipped] Mark sc-dev-plus-aosp-without-vendor@7634622 as merged am: 597d5d2b61 -s ours
am skip reason: Merged-In I905d1733efec72c8e2745cff51cec0547ea57fea with SHA-1 e4689257db is already in history

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

Change-Id: I59ff94ac3052c99c55017f8e2421d3424d8b5862
2021-08-14 06:29:57 +00:00
Xin Li 597d5d2b61 Mark sc-dev-plus-aosp-without-vendor@7634622 as merged
Merged-In: I905d1733efec72c8e2745cff51cec0547ea57fea
Change-Id: If3648949cabbd47830dabc09b8c293d3c2ee274b
2021-08-14 06:04:15 +00:00
Suren Baghdasaryan 93704f46a8 lmkd: Add thrashing and max_thrashing into killinfo reports am: 39b54809fb am: 145613c986 am: 31b3e7a5aa
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1790959

Change-Id: Ifebe0b2dd132eb629a3cf7f5f0cf691a27df58db
2021-08-12 02:40:56 +00:00
Suren Baghdasaryan 31b3e7a5aa lmkd: Add thrashing and max_thrashing into killinfo reports am: 39b54809fb am: 145613c986
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1790959

Change-Id: I76aec795719c4eec2eff0bb0b4b7c4f9a1d1e650
2021-08-12 02:26:14 +00:00
Suren Baghdasaryan 145613c986 lmkd: Add thrashing and max_thrashing into killinfo reports am: 39b54809fb
Original change: https://android-review.googlesource.com/c/platform/system/memory/lmkd/+/1790959

Change-Id: Ia780dc3b3b96fdcbd48cb72dff62cf52d33c7a0d
2021-08-12 02:10:36 +00: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