All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] mm/zsmalloc: don't need to reserve LSB in handle
@ 2024-02-28  2:38 Chengming Zhou
  2024-02-28  3:26 ` Sergey Senozhatsky
  0 siblings, 1 reply; 2+ messages in thread
From: Chengming Zhou @ 2024-02-28  2:38 UTC (permalink / raw)
  To: minchan, senozhatsky, akpm
  Cc: hannes, nphamcs, yosryahmed, linux-mm, linux-kernel, chengming.zhou

We will save allocated tag in the object header to indicate that it's
allocated.

	handle |= OBJ_ALLOCATED_TAG;

So the object header needs to reserve LSB for this tag bit.

But the handle itself doesn't need to reserve LSB to save tag, since
it's only used to find the position of object, by (pfn + obj_idx).
So remove LSB reserve from handle, one more bit can be used as obj_idx.

Signed-off-by: Chengming Zhou <chengming.zhou@linux.dev>
---
v2:
 - Improve the commit message to make it clearer, per Sergey.
 - Link to v1: https://lore.kernel.org/all/20240227030045.3443702-1-chengming.zhou@linux.dev/
---
 mm/zsmalloc.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 63ec385cd670..7d7cb3eaabe0 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -110,7 +110,7 @@
 #define OBJ_TAG_BITS	1
 #define OBJ_TAG_MASK	OBJ_ALLOCATED_TAG
 
-#define OBJ_INDEX_BITS	(BITS_PER_LONG - _PFN_BITS - OBJ_TAG_BITS)
+#define OBJ_INDEX_BITS	(BITS_PER_LONG - _PFN_BITS)
 #define OBJ_INDEX_MASK	((_AC(1, UL) << OBJ_INDEX_BITS) - 1)
 
 #define HUGE_BITS	1
@@ -737,14 +737,12 @@ static struct page *get_next_page(struct page *page)
 static void obj_to_location(unsigned long obj, struct page **page,
 				unsigned int *obj_idx)
 {
-	obj >>= OBJ_TAG_BITS;
 	*page = pfn_to_page(obj >> OBJ_INDEX_BITS);
 	*obj_idx = (obj & OBJ_INDEX_MASK);
 }
 
 static void obj_to_page(unsigned long obj, struct page **page)
 {
-	obj >>= OBJ_TAG_BITS;
 	*page = pfn_to_page(obj >> OBJ_INDEX_BITS);
 }
 
@@ -759,7 +757,6 @@ static unsigned long location_to_obj(struct page *page, unsigned int obj_idx)
 
 	obj = page_to_pfn(page) << OBJ_INDEX_BITS;
 	obj |= obj_idx & OBJ_INDEX_MASK;
-	obj <<= OBJ_TAG_BITS;
 
 	return obj;
 }
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] mm/zsmalloc: don't need to reserve LSB in handle
  2024-02-28  2:38 [PATCH v2] mm/zsmalloc: don't need to reserve LSB in handle Chengming Zhou
@ 2024-02-28  3:26 ` Sergey Senozhatsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sergey Senozhatsky @ 2024-02-28  3:26 UTC (permalink / raw)
  To: Chengming Zhou
  Cc: minchan, senozhatsky, akpm, hannes, nphamcs, yosryahmed,
	linux-mm, linux-kernel

On (24/02/28 02:38), Chengming Zhou wrote:
> We will save allocated tag in the object header to indicate that it's
> allocated.
> 
> 	handle |= OBJ_ALLOCATED_TAG;
> 
> So the object header needs to reserve LSB for this tag bit.
> 
> But the handle itself doesn't need to reserve LSB to save tag, since
> it's only used to find the position of object, by (pfn + obj_idx).
> So remove LSB reserve from handle, one more bit can be used as obj_idx.
> 
> Signed-off-by: Chengming Zhou <chengming.zhou@linux.dev>

Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-28  3:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-28  2:38 [PATCH v2] mm/zsmalloc: don't need to reserve LSB in handle Chengming Zhou
2024-02-28  3:26 ` Sergey Senozhatsky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.