From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 5913C3195EF for ; Tue, 28 Jul 2026 07:27:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785223665; cv=none; b=HUaniRIGNKkCh/rf3A1pt5qOckBmzWRvcfGpZvZ7lYEomLY71pLepjobwHltYok0UgFXpPtoOfZ4mP5+qOCwWr0E0FFBe9Swg7OuCgkb7ZU7r9eEoSyx1flVF+JNpDdWIgNbf/wtfcncedMzrAmah6RGXIqmyvTE1j91w6OQgHs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785223665; c=relaxed/simple; bh=+VIdQB8Y6n1nzeewNmjmBI5PJhNouHzScrlj27XZY/A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MG4ERM1aD0yapFZHOdNvI0f/H1DPcK+ifJMXsDHnpfr3NcrBtrw0DkZYy/fKayLAPqlA2F6qZOhpNDs0lf2gXAIIFNPkV4qHaJ3qUgtUpRUgYBms+X+SmEfPSUnxqvf2CDjM0f2JrlXEbjZVBcfBbJgvGqSbNG/HoziZ62ew/7E= 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=DHNIJQF+; arc=none smtp.client-ip=209.85.128.48 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="DHNIJQF+" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4954df200ddso23010045e9.0 for ; Tue, 28 Jul 2026 00:27:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1785223661; x=1785828461; 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=jftrX6lDinngHjdgigXRLobwfxyYWK7HW27rdPPfohU=; b=DHNIJQF+W7GdjTBnv7+n59VMMDByvfAGqL71yudWptu+c3ui/rIBo6yjilNRsjERpT S3PpdCM+aS1mkJYpHgIHkt6ep8zOyRGQPpHdnfsdETki6ob7FttS3Bo9mj9I1nfjaC5H v0hfQNlfc6rfQZW6qVva3LseAFVEnSew8UXArumaI/rDG5etLGGNa2YCFkfdX4Rr4SLL /FjlK/xKOnKXjZdDNdkLSbuNub+5RHNjWsm+gk4P3FrW0yCuqrycWNoxaXug+T/LQTvK It+M0Zorx9Qw6WaDuZYK4/SfSNaCTDweBJNg/z/qYnCDvWSUTTGRQ/sbh1NxFPHYqcyP ny4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785223661; x=1785828461; 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=jftrX6lDinngHjdgigXRLobwfxyYWK7HW27rdPPfohU=; b=qthe4kDSMHINifjT5SbmnyrcG8kAigJ5P9MnR0a7h4kvRPI64Al73jmjeo6oHmZOlM +T202W1All+9Vqw3RGIjVEpnfo9moJChgf+gu8ha0VxIepNj0BhrHX8pxom7VoKJnlch 8YW9ukpGyX40LZfo/8SZU+HFE+YMGL5DFylfBz/dQfgZOXcwM3esZa/6zUz7TmtCcErw GiJo46t5QJvVKeVBlY/dwLsMfjvzlXL6bmLPjHnH3Q3yAJwWrDSjXxs70EvU4x4QOrzO pwEe3R/BV0ME6y+HBCZl/dRmk5ibJxu8vQj17dyClb/jGWrYLR8jg7Je+L4Y7cLYcWt4 rTwQ== X-Forwarded-Encrypted: i=1; AHgh+RpFXTwvNN64Q+dQqpLuvaMu7N2YIv4rlbZeRmjB6Qmzo+CV8fjDx1F7BsCkEZXSW6vu2EpzQgbDsgzkxeE=@vger.kernel.org X-Gm-Message-State: AOJu0YydHD7it29fBlgnoQZLTM4dmS5od8JTqr07nX2NHh/1x7Lf9byk NGSYiF+cIg+EuYFCMthTyZALTi3NKPfvhxtjIdckwPnArRYcRRzMN6+YbjjJhIgPUjc= X-Gm-Gg: AR+sD10NpKBHH7Cw8Cij0PfdSASjyvwFO8xpQH02tGS2fqw14Mi2QSsAFFUMWzpLt2I 2j/fkQCvw4QR9bitmtJyhvScQ96JcTMmT6QbSQe2l6T+o93soD0EGRDcaQ5wgsYna41xXPqjcSI vi7jVKvGE8YJQ0mZal8HaDc43r8azeGXn0O3OVR4a2xlKRHniMcuT+erUnTOzKcrnYOkfnjTOtR l3hvQWInI6cLweQSYDVXMmLqUmRWZER85DN9gWcLw7I5uF/FYJB8sB6CLTm0FPnEXqqWLK1hlnw 0OoUW4rhr5NCMHQOKhRCP6l4Fd9w2/ytSI/7PZ/WsWNrPtSJ7l9gG0K4+SkLEwwj7Tf490Xk6To kT2Xf35dlSYbkgbBqgZEEEJ5XB/RbQSEWtc0nDluYLuJXDov3kJylaoiXH1Avw5YeB/9ZsCrm0+ geKMYzLPiyWA== X-Received: by 2002:a05:600c:1c27:b0:493:e974:41ac with SMTP id 5b1f17b1804b1-496c643c6f9mr11555145e9.16.1785223661467; Tue, 28 Jul 2026 00:27:41 -0700 (PDT) Received: from localhost (109-81-83-7.rct.o2.cz. [109.81.83.7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-496c4632263sm58920795e9.15.2026.07.28.00.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2026 00:27:41 -0700 (PDT) Date: Tue, 28 Jul 2026 09:27:39 +0200 From: Michal Hocko To: Shakeel Butt Cc: Andrew Morton , David Rientjes , Johannes Weiner , Roman Gushchin , Muchun Song , Thomas Gleixner , Ingo Molnar , Suren Baghdasaryan , Usama Arif , Peter Zijlstra , Darren Hart , Davidlohr Bueso , =?iso-8859-1?Q?Andr=E9?= Almeida , "Liam R . Howlett" , Yosry Ahmed , Rik van Riel , Nhat Pham , Meta kernel team , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC] Robust futex causing memcg OOM storm on exit Message-ID: References: <20260723001908.4046643-1-shakeel.butt@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: On Mon 27-07-26 13:48:58, Shakeel Butt wrote: > On Mon, Jul 27, 2026 at 08:38:37AM -0700, Shakeel Butt wrote: > > On Mon, Jul 27, 2026 at 04:36:23PM +0200, Michal Hocko wrote: > > > On Wed 22-07-26 17:19:07, Shakeel Butt wrote: > > [...] > > > > > > > TBH I am not entirely happy about this approach. It effectivelly reverts > > > a75ffa26122b ("memcg, oom: do not bypass oom killer for dying tasks"). > > > It just makes it lockless. Assumption that a dying task will do so > > > quickly and with bounded resources has turned wrong on several > > > occasions. > > > > That's why I kept it as RFC :) > > > > > > > > On the other hand I do undestand the contention issues and I can imagine > > > that the existing solution doesn't really work well for huge thread > > > groups that all end up lining up on the oom_lock just to learn there is > > > nothing really killable anymore because they are the oom victim... > > > > > > Would it be just safer to bail out only for oom victim threads. This > > > would narrow down potential runaways for oom victims which should be > > > more limited than any killed/exiting task. It would also give the oom > > > killer/reaper chance to work. WDYT? > > > > I will give the following patch a try with the reproducer I have. I am still > > improving the reproducer as I am still not able to recreate multi hour slowdown > > yet. I will report back once I have some results. > > > > I have some results with the reproducer I (AI) wrote. > > Setup: 20k threads, each with its robust_list head on its own page in a > large anon region pushed into a zswap pool (writeback off, so it's > unreclaimable and pins the memcg at the limit). On the OOM-group-kill > every thread faults that page in futex_cleanup() -> do_swap_page() -> > swapin charge -> memcg OOM. A separate thread holds mmap_lock for write > in a loop so the oom_reaper can't reap the pool -- matching the host, > where the reaper was blocked and the memcg never fell below the limit. > > I tested on next-20260726 as baseline and then tested your suggestion over it. > For baseline ~48k no-victim OOM invocations serialized on oom_lock; ~40s to > drain the 20k threads in a VM (hours on the host, where each invocation > was a dump_header over netconsole). With the patch the dying tasks stop > entering out_of_memory and the storm is gone. > > With the following suggestion, the threads of dying tasks stop entering > out_of_memory but the exit time doubled as each thread has to decompress the > page from zswap. > > if (tsk_is_oom_victim(current)) > goto force; > > I also tested by replacing goto force with goto nomem and the exit time halved > i.e. ~20 seconds. Looking deeper it seems like each thread is still going > through the reclaim loops. > > Just for testing purpose I moved this check along with goto nomem just before > the reclaim fuction i.e. try_to_free_mem_cgroup_pages() and the exit time falls > below 1 second. I think what we need is to detect early that the cgroup is > unreclaimable and the threads of exiting/reaped process should just return with > enomem. Do you mean, something like this? --- diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 6dc4888a90f3..66f1eebf8c22 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2648,6 +2648,18 @@ static int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask, if (!gfpflags_allow_blocking(gfp_mask)) goto nomem; + /* + * OOM victim still needs to charge memory to exit. OOM reaper should + * help but it might fail on mmap_lock contention. If the victim is a + * large thread group then all exiting threads might compete on oom_lock + * just to learn that there is nothing really killable anymore. Bail + * out early and fail the charge to expedite their exit. They are + * considered fully reclaimed by the oom reaper and they shouldn't contribute + * further charges. + */ + if (tsk_is_oom_victim(current) && mm_flags_test(current->signal->oom_mm)) + goto nomem; + __memcg_memory_event(mem_over_limit, MEMCG_MAX, allow_spinning); raised_max_event = true; -- Michal Hocko SUSE Labs