zsmalloc: zs_compact refactoring
Hello Minchan Kim,
The patch 9a0346061ab8: "zsmalloc: zs_compact refactoring" from Apr 2, 2016, leads to the following static checker warning:
mm/zsmalloc.c:1851 handle_from_obj() warn: bit shifter 'OBJ_ALLOCATED_TAG' used for logical '&'
mm/zsmalloc.c
1622 static unsigned long obj_malloc(struct size_class *class,
1623 struct page *first_page, unsigned long handle)
1624 {
1625 unsigned long obj;
1626 struct link_free *link;
1627
1628 struct page *m_page;
1629 unsigned long m_offset;
1630 void *vaddr;
1631
1632 obj = get_freeobj(first_page);
1633 objidx_to_page_and_offset(class, first_page, obj,
1634 &m_page, &m_offset);
1635
1636 vaddr = kmap_atomic(m_page);
1637 link = (struct link_free *)vaddr + m_offset / sizeof(*link);
1638 set_freeobj(first_page, link->next >> OBJ_ALLOCATED_TAG);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^OBJ_ALLOCATED_TAG is 1. Here it's used as a shifter.
1639 if (!class->huge)
1640 /* record handle in the header of allocated chunk */
1641 link->handle = handle | OBJ_ALLOCATED_TAG;
Here it's a bit mask. It's sort of confusing to re-use it like this. It's done through out the file.
1642 else 1643 /* record handle in first_page->private */ 1644 set_page_private(first_page, handle | OBJ_ALLOCATED_TAG); 1645 kunmap_atomic(vaddr); 1646 mod_zspage_inuse(first_page, 1); 1647 1648 obj = location_to_obj(m_page, obj); 1649 1650 return obj; 1651 }
regards,
dan carpenter
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hello Dan,
Quoted 27 lines · Dan Carpenter
Hello Minchan Kim,
The patch
9a0346061ab8: "zsmalloc:zs_compactrefactoring" from Apr 2, 2016, leads to the following static checker warning:mm/zsmalloc.c:1851 handle_from_obj() warn: bit shifter 'OBJ_ALLOCATED_TAG' used for logical '&'
mm/zsmalloc.c
1622 static unsigned long obj_malloc(structsize_class*class,
1623 struct page*first_page, unsigned long handle)
1624 {
1625 unsigned long obj;
1626 structlink_free*link;
16271628 struct page *m_page; 1629 unsigned long m_offset; 1630 void *vaddr; 1631 1632 obj = get_freeobj(first_page); 1633 objidx_to_page_and_offset(class, first_page, obj, 1634 &m_page, &m_offset); 1635 1636 vaddr = kmap_atomic(m_page); 1637 link = (struct link_free *)vaddr + m_offset / sizeof(*link); 1638 set_freeobj(first_page, link->next >> OBJ_ALLOCATED_TAG); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 8 lines
OBJ_ALLOCATED_TAGis 1. Here it's used as a shifter.1639 if (!class->huge)
1640 /* record handle in the header of allocated chunk */
1641link->handle= handle |OBJ_ALLOCATED_TAG;Here it's a bit mask. It's sort of confusing to re-use it like this. It's done through out the file.
I will send clean up patch.
Thanks.
Quoted 12 lines
1642 else 1643 /* record handle in first_page->private */ 1644 set_page_private(first_page, handle | OBJ_ALLOCATED_TAG); 1645 kunmap_atomic(vaddr); 1646 mod_zspage_inuse(first_page, 1); 1647 1648 obj = location_to_obj(m_page, obj); 1649 1650 return obj; 1651 }
Quoted 2 lines
regards,
dan carpenter
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>