From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (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 BDAB247DF9E for ; Thu, 2 Jul 2026 12:05:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782993925; cv=none; b=I4BsIL2KZ5mzlKib3VO5RDDjq0cMQY0A8DSyhlbaw0aberO+b8imwxryjnAdyY5QlxlysnYPiqf50TInGGarVIusAgkt+FWGsSTGt/vFWlND+L3tAZbcxQL+46b1dgWVHbxBGvvGsodpDkQISzItQj3JLxl786f3niCrMp0J2T0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782993925; c=relaxed/simple; bh=jBjMeoxS2UrjVupUSl3TuQp1cNzqpdOW5r3iSQHpqZQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z8QSqSxu6GDuvwrv/fTdWV2RrEHkpTHuHQ439d/PdOvV1s2VncGs/bbnUrK14ebDWMOMnMjmMuLhqz5DE1d57yERCChDi35OXR4PunnBel836/BHhaUFvWcDtZv72E72UucdufS83+mw4NttaQkv3o1POXGIZ2rMMFlO0SaU4CY= 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=Ef1oi9xC; arc=none smtp.client-ip=91.218.175.189 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="Ef1oi9xC" 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=1782993920; 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=IdKx32sSfIVhxQRbIzQTe7paHdZvr9txvT5DPnpAX6s=; b=Ef1oi9xC9KF3jOEG/WWDiNe3umVBLnYr97Jk7BKS3XflaW93GQEMRJXTdNaUXR7m4govMT /iMo2LgswKu9+aSX3fWD0BsofHhF3gwrgDIS7zhTyzTpf+O1qaPH3fw2VUeCHxuw869A4C bEsDwC/maqVvhLoNmQqTZbdFs/WkXrI= From: Jiayuan Chen To: linux-mm@kvack.org Cc: jiayuan.chen@shopee.com, Jiayuan Chen , Zhou Yingfu , Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , David Hildenbrand , Qi Zheng , Lorenzo Stoakes , Kairui Song , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/4] memcg: bail out memory.high when memcg is dying Date: Thu, 2 Jul 2026 20:02:27 +0800 Message-ID: <20260702120235.376752-2-jiayuan.chen@linux.dev> In-Reply-To: <20260702120235.376752-1-jiayuan.chen@linux.dev> References: <20260702120235.376752-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(). Cc: Jiayuan Chen Reported-by: Zhou Yingfu Acked-by: Johannes Weiner Signed-off-by: Jiayuan Chen --- mm/memcontrol.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index d20ffc827306..4519dc9eae33 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4794,6 +4794,10 @@ static ssize_t memory_high_write(struct kernfs_open_file *of, if (signal_pending(current)) break; + /* cgroup_rmdir() waits for us with cgroup_mutex held. */ + if (memcg_is_dying(memcg)) + break; + if (!drained) { drain_all_stock(memcg); drained = true; -- 2.43.0