From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (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 2E45138D684 for ; Wed, 11 Mar 2026 20:16:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773260202; cv=none; b=Hl5WTnjE+G4vYaSaYEtEh9HvqGN9VoZMqaOV83H9ZX4JMDUaQX+ho35pvqfS5ho9qcUUdDem3zwz83gKDCMx2K/v/IF5INKVuHI/yw73PSz0ldgbjBHQyfYtaY/rr8Q1IlO6p4EkBJTQxeAy9moWY13CHDdxdh4SLFBGBRzshQE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773260202; c=relaxed/simple; bh=PuLwnBc+8QrXgnn/i9pHH//tTmzGBq3UlkUOmAGXElM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ihh8bF7JjRxA815LV1TC67gYIJUhJ55L0LwSVvfoymyC5KcW70aqOPd+LJbHiN5mkI4nrMYKKvF0GvT7VzF+rEFOLWsMSDpe+kOCkIoiMllkIIGVQy8Jh+Z12IVaYLsORpNE1NA366Jn6coCczckWj49+86tbDiNFWFDg2suQYQ= 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=Cqtrehr8; arc=none smtp.client-ip=209.85.219.54 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="Cqtrehr8" Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-899ee87355dso3820136d6.1 for ; Wed, 11 Mar 2026 13:16:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1773260199; x=1773864999; 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=DtZj6h5RyCLZcb3faEPHDRcPqrY2sHgdB5FkBVVnG2Y=; b=Cqtrehr89QNFZltz5dcsMDHD/N4ccIP040MjrxLFZ3cehW0DAo1BYhdBlequD5a2CK t/yMPJtHU64wrl9xTcdhttyhNTDJSkwaE9hfNcjVhlgxwEylZrqIpdMYH7LSb07SL6Fx 93UshpDza5F/C1pZLmS/TJX2jhyOuDVbYQiXXYAUbbOsEzLvJ75Q2g1vu/Ia9ekuSV/J t4lr6gMoSY3FMoGMwdvX0ztYl5OZDTTxJwldL3FylZu5gwIE1yYkdoFu1uRI0tAeNP5t VcUQwhrz8BaW2oMA636m37p1YLw03OJEQm1nUDxPAxO3PljI+7s3VcRFHkh/KNzd938f br9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773260199; x=1773864999; 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=DtZj6h5RyCLZcb3faEPHDRcPqrY2sHgdB5FkBVVnG2Y=; b=tr6XrEskrm8Sn/DxXK8Vghlaf82OKRy38iEzQnFZJPnsYej6VgM5Bvs5Ai41cf5Mk6 SsjpLX5ikNEhLtWwWJI/vyUQzFmhLyqdJ09viFowb6XLGC2GYROHHUk9Tmyd7IMHxhxi Brq1TYVCk3sIsg2fgRrsqXZbWIOlJG17uedcorPBKMMDAhQF0CKBnzJvqhCQgydJxaKg pGk//MGxiD7l4kgyM/PkQ+pYATnpwI5Ll54KtH2+jwAQXr2xXkiR3+LVbKWMh5IlRJnS moNamxjlGDakRRkh3COKvpYy0obCFRNnUGSjiJXCu67Dm52SOr9dnYbu7Xf24Z0Wtd3I 9VYQ== X-Forwarded-Encrypted: i=1; AJvYcCWNXphpMK+j8B2YcENKWZM4HLx8smA1oWvn6J7BuayY7w1EXF7j54Q8HY2DihgbddYzCkJysfDNTEuo/oQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyyN0tOgpeSmShSO/x+spmqo2dYfVnqQB/zFqOwODg+NBgRvbnl pzbUzRBFwJbz3xgeuU/n/if0SClGpLflQoYUS1uvnR6TkPfNZmNQroiQu/eVv+DSpCc= X-Gm-Gg: ATEYQzyKCh+9S6fqiBJAFA/eAGBlpFVV+twvMVoxOjFWwc+xQ/Pcha6/c2SNrJUpoWN BOY0cN2KBBkOOe4VVhFXWhEkqec+Ojhan7q42ZtTZjzrrWV+InEYzdqJ8NNai7rdpRQ5CRgVYqC HKrdL9J74KlzkLgVukjcGD84fvXVqdnBjKxvO0vMeRnriaPqTvIsBvx+8BffmBNy8b9VoI0t+em PrvbxZwwrxgmNuROEBWbJuWS7flOJBc05O9DcbtIJGHkPlmg5sXNOHUSrc6HBry/6nOMbnxFBgp CFnEnQjDYvZOrxUy44NyW3YsVRxUYlZM8GuWq/KsTn4VhfU7Xu65d0kU+LK/x8H7AJlOF/JRj93 NRAnILrt5wfipoqIkyAyPcymvoymgBCdsDW1t8RhxEj+Q+krL0be/qr/fMX31oqCb2wb5RkjMIq U/sng8eXxC10+1zs3mP+LiqQ== X-Received: by 2002:a05:6214:3003:b0:89a:110f:894a with SMTP id 6a1803df08f44-89a669c4812mr51524686d6.12.1773260198806; Wed, 11 Mar 2026 13:16:38 -0700 (PDT) Received: from localhost ([2603:7000:c00:3a00:365a:60ff:fe62:ff29]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-89a65cd5fa8sm19798006d6.30.2026.03.11.13.16.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2026 13:16:37 -0700 (PDT) Date: Wed, 11 Mar 2026 16:16:34 -0400 From: Johannes Weiner To: Joshua Hahn 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 Message-ID: References: <20260311195153.4013476-1-joshua.hahnjy@gmail.com> <20260311195153.4013476-4-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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260311195153.4013476-4-joshua.hahnjy@gmail.com> 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); 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. 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.