From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-78.mta0.migadu.com [91.218.175.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E13BA33F8AD for ; Thu, 13 Aug 2026 09:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.78 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786614697; cv=none; b=qOSam4+sh5951TG9Fjsom/QbnJPSTG6sSV38T8U/zWhext/cS/3THvq9V0yldcPDCbJ2EiKrzsuEvh42npq4UPtwaxabrUmbZahbhRNDyVhhVoJzK0nIA6/mKoMBdE4L+s5WUpHFTP+lt/I9jAltU6S9uK/dGKIBOK9yoHuiE9k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786614697; c=relaxed/simple; bh=8rC0bQOD3kg50nWnBkgYGoITLbGcqBiHy42iACXOCI8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=dUwHdwc5KmyRB65ZxZK+vquhPvVhgI7jgCvNpMqJ06S1irF3jEBasckgouzqpkYV8hB4yIXw3GA/vnWDnXZUOFsksjktDVQHN/4MuzWUf82C5Au6fJVviJM7HkGSL2W9NNg2Meqtl8LY0xy4E2A3DvyD0mxIhK23JgTr8xemM0U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=lSBuLdhP; arc=none smtp.client-ip=91.218.175.78 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="lSBuLdhP" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=8rC0bQOD3kg50nWnBkgYGoITLbGcqBiHy42iACXOCI8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786614693; v=1; x=1787219493; b=lSBuLdhPrkOVEtkaJ0vTyiGt0C9Zyd0elw+o1UUC4J+kFgYAPU+MlNgYUkhj64A0CtnSYi5E LzDFefO/gvZeWYf5bB4WhQFFbiDIbGxDSF6c521+0YEsqJuV5jkStWrpl7SN84JMrSRbKA29JB8 c+91ofvgKUSyZ7wY0gmVIiTY= X-Envelope-To: linux-kernel@vger.kernel.org Received: from [192.168.111.29] (223.70.159.239) by smtp.migadu.com with ESMTPS id 433ca169b7a1f501; Thu, 13 Aug 2026 09:51:33 +0000 X-Migadu-Flow: FLOW_OUT Message-ID: Date: Thu, 13 Aug 2026 17:51:29 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/oom_kill: simplify remaining RCU sections with guard(rcu) To: Michal Hocko Cc: Andrew Morton , Ye Liu , David Rientjes , Shakeel Butt , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20260813032634.344946-1-ye.liu@linux.dev> Content-Language: en-US From: Ye Liu In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 2026/8/13 16:49, Michal Hocko 写道: > On Thu 13-08-26 11:26:33, Ye Liu wrote: >> From: Ye Liu >> >> Replace the remaining manual rcu_read_lock()/rcu_read_unlock() pairs >> in oom_cpuset_eligible(), select_bad_process(), dump_tasks(), >> task_will_free_mem(), and __oom_kill_process() with guard(rcu)() for >> consistency and simpler control flow. > > Could you use scoped_guard instead? While all these functions do not > perform anything pas the for loop this might change in the future and I > find it more obvious what the actual scope for the RCU is rather than > the full function one. >> Thanks for the suggestion, I've updated to V2. >> Signed-off-by: Ye Liu >> --- >> mm/oom_kill.c | 15 +++++---------- >> 1 file changed, 5 insertions(+), 10 deletions(-) >> >> diff --git a/mm/oom_kill.c b/mm/oom_kill.c >> index 4b5c70aaece4..8bbb5ca00bb6 100644 >> --- a/mm/oom_kill.c >> +++ b/mm/oom_kill.c >> @@ -94,7 +94,7 @@ static bool oom_cpuset_eligible(struct task_struct *start, >> bool ret = false; >> const nodemask_t *mask = oc->nodemask; >> >> - rcu_read_lock(); >> + guard(rcu)(); >> for_each_thread(start, tsk) { >> if (mask) { >> /* >> @@ -114,7 +114,6 @@ static bool oom_cpuset_eligible(struct task_struct *start, >> if (ret) >> break; >> } >> - rcu_read_unlock(); >> >> return ret; >> } >> @@ -368,11 +367,10 @@ static void select_bad_process(struct oom_control *oc) >> else { >> struct task_struct *p; >> >> - rcu_read_lock(); >> + guard(rcu)(); >> for_each_process(p) >> if (oom_evaluate_task(p, oc)) >> break; >> - rcu_read_unlock(); >> } >> } >> >> @@ -430,14 +428,13 @@ static void dump_tasks(struct oom_control *oc) >> struct task_struct *p; >> int i = 0; >> >> - rcu_read_lock(); >> + guard(rcu)(); >> for_each_process(p) { >> /* Avoid potential softlockup warning */ >> if ((++i & 1023) == 0) >> touch_softlockup_watchdog(); >> dump_task(p, oc); >> } >> - rcu_read_unlock(); >> } >> } >> >> @@ -894,7 +891,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(); >> + guard(rcu)(); >> for_each_process(p) { >> if (!process_shares_mm(p, mm)) >> continue; >> @@ -904,7 +901,6 @@ static bool task_will_free_mem(struct task_struct *task) >> if (!ret) >> break; >> } >> - rcu_read_unlock(); >> >> return ret; >> } >> @@ -960,7 +956,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(); >> + guard(rcu)(); >> for_each_process(p) { >> if (!process_shares_mm(p, mm)) >> continue; >> @@ -982,7 +978,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 > -- Thanks, Ye Liu