From nobody Sun Feb 8 19:56:11 2026 Received: from out-186.mta1.migadu.com (out-186.mta1.migadu.com [95.215.58.186]) (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 1C8841EB3A for ; Tue, 20 Feb 2024 06:53:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.186 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708411995; cv=none; b=ShvKMKkxwpiLq/cNbP62KTNsA/MXU5Gq/40aWCw1bpgsliybjkvhMfmgO9pbzzjL7ZjOSFPlIlTsTDj0ZMqNSKzA3zNTQ6C/i+uu9vkz6McsN5EK2BNo3V/ryybasarBaF91mlKH9sGQCTRogIDl2OwczBDGiBSrrf7GWvsQNAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708411995; c=relaxed/simple; bh=cqkPrPVAWUs+Ao8dP81X35doam5/5XwHmrqtbfkzja8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p5e9wjx0c+W+Q45jh8l6JG15Xs+0O50Jwx/y0UFp5nUgaCspis0wQTMIiM7tVSJndLcFMtD/IDU+Lq5b07315qch1TGQz2G2Wg7a5zIc94eZolo3Nc33ivoEEgZ2gzZ9rU+F9x+j921TJXhZUVOSJL1Nv1MZFqvZ7b2wFU+dzEY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=linux.dev; arc=none smtp.client-ip=95.215.58.186 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Tue, 20 Feb 2024 06:53:00 +0000 Subject: [PATCH 1/3] mm/zsmalloc: remove set_zspage_mapping() 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240220-b4-zsmalloc-cleanup-v1-1-5c5ee4ccdd87@bytedance.com> References: <20240220-b4-zsmalloc-cleanup-v1-0-5c5ee4ccdd87@bytedance.com> In-Reply-To: <20240220-b4-zsmalloc-cleanup-v1-0-5c5ee4ccdd87@bytedance.com> To: nphamcs@gmail.com, Andrew Morton , Sergey Senozhatsky , hannes@cmpxchg.org, yosryahmed@google.com, Minchan Kim Cc: Chengming Zhou , linux-kernel@vger.kernel.org, linux-mm@kvack.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1708411986; l=2317; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=cqkPrPVAWUs+Ao8dP81X35doam5/5XwHmrqtbfkzja8=; b=b6RxioH3nI4BzApNzDWLkeJUM2KNNI2jIWfPF0wnvNdHFanI0ZxZ8jRdFwHgIq3V0GN2CzKie q3prV92J9KxB5aPLZFDeZyXd2Qc3kEs2h5qb8Cu+K3t4Kjat+DJ1Zyp X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT We only need to update zspage->fullness when insert_zspage(), since zspage->class is never changed after allocated. Signed-off-by: Chengming Zhou --- mm/zsmalloc.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index a48f4651d143..a6653915bf17 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -486,14 +486,6 @@ static struct size_class *zspage_class(struct zs_pool = *pool, return pool->size_class[zspage->class]; } =20 -static void set_zspage_mapping(struct zspage *zspage, - unsigned int class_idx, - int fullness) -{ - zspage->class =3D class_idx; - zspage->fullness =3D fullness; -} - /* * zsmalloc divides the pool into various size classes where each * class maintains a list of zspages where each zspage is divided @@ -688,6 +680,7 @@ static void insert_zspage(struct size_class *class, { class_stat_inc(class, fullness, 1); list_add(&zspage->list, &class->fullness_list[fullness]); + zspage->fullness =3D fullness; } =20 /* @@ -725,7 +718,6 @@ static int fix_fullness_group(struct size_class *class,= struct zspage *zspage) =20 remove_zspage(class, zspage, currfg); insert_zspage(class, zspage, newfg); - set_zspage_mapping(zspage, class_idx, newfg); out: return newfg; } @@ -1005,6 +997,7 @@ static struct zspage *alloc_zspage(struct zs_pool *poo= l, create_page_chain(class, zspage, pages); init_zspage(class, zspage); zspage->pool =3D pool; + zspage->class =3D class->index; =20 return zspage; } @@ -1397,7 +1390,6 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t = size, gfp_t gfp) obj =3D obj_malloc(pool, zspage, handle); newfg =3D get_fullness_group(class, zspage); insert_zspage(class, zspage, newfg); - set_zspage_mapping(zspage, class->index, newfg); record_obj(handle, obj); atomic_long_add(class->pages_per_zspage, &pool->pages_allocated); class_stat_inc(class, ZS_OBJS_ALLOCATED, class->objs_per_zspage); @@ -1655,7 +1647,6 @@ static int putback_zspage(struct size_class *class, s= truct zspage *zspage) =20 fullness =3D get_fullness_group(class, zspage); insert_zspage(class, zspage, fullness); - set_zspage_mapping(zspage, class->index, fullness); =20 return fullness; } --=20 b4 0.10.1 From nobody Sun Feb 8 19:56:11 2026 Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) (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 E59CF1EB48 for ; Tue, 20 Feb 2024 06:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708411997; cv=none; b=ebhlbADiwPOgeUWKwy/1VwesLx5t2q8icvQiqwGar3iCiIFgatcK7u+MpTzdSPJ08UIPxhVjypsEZn5fWaDmJH82yyW0sUaQIkUbGXReaVpR8K9+5ykAGFa1qiE4u0DlAvz00NvFwTJgY54q6Zq3/sfKjdbY1kWDfsWsZzcbUbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708411997; c=relaxed/simple; bh=GQWspwGCFRIlLWu+jB/4L2Vh7hNigRDA/nhdzUelvTs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hwEAgGZG+z1k3r/SNRElcXA3j6YrGzqP4ZFNNtQCEv0Eny9r1dBwMEjFSTqqLOahQmf7DTLB8wwILRne1WBEzKOUzR6DNDo+Ki8UR3+STamMi/m3FRk86QgxlaiTVSFKcGyYVu6CxIb1qyEymzNGoufnoWoA/7X9kTTH9xwnm/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=linux.dev; arc=none smtp.client-ip=95.215.58.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Tue, 20 Feb 2024 06:53:01 +0000 Subject: [PATCH 2/3] mm/zsmalloc: remove_zspage() don't need fullness parameter 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240220-b4-zsmalloc-cleanup-v1-2-5c5ee4ccdd87@bytedance.com> References: <20240220-b4-zsmalloc-cleanup-v1-0-5c5ee4ccdd87@bytedance.com> In-Reply-To: <20240220-b4-zsmalloc-cleanup-v1-0-5c5ee4ccdd87@bytedance.com> To: nphamcs@gmail.com, Andrew Morton , Sergey Senozhatsky , hannes@cmpxchg.org, yosryahmed@google.com, Minchan Kim Cc: Chengming Zhou , linux-kernel@vger.kernel.org, linux-mm@kvack.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1708411986; l=2152; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=GQWspwGCFRIlLWu+jB/4L2Vh7hNigRDA/nhdzUelvTs=; b=JNIzIQ9Lci0B3n2FEPHyXk1U9Zo0P03ME5cMyqjBhp3RwTxfdYX46ff3p2X/QxYJ6NhSNNcY7 4xNL7yvbvQYC/xjoY/qcI71XYnv5VeaKzisgJeRm5rlJnnYxTN/4tk/ X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT We must remove_zspage() from its current fullness list, then use insert_zspage() to update its fullness and insert to new fullness list. Obviously, remove_zspage() doesn't need the fullness parameter. Signed-off-by: Chengming Zhou --- mm/zsmalloc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index a6653915bf17..c39fac9361d7 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -687,10 +687,10 @@ static void insert_zspage(struct size_class *class, * This function removes the given zspage from the freelist identified * by . */ -static void remove_zspage(struct size_class *class, - struct zspage *zspage, - int fullness) +static void remove_zspage(struct size_class *class, struct zspage *zspage) { + int fullness =3D zspage->fullness; + VM_BUG_ON(list_empty(&class->fullness_list[fullness])); =20 list_del_init(&zspage->list); @@ -716,7 +716,7 @@ static int fix_fullness_group(struct size_class *class,= struct zspage *zspage) if (newfg =3D=3D currfg) goto out; =20 - remove_zspage(class, zspage, currfg); + remove_zspage(class, zspage); insert_zspage(class, zspage, newfg); out: return newfg; @@ -878,7 +878,7 @@ static void free_zspage(struct zs_pool *pool, struct si= ze_class *class, return; } =20 - remove_zspage(class, zspage, ZS_INUSE_RATIO_0); + remove_zspage(class, zspage); __free_zspage(pool, class, zspage); } =20 @@ -1609,7 +1609,7 @@ static struct zspage *isolate_src_zspage(struct size_= class *class) zspage =3D list_first_entry_or_null(&class->fullness_list[fg], struct zspage, list); if (zspage) { - remove_zspage(class, zspage, fg); + remove_zspage(class, zspage); return zspage; } } @@ -1626,7 +1626,7 @@ static struct zspage *isolate_dst_zspage(struct size_= class *class) zspage =3D list_first_entry_or_null(&class->fullness_list[fg], struct zspage, list); if (zspage) { - remove_zspage(class, zspage, fg); + remove_zspage(class, zspage); return zspage; } } --=20 b4 0.10.1 From nobody Sun Feb 8 19:56:11 2026 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) (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 E24035A0EA for ; Tue, 20 Feb 2024 06:53:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708412002; cv=none; b=lcSkhogZml2s281+pASrW+R4S9ZNKZX539toPbFQnm6hSDDPhOLLazqKqHFzENHjWmqz89oc1anJBZPBrUpkYc34CI2EydBYkdC/+1AUFxgvlwwigDCt3XOUOrRftoPEvVPFxqTx/N5/z0oG3jsr0FIh298FPvPR3fBrBrpEd9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708412002; c=relaxed/simple; bh=Xgdlm55CLoh7bhkT80TmmQFtvDTRQ4HP1+zxTxJBYgU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=csdfBp9om3xLSuf75mQvrNWJTAshWvGKdUwzRWpg9ka9FIye+kjulrM7vj/AuP4Lu9Gt9YmHB8VS2bjZg7JX5egJAtzjvfOUa6lAPmtA3U9xa0nFKNm1Lg5nfiFdTEkrscD5S/GABiJatiYAfHERZ31yb0NG71XrzDS3RSJicls= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=linux.dev; arc=none smtp.client-ip=95.215.58.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Tue, 20 Feb 2024 06:53:02 +0000 Subject: [PATCH 3/3] mm/zsmalloc: remove get_zspage_mapping() 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240220-b4-zsmalloc-cleanup-v1-3-5c5ee4ccdd87@bytedance.com> References: <20240220-b4-zsmalloc-cleanup-v1-0-5c5ee4ccdd87@bytedance.com> In-Reply-To: <20240220-b4-zsmalloc-cleanup-v1-0-5c5ee4ccdd87@bytedance.com> To: nphamcs@gmail.com, Andrew Morton , Sergey Senozhatsky , hannes@cmpxchg.org, yosryahmed@google.com, Minchan Kim Cc: Chengming Zhou , linux-kernel@vger.kernel.org, linux-mm@kvack.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1708411986; l=2848; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=Xgdlm55CLoh7bhkT80TmmQFtvDTRQ4HP1+zxTxJBYgU=; b=4q+yd5glcFZOpqCIQVbVR4X3XsoatKtXTiqyOtq8q0ZNNs6UmVHGxbOU+0d386EdCTHQyVWJv SM+DhZwPpWWCQGQV68PH4ymGQj6BE3cFFbARfeA4fYqACKEosa6yAsu X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT Actually we seldom use the class_idx returned from get_zspage_mapping(), only the zspage->fullness is useful, just use zspage->fullness to remove this helper. Note zspage->fullness is not stable outside pool->lock, remove redundant "VM_BUG_ON(fullness !=3D ZS_INUSE_RATIO_0)" in async_free_zspage() since we already have the same VM_BUG_ON() in __free_zspage(), which is safe to access zspage->fullness with pool->lock held. Signed-off-by: Chengming Zhou --- mm/zsmalloc.c | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index c39fac9361d7..63ec385cd670 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -470,16 +470,6 @@ static inline void set_freeobj(struct zspage *zspage, = unsigned int obj) zspage->freeobj =3D obj; } =20 -static void get_zspage_mapping(struct zspage *zspage, - unsigned int *class_idx, - int *fullness) -{ - BUG_ON(zspage->magic !=3D ZSPAGE_MAGIC); - - *fullness =3D zspage->fullness; - *class_idx =3D zspage->class; -} - static struct size_class *zspage_class(struct zs_pool *pool, struct zspage *zspage) { @@ -708,12 +698,10 @@ static void remove_zspage(struct size_class *class, s= truct zspage *zspage) */ static int fix_fullness_group(struct size_class *class, struct zspage *zsp= age) { - int class_idx; - int currfg, newfg; + int newfg; =20 - get_zspage_mapping(zspage, &class_idx, &currfg); newfg =3D get_fullness_group(class, zspage); - if (newfg =3D=3D currfg) + if (newfg =3D=3D zspage->fullness) goto out; =20 remove_zspage(class, zspage); @@ -835,15 +823,11 @@ static void __free_zspage(struct zs_pool *pool, struc= t size_class *class, struct zspage *zspage) { struct page *page, *next; - int fg; - unsigned int class_idx; - - get_zspage_mapping(zspage, &class_idx, &fg); =20 assert_spin_locked(&pool->lock); =20 VM_BUG_ON(get_zspage_inuse(zspage)); - VM_BUG_ON(fg !=3D ZS_INUSE_RATIO_0); + VM_BUG_ON(zspage->fullness !=3D ZS_INUSE_RATIO_0); =20 next =3D page =3D get_first_page(zspage); do { @@ -1857,8 +1841,6 @@ static void async_free_zspage(struct work_struct *wor= k) { int i; struct size_class *class; - unsigned int class_idx; - int fullness; struct zspage *zspage, *tmp; LIST_HEAD(free_pages); struct zs_pool *pool =3D container_of(work, struct zs_pool, @@ -1879,10 +1861,8 @@ static void async_free_zspage(struct work_struct *wo= rk) list_del(&zspage->list); lock_zspage(zspage); =20 - get_zspage_mapping(zspage, &class_idx, &fullness); - VM_BUG_ON(fullness !=3D ZS_INUSE_RATIO_0); - class =3D pool->size_class[class_idx]; spin_lock(&pool->lock); + class =3D zspage_class(pool, zspage); __free_zspage(pool, class, zspage); spin_unlock(&pool->lock); } --=20 b4 0.10.1