From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (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 30B0C3655C2 for ; Tue, 30 Jun 2026 01:29:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782782985; cv=none; b=YARU+JUSbpP5xwE+A6Tz8Ay1koVXdqjm4aK4LfmhU3lNZ8tQbOxK5nvo+PsCG+f3BHHd5aINwRWTcYC2qi1ew07ENzfF9VqQKr8F54KPoXsZXwJdhddmIJB0W6+klic3ap/aGhsGFBQyC+LNKOFl9YFq2irMbibjIG+eLrDcyGU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782782985; c=relaxed/simple; bh=PX0TviRK2jhDbIilfyPSEen/iRd2DFRfTqG4llmEXE8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vzu4u0UWWbfW4kllG3J3DUL320xGEpgXjlhxj+6SpZ1VI4vl64DAYZUM0Hg8vaT7BhhqGHitRTcJwgGs9fpouortqvoSXcqQJzKzmRVPBNqo4vsSXrh0ev3ZTFVDg3SZxRqohUU+7Sad70LXtBQl+qXFZKalhXf/gyZWJ3vnnNU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=gY43CsnF; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="gY43CsnF" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1782782974; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AlkZCyTFI5I2PN93QEvND063eK33cy90zjCC7GApUko=; b=gY43CsnFlyku18PH/raJSWs+nfA9Q0KeTReLcS8iacsNFDifGqIuAou6YDWC8kzHB3f7Xi FD1U0Q58WGGUMsN0aWt/RQyM6KCRVTW76I9zTHMmnMX2kZtGuep/rp0O0a53uBRHx4cZX2 6pRijX+zQ4fr/isFEO+yEIjgLKBEFnY= From: Jiayuan Chen To: linux-mm@kvack.org Cc: jiayuan.chen@shopee.com, yingfu.zhou@shopee.com, Jiayuan Chen , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Kairui Song , Qi Zheng , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , David Hildenbrand , Lorenzo Stoakes , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] memcg: bail out memory.high when memcg is dying Date: Tue, 30 Jun 2026 09:29:01 +0800 Message-ID: <20260630012909.144372-2-jiayuan.chen@linux.dev> In-Reply-To: <20260630012909.144372-1-jiayuan.chen@linux.dev> References: <20260630012909.144372-1-jiayuan.chen@linux.dev> Precedence: bulk X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT From: Jiayuan Chen memory.high reclaims synchronously in the writer's context, and the latency can be very high - especially when reclaim performs swap I/O, or under thrashing where the loop may not converge for a long time. While this runs the kernfs active reference on the file is held, so a concurrent removal of the same cgroup blocks in kernfs_drain() under cgroup_mutex until it finishes. Reclaiming a dying cgroup is pointless, as its pages are reparented to the parent anyway. Mitigate this by bailing out of the reclaim loop once memcg_is_dying(). Reported-by: Zhou Yingfu Cc: Jiayuan Chen Signed-off-by: Jiayuan Chen --- mm/memcontrol.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index d20ffc827306..eca9f6091980 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4794,6 +4794,9 @@ static ssize_t memory_high_write(struct kernfs_open_file *of, if (signal_pending(current)) break; + if (memcg_is_dying(memcg)) + break; + if (!drained) { drain_all_stock(memcg); drained = true; -- 2.43.0