From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (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 DF81E30CD95 for ; Tue, 11 Aug 2026 04:14:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786421655; cv=none; b=SBRaraBYHltH0HpAEnxozdskYEweqe5FP2YAUycZgU3ABSBKW0k61Qxl8QGU39bwcvP+6T4Xs59+7BzD+7weTFyDaPFCeqDVumr9QOKA+TVyekajovii7BeKLYmTeAfu7yuVU6QvHyLKMv5gxCg5Z2Hhe3dLR8ZJIhsj5+zSVM0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786421655; c=relaxed/simple; bh=6Sq7HFt1juFO8o84F0wK9ElES3E0LdvFk237gwVws98=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=NqvuN9Pd8A7LAF9TQbzfvNpE0llEn3XhDB0Gm51f0ghwFsdHq0+EbqvWkGeQug+v1uFM9GN+QPb8HkBGEyIu5hHerk9oY5Sh6E4qGp8ivhaUy+e/1/LeuGTjnZJ+9NNYeFS7zdauVur2SJDsb5HHwJrM5ksvV7f5GHH4eTFw0ck= 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=RisPRFYq; arc=none smtp.client-ip=91.218.175.180 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="RisPRFYq" Message-ID: <7864bd62-7289-4741-a905-23593130cea9@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1786421650; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GgnpJ28vans1RntJYD4IuvfP0AmT4NAbCO4b8APJluQ=; b=RisPRFYqIgCnz1LNYTT0ra4MLK5/CZN+AT1pr362E9KitMbGDyIDueq/I2NNKXdddpBG2X 3wg30r2zPOtmIzV3VzBc/WVympEASKLpvXX2afZeR53fDSVgIsUf7Ki0N7Dpcq2uItR+e4 CaO1NWARimcCBTFCMHyyjeCz27w2EPY= Date: Tue, 11 Aug 2026 12:13:56 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Cc: cui.tao@linux.dev, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Guopeng Zhang , Michal Hocko Subject: Re: [PATCH v2] mm: memcg-v1: fix memsw and TCP failcnt accounting To: Guopeng Zhang , hannes@cmpxchg.org, mhocko@kernel.org, akpm@linux-foundation.org References: <20260811030843.109104-1-guopeng.zhang@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Tao Cui In-Reply-To: <20260811030843.109104-1-guopeng.zhang@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 在 2026/8/11 11:08, Guopeng Zhang 写道: > From: Guopeng Zhang > > Commit 0e2759afcaf9 ("page_counter: track failcnt only for legacy > cgroups") made failcnt accounting conditional on track_failcnt. It > enabled the flag for memcg->memory, but not for memcg->memsw or > memcg->tcpmem. > > Consequently, memory.memsw.failcnt remains zero when the memory+swap > limit is hit. memory.kmem.tcp.limit_in_bytes still sets > memcg->tcpmem.max, but TCP charge failures are not reflected in > memory.kmem.tcp.failcnt. > > Enable failcnt accounting for both v1 counters. > > To reproduce memory.memsw.failcnt: > > CG=/sys/fs/cgroup/memory/memsw-test > LIMIT=33554432 > mkdir "$CG" > echo "$LIMIT" > "$CG/memory.limit_in_bytes" > echo "$LIMIT" > "$CG/memory.memsw.limit_in_bytes" > > Start a child process in the cgroup and make it allocate and touch 96 MiB > of memory, causing a memcg OOM. > > cat "$CG/memory.memsw.failcnt" > > Without the patch, memory.memsw.failcnt is 0. With the patch, > memory.memsw.failcnt is greater than 0. > > To reproduce memory.kmem.tcp.failcnt: > > CG=/sys/fs/cgroup/memory/tcpmem-test > LIMIT=65536 > mkdir "$CG" > echo "$LIMIT" > "$CG/memory.kmem.tcp.limit_in_bytes" > > Start a child process in the cgroup, create a TCP socket, and reserve > 1 MiB of socket memory with SO_RESERVE_MEM. The reservation fails with > ENOMEM. > > cat "$CG/memory.kmem.tcp.failcnt" > > Without the patch, memory.kmem.tcp.failcnt is 0. With the patch, > memory.kmem.tcp.failcnt is greater than 0. > > Closes: https://sashiko.dev/#/patchset/20260810074247.52747-1-guopeng.zhang@linux.dev?part=1 > Fixes: 0e2759afcaf9 ("page_counter: track failcnt only for legacy cgroups") > Cc: stable@vger.kernel.org > Acked-by: Johannes Weiner > Acked-by: Michal Hocko > Signed-off-by: Guopeng Zhang > --- > Changes in v2: > - Enable failcnt tracking for tcpmem as suggested by Johannes Weiner. > - Add the memory.kmem.tcp.failcnt reproducer and test result. > - Update the subject and changelog to cover both counters. > - Add Cc: stable@vger.kernel.org and the received Acked-by tags. > > Link to v1: https://lore.kernel.org/r/20260810074247.52747-1-guopeng.zhang@linux.dev > > mm/memcontrol.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 70806373d5a9..17da1f43b7d3 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -4235,9 +4235,11 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) > #ifdef CONFIG_MEMCG_V1 > WRITE_ONCE(memcg->swappiness, mem_cgroup_swappiness(parent)); > memcg->memory.track_failcnt = !memcg_on_dfl; > + memcg->memsw.track_failcnt = !memcg_on_dfl; > WRITE_ONCE(memcg->oom_kill_disable, READ_ONCE(parent->oom_kill_disable)); > page_counter_init(&memcg->kmem, &parent->kmem, false); > page_counter_init(&memcg->tcpmem, &parent->tcpmem, false); > + memcg->tcpmem.track_failcnt = !memcg_on_dfl; > #endif > } else { > init_memcg_stats(); Reviewed-by: Tao Cui