From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (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 5FD0B2F3620 for ; Mon, 23 Feb 2026 16:22:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771863765; cv=none; b=FAl3uVTTZ+nTHTO1ka2dLPBaTdI94YDTRO6CZ87+MjRpOC2eeKEmjlbjy8nTTHLixY0hxVdn7TEdDjJO3w6JWPzHPor9RCzuEjKC2/st/L3w3MnBgsgnIoq7PTQt6damu7N+nu2lW3F2n7qUJd2zbYbu+0Bm/ia99RovFT39daU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771863765; c=relaxed/simple; bh=35e9HdDJb4AUDgpu7r/tl4U0+emTTuw0XGe4LiUPG0w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XZPih6AqCwEPCLIUqUi0GUEs9O+7/+ugzXIkEoOfBQRaT8KkPZvWVwrO4MQGTivhvhD1rZ/Gd3CilaekiKiK/CdvEHDkUgmVpZCyISmDcHbCIdmo3np3oT5Qo9PNU6gVwcXfg5QvsRVN5c2vfFNAHeCW438QVV3qUu5nojLFVyE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b=nvqtzL9K; arc=none smtp.client-ip=209.85.160.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b="nvqtzL9K" Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-50698970941so49547611cf.0 for ; Mon, 23 Feb 2026 08:22:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1771863761; x=1772468561; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=/ycxCWrwyhN+Wc3e1z7uOIm6Q5HGlQzORk9QGrhvwpg=; b=nvqtzL9K6Nv53x5RQeltg8zYIm/ozBMjKt3m0uKGdH5F3FDfYHbnU962vim3dyfNqc jlDC7B9FIbNbXIeoxs5iRG7o2qhBPqKTHPIX7lm1Gp33l+cdaeiKX2U3Sc3h0H+AyKG1 qDoMR64B993gq9Az7X8JxB11cNkTMhmfltU3rRKdqF7prLsWx4GBOo2BQCaxH7RSlwV4 Fxb3kjNpgwqLWsBeSqddNnqiBSpaEAqc//CKZ+ToSsWPAdYsfZ8xRIUU7zjJ0P6sh7XZ dlXltzGp8UYSQquRCdTo8SSX4F7qWbjezsWzdPE5Ap8pJpgvpL/JfG9q0UnEfbLL/Bsv aceA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771863761; x=1772468561; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/ycxCWrwyhN+Wc3e1z7uOIm6Q5HGlQzORk9QGrhvwpg=; b=UKFcB6uhiHXjgj8JZ7XUblPXcFwcRiZ1n34yTTt/M+qzLC9WeFvtQ5nWLBS71ZTLMQ D8Zowz0xo3vbUYrCcBZOlJMOYQ+BtQsJr+xZsC/1cRxHlGjUNZaBqz4AZ/qBdBp5Bnpj zUz/AaZuFUTc8L2YGSlODxpWZ7yl9UTx+oiJGshh9+GdA5Ge6JEjqEVJF1lYGU9nBXmn wihGBD2miXp2czUQV/iiDB3MCUI+YGnYylSmg3r8z/pJ93Cudn27TcZdisLIkPVpt/rA uGATIo+ZZ/nwpWtmD59TGBLA7UXjtlra55IziYvc/hfdtEgr1cqKMlsKchr66ozHZePI EiDA== X-Forwarded-Encrypted: i=1; AJvYcCUpUie5p4e8Wcy53ip3l3ZLnM48fFlYEUdyULwuwZpUYWNFydM14sXy2BqUMv7bnaB808vQsvYB+HLy/mo=@vger.kernel.org X-Gm-Message-State: AOJu0YzjccoPFMRoPoZ6uPHDngBCdvmvPrpjKnNMX5KNmb0CoHRFYxHZ Ht06khR4gc/x3T1d57DQBSjUmMSJ3ruZ7ZiJ3EhOMSTkfAdFOz64IpZjQdbezKL6g8w= X-Gm-Gg: AZuq6aK8idvMI2NfZdPiyAZ6NF1I71x2tVx53D+lmgEMilYGqdYm1P7H/AuBpn9XIIQ UBrYjhRYkKj5uhx3MbJNtI5FlKa/LU3Jn6NwBcnvSkkXQtpP52wy15IZm+jqIOzjIls2qUVaO4J FXWM8IdntjIUarJUHsGuEg7Q3R7WSq47OGklU4H2Q2G0IPARa4C7emNMDouHxJ4QWU6p/+782G/ TkXGiD9AQi2LCrb+l1UmmPJAuiK48Rx5zsP037JQqw71W+VQoV1bJRbi5QDjOUEJ7XydWFP2Ns6 yAk4zDLmv4Vjlgu5NeyPAZBzUz7cfmnGYID7Ftg6GQHgOtjnxGCyBQkNi+PokX5aM0ISAVhbPZp gmg6dETicZSDIs2VQEuBPemai7dSP4HL0DsxedwPA6eyeENmgjM1yrWsLsKkRQVfMn9Sy1e/dMa bK4NK+1f+Xu/1CbQlhI/IVWQ== X-Received: by 2002:a05:622a:1647:b0:502:f0fd:1837 with SMTP id d75a77b69052e-5070bcf94d5mr123459931cf.70.1771863760960; Mon, 23 Feb 2026 08:22:40 -0800 (PST) Received: from localhost ([2603:7000:c00:3a00:365a:60ff:fe62:ff29]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-5070d50c920sm73283081cf.7.2026.02.23.08.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Feb 2026 08:22:40 -0800 (PST) Date: Mon, 23 Feb 2026 11:22:36 -0500 From: Johannes Weiner To: Kairui Song via B4 Relay Cc: linux-mm@kvack.org, Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , Barry Song , Hugh Dickins , Chris Li , Kemeng Shi , Nhat Pham , Baoquan He , Yosry Ahmed , Youngjun Park , Chengming Zhou , Roman Gushchin , Shakeel Butt , Muchun Song , Qi Zheng , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Kairui Song Subject: Re: [PATCH RFC 06/15] memcg, swap: reparent the swap entry on swapin if swapout cgroup is dead Message-ID: References: <20260220-swap-table-p4-v1-0-104795d19815@tencent.com> <20260220-swap-table-p4-v1-6-104795d19815@tencent.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260220-swap-table-p4-v1-6-104795d19815@tencent.com> On Fri, Feb 20, 2026 at 07:42:07AM +0800, Kairui Song via B4 Relay wrote: > From: Kairui Song > > As a result this will always charge the swapin folio into the dead > cgroup's parent cgroup, and ensure folio->swap belongs to folio_memcg. > This only affects some uncommon behavior if we move the process between > memcg. > > When a process that previously swapped some memory is moved to another > cgroup, and the cgroup where the swap occurred is dead, folios for > swap in of old swap entries will be charged into the new cgroup. > Combined with the lazy freeing of swap cache, this leads to a strange > situation where the folio->swap entry belongs to a cgroup that is not > folio->memcg. > > Swapin from dead zombie memcg might be rare in practise, cgroups are > offlined only after the workload in it is gone, which requires zapping > the page table first, and releases all swap entries. Shmem is > a bit different, but shmem always has swap count == 1, and force > releases the swap cache. So, for shmem charging into the new memcg and > release entry does look more sensible. > > However, to make things easier to understand for an RFC, let's just > always charge to the parent cgroup if the leaf cgroup is dead. This may > not be the best design, but it makes the following work much easier to > demonstrate. > > For a better solution, we can later: > > - Dynamically allocate a swap cluster trampoline cgroup table > (ci->memcg_table) and use that for zombie swapin only. Which is > actually OK and may not cause a mess in the code level, since the > incoming swap table compaction will require table expansion on swap-in > as well. > > - Just tolerate a 2-byte per slot overhead all the time, which is also > acceptable. > > - Limit the charge to parent behavior to only one situation: when the > swap count > 2 and the process is migrated to another cgroup after > swapout, these entries. This is even more rare to see in practice, I > think. > > For reference, the memory ownership model of cgroup v2: > > """ > A memory area is charged to the cgroup which instantiated it and stays > charged to the cgroup until the area is released. Migrating a process > to a different cgroup doesn't move the memory usages that it > instantiated while in the previous cgroup to the new cgroup. > > A memory area may be used by processes belonging to different cgroups. > To which cgroup the area will be charged is in-deterministic; however, > over time, the memory area is likely to end up in a cgroup which has > enough memory allowance to avoid high reclaim pressure. > > If a cgroup sweeps a considerable amount of memory which is expected > to be accessed repeatedly by other cgroups, it may make sense to use > POSIX_FADV_DONTNEED to relinquish the ownership of memory areas > belonging to the affected files to ensure correct memory ownership. > """ > > So I think all of the solutions mentioned above, including this commit, > are not wrong. > > Signed-off-by: Kairui Song Those semantics look good to me. I think it's better than the status quo, actually.