From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 031C3C54ED1 for ; Fri, 23 May 2025 18:21:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A08F6B007B; Fri, 23 May 2025 14:21:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0046E6B00B9; Fri, 23 May 2025 14:21:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E851B6B00BA; Fri, 23 May 2025 14:21:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C4FCC6B00B8 for ; Fri, 23 May 2025 14:21:49 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5A744140CC7 for ; Fri, 23 May 2025 18:21:49 +0000 (UTC) X-FDA: 83474991138.03.BE8B056 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) by imf23.hostedemail.com (Postfix) with ESMTP id 7304C14000A for ; Fri, 23 May 2025 18:21:47 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=u4+4mLQa; spf=pass (imf23.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.180 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1748024507; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9GcVUed+F9NvfABQQn7JwQ6fDdObSd9v2gwZ5/oOI4M=; b=h4GYbODqurHUSuLQYc/eV6f2+R+fyyQsiqZJhPBetejp0UoumrqhIP8LgghCGMb07CnoSF fHCrimcgZSb67WwQ9/TsvLSgK7SP+QUGllGiqUDkVJHx7ANfuW6PTNKiGMc544fuuCKOyX 8LTCqQbUewtmHxvdS6b05WNJ7DQiziA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1748024507; a=rsa-sha256; cv=none; b=TES6qgjmhCyfLlrVRsK4bs1pU0niSD4iqnm3PHGT4VhJliZEMfRSUbK4o1wPrelb14m2VY b2s3I0fQQ3GSxY0e7DQMuSlx3jUFlT84R8SmmSMwmxhZ4ZEcOccz17m2C11P0UbZRnkRaV HCfxCph+vX/hpCTnv5vX6KAU4zUqi5w= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=u4+4mLQa; spf=pass (imf23.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.180 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev Date: Fri, 23 May 2025 11:21:39 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1748024505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=9GcVUed+F9NvfABQQn7JwQ6fDdObSd9v2gwZ5/oOI4M=; b=u4+4mLQaOqcYqcofYG5LY1w56+zv4vr2CilC+OslZZYWDtT/N3C+7BnPWib9fzr9iOypRl b/Q0P+dQeHpTaRRsMa53vqEKUddVoMztdhwy19cukLaz0Rn3yad5SE/jT7+UyiMRFcwS2E fR4tFXLDOlHKsf63TufOYWOKphxptuI= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Breno Leitao Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Andrew Morton , Chen Ridong , Greg Kroah-Hartman , Michal Hocko , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, Michael van der Westhuizen , Usama Arif , Pavel Begunkov , Rik van Riel Subject: Re: [PATCH] memcg: Always call cond_resched() after fn() Message-ID: References: <20250523-memcg_fix-v1-1-ad3eafb60477@debian.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250523-memcg_fix-v1-1-ad3eafb60477@debian.org> X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7304C14000A X-Stat-Signature: ps18pt1q8odk7cdiitq1d1piwa391nyt X-Rspam-User: X-HE-Tag: 1748024507-645620 X-HE-Meta: U2FsdGVkX19DqyPi+nTYdq2AtNzv6htWY9mwSMKcu5JZh8drSdqtCjtRw4tHihGcHZViO3fahpBhj0ZlhNfvNZBfC2er9QERtrer6tDaJW4mtI6jfbOh6GCTPOFdTWWXmXIFENTe4BCrMNv1Hfh/53lbIR/WXxeaIvHnb0hBqqmB2qSxrfPvoqLm6kxHj9Ny8OwgS+55JhdxvJqd/2fiiXqgxngp3V4aO0iNohM2jxcUhKh/glZroO7so6OVKckGhdyi0ipQ8lQypBTWdKqP944wHlPaGkFMr3m+bR1CsBRpDjD4/s5feX8/aM+JC46jZeeAESZgmSFw5XwoHSi7AMEd2t2p3WcjcyutUiFFQYwta5vQFkq2SXCR3MkLDp00mMJ49C+yiplsw/SM9xNAGewY4psaTikAurrPYETmJMFHvXHmkop1BJ5nmbSRzwvgdq2UfGzollGCGr5Zuf7O/0lGFkGCwTh2GeiMK2/3+1xQOsHxRAPKL9mQttjkZgEZfSGboKeXfBVkDHlN5d2Dwu4E9ng0Z6mFLSB3FxTPvnmgz8Oi5vpO6/eRsaHCOo2JHLepjnPs4dpZt6zt16GJ+HhQj7gpl1J56Nvnbdz14Fpk1oxLbrCL3cBVXEeP1JHU9Lr5cuyQo394E8y4qAcUGZMBltWDhMPZovp9Lr0jvyy8KaislVJIaXsPTb4brL7qDmeMcPxFdh5UJXwcCt9ykQw7Ad6LpyY5Ma8fjXLUEDnOwKYe2fYfw+e2hCGcBHqAL+ts5tOEUSbWwurIEH/jQmA8niRA44U5xI5hpnTGZqzDzulqCKxhAXzwEjqJ70vpwMWYIGZ1WFhOd1Sx3DubHwYzUL/uw39f7NEjwt4627EVj5kfHQoDZHDJn0FbH0FGv9HI+gNrs7ssHTaRW7Fz/yxF83s/W1/JxFUbT37vcDUAYxhAYn58hsX2l31kCEhkIJRkmSXCe0rYATqV5xa xnr2DRb+ 0utMJBx8FwiSDjWKcJSWDWmSzwfjwliPtPw/Q4WcFKFHdg6vS+XclJfO/0qnWAuhI+BvVNQZSoI176YGizZsLIcqTdxwPUkWmV3tGChavItrttuc+cCvmDvmt6MlRBqCiXwrC0LD0oBBT7PLaZxmQ19kVgh830TdLvAR7l4YxYkGEdYF3k0S3UFywNl9mWoxjjFRHPVl8KDvGJmg+bO0Ve95bTk5mqyj8zUw26aJkIJv6NDBYlbQET/alUtMrUiza1nbv/cllCsvig2O/reuNnl68I9hHFi/pY3xB0egb+EH361kqaRCV7/7nmf9hN+SZg3WOFp29XBoAYeMXEJ2J0LdF3bNPQiuNDBBaunpjW269VpnFYaiwIsk2rlFMhR/KAqkHVSAcJj1leKI/R6U4e43OZaJ0yirFhiDSg4qMGPfKgNugHpKBU2h2b93ycdZgWOEb78UOwndAb5cB63LhrQSfQ/nwV9VvZXs0YcQ189ESOTwSAKimiHKI3g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Fri, May 23, 2025 at 10:21:06AM -0700, Breno Leitao wrote: > I am seeing soft lockup on certain machine types when a cgroup > OOMs. This is happening because killing the process in certain machine > might be very slow, which causes the soft lockup and RCU stalls. This > happens usually when the cgroup has MANY processes and memory.oom.group > is set. > > Example I am seeing in real production: > > [462012.244552] Memory cgroup out of memory: Killed process 3370438 (crosvm) .... > .... > [462037.318059] Memory cgroup out of memory: Killed process 4171372 (adb) .... > [462037.348314] watchdog: BUG: soft lockup - CPU#64 stuck for 26s! [stat_manager-ag:1618982] > .... > > Quick look at why this is so slow, it seems to be related to serial > flush for certain machine types. For all the crashes I saw, the target > CPU was at console_flush_all(). > > In the case above, there are thousands of processes in the cgroup, and > it is soft locking up before it reaches the 1024 limit in the code > (which would call the cond_resched()). So, cond_resched() in 1024 blocks > is not sufficient. > > Remove the counter-based conditional rescheduling logic and call > cond_resched() unconditionally after each task iteration, after fn() is > called. This avoids the lockup independently of how slow fn() is. > > Cc: Michael van der Westhuizen > Cc: Usama Arif > Cc: Pavel Begunkov > Suggested-by: Rik van Riel > Signed-off-by: Breno Leitao > Fixes: 46576834291869457 ("memcg: fix soft lockup in the OOM process") Can you share the call stack but I think from the above, it seems to be from oom_kill_memcg_member(). Have you tried making __oom_kill_process not chatty? Basically instead of dumping to serial directly, use local buffer and then dump once it is full. Anyways, that would be a bit more involved and until then this seems fine to me. Acked-by: Shakeel Butt