From: Ye Liu <[email protected]>

Replace the manual rcu_read_lock()/rcu_read_unlock() pairs wrapping
for_each_process()/for_each_thread() loops with for_each_process_rculock()
and for_each_thread_rculock(), which scope the RCU read lock to the
loop body via scoped_guard(rcu).

No functional change.

Signed-off-by: Ye Liu <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Reviewed-by: SJ Park <[email protected]>
---
Changes in v2:
  - Rename *_rcu to *_rculock
 mm/oom_kill.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 5f372f6e26fa..ef2e1c423c1d 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -94,8 +94,7 @@ static bool oom_cpuset_eligible(struct task_struct *start,
        bool ret = false;
        const nodemask_t *mask = oc->nodemask;
 
-       rcu_read_lock();
-       for_each_thread(start, tsk) {
+       for_each_thread_rculock(start, tsk) {
                if (mask) {
                        /*
                         * If this is a mempolicy constrained oom, tsk's
@@ -114,7 +113,6 @@ static bool oom_cpuset_eligible(struct task_struct *start,
                if (ret)
                        break;
        }
-       rcu_read_unlock();
 
        return ret;
 }
@@ -368,11 +366,9 @@ static void select_bad_process(struct oom_control *oc)
        else {
                struct task_struct *p;
 
-               rcu_read_lock();
-               for_each_process(p)
+               for_each_process_rculock(p)
                        if (oom_evaluate_task(p, oc))
                                break;
-               rcu_read_unlock();
        }
 }
 
@@ -430,14 +426,12 @@ static void dump_tasks(struct oom_control *oc)
                struct task_struct *p;
                int i = 0;
 
-               rcu_read_lock();
-               for_each_process(p) {
+               for_each_process_rculock(p) {
                        /* Avoid potential softlockup warning */
                        if ((++i & 1023) == 0)
                                touch_softlockup_watchdog();
                        dump_task(p, oc);
                }
-               rcu_read_unlock();
        }
 }
 
@@ -894,8 +888,7 @@ static bool task_will_free_mem(struct task_struct *task)
         * are dying as well to make sure that a) nobody pins its mm and
         * b) the task is also reapable by the oom reaper.
         */
-       rcu_read_lock();
-       for_each_process(p) {
+       for_each_process_rculock(p) {
                if (!process_shares_mm(p, mm))
                        continue;
                if (same_thread_group(task, p))
@@ -904,7 +897,6 @@ static bool task_will_free_mem(struct task_struct *task)
                if (!ret)
                        break;
        }
-       rcu_read_unlock();
 
        return ret;
 }
@@ -960,8 +952,7 @@ static void __oom_kill_process(struct task_struct *victim, 
const char *message)
         * That thread will now get access to memory reserves since it has a
         * pending fatal signal.
         */
-       rcu_read_lock();
-       for_each_process(p) {
+       for_each_process_rculock(p) {
                if (!process_shares_mm(p, mm))
                        continue;
                if (same_thread_group(p, victim))
@@ -982,7 +973,6 @@ static void __oom_kill_process(struct task_struct *victim, 
const char *message)
                        continue;
                do_send_sig_info(SIGKILL, SEND_SIG_PRIV, p, PIDTYPE_TGID);
        }
-       rcu_read_unlock();
 
        if (can_oom_reap)
                queue_oom_reaper(victim);
-- 
2.25.1


Reply via email to