From 07737c4d5cdab31c4b495ee3a6d4b077adc909df Mon Sep 17 00:00:00 2001 From: Sultan Alsawaf Date: Mon, 18 Feb 2019 11:52:13 -0800 Subject: [PATCH] simple_lmk: React faster to kswapd reclaim events With the previous change, there would be up to a KSWAPD_LMK_EXPIRES delay before Simple LMK would react to a kswapd reclaim being needed, and it would still make it difficult for a kswapd reclaim to occur if an oom reclaim occurred less than KSWAPD_LMK_EXPIRES ago. To remedy Simple LMK's slow kswapd reaction time, poll every other jiffy once kswapd has been running without sleeping for at least KSWAPD_LMK_EXPIRES' worth of _wall time_. In addition, when a kswapd reclaim is needed, don't disregard it if an oom reclaim has occurred recently; in other words, kswapd reclaims are considered to be of high importance and should not be ignored. Signed-off-by: Sultan Alsawaf Signed-off-by: kdrag0n --- drivers/staging/android/simple_lmk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/staging/android/simple_lmk.c b/drivers/staging/android/simple_lmk.c index 55d53f717593..e39c0fc11a59 100644 --- a/drivers/staging/android/simple_lmk.c +++ b/drivers/staging/android/simple_lmk.c @@ -150,7 +150,7 @@ static cputime_t get_kswapd_cputime(void) static void simple_lmk_reclaim_work(struct work_struct *work) { - unsigned long mib_freed = 0; + unsigned long mib_freed, resched_delay_jiffies = 1; cputime_t kswapd_time_now; u64 delta_us; @@ -162,15 +162,15 @@ static void simple_lmk_reclaim_work(struct work_struct *work) kswapd_start_time = kswapd_time_now; mutex_lock(&reclaim_lock); - if (time_after_eq(jiffies, last_reclaim_jiffies + KSWAPD_LMK_EXPIRES)) - mib_freed = do_lmk_reclaim(MIN_FREE_PAGES); + mib_freed = do_lmk_reclaim(MIN_FREE_PAGES); mutex_unlock(&reclaim_lock); if (mib_freed) pr_info("kswapd: freed %lu MiB\n", mib_freed); + resched_delay_jiffies = KSWAPD_LMK_EXPIRES; reschedule: - queue_delayed_work(simple_lmk_wq, &reclaim_work, KSWAPD_LMK_EXPIRES); + queue_delayed_work(simple_lmk_wq, &reclaim_work, resched_delay_jiffies); } void simple_lmk_one_reclaim(void)