From a63948e4552722ca99d705c5da1c9fd3dd92ebdf Mon Sep 17 00:00:00 2001 From: JohnHsu Date: Mon, 9 Sep 2024 19:49:26 +0800 Subject: [PATCH] lmkd: count the number of times LMKD wakes up LMKD was woken up when the memory pressure was high enough either in either the psi or the vmpressure mechanism. The memory reclaim ability is based on CPUs' capacity of a chip and it is different from each others. This patch can count the number of lmkd wake up when meet the memory pressure threshold instead of heavy-loading logging. To show the count, we can just re-init the lmkd, and it will print in the android logcat and reset the count to zero. Test: Run APP rotation Bug: 365748420 Signed-off-by: JohnHsu Change-Id: I3980d2a90a910c64449b4ad2b005e4d0437097e8 --- lmkd.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lmkd.cpp b/lmkd.cpp index 1030147..f92acee 100644 --- a/lmkd.cpp +++ b/lmkd.cpp @@ -245,6 +245,8 @@ static struct psi_threshold psi_thresholds[VMPRESS_LEVEL_COUNT] = { { PSI_FULL, 70 }, /* 70ms out of 1sec for complete stall */ }; +static uint64_t mp_event_count; + static android_log_context ctx; static Reaper reaper; static int reaper_comm_fd[2]; @@ -2716,6 +2718,12 @@ static void mp_event_psi(int data, uint32_t events, struct polling_params *poll_ long direct_reclaim_duration_ms; bool in_kswapd_reclaim; + mp_event_count++; + if (debug_process_killing) { + ALOGI("%s memory pressure event #%" PRIu64 " is triggered", + level_name[level], mp_event_count); + } + if (clock_gettime(CLOCK_MONOTONIC_COARSE, &curr_tm) != 0) { ALOGE("Failed to get current time"); return; @@ -3066,8 +3074,10 @@ static void mp_event_common(int data, uint32_t events, struct polling_params *po }; static struct wakeup_info wi; + mp_event_count++; if (debug_process_killing) { - ALOGI("%s memory pressure event is triggered", level_name[level]); + ALOGI("%s memory pressure event #%" PRIu64 " is triggered", + level_name[level], mp_event_count); } if (!use_psi_monitors) { @@ -3582,6 +3592,8 @@ static void kernel_event_handler(int data __unused, uint32_t events __unused, } static bool init_monitors() { + ALOGI("Wakeup counter is reset from %" PRIu64 " to 0", mp_event_count); + mp_event_count = 0; /* Try to use psi monitor first if kernel has it */ use_psi_monitors = GET_LMK_PROPERTY(bool, "use_psi", true) && init_psi_monitors();