From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) (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 95862318139 for ; Wed, 11 Mar 2026 20:20:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773260441; cv=none; b=ddwDIxeU9Wn3MEu3GG7FObdEu7yM0cSDv1WSs8oP9qjgnyg5GTc/6CUgDfXJH+7zWv0OexXEv2Xvmz6cwCYsK5TwtFac0U4lHhcbrAZd5rwf/M0juoOWeZ0VSmvJpmIY1hORf0z3v2MbRSwWdebTScw9RqfFqD8zkw2LMJVTsnY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773260441; c=relaxed/simple; bh=OvmUYdWzF0lOI7ZgsHuDpQpSQa83TBI+cCxemeaCp6c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L72vFX0lo1c0XyAtxk35WBqVzH++0hXMr5l5d6Pn7og/QiPOoWrKvrS1jzbxB+mKOwA4r4vH/qEeBoGp3imIFw0lDkPpRaDotAQvDWBqN9j6RQDtO5j3+4pbe26uPn6c8oxe1f8Gapqxre5dnV3tuA49UVMBtIVTirG2jQ55W+M= 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=IJIAvcAB; arc=none smtp.client-ip=209.85.167.179 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="IJIAvcAB" Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-46702742c99so191524b6e.3 for ; Wed, 11 Mar 2026 13:20:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773260439; x=1773865239; 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=L3yE0fOt9QsxeZmuU8QoQzZqCv9ze5YFahl5XE1THs8=; b=IJIAvcABv3XV1UIOmQLaXDeSnkcZXG8By9HWG77f0mlAbK6SET02a7VGjErLK6d2Mm cNj5WgGbn3tumC4rC60PP5+zI1+tVezjyK8uwFl3SHEQmKTN52UX/wu0BrhCYj+JqaJY zs/WKsvd96e5ZAYp8JxBg95GycSL9Fb7QB0/TOyisq+KH9Dr/8Olfg5mxtQrTBIITXpQ N8trPbUQLxnKEt2oxoz6pC9umaxdfLuuSdzMctAalrt3OhAUSMVbYBL+sg7BIlDbUz0B m6RjOmylYkfzHF3Cm34KX1wZqeMPG+NYRxoELXRo/Rx7WL2yWA08foztssoS+n0u8YMK nw3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773260439; x=1773865239; 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=L3yE0fOt9QsxeZmuU8QoQzZqCv9ze5YFahl5XE1THs8=; b=wXwX2iN1jwGPIpUm/sHS6X6XNj0bBm9mk/U9apcuAV/WMNSIO+z2GwMzv37Xc2mQIZ SDAV0aVfun/fI139pi0KTnIJk+U0vhDlGpAf0kKW2lZ21H9VYXFsWGo4fQg5OolrlF9J VqURwWHQbp3zDGSRph5pR5/y3zFXmyA1iynhp1w6ExVZQ9NgQNzRLrMdJImfXd477el+ EzGKErcWjpMBhmu0SjoM2llh7XpqCeVaQZui2rvdEafzM088S/NCacEjhQG0jjeLXgRn +/aYQYWV71QyTqd+GC8FDmIW34MGkb0iHMSQC8/E/VE1TnUMcjaSmLK+SftAcRdz/Adq X2zQ== X-Forwarded-Encrypted: i=1; AJvYcCVl0uRsoagMlrCuiM8mLOasHA62j2zgu9HK+Q80s3qVemWvEkdzUvzSy7aYFHpO0uGV7yNwDg21odunPWo=@vger.kernel.org X-Gm-Message-State: AOJu0YxEO7HQwnOFi9DCP7iGx19+3oUux1mlKLlBxko3LuU23ApdaKmv j3qJaFh9y2c7Az554NoMVxO5xe670K6cVct3uOebttNhxSn7a/VKCx2h X-Gm-Gg: ATEYQzylKVfrht+IS6ztFfWoQN6W46pbyTepPb0AIhqjcIGwLj7mBn6jh9x7O/4oah4 nKUXtkt3D2pQWF/gAeOtSmI1N3ADTLEXX4I8UrQJm77L3lJypTGABd2pHCxFOcZU9hSI/awRu8z zSBxOneg/e7QKGvJKrM8Azz/Zv2PZh3nHrWmwgiG1b/EhtyT2O15fmXtX4QVSEbnsOQVX8JB6X4 Od9AOkO3c9e/RZhhXVXE+rAWloQsLXMLIQ6uCvx/LG7lJLecs/yzsnT0Ch4X4a0kEFYooxRJqWF B5X0Bw5QB+MnzkeM0te4W/WtpHI2Qt/EOj03P2jsMZ9z06ib5V06gQ+RDEyR2OAmpbeEWZkHVXo 7nQykpTzwTUVRCXHFD59WlIAo89LEE+btZA+Pad1bRd8zfJSJ6GU0tnj21AbAe/mzYZQ9b4cjpZ ufkEc9CaOuMi8PdymrQ9j6Fg== X-Received: by 2002:a05:6808:4f6b:b0:459:b569:702f with SMTP id 5614622812f47-46733431a6emr1950640b6e.15.1773260439503; Wed, 11 Mar 2026 13:20:39 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:53::]) by smtp.gmail.com with ESMTPSA id 5614622812f47-467342c0382sm1914583b6e.10.2026.03.11.13.20.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2026 13:20:38 -0700 (PDT) From: Joshua Hahn To: Johannes Weiner Cc: Minchan Kim , Sergey Senozhatsky , 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: Re: [PATCH 03/11] mm/zsmalloc: Introduce conditional memcg awareness to zs_pool Date: Wed, 11 Mar 2026 13:20:37 -0700 Message-ID: <20260311202037.265101-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-Transfer-Encoding: 8bit On Wed, 11 Mar 2026 16:16:34 -0400 Johannes Weiner wrote: > On Wed, Mar 11, 2026 at 12:51:40PM -0700, Joshua Hahn wrote: > > 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 > > --- > > 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 disksize) > > if (!zram->table) > > return false; > > > > - zram->mem_pool = zs_create_pool(zram->disk->disk_name); > > + /* zram does not support memcg accounting */ > > + zram->mem_pool = zs_create_pool(zram->disk->disk_name, false, 0, 0); Hello Johannes, Thank you for your review! I hope you are doing well : -) > It's a bit awkward that 0 is valid (MEMCG_SWAP). Plus you store these > values in every pool, even though they're always the same for all > zswap pools. Agreed. Originally I thought of removing memcg_aware and doing a bitwise OR check of the two stats, but thought this was also a bit strange (also because 0 is not a valid enum state for memcg_stat_item anyways) > How about: > > /* zsmalloc.h */ > struct zs_memcg_params { > enum memcg_stat_item compressed; > enum memcg_stat_item uncompressed; > }; > struct zs_pool *zs_create_pool(const char *name, struct zs_memcg_params *memcg_params); > > /* zswap.c */ > static struct zs_memcg_params zswap_memcg_params = { > .compressed = MEMCG_ZSWAP_B, > .uncompressed = MEMCG_ZSWAPPED, > }; > > then pass &zswap_memcg_params from zswap and NULL from zram. > > > @@ -2071,6 +2079,9 @@ struct zs_pool *zs_create_pool(const char *name) > > rwlock_init(&pool->lock); > > atomic_set(&pool->compaction_in_progress, 0); > > > > + pool->memcg_aware = memcg_aware; > > + pool->compressed_stat = compressed_stat; > > + pool->uncompressed_stat = uncompressed_stat; > > pool->memcg_params = memcg_params; > > And then use if (pool->memcg_params) to gate in zsmalloc.c. These definitely look a lot cleaner. Will make these changes in v3! Thanks again. I hope you have a great day! Joshua