Re: [PATCH v1 11/19] zsmalloc: squeeze freelist into page->mapping

From
Minchan Kim <minchan@kernel.org>
Date
2016-03-15 06:51:26
On Tue, Mar 15, 2016 at 03:40:53PM +0900, Sergey Senozhatsky wrote:
On (03/11/16 16:30), Minchan Kim wrote:
quoted
-static void *location_to_obj(struct page *page, unsigned long obj_idx)
+static void objidx_to_page_and_ofs(struct size_class *class,
+				struct page *first_page,
+				unsigned long obj_idx,
+				struct page **obj_page,
+				unsigned long *ofs_in_page)
this looks big; 5 params, function "returning" both page and offset...
any chance to split it in two steps, perhaps?
Yes, it's rather ugly but I don't have a good idea.
Feel free to suggest if you have a better idea.
besides, it is more intuitive (at least to me) when 'offset'
shortened to 'offt', not 'ofs'.
Indeed. I will change it to get_page_and_offset instead of
abbreviation if we cannot refactor it more.
	-ss
quoted
 {
-	unsigned long obj;
+	int i;
+	unsigned long ofs;
+	struct page *cursor;
+	int nr_page;
 
-	if (!page) {
-		VM_BUG_ON(obj_idx);
-		return NULL;
-	}
+	ofs = obj_idx * class->size;
+	cursor = first_page;
+	nr_page = ofs >> PAGE_SHIFT;
 
-	obj = page_to_pfn(page) << OBJ_INDEX_BITS;
-	obj |= ((obj_idx) & OBJ_INDEX_MASK);
-	obj <<= OBJ_TAG_BITS;
+	*ofs_in_page = ofs & ~PAGE_MASK;
+
+	for (i = 0; i < nr_page; i++)
+		cursor = get_next_page(cursor);
 
-	return (void *)obj;
+	*obj_page = cursor;
 }
Thread (1 message) 1 message, 1 author, last reply 2016-03-15
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help