@@ -877,13 +877,21 @@ static unsigned long handle_to_obj(unsigned long handle)
877
877
return * (unsigned long * )handle ;
878
878
}
879
879
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 )
881
881
{
882
+ unsigned long handle ;
883
+
882
884
if (unlikely (PageHugeObject (page ))) {
883
885
VM_BUG_ON_PAGE (!is_first_page (page ), page );
884
- return page -> index ;
886
+ handle = page -> index ;
885
887
} 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;
887
895
}
888
896
889
897
static inline int testpin_tag (unsigned long handle )
@@ -1606,7 +1614,6 @@ static void zs_object_copy(struct size_class *class, unsigned long dst,
1606
1614
static unsigned long find_alloced_obj (struct size_class * class ,
1607
1615
struct page * page , int * obj_idx )
1608
1616
{
1609
- unsigned long head ;
1610
1617
int offset = 0 ;
1611
1618
int index = * obj_idx ;
1612
1619
unsigned long handle = 0 ;
@@ -1616,9 +1623,7 @@ static unsigned long find_alloced_obj(struct size_class *class,
1616
1623
offset += class -> size * index ;
1617
1624
1618
1625
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 )) {
1622
1627
if (trypin_tag (handle ))
1623
1628
break ;
1624
1629
handle = 0 ;
@@ -1928,7 +1933,7 @@ static int zs_page_migrate(struct address_space *mapping, struct page *newpage,
1928
1933
struct page * dummy ;
1929
1934
void * s_addr , * d_addr , * addr ;
1930
1935
int offset , pos ;
1931
- unsigned long handle , head ;
1936
+ unsigned long handle ;
1932
1937
unsigned long old_obj , new_obj ;
1933
1938
unsigned int obj_idx ;
1934
1939
int ret = - EAGAIN ;
@@ -1964,9 +1969,7 @@ static int zs_page_migrate(struct address_space *mapping, struct page *newpage,
1964
1969
pos = offset ;
1965
1970
s_addr = kmap_atomic (page );
1966
1971
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 )) {
1970
1973
if (!trypin_tag (handle ))
1971
1974
goto unpin_objects ;
1972
1975
}
@@ -1982,9 +1985,7 @@ static int zs_page_migrate(struct address_space *mapping, struct page *newpage,
1982
1985
1983
1986
for (addr = s_addr + offset ; addr < s_addr + pos ;
1984
1987
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 )) {
1988
1989
BUG_ON (!testpin_tag (handle ));
1989
1990
1990
1991
old_obj = handle_to_obj (handle );
@@ -2029,9 +2030,7 @@ static int zs_page_migrate(struct address_space *mapping, struct page *newpage,
2029
2030
unpin_objects :
2030
2031
for (addr = s_addr + offset ; addr < s_addr + pos ;
2031
2032
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 )) {
2035
2034
BUG_ON (!testpin_tag (handle ));
2036
2035
unpin_tag (handle );
2037
2036
}
0 commit comments