From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38B5C225388; Mon, 2 Jun 2025 14:35:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748874936; cv=none; b=gs/1bZd/1yPxyhwIOayXjHMfnUaqSKf3h14PYz6sx1pxcaZ8zj2aJ9G/PyZ/s0ABCb23jf1N11uT5edlUKasCkMyHIxyRAMyxnE6SPIBpZYalx+OZqmXidsUtSejSsUvPLFA0sUSrAjV/1Og7vW6ZsYsGk52PedWFQ++nERkeEs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748874936; c=relaxed/simple; bh=KGaqco5ZG0f3F7umkwTDZNaqIUOS178yhtIkT6kwqg8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fUr4mvT56n1GDdNzACFgdASH7a2rHhWPswyUT/8OUP2g3pwirdkaVMIM4jrCCLpIDtN5h3n4bzOTkbii3ivmsChugwtsOE7yc2vsZLYNZR5b68map8C5CC2DPN5WmOucQeDpkNnbwH3D4EBGzhb3ckyADyly0BzRMN95z0Eo4g8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=pjZezdrs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="pjZezdrs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44AA0C4CEEB; Mon, 2 Jun 2025 14:35:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1748874934; bh=KGaqco5ZG0f3F7umkwTDZNaqIUOS178yhtIkT6kwqg8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pjZezdrsmsxHxuNJUFu3xqTb3xmqIb/8rzrCqbM1yJW3+OqfMitO+wagC2a2I7n8V FfbC2j2d5/JLRjJHn0GqO5ObB6noSIfkdVlz3jVXl3rznqUToQ3BSLPgtqUPbm3/Nj ac9qnOrTrkj3n3QSDXX5bdg8jDWbjk3ilHKLc300= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Breno Leitao , Rik van Riel , Shakeel Butt , Michael van der Westhuizen , Usama Arif , Pavel Begunkov , Chen Ridong , Johannes Weiner , Michal Hocko , Michal Hocko , Muchun Song , Roman Gushchin , Andrew Morton Subject: [PATCH 5.4 181/204] memcg: always call cond_resched() after fn() Date: Mon, 2 Jun 2025 15:48:34 +0200 Message-ID: <20250602134302.771882417@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250602134255.449974357@linuxfoundation.org> References: <20250602134255.449974357@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Breno Leitao commit 06717a7b6c86514dbd6ab322e8083ffaa4db5712 upstream. 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. Link: https://lkml.kernel.org/r/20250523-memcg_fix-v1-1-ad3eafb60477@debian.org Fixes: ade81479c7dd ("memcg: fix soft lockup in the OOM process") Signed-off-by: Breno Leitao Suggested-by: Rik van Riel Acked-by: Shakeel Butt Cc: Michael van der Westhuizen Cc: Usama Arif Cc: Pavel Begunkov Cc: Chen Ridong Cc: Greg Kroah-Hartman Cc: Johannes Weiner Cc: Michal Hocko Cc: Michal Hocko Cc: Muchun Song Cc: Roman Gushchin Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/memcontrol.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1221,7 +1221,6 @@ int mem_cgroup_scan_tasks(struct mem_cgr { struct mem_cgroup *iter; int ret = 0; - int i = 0; BUG_ON(memcg == root_mem_cgroup); @@ -1231,10 +1230,9 @@ int mem_cgroup_scan_tasks(struct mem_cgr css_task_iter_start(&iter->css, CSS_TASK_ITER_PROCS, &it); while (!ret && (task = css_task_iter_next(&it))) { - /* Avoid potential softlockup warning */ - if ((++i & 1023) == 0) - cond_resched(); ret = fn(task, arg); + /* Avoid potential softlockup warning */ + cond_resched(); } css_task_iter_end(&it); if (ret) {