From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.44]) (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 94BC63F660B for ; Tue, 17 Mar 2026 19:13:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773774811; cv=none; b=ODoAnV5Neck4jNuEnjJsppp92uV9JBW25JMWb1zQJHbHLywioeJw29vJoXwcjwFtGSoNPUSNEp3s8sqOB84W6MurFCr+b8rPqdPmKDbyQ2v2iEKRDwtQRjcUFHy1NGI7+8ZKzo2qV7wNXtGOsPUOekCpouVAQF+X+M9f6yu5QR0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773774811; c=relaxed/simple; bh=FIH3EfPbv9x9yhqNZFM8ItzyRZreHzjELJ0ci6yh64M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=q6J0WtFkCC6tyG/O53fxXG0H+2nf/1oy/5sQvc3lJlDcf6mT1UcrnIU8MyNaFZppce4pCVRySQaawbuxSQFANOgpFeLrIFlGE3v5VXTPTMobrAS+rYNfTDzYAATQLKyZDvaNnXoTvxLVVifOt78/jPBoWLbAjmIbfdTXmG1ogZA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gosyCRMh; arc=none smtp.client-ip=209.85.161.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gosyCRMh" Received: by mail-oo1-f44.google.com with SMTP id 006d021491bc7-66f747175d8so3229169eaf.0 for ; Tue, 17 Mar 2026 12:13:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773774809; x=1774379609; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U1WSlRQanpR5FK/cre1jv5yq/0lla158MVh0Hd3IbjY=; b=gosyCRMhgSFw48b4a2OurjBNDNhO/meUQHofZV3da0eBRe5/BQSQsZDae0Ob7y0Hth egtAw41yF2C3P2svOkEkyWrP4YmPR2JfahzhhBSsZ9/qh2cn63MNKqbYj2Ug0OCwkrqE uzMaG+mJCdMc5DXKTopBJDnUJ7aBCynYSek+t4qYRCmA+OdyH+ZyL1gArM8UxriNwhsV V9w1CTZ8P/AOfbWN1aXSxjSmrbhvC82kf5dVxXPAs+kzNUIE3fmWfTNsiWWiy0YExlhC 2DFCe7gh3ANtJUX1qd8ROhERQIa5LV3Q41zrslbu1W7x72Khusa5uxYRJXBj4T1fBKkB fDAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773774809; x=1774379609; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=U1WSlRQanpR5FK/cre1jv5yq/0lla158MVh0Hd3IbjY=; b=jwbKb0U9J3zCVv0oBDO/5o/S/fw7PxVKDeTb9+Z3hJHK6xyaKbgD4yIIiyCF/CM84W C7ifDwX4nANfgvGjJO8KAiFwUAwLSsLyglLNPjHhBK7cJ1IiPcs0/1RytqCiumS6awC5 9Wje8btdrn+5eEivuORSTEgQqCig9tArwgFff5PZdJDHJfPNQUm6hFN8slPAiI4uxl7g d1KKcZZdXzxaFHEFmMEOxamXBTZvyPtTMtrQJK1S2pZdc5J/DsmgsNbbln5vTegGD8XO 8AYlRfLqoqGFMjilZu9S+XZ/ASxOC7O7m/NtSSXVdlj9yMg3cdT9XUSYcOgNVohDEw6V IJJw== X-Forwarded-Encrypted: i=1; AJvYcCURtfwZuWBWMQaBD793KjYnLCpIARIn1V9IOaGyAdMbi9CFYD7aznCX95y4s+6zfxtXFcO/b5TUfKVU2ow=@vger.kernel.org X-Gm-Message-State: AOJu0Yz606uefXbJ6eG31ffruEn1tx2+9EzSbeZTgEKBbA24PZQPhgUC pOharh2LVvx7x4uttx0X72WRivO/Yxujw3WNJfXtlLdVL7/uE0DR9sB+ X-Gm-Gg: ATEYQzw+e6oxendV3jzxfUmmwthJkQMPfOEDDhHjrlaX9xz5k3VDQS9vKuTmoclXR0y 3tqpt3jGXsIoccz/va8W6DtPb9zMqRPBOqLqsy/S4xWjPJMi+F8j3GlMtvECHMOvv3HRv0pzH+q 9g2pkid2ijOFsOWATVvQEDMMI4nywAhzKW9ejVaUm3rytbmLaG6z+IRe5zx6ckeBea5CzznpKQn ogPdFTf2QARkd1Pb71RjEXydqr20GXgvIXRSqsLsYp7Sdz4M5w0TOWaZq670iwebUchitb/M9e6 J7S7HBt+kZ2jN/R8dXo309RclslANZFXFdlr5YOAywOGaiQnqkDjpyCoZYxK0ZoL0E82eMh+W29 uTSDBbM8yxQ90TsNBewqQiMuAGPzEwOdZ0WLVhsdLPOdZw8BDHSNF2nevPBx2GJWPTNcG1ePKJD ucPA3U7ZRvExtzi2G/hg== X-Received: by 2002:a05:6820:4812:b0:67b:b5db:f0dd with SMTP id 006d021491bc7-67c0da82fccmr277290eaf.15.1773774809295; Tue, 17 Mar 2026 12:13:29 -0700 (PDT) Received: from localhost ([2a03:2880:10ff::]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-67c0d7e5ca8sm279832eaf.1.2026.03.17.12.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Mar 2026 12:13:28 -0700 (PDT) From: Joshua Hahn To: Nhat Pham Cc: Minchan Kim , Sergey Senozhatsky , Johannes Weiner , Yosry Ahmed , Nhat Pham , Chengming Zhou , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: Re: [PATCH 08/11] mm/memcontrol: Track MEMCG_ZSWAPPED in bytes Date: Tue, 17 Mar 2026 12:13:25 -0700 Message-ID: <20260317191326.2208313-1-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: 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=UTF-8 Content-Transfer-Encoding: 8bit On Wed, 11 Mar 2026 13:33:34 -0700 Nhat Pham wrote: > On Wed, Mar 11, 2026 at 12:52 PM Joshua Hahn wrote: > > > > Zswap compresses and uncompresses in PAGE_SIZE units, which simplifies > > the accounting for how much memory it has compressed. However, when a > > compressed object is stored at the boundary of two zspages, accounting > > at a PAGE_SIZE granularity makes it difficult to fractionally charge > > each backing zspage with the ratio of memory it backs for the > > compressed object. > > > > To make sub-PAGE_SIZE granularity charging possible for MEMCG_ZSWAPPED, > > track the value in bytes and adjust its accounting accordingly. > > > > No functional changes intended. > > > > Signed-off-by: Joshua Hahn > > LGTM. > Reviewed-by: Nhat Pham [...snip...] > > @@ -1066,7 +1066,7 @@ static void zs_uncharge_objcg(struct zs_pool *pool, struct obj_cgroup *objcg, > > rcu_read_lock(); > > memcg = obj_cgroup_memcg(objcg); > > mod_memcg_state(memcg, pool->compressed_stat, -size); > > - mod_memcg_state(memcg, pool->uncompressed_stat, -1); > > + mod_memcg_state(memcg, pool->uncompressed_stat, -(int)PAGE_SIZE); > > nit: seems a bit awkward lol? Hello Nhat, I totally just saw the Reviewed-by and moved on and didn't see this nit here :p sorry!! But yeah, I agree that it looks very awkward. AFAICT I don't think there's a signed version of PAGE_SIZE or a negative PAGE_SIZE definition, so unfortunately this cast is needed : -( mm/zsmalloc.c: In function ‘zs_uncharge_objcg’: mm/zsmalloc.c:1068:66: warning: overflow in conversion from ‘long unsigned int’ to ‘int’ changes value from ‘18446744073709547520’ to ‘-4096’ [-Woverflow] 1068 | mod_memcg_state(memcg, pool->memcg_params->uncompressed, -PAGE_SIZE); | ^~~~~~~~~~ I will note that this is a temporary cast, we immediately remove this line in the next patch. I did this because I wanted to show a natrual transition from MEMCG_ZSWAPPED --> MEMCG_ZSWAPPED_B --> NR_ZSWAPPED_B and thought it would be easier to review, but this does leave some intermediary changes in this patch that are removed right away. If you would prefer that I squash this commit and the next into a single patch so that there is less intermediate code, I would be happy to do that instead! I hope you have a great day! Joshua