From 0787646d32bdf0001b6a61f8bd68a3e604fb96a7 Mon Sep 17 00:00:00 2001 From: Sultan Alsawaf Date: Sun, 7 May 2023 11:25:37 -0700 Subject: [PATCH] simple_lmk: Reduce unnecessary wake ups We can check if the waitqueue is actually active before calling wake_up() in order to avoid an unnecessary wake_up() if the reclaim thread is already running. Furthermore, the release barrier when zeroing needs_reclaim is unnecessary, so remove it. Signed-off-by: Sultan Alsawaf --- drivers/android/simple_lmk.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/android/simple_lmk.c b/drivers/android/simple_lmk.c index c9db1dfd3404..6d53ea62c2b3 100644 --- a/drivers/android/simple_lmk.c +++ b/drivers/android/simple_lmk.c @@ -290,7 +290,7 @@ static int simple_lmk_reclaim_thread(void *data) while (1) { wait_event_freezable(oom_waitq, atomic_read(&needs_reclaim)); scan_and_kill(); - atomic_set_release(&needs_reclaim, 0); + atomic_set(&needs_reclaim, 0); } return 0; @@ -318,8 +318,12 @@ void simple_lmk_mm_freed(struct mm_struct *mm) static int simple_lmk_vmpressure_cb(struct notifier_block *nb, unsigned long pressure, void *data) { - if (pressure == 100 && !atomic_cmpxchg_acquire(&needs_reclaim, 0, 1)) - wake_up(&oom_waitq); + if (pressure == 100) { + atomic_set(&needs_reclaim, 1); + smp_mb__after_atomic(); + if (waitqueue_active(&oom_waitq)) + wake_up(&oom_waitq); + } return NOTIFY_OK; }