From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4BD83A4F3B for ; Mon, 21 Sep 2026 07:00:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789974037; cv=none; b=e/7NpkWEUbf5Xty5LK8qJdRjy1x6hA3ZYd250xcDv+u0HWsb3kI86fvs/Y+BiBFG5NabOAAJ5RcfVK0Tl6+qoe4UfuV1q6yhdDVPOpwtBTIBw4iH6FwQPo1B6foMszLeIw54ENp8FgHnRUgptT+0BEfaEUFNn8RBVQ8i5sVMAlU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789974037; c=relaxed/simple; bh=Vbt4/5LAV2w0dL6pb/t0et3MVMocHRdRtbThpOXu98I=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=jeUoyn6TOPEBE+i6Ar5M4NSruVXWgPmhVsBcIb/0boxU+mXvU7W3SHJUWBzwPI44M065LFWvJbD5LCKtvzK3+9tLgQG2OhWKtyYdI2IxxTXS85WInvsfzeTA/InKTao9+Fe+CDQK0EMqkvAKLJw3Z4uuQlcsQvmZpdHNliSlMf8= 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=OTzlQF8x; arc=none smtp.client-ip=91.218.175.173 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="OTzlQF8x" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=Vbt4/5LAV2w0dL6pb/t0et3MVMocHRdRtbThpOXu98I=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1789974032; v=1; x=1790578832; b=OTzlQF8x8c7RFKdIVcny1Yxlog8DnBk5TbMGtkcqgY2gJaRa5rRJdoj6aQi25QdyCHVt6DJv jq29wmrPJfp9t8oB2gIMD/34/SwjxTo40bMWkc6oTaQwAMI6xleqmA4OFA8GWomU+uwKq29V8py 6F/1xK9046/Tgs52AeyiLFrE= X-Envelope-To: linux-kernel@vger.kernel.org Received: by mta11.migadu.com with ESMTPS id acb919ec4e2ec370; Mon, 21 Sep 2026 07:00:24 +0000 X-Mizu-Trace-ID: acb919ec4e2ec370 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset=us-ascii Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.700.51.1.1\)) Subject: Re: [PATCH v2 4/4] memcg: move memcg private ID refcount to objcg From: Muchun Song In-Reply-To: <20260921-bingfangguo-memcgid-rework-v2-4-6c0637dc0edb@tencent.com> Date: Mon, 21 Sep 2026 14:59:58 +0800 Cc: Johannes Weiner , Michal Hocko , Roman Gushchin , Shakeel Butt , Andrew Morton , Dave Chinner , Qi Zheng , Kairui Song , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , David Hildenbrand , Lorenzo Stoakes , Bingfang Guo , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <59BF36D0-0328-4CFF-8DD6-DF73AF209118@linux.dev> References: <20260921-bingfangguo-memcgid-rework-v2-0-6c0637dc0edb@tencent.com> <20260921-bingfangguo-memcgid-rework-v2-4-6c0637dc0edb@tencent.com> To: bingfangguo@tencent.com X-Mailer: Apple Mail (2.3864.700.51.1.1) > On Sep 21, 2026, at 14:16, Bingfang Guo via B4 Relay = wrote: >=20 > From: Bingfang Guo >=20 > The memcg private ID is used by objects that can't afford storing a > whole pointer and can outlive memcgs to track the memcg (notably swap > entries). The current design holds a refcount to the css, preventing = the > memcg from being freed. >=20 > This patch unbinds the lifetime of memcgid from the memcg so it can be > freed. The idea is to move the refcount of memcgid to one of the > memcg's objcg. The objcg is stored in the global memcgid xarray = instead > and used for retrieving the online memcg from it. So swapped out = pages > no longer pin the dying memcg. >=20 > After the change, a memcgid can refer to a non present memcg. To = handle > this situation, when trying to get the original memcg from the id, > compare the memcgid passed in with that of the memcg, and return NULL = to > indicate its death if they differ. NULL checks are added for > list_lru_walk_node(), workingset_test_recent() to skip dead memcgs. = For > MGLRU recency test, mem_cgroup_lruvec() will substitute NULL with > root_mem_cgroup. >=20 > In the earlier patch, an extra xarray lookup was introduced in swap > uncharging path. Now that we have the objcg pointer in the function, > the extra overhead can be removed by using it for putting directly. >=20 > Signed-off-by: Bingfang Guo Acked-by: Muchun Song Thanks.