Add function obj_handle_is_free() which scans through the entire singly-linked list of free objects inside the provided zspage to determine if the provided object handle is free or not. This is required by zspage reclaiming, which needs to evict each object that is currently in use by the zs_pool owner, but has no other way to determine if an object is in use. Signed-off-by: Dan Streetman <ddstreet@xxxxxxxx> Cc: Minchan Kim <minchan@xxxxxxxxxx> --- mm/zsmalloc.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 3dc7dae..ab72390 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -605,6 +605,33 @@ static unsigned long obj_idx_to_offset(struct page *page, return off + obj_idx * class_size; } +static bool obj_handle_is_free(struct page *first_page, + struct size_class *class, unsigned long handle) +{ + unsigned long obj, idx, offset; + struct page *page; + struct link_free *link; + + BUG_ON(!is_first_page(first_page)); + + obj = (unsigned long)first_page->freelist; + + while (obj) { + if (obj == handle) + return true; + + obj_handle_to_location(obj, &page, &idx); + offset = obj_idx_to_offset(page, idx, class->size); + + link = (struct link_free *)kmap_atomic(page) + + offset / sizeof(*link); + obj = (unsigned long)link->next; + kunmap_atomic(link); + } + + return false; +} + static void obj_free(unsigned long obj, struct page *page, unsigned long offset) { struct page *first_page = get_first_page(page); -- 1.8.3.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>