From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B1A1606A31F for ; Sun, 6 Dec 2026 02:20:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Fg4h+h0w Received: by kanga.kvack.org (Postfix) id 11EA16B00EF; Sat, 5 Dec 2026 21:20:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D0406B05B1; Sat, 5 Dec 2026 21:20:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F00A56B05B2; Sat, 5 Dec 2026 21:20:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BE5106B00EF for ; Sat, 5 Dec 2026 21:20:12 -0500 (EST) Received: from smtpin21.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E1772A03D7 for ; Sun, 6 Dec 2026 02:20:11 +0000 (UTC) X-FDA: 85511953422.21.B8AC40D Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf27.hostedemail.com (Postfix) with ESMTP id 3EE104000F for ; Sun, 6 Dec 2026 02:20:10 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=Fg4h+h0w; spf=pass (imf27.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796523610; b=XASBusf55OvB5LOo6fxQwQU8MbJimHHf39AaSO8/+TeiwVoCXQ8yavY4lWsKSJIFmn2FoJ YKLYiJ0x5lfmpnCPMsnDPLipr4FfoKZAIh5Y1Mbs+Yu33XM8RuyfKsnrU9z2cMPvrZBWkg y1466MLUHzBLI8FvDxKaLNqHx0GKgag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796523610; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2/SF20CaesWE+v+ACzmVTTX9J638ZluEwvrnxFpOnhk=; b=67Ks+VvUJEtWPZnqqdFdhPokffKRDRLBRQyUPNLFq7WgYU5vecDykHRknH9H9V0Khur2mI s+PQdmKpg6FKeoNyWFa+vfjs4Rm3UO3gkHCCDURM4P84naO/NHVSGwbXZKXUQ2gFec6ald cf2AAlAf0mn9vR5bpzHoX/fqGHY2vUs= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=Fg4h+h0w; spf=pass (imf27.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id AC33940A18; Sun, 6 Dec 2026 02:20:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C230E1F0092B; Sun, 6 Dec 2026 02:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796523608; bh=2/SF20CaesWE+v+ACzmVTTX9J638ZluEwvrnxFpOnhk=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Fg4h+h0w+BeDyNuIfZY+TtsxC0uUc020xIJCOwvrTmGRA9Yk3/1SjoAOn1WS5NlYP G6Oek2kBCPz7tgRPLLNrFHMoVJGcLiPQ7oD1J9XxblKkiQWFxDgjUNHrAgEC8gW8QJ YKhrWJnBbD41PmYaAT1si7mxIvUMFRmHm+xVcRDtvVy2FJOVHGZ7A3E606u9dqemau wdyxLyDjv26oJO8PW+lyAF4im0SscLT6Sac5hLrU440pD2lE25uT4FnZnLZwlblwoY oFiEFI/T2VevLNQ4T5rzYBdAI9xRn8k97LYgvwXh82xeXxnNzjhiA/mlJd+8ZxEjMj iskgXzRuwwh8w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 1/4] mm: zsmalloc: support objects compressed based on multiple pages Reply-To: sashiko-reviews@lists.linux.dev To: "Nanzhe Zhao" , "Andrew Morton" Cc: linux-mm@kvack.org, "Jens Axboe" , "Sergey Senozhatsky" , "Minchan Kim" , "Kairui Song" , "Johannes Weiner" , "Nhat Pham" , "Usama Arif" , "Yosry Ahmed" , "Chengming Zhou" , "Chris Li" , "David Hildenbrand" , "Ying Huang" , "Suren Baghdasaryan" , "Ryan Roberts" , "Kanchana P Sridhar" , "Wajdi K Feghali" , "Bala Seshasayee" , "Nick Terrell" , "Barry Song" , "Tangquan Zheng" , "Bo Zhang" In-Reply-To: <20261205021803.3704464-2-zhaonanzhe@xiaomi.com> References: <20261205021803.3704464-1-zhaonanzhe@xiaomi.com> <20261205021803.3704464-2-zhaonanzhe@xiaomi.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 02:20:07 +0000 X-Rspam-User: X-Rspamd-Queue-Id: 3EE104000F X-Rspamd-Server: rspam03 X-Stat-Signature: fbyourp4jc616karmq3e8ziicni5wytf X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn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E27mwWP47BdydoE2IyKGulXG+v7+c0daU/jdlg3iX0zmdFXxVGVbJ8ISRDShP8bqwZxndqnziNHzqIuHjUs+RiMNWoHvxE1rzPI+WDj7RIMACw5tce6FvzeUR+sm3Cqs0SK85QxkSDQecBbk5qAEMaRvf79e2LLc1yG+aZrXt7xn9PjSbzJBY7eYiB6jPoi2AFPQyTTm/TLovJwNQUSK0IkU0HT7GVdI5TdnSP2pXTiRg9V4hVL1l95gLW8YVgM4M+j/7LCVdvaMWtDrk50gQz2/HvWCpKnLolPmwF+DF/MMx9Sal7USqjAGEKBVzfS+cJlxmVFt/g2pfcPqxOfFEWoit9G5BwViENXnPf7t9zWUHliJqlcTGq3vY1vpkeX7KJw0Ya/Jx7EYAu6HVy8j6y/Eb0K6bC8UvreP9TJLWk/T0sd4udiYTIizkwe4Zxvp+8AaCzK6MviW923IzvXCkqxt5aAsVp3fFu5ByEMar2FxQEEankaaSVUuJWj++NZkKDhA4Iye0x04t27OhqgeGNM3SD/QIhE396G2hGQlUUVNmQyDP7ih3MC+If5NRDNyHa1HZec58Yq5rj92+su5vC7av9m7hKBjHkE8MJT9skfCKhwCvgnhNQQReTFWsuIbIkWj0zG4Q2cnbTDFsJN9qgkUkylvNeGsjZdJPz3n9U4M0j/duqxuxD3gN/kFAicZRxqBlr02d9+X2mATBEtv13Z9Qaa6CUbCPudj7p5oBXChEe8km6/mP1d6iZgaXZkn5faNvOm4aj9b3CxJcmrA0Z7ckqm9q9Bg== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] mm: zsmalloc: zs_rebind_handle() uses offset_in_page() on multi-page zpdescs - [Medium] mm: zsmalloc: CLASS_BITS bump expands ZS_OBJ_CLASS_BITS to 10 bits - [Medium] mm: zsmalloc: __zs_compact() write-locks pool for empty multi-page classes - [Low] mm: zsmalloc: pages_per_zspage doc mismatches zs_stats_size_show() output -- commit 2914fdff611ccc07d7896b5a0cd7f8a5cb3a06ab Author: Tangquan Zheng mm: zsmalloc: support objects compressed based on multiple pages This patch adds CONFIG_ZSMALLOC_MULTI_PAGES support to zsmalloc so it can allocate and store compressed objects larger than PAGE_SIZE (up to PAGE_SIZE << CONFIG_ZSMALLOC_MULTI_PAGES_ORDER) using higher-order compound pages and additional multi-page size classes. > diff --git a/Documentation/mm/zsmalloc.rst b/Documentation/mm/zsmalloc.rst > index 8132cd70a61f2..283d22cb8abac 100644 > --- a/Documentation/mm/zsmalloc.rst > +++ b/Documentation/mm/zsmalloc.rst [ ... ] > @@ -85,7 +98,9 @@ obj_used > pages_used > the number of pages allocated for the class > pages_per_zspage > - the number of 0-order pages to make a zspage > + the number of pages (or higher-order allocation units) to make a zspage > +objs_per_zspage > + the total number of objects that a single zspage of this class can hold > freeable > the approximate number of pages class compaction can free [Severity: Low] Does this description of pages_per_zspage match what zs_stats_size_show() prints? zs_stats_size_show() outputs class_pages_per_zspage(class), which shifts zpdescs_per_zspage by the class order and reports the total number of base order-0 physical pages in a zspage rather than the count of higher-order allocation units. [ ... ] > diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c > index f263bd2b8d468..171cb787fe6b5 100644 > --- a/mm/zsmalloc.c > +++ b/mm/zsmalloc.c [ ... ] > @@ -115,7 +121,7 @@ > =20 > #define HUGE_BITS 1 > #define FULLNESS_BITS 4 > -#define CLASS_BITS 8 > +#define CLASS_BITS 9 > #define MAGIC_VAL_BITS 8 [Severity: Medium] Does raising CLASS_BITS to 9 unnecessarily expand ZS_OBJ_CLASS_BITS to 10 bits and regress riscv64? ZS_SIZE_CLASSES is at most 481 even with CONFIG_ZSMALLOC_MULTI_PAGES enabled at order 3, which already fits in the existing 9-bit CLASS_BITS + 1 field. Unconditionally bumping CLASS_BITS to 9 increases ZS_OBJ_CLASS_BITS to 10 bits even when CONFIG_ZSMALLOC_MULTI_PAGES is disabled. On riscv64 (56-bit physical addresses, 4 KiB pages, ZS_OBJ_PFN_SHIFT =3D 20= ), this folds ZS_OBJ_CLASS_BITS to 0 for CONFIG_ZSMALLOC_CHAIN_SIZE in 9..16, disabling the lockless class lookup in obj_class_get_and_lock() and forcing every zs_free() and zs_rebind_handle() onto read_lock(&pool->lock). With the default chain size of 8, it shrinks ZS_OBJ_IDX_BITS from 11 to 10 and inflates ZS_MIN_ALLOC_SIZE from 32 to 40 bytes. [ ... ] > +#ifdef CONFIG_ZSMALLOC_MULTI_PAGES > +#define ZS_MULTI_PAGES_SIZE_CLASS_DELTA (ZSMALLOC_MULTI_PAGES_SIZE >> (C= LASS_BITS - 1)) > +#define ZS_MULTI_PAGES_SIZE_CLASSES (DIV_ROUND_UP(ZS_MAX_ALLOC_SIZE - PA= GE_SIZE, \ > + ZS_MULTI_PAGES_SIZE_CLASS_DELTA)) > +#define ZS_SIZE_CLASSES (ZS_PAGE_SIZE_CLASSES + ZS_MULTI_PAGES_SIZE_CLA= SSES) > +#else [Severity: Medium] Can appending these multi-page size classes cause zs_compact() to repeatedly stall concurrent readers on empty classes? zs_compact() iterates over all ZS_SIZE_CLASSES and calls __zs_compact() for every distinct class, where __zs_compact() acquires write_lock(&pool->lock) and spin_lock(&class->lock) before checking zs_can_compact(class). With CONFIG_ZSMALLOC_MULTI_PAGES enabled, every pool (including zswap and 4 KiB-only zram pools) now takes write_lock(&pool->lock) for each empty multi-page class, blocking concurrent zs_obj_read_sg_begin() readers during reclaim or compaction. Pre-checking zs_can_compact(class) before taking write_lock(&pool->lock), as zs_shrinker_count() already does, would avoid these stalls. [ ... ] > @@ -1551,6 +1631,8 @@ static void zs_object_copy(struct size_class *class= , unsigned long dst, > struct zpdesc *s_zpdesc, *d_zpdesc; > unsigned int s_objidx, d_objidx; > unsigned long s_off, d_off; > + unsigned long page_size =3D class_size_to_zs_size(class->size); > + unsigned long page_mask =3D ~(page_size - 1); > void *s_addr, *d_addr; > int s_size, d_size, size; > int written =3D 0; [Severity: High] Was zs_rebind_handle() missed when updating object offset calculations for multi-page zpdescs? mm/zsmalloc.c:zs_rebind_handle() { ... if (likely(!ZsHugePage(zspage))) { obj_to_location(obj, &zpdesc, &obj_idx); off =3D offset_in_page(class->size * obj_idx); vaddr =3D kmap_local_zpdesc(zpdesc); link =3D (struct link_free *)(vaddr + off); link->handle =3D (unsigned long)dst | OBJ_ALLOCATED_TAG; kunmap_local(vaddr); } ... } For any non-huge multi-page object whose offset within its compound zpdesc is at least PAGE_SIZE, offset_in_page() wraps into the first base page, corrupting 8 bytes of another object's data or header with the dst handle address while leaving the real object header pointing to src. If the caller then frees src as documented on struct zs_handle, a subsequent zs_compact() -> migrate_zspage() reads the stale src handle from the real header, causing a use-after-free while leaving dst dangling. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205021803.3704= 464-1-zhaonanzhe@xiaomi.com?part=3D1