Skip to content

Commit 3ae92ac

Browse files
minchanktorvalds
authored andcommitted
zsmalloc: introduce obj_allocated
The usage pattern for obj_to_head is to check whether the zpage is allocated or not. Thus, introduce obj_allocated. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Minchan Kim <[email protected]> Acked-by: Sebastian Andrzej Siewior <[email protected]> Tested-by: Sebastian Andrzej Siewior <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Peter Zijlstra (Intel) <[email protected]> Cc: Sergey Senozhatsky <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 0a5f079 commit 3ae92ac

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

mm/zsmalloc.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -877,13 +877,21 @@ static unsigned long handle_to_obj(unsigned long handle)
877877
return *(unsigned long *)handle;
878878
}
879879

880-
static unsigned long obj_to_head(struct page *page, void *obj)
880+
static bool obj_allocated(struct page *page, void *obj, unsigned long *phandle)
881881
{
882+
unsigned long handle;
883+
882884
if (unlikely(PageHugeObject(page))) {
883885
VM_BUG_ON_PAGE(!is_first_page(page), page);
884-
return page->index;
886+
handle = page->index;
885887
} else
886-
return *(unsigned long *)obj;
888+
handle = *(unsigned long *)obj;
889+
890+
if (!(handle & OBJ_ALLOCATED_TAG))
891+
return false;
892+
893+
*phandle = handle & ~OBJ_ALLOCATED_TAG;
894+
return true;
887895
}
888896

889897
static inline int testpin_tag(unsigned long handle)
@@ -1606,7 +1614,6 @@ static void zs_object_copy(struct size_class *class, unsigned long dst,
16061614
static unsigned long find_alloced_obj(struct size_class *class,
16071615
struct page *page, int *obj_idx)
16081616
{
1609-
unsigned long head;
16101617
int offset = 0;
16111618
int index = *obj_idx;
16121619
unsigned long handle = 0;
@@ -1616,9 +1623,7 @@ static unsigned long find_alloced_obj(struct size_class *class,
16161623
offset += class->size * index;
16171624

16181625
while (offset < PAGE_SIZE) {
1619-
head = obj_to_head(page, addr + offset);
1620-
if (head & OBJ_ALLOCATED_TAG) {
1621-
handle = head & ~OBJ_ALLOCATED_TAG;
1626+
if (obj_allocated(page, addr + offset, &handle)) {
16221627
if (trypin_tag(handle))
16231628
break;
16241629
handle = 0;
@@ -1928,7 +1933,7 @@ static int zs_page_migrate(struct address_space *mapping, struct page *newpage,
19281933
struct page *dummy;
19291934
void *s_addr, *d_addr, *addr;
19301935
int offset, pos;
1931-
unsigned long handle, head;
1936+
unsigned long handle;
19321937
unsigned long old_obj, new_obj;
19331938
unsigned int obj_idx;
19341939
int ret = -EAGAIN;
@@ -1964,9 +1969,7 @@ static int zs_page_migrate(struct address_space *mapping, struct page *newpage,
19641969
pos = offset;
19651970
s_addr = kmap_atomic(page);
19661971
while (pos < PAGE_SIZE) {
1967-
head = obj_to_head(page, s_addr + pos);
1968-
if (head & OBJ_ALLOCATED_TAG) {
1969-
handle = head & ~OBJ_ALLOCATED_TAG;
1972+
if (obj_allocated(page, s_addr + pos, &handle)) {
19701973
if (!trypin_tag(handle))
19711974
goto unpin_objects;
19721975
}
@@ -1982,9 +1985,7 @@ static int zs_page_migrate(struct address_space *mapping, struct page *newpage,
19821985

19831986
for (addr = s_addr + offset; addr < s_addr + pos;
19841987
addr += class->size) {
1985-
head = obj_to_head(page, addr);
1986-
if (head & OBJ_ALLOCATED_TAG) {
1987-
handle = head & ~OBJ_ALLOCATED_TAG;
1988+
if (obj_allocated(page, addr, &handle)) {
19881989
BUG_ON(!testpin_tag(handle));
19891990

19901991
old_obj = handle_to_obj(handle);
@@ -2029,9 +2030,7 @@ static int zs_page_migrate(struct address_space *mapping, struct page *newpage,
20292030
unpin_objects:
20302031
for (addr = s_addr + offset; addr < s_addr + pos;
20312032
addr += class->size) {
2032-
head = obj_to_head(page, addr);
2033-
if (head & OBJ_ALLOCATED_TAG) {
2034-
handle = head & ~OBJ_ALLOCATED_TAG;
2033+
if (obj_allocated(page, addr, &handle)) {
20352034
BUG_ON(!testpin_tag(handle));
20362035
unpin_tag(handle);
20372036
}

0 commit comments

Comments
 (0)