Skip to contentSkip to conversation

mm/zsmalloc: don't need to reserve LSB in handle

PATCH Applied Chengming Zhou 2 participants 2 messages Feb 28, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mm/zsmalloc: don't need to reserve LSB in handle

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.

---
v2:
- Improve the commit message to make it clearer, per Sergey.
- Link to v1: https://lore.kernel.org/all/[email protected]/

---
 mm/zsmalloc.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
mm/zsmalloc.c +1 -4
index 63ec385cd670..7d7cb3eaabe0 100644
@@ -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;
 }
Signature · 1 line
2.40.1
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Chengming Zhou

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

	handle |= OBJ_ALLOCATED_TAG;
Quoted 7 lines

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.