From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 8D1B832B114 for ; Thu, 13 Aug 2026 08:49:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786610978; cv=none; b=ZfZPfv6w5yzW9QxnAgRO4QnT+tbuR63fv855ddfYW/PBYzOBN5AOvaXc7crF9WnluGiAMA3aLyzOSWRgSM5g+6zLFZJRA64IvKjtKIco9+o/dbtyR6XYvGAumlbSl+e/XHA19C+eV/nvMW30y54hprqCgboKz8qWTRJBtNMdKO0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786610978; c=relaxed/simple; bh=RA85jXK9aYXoO9Nf6XCGYKSUHxBUbLM07XkDxqaGowA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=X07KfKZ+2r5179dj2V769dyVpX4N8yHXChuU9CPY210nG0XpEaak0YBh0ZtG05pybZXOL026Dw+LYaElemmlM6ZX1awf5mP7vOX1UwZRpkHKUTfxDceCbG8r7sdMXWHTirK177ATIQ6avNf4wfP2CstoUsbp99May23VDma6Z+c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Qr3pj9Ob; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Qr3pj9Ob" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-495590dde14so22494075e9.0 for ; Thu, 13 Aug 2026 01:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1786610975; x=1787215775; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=ud3PerIKkxv+VQSOh8f05M4PIN0Du2TXNILy0NYD9Lo=; b=Qr3pj9ObCQf7n3txVR8IYBqv2q7eNUFSfvUm80ujjNgmiDHmlkxoCBYxaqD/pBwzwa HJQo1TjtlzICTrQXs1/oX23pevJ/i5ctv9wzPPnCJgOMk0BXDWiZN6FTESMXfRO7Yi0R G062Voi9PeAE+36B/Mjt/SrmYFdPb1EZrDZBO5+Q/JhcdklzJBceMp66DjMJIdfVBiJo P6CFj934AdNrWUXF4XkvAFK5lW/8oU71P5CS9tjJMJcgsHbfvG4bwF8JPbGy5idw40NM RV3rfReFoelt7sBFSG57/UoB22MTodaFRNHJ+EGeQ8aVodoyi+oQI5Wdsb8RB9eCoQXc Ry0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786610975; x=1787215775; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ud3PerIKkxv+VQSOh8f05M4PIN0Du2TXNILy0NYD9Lo=; b=N3vjItPwXrN8viXHy1TbhZiB2r60+MDEI6Z2QPRz5Stg/g2o03ZTTpdD8KTEY+NENo 80bBnwLRB8iFO9mA890qYPw2Y21VPOyvu600UAgDXADoPBFmQUurMYo4ZdJc+uqpzCe2 DCME4tkVrcUp+2hID0n7dBW/fxHswhELZwIMtuoFY2vD8sg/pkMMZZOzKH0MUka0jP4O pQXBc5la0i5eJ8eNOnu0jd/Gm71G2ReAPMk+LEfKBPZ5HqkLGe45RtZ0RWrPlv7plVpY wz96UYd8BoBMflKf8T3Fu30aVhSjQs4HBjD1suM0RZgDlypP9gKMDabi3RP8A6I33rKN RdEQ== X-Forwarded-Encrypted: i=1; AHgh+RokqVNuJWjG9z+MbV5MtlW8xXJfrOPohr3QMVs8uVrPpOkDCnQlZFMSL7nDymRLFEip59JgMzN1uX/44UA=@vger.kernel.org X-Gm-Message-State: AOJu0Yxmg0DIGuOeo6xW4Hg7JHHwNxRE8Ycz7PLlx8i5sRIxq5zOJ8Li c5VEwd03IHeFc41tob7cM1RMRlHUl2dsWgwcndKSlDy2gzdI5fcuUZzAja+rAc+wb/Q= X-Gm-Gg: AR+sD13L33pU5ihBqVnegC2VFNLU613RtZKWOTSbhcnyyaTSeS8ExS553mX9g+6A4A4 CnvP2l2U47WhaALaV8JYDSg3ESQ5dRk3XdV5qY/73z33Rk0SXzM4Gj6QNnWln60Narh6eLtI3F0 5dhSrbM3WkIRUb1JJ6p+g4pW8lFLI6E1ympRXK6djQS1JU+bFOfQQ760K3t8CGou0nGduNbiqcn xb93aV75gXXLAP2FePju2yuVc8UfL259USDLVGbPKG9kAD7j+dieNiw+kQix8hhoMPKclboCZon ExKcyS72CYRrz+DdkSMIQqBXNAesP3mzx7dmk7+ICoLLvvSsAw8iB4mE/qN/AFbP09625hEZ18U cOq35OXarNCFhBpcHlbGggnBopwaEYgZNNsc1elE5kxvcMgfRCAezJ5qS7ii8+U8MgBGSZYDmj1 eAQbgWI2jo4Rlu0+85+sjHM+sd3gOAzMZCbdj5SdDKexj8yg539Zc8eC7Y5Tz1y5bnFdi+f+0= X-Received: by 2002:a05:600c:4e87:b0:495:4859:8f9b with SMTP id 5b1f17b1804b1-499821add3amr43510945e9.9.1786610974833; Thu, 13 Aug 2026 01:49:34 -0700 (PDT) Received: from localhost (109-81-29-60.rct.o2.cz. [109.81.29.60]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49981abd6desm54463045e9.0.2026.08.13.01.49.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2026 01:49:34 -0700 (PDT) Date: Thu, 13 Aug 2026 10:49:32 +0200 From: Michal Hocko To: Ye Liu Cc: Andrew Morton , Ye Liu , David Rientjes , Shakeel Butt , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/oom_kill: simplify remaining RCU sections with guard(rcu) Message-ID: References: <20260813032634.344946-1-ye.liu@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260813032634.344946-1-ye.liu@linux.dev> 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. > > 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 -- Michal Hocko SUSE Labs