From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796239985; b=02X3HPltzvN7WCOQHp2IAfyafBiB9I/F+OcCQKfEWCKV/wCrsRsPogC4nCE4UsdTUoan aNsdOZ5ZBTBCPJ1k19CX0a2ETmoZpSWzDnVtReXluDPQyUebZTHjJzO90qZqYqrPbtfTX dR/J2a/UAu5ArhwdoP5Lcz37oFlOkxlnrJqFMc7nlYxpt9SDPDoY1U5f1uj5QI4YW5dPb 3UkmrEicF6XXsAcYybp5abAUA+ITD4Fl4j4a+so+CvWJ1i8XQTYB7PqeAX1aFzAJfekjc BOYQynQAHe3+Ub4WyJvfTbEigX8arESVVzEgWQo+SuqJRp6/G3Ec9GFj7CjsWlB89jQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796239985; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=vorLw+zxK/6OWTdQzK8aDYUjeQ6ABv2rwu1cJ+c6Sk0=; b=jFg6AJ9DwOB8O+kRhNIXcfRu6xa+OB0WD+xf9lvGMY6TWQi9lyENqpiU2aoeEv2Yn3d8 o06plupevp92K5DtDDLxmJHOy/6UVbj/Zro+JNxRIAgexxDfenWzA9c5XgTkl2XQNb0+D rjWURPn9LKQ7NE3cKJLh8mBNRhfX4Q3BjtJ4PHxGDKZL3XAU6po0W9QaSp0jfcklSjMnW mUS+sZqyA4ewmjE7IjdBDeyDQdPbx2EB+E5HfRimfSpyo8trGvo6Fiwr5BpPBetQWBu1/ dxtsQ/yndSfZTp4IDLkkN8ie/5u1P2Lzqn44VmKyve8jYbOEm8CLvdUFxI6jPCcrzNQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b="UNDBn3/T"; arc=none smtp.remote-ip=209.85.128.45 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92442606A322 for ; Wed, 2 Dec 2026 19:33:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 92442606A322 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.a=rsa-sha256 header.s=google header.b=UNDBn3/T Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4bba5e17cbeso72652945e9.1 for ; Wed, 02 Dec 2026 11:33:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1796239983; x=1796844783; 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=vorLw+zxK/6OWTdQzK8aDYUjeQ6ABv2rwu1cJ+c6Sk0=; b=UNDBn3/TCUQSWrD/CXdMd3MuS7hpzpWariOuwNmyAR+A7kejSZUPxPDipOajUqpkK0 a86AaTLR3jxzVx40ixXNsc7eZGyZe2EywIxHeISVP4ISIF2TA6/Qq5Je88/D21hjqQ7g qx5FD0KuLGp248i4EX7HtL/NDoBhnG0lx+cjhS2F5UOkrcnFRt63gPs+gW8ELFInts1m INCV8yjnbdVJgbmuhi8f2h4Au7WAaNpkyNMkpXPC6uIvRxgB8ZRnNYqTywxE9j0wjAlG DoSLMI5JaMoKhZtqhz33dLg7oCnK0JDPQVY0lLovzRz86wYk/eXYDa18tx0rEVO5LHSY ywRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796239983; x=1796844783; 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=vorLw+zxK/6OWTdQzK8aDYUjeQ6ABv2rwu1cJ+c6Sk0=; b=CojsFVy1NsPK70hXpTUCObf8YVYm9+G6e/CVI/OLcGfHY3R1sSLJoBRa7qgOoPVMnW GE8dtwMNV7lJWalQ20rq2BW7WQKPr3fZJF+XGt832kLIcnhMn4TKSrFRxUz52Jf3awyw k3a09uFMkCztxILb7lGzAs/DbCgIYFnKaeng5bsfVfY8U7TbKtlXNeotNCwu9OqRCJnE BZhZa2WH09wDHMh+fkZai4smFC95g8oLWFQICLNq6JavVknOb9fCkbbDfLpchSzENrOV QNOpZ0AFGLUySDaYBfB7CqHH+8sgOMmtRA8RCwvr13gNDzAMFhjI9li6vB+iJOSYal1x f/uQ== X-Forwarded-Encrypted: i=1; AL+hErEiTr0VDXTVWbbqLdfBYFMgEHQvxA/s/sQvhWtFtI/m9nwzm89WULRAts1G+QOP5TtXgf/krO1GodUMAh4=@vger.kernel.org X-Gm-Message-State: APuU4Z/feoUfE0uaUgs57AA91CIb/q+ZQxcynE6rm9/R5UG15YMKnHqF PAm2X2yj4y5uDlIWRJ5Lm3CUEBQXvKwH3ohCsefAkdcsvSWcKRSMT0GzWaESaQgYa8g= X-Gm-Gg: AZFdTZdJErx4q0VQqj/tDlUDU8f9hML9PSxyPdOX+w/FiA9oJMYBZrZIIHKc8Aj4nvA yPnhsezISew+QXpYbT6Zd82/dNSTEiZglH55j0+VsRcNq4bzRvmqmompz5hV3+b/4ch1Jx+7nse 3BybCEKQOSzDbdMY1N9FpZwcwF3nj8yniSlZgjSrsKZqs8T+lps15rnWc7/ZrjWyqeo7WZUNqiM A0SyeE92I2CblnD5pK6JKh4Y+/e0sO1ekjosjMPEM6NUvr3WUc8Y2OC2hf+NV9QMtqcnOIi5awJ OlS69q2HbVOcHgyZKIppeT05BU9P8sxsBlgeE/PJ8kuT3hp0Mz/1XCIuzi5GijvSvDfTZHk4yJI G1rdT1vnr9A90ggqsohkpjbxXmZIR9oh/DBtirGVz9HIZKOCCn4eiLm0B+QfQKljarsNFIOqobX 8pjvIfajNJS3wHKUJG2hYX5xJpqjgMbi+JN28yrAv6bptz84LLzOXnPtpsmHh0wqETKlavBQfxy AvvRG8Z9ZxilPrgz/7VkP91yoGccXOIeeZG6o3idSSeOQ+fcbUzDh76hqTohXrlOVTQyLS2gFwx s0faL8UrvXywH9oxHSrIhcRRRmGhgMjJSU1dN7w= X-Received: by 2002:a05:600c:3b84:b0:4bb:6f45:2a6d with SMTP id 5b1f17b1804b1-4bb888074bbmr972051575e9.12.1796239982909; Wed, 02 Dec 2026 11:33:02 -0800 (PST) Received: from localhost (109-81-21-11.rct.o2.cz. [109.81.21.11]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe0055483sm10653475e9.6.2026.12.02.11.33.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 11:33:02 -0800 (PST) Date: Wed, 2 Dec 2026 20:33:01 +0100 From: Michal Hocko To: Harry Yoo Cc: David Hildenbrand , David Rientjes , Ben Gardon , Johannes Weiner , Andrew Morton , linux-mm@kvack.org, LKML , Chris Mason Subject: Re: [PATCH 07/10] memcg, oom: wait for rcu_call callbacks before retrying reclaim Message-ID: References: <20261202095450.296675-1-mhocko@kernel.org> <20261202095450.296675-8-mhocko@kernel.org> 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 Wed 02-12-26 19:22:20, Harry Yoo wrote: > On Wed, Dec 02, 2026 at 10:54:00AM +0100, Michal Hocko wrote: > > From: Michal Hocko > > > > In a memory cgroup with a small limit, the OOM killer can kill a task > > while most of the limit is taken up by memory that is already queued to > > be freed after an RCU grace period. > > > > Memory that was passed to call_rcu() stays charged until its callback > > frees it. The task_struct and the credentials of an exited child are > > freed that way. With MMU_GATHER_RCU_TABLE_FREE, so are its page tables. > > Reclaim cannot free such memory, and call_rcu() does not throttle its > > caller. > > > > So tasks that fork short-lived children can fill the limit with > > memory that only waits to be freed. When a charge then fails at the > > limit, try_charge_memcg() reclaims and drains the per-CPU stocks. It > > then calls mem_cgroup_oom() without waiting for a grace period. > > > > Call rcu_barrier before retrying the charge after unsuccessful reclaim > > (slow path) to reduce this potential issue. > > > > Reported-by: Chris Mason > > Signed-off-by: Michal Hocko > > --- > > I was wondering why we have to call rcu_barrier() for every retry > instead of just once before OOM. Retrying memory won't free page > tables anyway. > > Apparently sashiko wondered it too. I considered this to be a slow path (the full reclaim round to fail) so additional wait on rcu_barrier doesn't seem all that terrible. Yet we capture potential memory freers before retrying the charge. I could have done something like diff --git a/mm/memcontrol.c b/mm/memcontrol.c index a8dd933273c8..7a1e9afed685 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2802,7 +2802,8 @@ static int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask, if (nr_retries--) { /* Wait for any potential call_rcu memory freers */ - rcu_barrier(); + if (!nr_retries) + rcu_barrier(); goto retry; } to reduce that to the very last run. But this is a bit confusing and in the worst case we are going through more expensive reclaim rounds while there might be rcu callbacks sitting and waiting. I do not think we have a decent way of knowning and making that more directed. But if there is a general agreement that this is the right way, I can go with that of course. This would be really hard to measure without artificial workloads which I do not want to really optimize for. -- Michal Hocko SUSE Labs