From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013035.outbound.protection.outlook.com [40.93.196.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EB103AE6E6 for ; Mon, 3 Aug 2026 21:05:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.196.35 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785791126; cv=fail; b=vDKPf06k9Gy6JUh76VQ12olIntaHIfEOut0JVJaho00AUFzYxE1u9TGXmqfm2D5NDEG2ppc1CCvwjA8T1wcGkYYz9dy4jztxiBKg5mHWDzrrSf4jgJGM6dXus+M9xt8fRnIFlFdmGFoEnBszDfh5VX0hoKB2Ytdjwh53i/3nHo8= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785791126; c=relaxed/simple; bh=AhUFwQN2IytUdvKIR24cJ9/yRFFwXQaBiKJzn7eqqOY=; h=Content-Type:Date:Message-Id:Cc:To:From:Subject:References: In-Reply-To:MIME-Version; b=b1FmD3KzdqdpygSxJAyke4nWzTZSLavUvAehH+e2qOj/71oNIaeIdu8ADkFyM52tEQeUQDEPm0SEnPK+HnCVdT5UHGBWzt6MoIebAVg1dfDs6dT34U9EEF7+b01LEYXhatBCHPlsNqfZmpuJLQQAznH+HULQpkPLGfd8BvZVrGY= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=okQQYAJn; arc=fail smtp.client-ip=40.93.196.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="okQQYAJn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iRbqIDYTQckXuGlw1HQqIOepasaRaCLp/zES+D4zJ7faSFxvx+nr+GesT+3UxLAtbtJFid1Mu2aDOiCKreUX77HFqt6CCuShX2y6OEa2fTKf0qs4ZjDL1Q+RnHbSkyrVqj7iVX3zO62uloyUP4u6WArgwLnocRR3Nf4O9Z50ekG3st94SWLBSnoiR6f1KbaAL0vptSwoggZSTrT7gQISoqES2CA+p3UQAn6mZdp5j3PsmaiQiNmc4MzS3DB8m4RSWDsar9fH0L4f6ltpFy/UlU7ub4eznS80C7OYrEUvM2fuDYI7jDLyJ2P2i6xE5DzAjuI/+1eEqoDG+djvXswYYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XREpuZBe0n3lN7r7Qv8j0KvE4PoKPPmkt622YERMb9o=; b=Acnk/q9/q+zOBPHJy/Ss3VuhU81yyjIxSMyYneDrCAwprbpVLDyQvXkk3iGhxvVPSQxZEd/aQPPRzitoG9bAtojD5oM9ON+Hiokq+Vy825ySJFD+vfWMAcA05yGLo69Cb/fUi9tsmOu+Fs8MQWrVnN6d4aUONB3ToaXQYLMfcod2FuoxYzMNW8S+lAYC/S1fkIhhcc7aIJBwJMz4uTokKzzgpOP8C0aPB5BfwGn5eOs+MhDSiTWWXXw0TkbRplb3N80tbfQz02y29C1ErcpdWQN4n63Ue/PFtU+LaV8TY9mVTS6U1ewLFJVMqjtmzIwSKn8Ygk/mlomx/z4tV1Awzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XREpuZBe0n3lN7r7Qv8j0KvE4PoKPPmkt622YERMb9o=; b=okQQYAJnam8O0eeLuY8Eu8qgZZv/ZkyPIW/Mkk9RHxETM2FklZ0Jjyc/SYbLYemd1zePuPK1soXGxUToHfyXtOikRgi08+MWKoGnWfhXpI3g2EZJ8EslIy8NdvaOvlGFPtHcRhIN/y0gkjcsB21LBAfVYv/pXCHpoel8UYvksFEGhmWYqbidnrC8kQOdbc/efyx1tNgvapHsjIh6QLuoRGfDWzboz3h4epBlw581LanjlmTShO6i/OelbzOuB6mHL8E0o4QRvFr9zcPQqa/uy1NZo5T9QDLLEm1Yj64W43TgOXA+S8VDU4lnndbn+ipnyS+P+YfNmC2oJHn03feZJQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from IA0PR12MB8374.namprd12.prod.outlook.com (2603:10b6:208:40e::7) by DM4PR12MB9735.namprd12.prod.outlook.com (2603:10b6:8:225::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.270.17; Mon, 3 Aug 2026 21:05:17 +0000 Received: from IA0PR12MB8374.namprd12.prod.outlook.com ([fe80::d85f:4c87:ae84:3f16]) by IA0PR12MB8374.namprd12.prod.outlook.com ([fe80::d85f:4c87:ae84:3f16%5]) with mapi id 15.21.0270.017; Mon, 3 Aug 2026 21:05:17 +0000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 03 Aug 2026 17:05:12 -0400 Message-Id: Cc: "David Hildenbrand" , "Matthew Wilcox (Oracle)" , "Andrew Morton" , "Muchun Song" , "Lorenzo Stoakes" , "Liam R. Howlett" , "Vlastimil Babka" , "Mike Rapoport" , "Suren Baghdasaryan" , "Michal Hocko" , "Baolin Wang" , "Nico Pache" , "Ryan Roberts" , "Dev Jain" , "Barry Song" , "Lance Yang" , "Usama Arif" , "Gregory Price" , "Ying Huang" , "Alistair Popple" , "Qi Zheng" , "Shakeel Butt" , "Kairui Song" , , , "Minchan Kim" , "Sergey Senozhatsky" To: "Johannes Weiner" From: "Zi Yan" Subject: Re: [PATCH RFC 01/14] mm/zsmalloc: replace PG_private with pointer comparison X-Mailer: aerc 0.21.0 References: <20260731-remove-pg_private-v1-0-142c97ba3562@nvidia.com> <20260731-remove-pg_private-v1-1-142c97ba3562@nvidia.com> In-Reply-To: X-ClientProxiedBy: CY5PR19CA0061.namprd19.prod.outlook.com (2603:10b6:930:69::7) To IA0PR12MB8374.namprd12.prod.outlook.com (2603:10b6:208:40e::7) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: IA0PR12MB8374:EE_|DM4PR12MB9735:EE_ X-MS-Office365-Filtering-Correlation-Id: 345d2414-cf16-4c92-732c-08def1a2eb95 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|23010399003|376014|7416014|18002099003|22082099003|5023799004|4143699003|11063799006|10067099003|56012099006; X-Microsoft-Antispam-Message-Info: tKbd1WCLdxWpKtSAvhAmQPkk5FYu4/bFu2DLVrrRmlxPV+I8bH3fnXMCoj7wwN/04KY63ws5tZd7tkHeWDdOE84VwyjhFmBU6KASbkLUIo3EfirZugRVffC0I/shUGrOHxBJzQYKWlIRsgOJjM1gMdjxVTEzyN/jHOeyfTp3LbjqodeOXYaV0+g7gaYktWg4mVb40tscoMJ9Z3+M+2aFxZyleJTH9z0G7xC+6f5GbG2xgmg1VwYib3VyMgFHDmzUynNqWevOAXTitfuQS0nr/90OrDGxRUDB0PyzhZSHtYJTuu8l/LECF1Xk58u+jKVd41QIdf58BHQIxt5OfMz26Ddy5eUF/rJMnOxeyK6mzUrctltaptQ8fmnqfHW1Oo/3E+VMk1l6J3IwFjeHu7QL2Fkayf5YNWFjN+PnllIpvf7IYn4lu/6rc8W1vrTLZggAPTNayROfRdqneW95qgVldgtGJA7t4qaANw3+MME0ldFlUxmWWyhhAfXPlsmMSDVrz1sziXJofgLVQYvF6iZ4XKMrKTBRJ4BfulrcPbp3ZhW53MkHilGVuLf3/aSBd9aOdjnW4goi3GaYx3IK7+F/zDQ2XG6CmUIRzZDR/yjS4iXrpvxH4pA0m1jEvJWKBlAws0ENEjHy/yGvhOikGABDYeq9paCz6QyvzsU8NWprkhA= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:IA0PR12MB8374.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(23010399003)(376014)(7416014)(18002099003)(22082099003)(5023799004)(4143699003)(11063799006)(10067099003)(56012099006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?R1E0Qzg5NEJiVENYck4vZTdxNHl5TlRYazNoTUZuOU80ai9NT2xDUnpoSjl3?= =?utf-8?B?Y1IrMVRRenVad1ZVbmhHZHVSUGlDczB3Vk1VNmdnRmtVMFFmbm5sN1dkM3Zu?= =?utf-8?B?Ri9mTlNNUUl5STV5cVloVVphekYyTjBZTjVmeGlYNDE4eEFGendJb0VwL2Iw?= =?utf-8?B?YmUzaWhhR3NYc1hyMGdpOWtIOElvS2hnZS9LcTQxb0tLQkNJcUhiYkNkbFA0?= =?utf-8?B?QlorQmROcENEaUlkUUVURXBoSit6UVhkampON1RWYndZOWZCeWlFUVliNC9n?= =?utf-8?B?ZnE0V3Vv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QWxydzN4K1pSb0JBeFJN?= =?utf-8?B?UmdvelpLMFlsRHRlQkZwRFFBTUpSaTRINGQ3UXdWeFNsY3ZyZk40MXN2VWk5?= =?utf-8?B?cW0ydGNlaGZmYWcraldkbk8xdTB6TUJqQUpWaER0RVBTSzJmYUlucG9DTGto?= =?utf-8?B?VzFxcEJnQjdFellZWUd5bkF5bk1YempsRjN3ODdFTEFUSlByZWQ3UmZQcTNE?= =?utf-8?Q?pYH0bG2+wR08arRE8B?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 345d2414-cf16-4c92-732c-08def1a2eb95 X-MS-Exchange-CrossTenant-AuthSource: IA0PR12MB8374.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2026 21:05:17.4566 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eFM3iVQk3BUJTZKA5I94XWwBcEB83owOnF4bp3XOOEbRpzMszk6j7fcUH8U9j1Xd X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB9735 On Mon Aug 3, 2026 at 12:53 PM EDT, Johannes Weiner wrote: > On Mon, Aug 03, 2026 at 11:34:35AM -0400, Zi Yan wrote: >> On Mon Aug 3, 2026 at 11:04 AM EDT, Johannes Weiner wrote: >> > On Fri, Jul 31, 2026 at 10:13:24PM -0400, Zi Yan wrote: >> >> zsmalloc uses PG_private to indicate first zpdesc in the zspage chain= . >> >> Replace it with zpdesc->zspage->first_zpdesc =3D=3D zpdesc. The check= , >> >> is_first_zpdesc(), is only used in VM_BUG_ON(), so performance impact >> >> should be negligible. >> >>=20 >> >> It prepares for a future commit that remove PG_private. >> >>=20 >> >> No functional change intended. >> >>=20 >> >> Assisted-by: Claude:claude-opus-4-8 >> >> Assisted-by: Codex:gpt-5 >> >> Signed-off-by: Zi Yan >> >> To: Minchan Kim >> >> To: Sergey Senozhatsky >> >> To: Andrew Morton >> >> Cc: linux-mm@kvack.org >> >> Cc: linux-kernel@vger.kernel.org >> >> --- >> >> mm/zpdesc.h | 2 +- >> >> mm/zsmalloc.c | 15 +++------------ >> >> 2 files changed, 4 insertions(+), 13 deletions(-) >> >>=20 >> >> diff --git a/mm/zpdesc.h b/mm/zpdesc.h >> >> index b8258dc78548d..4fd81c2e80769 100644 >> >> --- a/mm/zpdesc.h >> >> +++ b/mm/zpdesc.h >> >> @@ -26,8 +26,8 @@ >> >> * with memcg_data. >> >> * >> >> * Page flags used: >> >> - * * PG_private identifies the first component page. >> >> * * PG_locked is used by page migration code. >> >> + * The first component page has zpdesc->zspage->first_zpdesc =3D=3D = zpdesc >> >> */ >> >> struct zpdesc { >> >> unsigned long flags; >> >> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c >> >> index 8204b76f78308..e8ef227624efa 100644 >> >> --- a/mm/zsmalloc.c >> >> +++ b/mm/zsmalloc.c >> >> @@ -290,11 +290,6 @@ struct zs_pool { >> >> atomic_t compaction_in_progress; >> >> }; >> >> =20 >> >> -static inline void zpdesc_set_first(struct zpdesc *zpdesc) >> >> -{ >> >> - SetPagePrivate(zpdesc_page(zpdesc)); >> >> -} >> >> - >> >> static inline void zpdesc_inc_zone_page_state(struct zpdesc *zpdesc) >> >> { >> >> inc_zone_page_state(zpdesc_page(zpdesc), NR_ZSPAGES); >> >> @@ -478,7 +473,7 @@ static void record_obj(unsigned long handle, unsi= gned long obj) >> >> =20 >> >> static inline bool __maybe_unused is_first_zpdesc(struct zpdesc *zpd= esc) >> >> { >> >> - return PagePrivate(zpdesc_page(zpdesc)); >> >> + return zpdesc->zspage->first_zpdesc =3D=3D zpdesc; >> >> } >> > >> > There are two checks: get_first_zpdesc() and obj_allocated(). >> > >> > static struct zpdesc *get_first_zpdesc(struct zspage *zspage) >> > { >> > struct zpdesc *first_zpdesc =3D zspage->first_zpdesc; >> > >> > VM_BUG_ON_PAGE(is_first_zpdesc(first_zpdesc), zpdesc_page(first_zpdes= c)); >> > return first_zpdesc; >> > } >> > >> > If you expand the helper, this seems kind of pointless now: >> > >> > first_zpdesc =3D zspage->first_zpdesc; >> > VM_BUG_ON_PAGE(first_zpdesc !=3D first_zpdesc->zspage->first_zpdesc, = ...); >> > >> > Mayyybe it could make sense to assert first_zpdesc->zspage !=3D >> > zspage. But that's a separate issue that the previous check didn't >>=20 >> Usama has the same comment about this. >>=20 >> > necessarily catch. And might not be worth checking, considering how >> > trivial create_page_chain() is. >> > >> > In any case, it doesn't seem worth keeping the check as-is. >> > >> > And with one caller remaining, you could delete the helper and inline >> > that expression into the check in obj_allocated(). What it does now is >> > self-explanatory; it doesn't need another name like that PagePrivate() >> > check before did. >>=20 >> How about the version below? Basically, I made is_first_zpdesc() more >> straightforward for backpointer checking and first_zpdesc checking. >>=20 >> 1. get_first_zpdesc() needs the backpointer check; the first_zpdesc chec= k is >> meaningless, since the assignment is done above. >>=20 >> 2. obj_allocated() needs the first_zpdesc check; the backpointer check >> is meaningless, since the zspage is from get_zspage(). > > Personally, I'm not a fan of "super predicates" where individual > conditions are only useful for only some of the callsites. They tend > to become obstacles to understanding the code and lead to subtle bugs > when developers misunderstand context requirements. > > IMO it's better to just precisely express what each callsite > needs. Only factor a common helper if it's actually the same. OK. The below is what I come up with like you suggested. I realize that there are actually two things to check for a zspage chain: 1. all zpdescs point to the same zspage, 2. for a ZsHugePage, handle is only in the first zpdesc. get_first_zpdesc() checks 1 and obj_allocated() checks 2. So I added comments to them. >From 4567d7d9cc8c84d5c05de92ee8905f4c5e5cf67f Mon Sep 17 00:00:00 2001 From: Zi Yan Date: Tue, 28 Jul 2026 22:41:23 -0400 Subject: [PATCH] mm/zsmalloc: replace PG_private with pointer comparison zsmalloc uses PG_private to indicate first zpdesc in a zspage chain. It is equivalent to check zpdesc =3D=3D zspage->first_zpdesc. Replace is_first_zpdesc() with zpdesc =3D=3D zspage->first_zpdesc in obj_allocated(= ). For get_first_zpdesc(), first_zpdesc is from zspage->first_zpdesc, so replace is_first_zpdesc() with first_zpdesc->zspage =3D=3D zspage, the seco= nd requirement of a zspage chain, where all zpdescs point to the same zspage. is_first_zpdesc(), is only used in VM_BUG_ON_PAGE(), so performance impact should be negligible. While at it, change VM_BUG_ON() to VM_WARN_ON_ONCE_PAGE(). It prepares for a future commit that remove PG_private. No functional change intended. Assisted-by: Claude:claude-opus-4-8 Assisted-by: Codex:gpt-5 Signed-off-by: Zi Yan To: Minchan Kim To: Sergey Senozhatsky To: Andrew Morton Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- mm/zpdesc.h | 2 +- mm/zsmalloc.c | 24 ++++++------------------ 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/mm/zpdesc.h b/mm/zpdesc.h index b8258dc78548d..4fd81c2e80769 100644 --- a/mm/zpdesc.h +++ b/mm/zpdesc.h @@ -26,8 +26,8 @@ * with memcg_data. * * Page flags used: - * * PG_private identifies the first component page. * * PG_locked is used by page migration code. + * The first component page has zpdesc->zspage->first_zpdesc =3D=3D zpdesc */ struct zpdesc { unsigned long flags; diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 8204b76f78308..b87679757e7b1 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -290,11 +290,6 @@ struct zs_pool { atomic_t compaction_in_progress; }; =20 -static inline void zpdesc_set_first(struct zpdesc *zpdesc) -{ - SetPagePrivate(zpdesc_page(zpdesc)); -} - static inline void zpdesc_inc_zone_page_state(struct zpdesc *zpdesc) { inc_zone_page_state(zpdesc_page(zpdesc), NR_ZSPAGES); @@ -476,11 +471,6 @@ static void record_obj(unsigned long handle, unsigned = long obj) WRITE_ONCE(*(unsigned long *)handle, obj); } =20 -static inline bool __maybe_unused is_first_zpdesc(struct zpdesc *zpdesc) -{ - return PagePrivate(zpdesc_page(zpdesc)); -} - /* Protected by class->lock */ static inline int get_zspage_inuse(struct zspage *zspage) { @@ -496,7 +486,8 @@ static struct zpdesc *get_first_zpdesc(struct zspage *z= spage) { struct zpdesc *first_zpdesc =3D zspage->first_zpdesc; =20 - VM_BUG_ON_PAGE(!is_first_zpdesc(first_zpdesc), zpdesc_page(first_zpdesc))= ; + /* the first zpdesc must point back to this zspage */ + VM_WARN_ON_ONCE_PAGE(first_zpdesc->zspage !=3D zspage, zpdesc_page(first_= zpdesc)); return first_zpdesc; } =20 @@ -833,7 +824,8 @@ static inline bool obj_allocated(struct zpdesc *zpdesc,= void *obj, struct zspage *zspage =3D get_zspage(zpdesc); =20 if (unlikely(ZsHugePage(zspage))) { - VM_BUG_ON_PAGE(!is_first_zpdesc(zpdesc), zpdesc_page(zpdesc)); + /* only first zpdesc holds the handle */ + VM_WARN_ON_ONCE_PAGE(zspage->first_zpdesc !=3D zpdesc, zpdesc_page(zpdes= c)); handle =3D zpdesc->handle; } else handle =3D *(unsigned long *)obj; @@ -848,9 +840,6 @@ static inline bool obj_allocated(struct zpdesc *zpdesc,= void *obj, =20 static void reset_zpdesc(struct zpdesc *zpdesc) { - struct page *page =3D zpdesc_page(zpdesc); - - ClearPagePrivate(page); zpdesc->zspage =3D NULL; zpdesc->next =3D NULL; /* PageZsmalloc is sticky until the page is freed to the buddy. */ @@ -1001,8 +990,8 @@ static void create_page_chain(struct size_class *class= , struct zspage *zspage, * 1. all pages are linked together using zpdesc->next * 2. each sub-page point to zspage using zpdesc->zspage * - * we set PG_private to identify the first zpdesc (i.e. no other zpdesc - * has this flag set). + * The first zpdesc has its zspage->first_zpdesc set to itself, no + * other zpdesc has this set. */ for (i =3D 0; i < nr_zpdescs; i++) { zpdesc =3D zpdescs[i]; @@ -1010,7 +999,6 @@ static void create_page_chain(struct size_class *class= , struct zspage *zspage, zpdesc->next =3D NULL; if (i =3D=3D 0) { zspage->first_zpdesc =3D zpdesc; - zpdesc_set_first(zpdesc); if (unlikely(class->objs_per_zspage =3D=3D 1 && class->pages_per_zspage =3D=3D 1)) SetZsHugePage(zspage); --=20 2.53.0 --=20 Best Regards, Yan, Zi