[PATCH v3 03/11] zsmalloc: return handle from obj_allocated()
From: Sergey Senozhatsky
Date: Wed Nov 11 2026 - 01:54:47 EST
Allocated handles are valid kernel addresses and never 0, so let
obj_allocated() return the handle directly (or 0 if unallocated)
instead of returning a bool.
No functional change.
Suggested-by: Yosry Ahmed <yosry@xxxxxxxxxx>
Reviewed-by: Yosry Ahmed <yosry@xxxxxxxxxx>
Reviewed-by: Nhat Pham <nphamcs@xxxxxxxxx>
Signed-off-by: Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>
---
mm/zsmalloc.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 7ef80e0da626..dab71f582103 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -822,8 +822,7 @@ static unsigned long handle_to_obj(unsigned long handle)
return READ_ONCE(*(unsigned long *)handle);
}
-static inline bool obj_allocated(struct zpdesc *zpdesc, void *obj,
- unsigned long *phandle)
+static inline unsigned long obj_allocated(struct zpdesc *zpdesc, void *obj)
{
unsigned long handle;
struct zspage *zspage = get_zspage(zpdesc);
@@ -836,11 +835,10 @@ static inline bool obj_allocated(struct zpdesc *zpdesc, void *obj,
handle = *(unsigned long *)obj;
if (!(handle & OBJ_ALLOCATED_TAG))
- return false;
+ return 0;
/* Clear all tags before returning the handle */
- *phandle = handle & ~OBJ_TAG_MASK;
- return true;
+ return handle & ~OBJ_TAG_MASK;
}
static void reset_zpdesc(struct zpdesc *zpdesc)
@@ -1571,7 +1569,8 @@ static unsigned long find_alloced_obj(struct size_class *class,
offset += class->size * index;
while (offset < PAGE_SIZE) {
- if (obj_allocated(zpdesc, addr + offset, &handle))
+ handle = obj_allocated(zpdesc, addr + offset);
+ if (handle)
break;
offset += class->size;
@@ -1824,8 +1823,8 @@ static int zs_page_migrate(struct page *newpage, struct page *page,
for (addr = s_addr + offset; addr < s_addr + PAGE_SIZE;
addr += class->size) {
- if (obj_allocated(zpdesc, addr, &handle)) {
-
+ handle = obj_allocated(zpdesc, addr);
+ if (handle) {
old_obj = handle_to_obj(handle);
obj_to_location(old_obj, &dummy, &obj_idx);
new_obj = location_to_obj(newzpdesc, obj_idx,
--
2.56.0.542.g3ef89b7020-goog