From nobody Tue Apr 7 18:51:22 2026 Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) (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 EB665382F24 for ; Wed, 11 Mar 2026 19:52:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773258731; cv=none; b=QZak0TvAsHJsfB9g5vB2RznkWFPV099WBgsESf/cArdYdsI9Mv9HT7cMVt5R1oVQsXqJS5+SqMoOz6mpitVwviVj3WiVYInQy6zcnW1lOOuwqi8/4NkR6K1YE5efOXDPBiup4+4fkrKikFgauaiV93Yx05YQ8LDoeeG4X3PTHIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773258731; c=relaxed/simple; bh=HF2J8eGf9ezx76WeuiLEbVDyfaZqYDKuQnnfjxWeg54=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cuhbs+JUvWMq115gkukHdr7MKYGCFlrg47z/hssC3j09XMdQeTSS/SpifDg6hER8bs7+1T9MH0SyfSf3MzRKgF2mmWy+5w9n2nj0eMd9HCnHD/Lj2VIczSBY0rsuZqZ3A4UtHJLWy7aWgRw1DON0f7q3JkCOKlz7rPANIpx7Nt4= 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=Hxnu4Tee; arc=none smtp.client-ip=209.85.160.45 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="Hxnu4Tee" Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-415e568a7ecso127248fac.0 for ; Wed, 11 Mar 2026 12:52:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773258725; x=1773863525; 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=9uGTcZbp7r+H1UaYa68xNPMIKqxUKJCwYhvaf1Y6xf8=; b=Hxnu4Tee603RcE0HCPjo47X15Y6evAy+vlzl0CBtZSOCXXb+i9TjhKjEwShWI2QEDD kRN3zlACPOTzsw1lCK2TJrOPr+Ii8vlrgoLVgF1eupIa6KAIOMaiqvql+OVhOq/AP23r 3ZwQiRma01TTys1e1JKbFkewmnc0/u6vjkeiNoKOVQtYLgHl0Zzr2YS2hwqW5g0sXz4Y amrrm0fx+FdRDG1f6UmMmA+65xic+rmOe3enDorLXS49ZidXl8quPNQXelizEc7Z56DQ Rrbo219EO0KIEjxlVEivA8AMTNIumxHdXgrlIke+N3a+rhdz5ip9IIgSXmtKqMmxWPpE aspQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773258725; x=1773863525; 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=9uGTcZbp7r+H1UaYa68xNPMIKqxUKJCwYhvaf1Y6xf8=; b=G0obxtLBmyhowRQj5BqLqWogcNoHmuoN1CKuj2p2pdUaa+ZwS+CDokGF+avJ9BxtID uMygJ7haP5Rq+fOD4smyK/6i7sOt2tDED/0fYAc/g9sJZfpE0YvHRh+be971Sgy9WE73 lRSTjKmYnuel0tUSC3BPPSvdBnHz9vNbQICevFrdt3KklDCfw37IQstfsEnJKPq0tnFT Ik5Ghmz3zDAojghbUgTOzHo6hTAXi/Qk3aPOHhhSKLWTxwR9R7Ff0SWmJo0WJNBT+Sj9 A8YyJYK87I6/xoZMhD+qBOx1RvLx3vqxLzxyc5KXrK11dX579PJWMsMjynsH37lnFFwU 5fjw== X-Forwarded-Encrypted: i=1; AJvYcCUGQ69WZW8NTNXw5QEzCEGOpsDcsYfKOymieg2loFbhhdQjeuvXnDUwGY62YQ7t4LEH7wVPmO+r9VubZ5E=@vger.kernel.org X-Gm-Message-State: AOJu0YwblJ6Rl/DCVRElK4UG33gsWzYBd3R0O8eNvxivAEjv44IXd2Mr /6i7TU7iarl5kZr+3D40B865AiTkS62dVP6znB6dh68RjBRlCVDKuH8/ X-Gm-Gg: ATEYQzwiR55Xsg5a+Lyt3coTlqR1mPdZnrKe4KDfgKtXkc1QuVU7gWBEBiCAORmEMQA 9SsHaJ5TbQv+dINpvD61kyJq3P/C+OgXqFWEVt9u4bMjI69ky6cMd7jT8eVNq1EAdGDoTngwnJg ZlQCTx3Onh3IjvAkg1RTGdzZEZ5I5PyMrImUNximsASKfyI7eAWMIx2wpnuyN0g2J7wxqtWxbG8 SVU6gJq6PW+szZFdzt6ijILXoYXkTWpReLFxwngzthm98vNMIHMKV1eceaOWIEYRyAta09b/cMI lBfPX89iDfBKZpzdj1JL4LVPiZeY68mLERFg9daI+Pw96Kct2QVOFriqeM7a/eWWLcYVkqnW1qv 6Ol2ByKS3+qkLVNLw0y3j/2TABOrBEIZkp92xOB24mMtfGfzLAHBkwad6DGR4eFDsXZiwvZ8auY TKkzTOe7QuvZk56ApzyPNZ3g== X-Received: by 2002:a05:6870:3c8b:b0:417:31f3:5def with SMTP id 586e51a60fabf-4177ca59b45mr2303457fac.32.1773258725506; Wed, 11 Mar 2026 12:52:05 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:46::]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4177e64a931sm3100861fac.14.2026.03.11.12.52.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2026 12:52:05 -0700 (PDT) From: Joshua Hahn To: Minchan Kim , Sergey Senozhatsky Cc: Johannes Weiner , Yosry Ahmed , Nhat Pham , 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: [PATCH 08/11] mm/memcontrol: Track MEMCG_ZSWAPPED in bytes Date: Wed, 11 Mar 2026 12:51:45 -0700 Message-ID: <20260311195153.4013476-9-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260311195153.4013476-1-joshua.hahnjy@gmail.com> References: <20260311195153.4013476-1-joshua.hahnjy@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Nhat Pham --- include/linux/memcontrol.h | 2 +- mm/memcontrol.c | 5 +++-- mm/zsmalloc.c | 4 ++-- mm/zswap.c | 8 +++++--- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 701d9ab6fef1..ce2e598b5963 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -38,7 +38,7 @@ enum memcg_stat_item { MEMCG_VMALLOC, MEMCG_KMEM, MEMCG_ZSWAP_B, - MEMCG_ZSWAPPED, + MEMCG_ZSWAPPED_B, MEMCG_NR_STAT, }; =20 diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 68139be66a4f..1cb02d2febe8 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -342,7 +342,7 @@ static const unsigned int memcg_stat_items[] =3D { MEMCG_VMALLOC, MEMCG_KMEM, MEMCG_ZSWAP_B, - MEMCG_ZSWAPPED, + MEMCG_ZSWAPPED_B, }; =20 #define NR_MEMCG_NODE_STAT_ITEMS ARRAY_SIZE(memcg_node_stat_items) @@ -1364,7 +1364,7 @@ static const struct memory_stat memory_stats[] =3D { { "shmem", NR_SHMEM }, #ifdef CONFIG_ZSWAP { "zswap", MEMCG_ZSWAP_B }, - { "zswapped", MEMCG_ZSWAPPED }, + { "zswapped", MEMCG_ZSWAPPED_B }, #endif { "file_mapped", NR_FILE_MAPPED }, { "file_dirty", NR_FILE_DIRTY }, @@ -1412,6 +1412,7 @@ static int memcg_page_state_unit(int item) switch (item) { case MEMCG_PERCPU_B: case MEMCG_ZSWAP_B: + case MEMCG_ZSWAPPED_B: case NR_SLAB_RECLAIMABLE_B: case NR_SLAB_UNRECLAIMABLE_B: return 1; diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 291194572a09..24665d7cd4a9 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1047,7 +1047,7 @@ static void zs_charge_objcg(struct zs_pool *pool, str= uct obj_cgroup *objcg, rcu_read_lock(); memcg =3D 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, PAGE_SIZE); rcu_read_unlock(); } =20 @@ -1066,7 +1066,7 @@ static void zs_uncharge_objcg(struct zs_pool *pool, s= truct obj_cgroup *objcg, rcu_read_lock(); memcg =3D 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); rcu_read_unlock(); } #else diff --git a/mm/zswap.c b/mm/zswap.c index bca29a6e18f3..d81e2db4490b 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -257,7 +257,7 @@ static struct zswap_pool *zswap_pool_create(char *compr= essor) /* unique name for each pool specifically required by zsmalloc */ snprintf(name, 38, "zswap%x", atomic_inc_return(&zswap_pools_count)); pool->zs_pool =3D zs_create_pool(name, true, MEMCG_ZSWAP_B, - MEMCG_ZSWAPPED); + MEMCG_ZSWAPPED_B); if (!pool->zs_pool) goto error; =20 @@ -1214,8 +1214,10 @@ static unsigned long zswap_shrinker_count(struct shr= inker *shrinker, */ if (!mem_cgroup_disabled()) { mem_cgroup_flush_stats(memcg); - nr_backing =3D memcg_page_state(memcg, MEMCG_ZSWAP_B) >> PAGE_SHIFT; - nr_stored =3D memcg_page_state(memcg, MEMCG_ZSWAPPED); + nr_backing =3D memcg_page_state(memcg, MEMCG_ZSWAP_B); + nr_backing >>=3D PAGE_SHIFT; + nr_stored =3D memcg_page_state(memcg, MEMCG_ZSWAPPED_B); + nr_stored >>=3D PAGE_SHIFT; } else { nr_backing =3D zswap_total_pages(); nr_stored =3D atomic_long_read(&zswap_stored_pages); --=20 2.52.0