From nobody Tue Apr 7 18:51:21 2026 Received: from mail-oa1-f46.google.com (mail-oa1-f46.google.com [209.85.160.46]) (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 890F137C0F8 for ; Wed, 11 Mar 2026 19:51:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773258723; cv=none; b=Vod3Q6cbhW2UcY4CFaF9ELGaZIKFyJkV6RyyHVbbJJqLVebvu0UUMj7+Wm7Hk+9pNx93/26f97kDnh3Ezv2jvpU8KayQrgYozROMX+qrPlxAlKz4S5RnHrwu+aLBDevbe5JoXl/nFQQ/jjVQ8rVPjV0rrvPIf1oG9mMsdHhOBx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773258723; c=relaxed/simple; bh=DZCEel+gASKs1YULBRoMAZRVMrRj9weWbG1mBFEBaxA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lsCwx+V5KhfLOVYo9trkB2vO7qh6AzlKVrxequ5QEsrWKp1bnY5qFEBX+012wtesuvz+Z+T7IlkaGkgZaRt+mOaf3Nqh7hFAqEMjgHgERXXgGflT7qM/fvrl3AJwxApadOEo0d48OkU/izf2ZceQ/iO3NpxsJyifnWHOJtMntTE= 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=YnnNA+Dy; arc=none smtp.client-ip=209.85.160.46 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="YnnNA+Dy" Received: by mail-oa1-f46.google.com with SMTP id 586e51a60fabf-4171451e89aso174745fac.3 for ; Wed, 11 Mar 2026 12:51:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773258718; x=1773863518; 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=xHiXRPU0oj2HIsyVL3yHXql4isoiizU2/nOjnBQn0Ag=; b=YnnNA+DyqHV+7WGhKKZQpaWCFo2/y8o9ZrLvOKKtAKeYx5Y70QC6p7Dho6K+SP3uGr jdLaja0Dkk7rA/4nKXBO4ay5zzAMM3mphLO8xAFVY9W5hfXJ0Y81CZ4f3fiGxh+0KcJp 2lAhp/neawJfeOInaoyIQjl2cbPzGsCdRgUFDDuwwthVGI8keIC/jVHWQG6A5ikE+EWM bin1EuSzvpBEKnIa697x1nVWzRy5YJnnf6nVpdGhAYpdhrbgNc20mm6zvuqNx45zgxpD KFsXlFiKD+cEmVdQGV2GU9k/ml9Iw6qoCPXcxoI/p7/EK6T1l84qUUmdpk3dK5witaPI Qp2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773258718; x=1773863518; 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=xHiXRPU0oj2HIsyVL3yHXql4isoiizU2/nOjnBQn0Ag=; b=DI9efQ0p8yjaMMnms3fcpBS+0X/k8A7ik/4nIfPRF76qQUe9Wchb6y4E5So/YRRTIe kWbBSzwGOWi3GfCjFgw9dx3V/XS7zBWsNk9rD5JfRIJnclHm4s9x72rjhyvAc3jvXVfF lPHzwT57Rswyf1vQglmLgNmT1Y++wuTIib4kc03zluS0VlOZgZk4dgV2cSUvIIp4h9wS K7dGx2Y75Yr6pwUNe2AGqflNnHL+UgGZWNodpJMGTxT4Zg7csQsRFb3vAmgPUJfjt5wh WUj25lGup5x9DxCDpdSor74XltxJRYmjmWE/eMh4W/Il1ZKIPUMjPpdoz7qgxQGi5SD3 KRkg== X-Forwarded-Encrypted: i=1; AJvYcCXs5/HI28iUg4cwvXT3iychAPxVGzQIFv4Pon+dbNf6eDAWfW5PRnMrYyy3WDLVsVi2u/JT+hj44OLufM0=@vger.kernel.org X-Gm-Message-State: AOJu0YxFBLgxPzH1NOer6tsC205jFuVtEhbugP6JfHVfjglZj3v9Yc8U JGccOJcWTGF6ut8HvJjeT2bMDoS5M1CSkVL8j/Co7SWl0/QMzrbSrMTU X-Gm-Gg: ATEYQzxWK9m8M1kE4NueXUK1z01DQn3xIFeZWVcbAu7vXXT7QhREObflAbYnCAM5kxE GOwUtBNNohni0RKycP1Uqq8Y4L9Gt5Bxc4L+enoRfcBEf+BtikP3I8VGpeqrbf+vOXkp/alPLL2 1VZ//3dcmWqSGCZSMZf/uGzn6u+SmPViRT0D6SfyQ1tN130FpFCoVpOU17GpXtzxT8pgC/8CVwK ky2rIt7Z/tAYpo1pdGWQjt+hjLPsFu5lhXU4LJ9on5STtVibk8yxs8dOWRPhe3WB8tVKrZLvGZi ggLkNKQoNgQRNYtrOrO5Acpo0gUZR0AToZ+kZEYPJINULqcR9rt2rZapAJ6bEXd56z81xabW1AD StseSiCrGesaf2TcRnJA66bbYA6Dyn6z0wfceObD1hYi/5vxP5CEAEg3Qu9JAi8JUior5zdaTcH sFfg/BjHmnKzyACHR32NObmBfe1apZOw3v X-Received: by 2002:a05:6870:3314:b0:3d9:2fe2:f5c8 with SMTP id 586e51a60fabf-4177c8bcaf6mr2475836fac.32.1773258718211; Wed, 11 Mar 2026 12:51:58 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:55::]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4177e64a931sm3100578fac.14.2026.03.11.12.51.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2026 12:51:57 -0700 (PDT) From: Joshua Hahn To: Minchan Kim , Sergey Senozhatsky Cc: Johannes Weiner , Yosry Ahmed , Nhat Pham , Nhat Pham , Chengming Zhou , Andrew Morton , linux-mm@kvack.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [PATCH 03/11] mm/zsmalloc: Introduce conditional memcg awareness to zs_pool Date: Wed, 11 Mar 2026 12:51:40 -0700 Message-ID: <20260311195153.4013476-4-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" Introduce 3 new fields to struct zs_pool to allow individual zpools to be "memcg-aware": memcg_aware, compressed_stat, and uncompressed_stat. memcg_aware is used in later patches to determine whether memory should be allocated to keep track of per-compresed object objgs. compressed_stat and uncompressed_stat are enum indices that point into memcg (node) stats that zsmalloc will account towards. In reality, these fields help distinguish between the two users of zsmalloc, zswap and zram. The enum indices compressed_stat and uncompressed_stat are parametrized to minimize zswap-specific hardcoding in zsmalloc. Suggested-by: Yosry Ahmed Signed-off-by: Joshua Hahn Acked-by: Nhat Pham --- drivers/block/zram/zram_drv.c | 3 ++- include/linux/zsmalloc.h | 5 ++++- mm/zsmalloc.c | 13 ++++++++++++- mm/zswap.c | 3 ++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index bca33403fc8b..d1eae5c20df7 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1980,7 +1980,8 @@ static bool zram_meta_alloc(struct zram *zram, u64 di= sksize) if (!zram->table) return false; =20 - zram->mem_pool =3D zs_create_pool(zram->disk->disk_name); + /* zram does not support memcg accounting */ + zram->mem_pool =3D zs_create_pool(zram->disk->disk_name, false, 0, 0); if (!zram->mem_pool) { vfree(zram->table); zram->table =3D NULL; diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h index 478410c880b1..24fb2e0fdf67 100644 --- a/include/linux/zsmalloc.h +++ b/include/linux/zsmalloc.h @@ -23,8 +23,11 @@ struct zs_pool_stats { =20 struct zs_pool; struct scatterlist; +enum memcg_stat_item; =20 -struct zs_pool *zs_create_pool(const char *name); +struct zs_pool *zs_create_pool(const char *name, bool memcg_aware, + enum memcg_stat_item compressed_stat, + enum memcg_stat_item uncompressed_stat); void zs_destroy_pool(struct zs_pool *pool); =20 unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t flags, diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 7758486e1d06..3f0f42b78314 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -214,6 +214,9 @@ struct zs_pool { #ifdef CONFIG_COMPACTION struct work_struct free_work; #endif + bool memcg_aware; + enum memcg_stat_item compressed_stat; + enum memcg_stat_item uncompressed_stat; /* protect zspage migration/compaction */ rwlock_t lock; atomic_t compaction_in_progress; @@ -2050,6 +2053,9 @@ static int calculate_zspage_chain_size(int class_size) /** * zs_create_pool - Creates an allocation pool to work from. * @name: pool name to be created + * @memcg_aware: whether the consumer of this pool will account memcg stats + * @compressed_stat: compressed memcontrol stat item to account + * @uncompressed_stat: uncompressed memcontrol stat item to account * * This function must be called before anything when using * the zsmalloc allocator. @@ -2057,7 +2063,9 @@ static int calculate_zspage_chain_size(int class_size) * On success, a pointer to the newly created pool is returned, * otherwise NULL. */ -struct zs_pool *zs_create_pool(const char *name) +struct zs_pool *zs_create_pool(const char *name, bool memcg_aware, + enum memcg_stat_item compressed_stat, + enum memcg_stat_item uncompressed_stat) { int i; struct zs_pool *pool; @@ -2071,6 +2079,9 @@ struct zs_pool *zs_create_pool(const char *name) rwlock_init(&pool->lock); atomic_set(&pool->compaction_in_progress, 0); =20 + pool->memcg_aware =3D memcg_aware; + pool->compressed_stat =3D compressed_stat; + pool->uncompressed_stat =3D uncompressed_stat; pool->name =3D kstrdup(name, GFP_KERNEL); if (!pool->name) goto err; diff --git a/mm/zswap.c b/mm/zswap.c index e6ec3295bdb0..ff9abaa8aa38 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -257,7 +257,8 @@ static struct zswap_pool *zswap_pool_create(char *compr= essor) =20 /* 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); + pool->zs_pool =3D zs_create_pool(name, true, MEMCG_ZSWAP_B, + MEMCG_ZSWAPPED); if (!pool->zs_pool) goto error; =20 --=20 2.52.0