linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* re: zsmalloc: support compaction
@ 2016-06-06 20:11 Dan Carpenter
  2016-06-07  4:51 ` Minchan Kim
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2016-06-06 20:11 UTC (permalink / raw)
  To: minchan; +Cc: Sergey Senozhatsky, linux-mm

Hello Minchan Kim,

The patch 312fcae22703: "zsmalloc: support compaction" from Apr 15,
2015, leads to the following static checker warning:

	mm/zsmalloc.c:1521 obj_malloc()
	warn: 'OBJ_ALLOCATED_TAG' is a shifter (not for '|=').

mm/zsmalloc.c
  1510  static unsigned long obj_malloc(struct size_class *class,
  1511                                  struct zspage *zspage, unsigned long handle)
  1512  {
  1513          int i, nr_page, offset;
  1514          unsigned long obj;
  1515          struct link_free *link;
  1516  
  1517          struct page *m_page;
  1518          unsigned long m_offset;
  1519          void *vaddr;
  1520  
  1521          handle |= OBJ_ALLOCATED_TAG;
                          ^^^^^^^^^^^^^^^^^
It's weird to use the same define for a bit number

  1522          obj = get_freeobj(zspage);
  1523  
  1524          offset = obj * class->size;
  1525          nr_page = offset >> PAGE_SHIFT;
  1526          m_offset = offset & ~PAGE_MASK;
  1527          m_page = get_first_page(zspage);
  1528  
  1529          for (i = 0; i < nr_page; i++)
  1530                  m_page = get_next_page(m_page);
  1531  
  1532          vaddr = kmap_atomic(m_page);
  1533          link = (struct link_free *)vaddr + m_offset / sizeof(*link);
  1534          set_freeobj(zspage, link->next >> OBJ_ALLOCATED_TAG);
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
And also a bit shifter.  TAG normally implies it is a bit and not a
shift?

  1535          if (likely(!PageHugeObject(m_page)))
  1536                  /* record handle in the header of allocated chunk */
  1537                  link->handle = handle;
  1538          else
  1539                  /* record handle to page->index */
  1540                  zspage->first_page->index = handle;
  1541  
  1542          kunmap_atomic(vaddr);
  1543          mod_zspage_inuse(zspage, 1);
  1544          zs_stat_inc(class, OBJ_USED, 1);
  1545  
  1546          obj = location_to_obj(m_page, obj);
  1547  
  1548          return obj;
  1549  }

regards,
dan carpenter

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: zsmalloc: support compaction
  2016-06-06 20:11 zsmalloc: support compaction Dan Carpenter
@ 2016-06-07  4:51 ` Minchan Kim
  0 siblings, 0 replies; 2+ messages in thread
From: Minchan Kim @ 2016-06-07  4:51 UTC (permalink / raw)
  To: Dan Carpenter, Andrew Morton; +Cc: Sergey Senozhatsky, linux-mm

On Mon, Jun 06, 2016 at 11:11:51PM +0300, Dan Carpenter wrote:
> Hello Minchan Kim,
> 
> The patch 312fcae22703: "zsmalloc: support compaction" from Apr 15,
> 2015, leads to the following static checker warning:
> 
> 	mm/zsmalloc.c:1521 obj_malloc()
> 	warn: 'OBJ_ALLOCATED_TAG' is a shifter (not for '|=').
> 
> mm/zsmalloc.c
>   1510  static unsigned long obj_malloc(struct size_class *class,
>   1511                                  struct zspage *zspage, unsigned long handle)
>   1512  {
>   1513          int i, nr_page, offset;
>   1514          unsigned long obj;
>   1515          struct link_free *link;
>   1516  
>   1517          struct page *m_page;
>   1518          unsigned long m_offset;
>   1519          void *vaddr;
>   1520  
>   1521          handle |= OBJ_ALLOCATED_TAG;
>                           ^^^^^^^^^^^^^^^^^
> It's weird to use the same define for a bit number
> 
>   1522          obj = get_freeobj(zspage);
>   1523  
>   1524          offset = obj * class->size;
>   1525          nr_page = offset >> PAGE_SHIFT;
>   1526          m_offset = offset & ~PAGE_MASK;
>   1527          m_page = get_first_page(zspage);
>   1528  
>   1529          for (i = 0; i < nr_page; i++)
>   1530                  m_page = get_next_page(m_page);
>   1531  
>   1532          vaddr = kmap_atomic(m_page);
>   1533          link = (struct link_free *)vaddr + m_offset / sizeof(*link);
>   1534          set_freeobj(zspage, link->next >> OBJ_ALLOCATED_TAG);
>                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> And also a bit shifter.  TAG normally implies it is a bit and not a
> shift?

Thanks for the report, Dan!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-06-07  4:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-06 20:11 zsmalloc: support compaction Dan Carpenter
2016-06-07  4:51 ` Minchan Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).