From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796333811; b=jV2kwdB+hu1byIxAOPP4e3J4N1LPsIV3DpO2LHJfGjuZxweuENullw6+pC3TNzT/yjrH UCRA3ODLSBkwAlqBmGQPM/GQpJ6XCt9qUiZ7Ey/bci5see/5+uulKg70Fwgdighli9gfL wnebrL8hT71+QP502z+7tWylKeTDe6bZeY9sOhyKtK8Uuogele9idTvOQj67cPKSRcgJ9 5I/y2/T/VFyCucPEMvVIeBu9ugLGuc+yotodPEQi2ohG8GrKmU4Tcv2S8yyt260gxkg76 Z4we/I9G0JFDa8b3MxDlaYZVV3XpMrCnSPiov3LmFGJkpL2QA8pvxsXNjIsW47i1jww== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796333811; h=Received:DKIM-Signature:Received:Date:From:To:Cc:Subject:Message-ID: Reply-To:References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To; bh=GLu2VRArok/F/eVVlVa0yxeOJjm9OKATV0pRJTVlD0k=; b=AVycGVM+QS50RQx1hqgy1UT1As2YKYJ9G+qNg8rmNzO4m9xJb9WZURkBbuWoEyFs3DIG OgkSD2sLytZcr/HRMmG5xJFVySsll9Qe/Cpw0AiniEugBDR8IKQuQEnZpYlNLjs0AqrJB 4q946riKxRhEQybxTclYA4JNxTRdE2Y7FxXkcvaoBMOKD2KOd3jhfb9XWqId3eEb3b3DA 151sv2kNOjC1b83KEreUB2sEn2ITD6/s6Dv43lY4fFqWUZcshhQKUJ+Vt6zymkbot3sMN 3jwWdU5cyznDICCJ5oh6x/ih6iEhVexIGsynzQ8DsCOVvhpasOUxL1lYskjLex2kTPg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cKR+suwB; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27783606A32D for ; Thu, 3 Dec 2026 21:36:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cKR+suwB Received: by smtp.kernel.org (Postfix) with ESMTPSA id F22581F000C2; Thu, 3 Dec 2026 21:36:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796333811; bh=GLu2VRArok/F/eVVlVa0yxeOJjm9OKATV0pRJTVlD0k=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To; b=cKR+suwB4uhWDMPs1rdF+FV1PgF6hwgwwqiZcV5RNqENCij2BRinp0ptTj6pea4oW 44FHLiJN8CU3XFP0BpSyDSiJEnrj0fcXMkcjRzExexUau4r1ARK4jFQSZsYkPhXfae 4Iiko+Jffe3e5ULWeW99lzQuvR2473PT7UEDHvSR0ZP1QDS0A7M0pOxUFoThxvwflY +DkFPT+nzubdih1ZRA+0yIILuF9c4hkU38I0ngo2gaP9Sh03/1vlT6lDUBHoQWXLM1 NhI5DncraYUpZoNyM/EUaJ0VIg3SpsI1XX7kOcdOdlrARS2y5tXtjAn6I9KaxAAN3G EYKQgWF8lZ3Gw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id BA5FBCE08CF; Thu, 3 Dec 2026 13:36:50 -0800 (PST) Date: Thu, 3 Dec 2026 13:36:50 -0800 From: "Paul E. McKenney" To: Michal Hocko Cc: "Lorenzo Stoakes (ARM)" , David Hildenbrand , Andrew Morton , David Rientjes , Ben Gardon , Johannes Weiner , linux-mm@kvack.org, LKML , Chris Mason Subject: Re: [PATCH v2] mm, oom: add rcu_barrier before hiding victim from the oom killer Message-ID: Reply-To: paulmck@kernel.org References: <20261202095450.296675-10-mhocko@kernel.org> <20261202212147.379270-1-mhocko@kernel.org> <71c575f6-60e6-48cf-9673-2727458733f4@paulmck-laptop> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Dec 03, 2026 at 09:42:24PM +0100, Michal Hocko wrote: > On Thu 03-12-26 12:02:00, Paul E. McKenney wrote: > > On Thu, Dec 03, 2026 at 07:11:39PM +0100, Michal Hocko wrote: > > > On Thu 03-12-26 09:39:53, Paul E. McKenney wrote: > > > [...] > > > > > And this is a super sensitive point - will this always result in forward > > > > > progress? Could it be significantly delayed? > > > > > > > > Normal grace period latencies tend to be in the tens or hundreds of > > > > milliseconds. And RCU CPU stall warnings happen when a given grace period > > > > extends for more than 21 *seconds*, so long RCU grace periods can happen. > > > > On the other hand, grace periods this long are (and should be) treated > > > > as bugs. > > > > > > Yes, I guess it is expected that this can take a long time. And this > > > particular patch adds it to two places: > > > - exit_mmap for an oom_victim > > > - oom_reaper > > > > > > The former is dying and if that takes longer while it is guaranteed to > > > release its own memory from page tables which are freed through RCU then > > > this is good. We do not even need a guarantee of a fwd progress here. > > > > > > The latter is more sensitive as it needs the guarantee of fwd progress. > > > Although it doesn't hold any locks explicitly it ensures that the > > > currently selected oom victims will be torn down - either through them > > > exiting or remotely through the reaper. In either case they are declared > > > MMF_OOM_SKIP in the end. > > > If that takes longer then still not anything really earth shattering as > > > long as this cannot block for unbound amount of time. > > > > OK, good to know! > > > > > > > Are there any lock dependencies that could be problematic? > > > > > > > > Given that you are asking this, I am assuming that if this rcu_barrier() > > > > gets stuck, reclaim also gets stuck. > > > > > > > > You are not allowed to acquire sleeplocks in RCU callback functions, > > > > and you are not allowed to hold spinlocks across an rcu_barrier(), so > > > > at a high level, no. > > > > > > Thanks for the confirmation. That was my understanding. > > > > > > > One theoretical problem would be if RCU allocated > > > > memory while doing a grace period, and the call to rcu_barrier() blocked > > > > the grace period that its callback functions were in turn waiting on. > > > > And there might be something like this that could happen when a CPU > > > > was coming online for the very first time, especially if that CPU was > > > > a rcu_nocbs CPU, which needs kthreads to be created. > > > > > > > > No locks involved, but self-deadlock nevertheless. > > > > > > Could you clarify a bit please? So this would be possible only during > > > early boot while hitting OOM because RCU internals would be blocked on > > > the memory allocation which cannot be resolved? > > > > Also when bringing a CPU online during runtime, potentially. There are > > some oddball configurations that bring up only some of the CPUs initially, > > and bring up the rest later. One way to do this is to have qemu and > > the kernel have different ideas about the number of CPUs that exist. > > > > And yes, my concern is that RCU grace periods are blocked on reclaim > > while reclaim blocks on an RCU grace period. But maybe this code is > > guaranteed to run in its own kthreads or similar? > > Yes, oom_reaper itself is running in a dedicated kernel thread. Is that > sufficient? I thought we could have an indirect dependency chain > > RCU grace period oom_reaper oom_victim > allocates memory [blocked] > looping in reclaim rcu_barrier(); > [blocked] > MMF_OOM_SKIP Good point, RCU would need to do non-blocking allocations to avoid that dependency chain. > > Either way, I freely confess that I have not traced out an actual > > failure scenario. > > > > > > So maybe make that rcu_barrier() execute asynchronously? > > > > > > Well the thing is that we need to use it to order MMF_OOM_SKIP setting > > > in the oom_reaper case. > > > > OK, that would rule out asynchrony. ;-) > > > > > > And/or do a > > > > synchronize_rcu_expedited(), also asynchronously? > > > > > > As this is mostly a best effort to ensure a lot of memory is not sitting > > > to be freed in rcu callbacks then I would much rather just drop the > > > rcu_barrier from oom_reap_task. > > > > The main advantage of doing an rcu_barrier() would be in kernels built > > with CONFIG_RCU_LAZY=y, in which case rcu_barrier() would "motivate" > > lazy callbacks, potentially large numbers of them. > > > > On the other hand, RCU does a shrinker_register() in that case, so > > maybe those lazy callbacks are already covered. > > That only involves k[v]free_rcu ones right? So for example page tables > wouldn't fall into that category. This one registers lazy_rcu_shrink_count() and lazy_rcu_shrink_scan() in kernel/rcu/tree_nocb.h, which look to me like they are dealing with lazy callbacks. Thanx, Paul