linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] zsmalloc: fix obj_to_head use page_private(page) as value but not pointer
@ 2015-10-05  8:23 Hui Zhu
  2015-10-06 10:59 ` Sergey Senozhatsky
  2015-10-06 13:54 ` Minchan Kim
  0 siblings, 2 replies; 5+ messages in thread
From: Hui Zhu @ 2015-10-05  8:23 UTC (permalink / raw)
  To: minchan, ngupta, linux-mm, linux-kernel; +Cc: teawater, Hui Zhu

In function obj_malloc:
	if (!class->huge)
		/* record handle in the header of allocated chunk */
		link->handle = handle;
	else
		/* record handle in first_page->private */
		set_page_private(first_page, handle);
The huge's page save handle to private directly.

But in obj_to_head:
	if (class->huge) {
		VM_BUG_ON(!is_first_page(page));
		return page_private(page);
	} else
		return *(unsigned long *)obj;
It is used as a pointer.

So change obj_to_head use page_private(page) as value but not pointer
in obj_to_head.

Signed-off-by: Hui Zhu <zhuhui@xiaomi.com>
---
 mm/zsmalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index f135b1b..e881d4f 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -824,7 +824,7 @@ static unsigned long obj_to_head(struct size_class *class, struct page *page,
 {
 	if (class->huge) {
 		VM_BUG_ON(!is_first_page(page));
-		return *(unsigned long *)page_private(page);
+		return page_private(page);
 	} else
 		return *(unsigned long *)obj;
 }
-- 
1.9.1


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

* Re: [PATCH] zsmalloc: fix obj_to_head use page_private(page) as value but not pointer
  2015-10-05  8:23 [PATCH] zsmalloc: fix obj_to_head use page_private(page) as value but not pointer Hui Zhu
@ 2015-10-06 10:59 ` Sergey Senozhatsky
  2015-10-06 13:54 ` Minchan Kim
  1 sibling, 0 replies; 5+ messages in thread
From: Sergey Senozhatsky @ 2015-10-06 10:59 UTC (permalink / raw)
  To: Hui Zhu
  Cc: minchan, linux-mm, linux-kernel, teawater, Andrew Morton,
	Sergey Senozhatsky

On (10/05/15 16:23), Hui Zhu wrote:
> In function obj_malloc:
> 	if (!class->huge)
> 		/* record handle in the header of allocated chunk */
> 		link->handle = handle;
> 	else
> 		/* record handle in first_page->private */
> 		set_page_private(first_page, handle);
> The huge's page save handle to private directly.
> 
> But in obj_to_head:
> 	if (class->huge) {
> 		VM_BUG_ON(!is_first_page(page));
> 		return page_private(page);
> 	} else
> 		return *(unsigned long *)obj;
> It is used as a pointer.
> 

um...
obj_to_head() is not for obj_malloc(), but for record_obj() that follows.
handle is a `void *' returned from alloc_handle()->kmem_cache_alloc(), and
casted to 'unsigned long'.

we store obj as:

static void record_obj(unsigned long handle, unsigned long obj)
{
	*(unsigned long *)handle = obj;
}

regardless `class->huge'.


and retrieve it as  `*(unsigned long *)foo', which is either
	`*(unsigned long *)page_private(page)'
or
	`*(unsigned long *)obj'

'return p' and `return *p' do slightly different things for pointers.


am I missing something?

	-ss

> So change obj_to_head use page_private(page) as value but not pointer
> in obj_to_head.
> 
> Signed-off-by: Hui Zhu <zhuhui@xiaomi.com>
> ---
>  mm/zsmalloc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> index f135b1b..e881d4f 100644
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
> @@ -824,7 +824,7 @@ static unsigned long obj_to_head(struct size_class *class, struct page *page,
>  {
>  	if (class->huge) {
>  		VM_BUG_ON(!is_first_page(page));
> -		return *(unsigned long *)page_private(page);
> +		return page_private(page);
>  	} else
>  		return *(unsigned long *)obj;
>  }
> -- 
> 1.9.1
> 
> --
> 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] 5+ messages in thread

* Re: [PATCH] zsmalloc: fix obj_to_head use page_private(page) as value but not pointer
  2015-10-05  8:23 [PATCH] zsmalloc: fix obj_to_head use page_private(page) as value but not pointer Hui Zhu
  2015-10-06 10:59 ` Sergey Senozhatsky
@ 2015-10-06 13:54 ` Minchan Kim
  2015-10-07  4:44   ` Hui Zhu
  2015-10-07  4:45   ` [PATCH v2] " Hui Zhu
  1 sibling, 2 replies; 5+ messages in thread
From: Minchan Kim @ 2015-10-06 13:54 UTC (permalink / raw)
  To: Hui Zhu
  Cc: ngupta, linux-mm, linux-kernel, teawater, Andrew Morton,
	Sergey Senozhatsky

Hello,

On Mon, Oct 05, 2015 at 04:23:01PM +0800, Hui Zhu wrote:
> In function obj_malloc:
> 	if (!class->huge)
> 		/* record handle in the header of allocated chunk */
> 		link->handle = handle;
> 	else
> 		/* record handle in first_page->private */
> 		set_page_private(first_page, handle);
> The huge's page save handle to private directly.
> 
> But in obj_to_head:
> 	if (class->huge) {
> 		VM_BUG_ON(!is_first_page(page));
> 		return page_private(page);

Typo.
 		return *(unsigned long*)page_private(page);

Please fix the description.

> 	} else
> 		return *(unsigned long *)obj;
> It is used as a pointer.
> 
> So change obj_to_head use page_private(page) as value but not pointer
> in obj_to_head.

The reason why there is no problem until now is huge-class page is
born with ZS_FULL so it couldn't be migrated.
Therefore, it shouldn't be real bug in practice.
However, we need this patch for future-work "VM-aware zsmalloced
page migration" to reduce external fragmentation.

> 
> Signed-off-by: Hui Zhu <zhuhui@xiaomi.com>

With fixing the comment,

Acked-by: Minchan Kim <minchan@kernel.org>

Thanks for the fix, Hui.

-- 
Kind regards,
Minchan Kim

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

* Re: [PATCH] zsmalloc: fix obj_to_head use page_private(page) as value but not pointer
  2015-10-06 13:54 ` Minchan Kim
@ 2015-10-07  4:44   ` Hui Zhu
  2015-10-07  4:45   ` [PATCH v2] " Hui Zhu
  1 sibling, 0 replies; 5+ messages in thread
From: Hui Zhu @ 2015-10-07  4:44 UTC (permalink / raw)
  To: Minchan Kim
  Cc: Hui Zhu, ngupta, Linux Memory Management List, linux-kernel,
	Andrew Morton, Sergey Senozhatsky

On Tue, Oct 6, 2015 at 9:54 PM, Minchan Kim <minchan@kernel.org> wrote:
> Hello,
>
> On Mon, Oct 05, 2015 at 04:23:01PM +0800, Hui Zhu wrote:
>> In function obj_malloc:
>>       if (!class->huge)
>>               /* record handle in the header of allocated chunk */
>>               link->handle = handle;
>>       else
>>               /* record handle in first_page->private */
>>               set_page_private(first_page, handle);
>> The huge's page save handle to private directly.
>>
>> But in obj_to_head:
>>       if (class->huge) {
>>               VM_BUG_ON(!is_first_page(page));
>>               return page_private(page);
>
> Typo.
>                 return *(unsigned long*)page_private(page);
>
> Please fix the description.
>
>>       } else
>>               return *(unsigned long *)obj;
>> It is used as a pointer.
>>
>> So change obj_to_head use page_private(page) as value but not pointer
>> in obj_to_head.
>
> The reason why there is no problem until now is huge-class page is
> born with ZS_FULL so it couldn't be migrated.
> Therefore, it shouldn't be real bug in practice.
> However, we need this patch for future-work "VM-aware zsmalloced
> page migration" to reduce external fragmentation.
>
>>
>> Signed-off-by: Hui Zhu <zhuhui@xiaomi.com>
>
> With fixing the comment,
>
> Acked-by: Minchan Kim <minchan@kernel.org>
>
> Thanks for the fix, Hui.
>

Thanks!  I will post a new version.

Best,
Hui

> --
> Kind regards,
> Minchan Kim

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

* [PATCH v2] zsmalloc: fix obj_to_head use page_private(page) as value but not pointer
  2015-10-06 13:54 ` Minchan Kim
  2015-10-07  4:44   ` Hui Zhu
@ 2015-10-07  4:45   ` Hui Zhu
  1 sibling, 0 replies; 5+ messages in thread
From: Hui Zhu @ 2015-10-07  4:45 UTC (permalink / raw)
  To: minchan, ngupta, linux-mm, linux-kernel
  Cc: teawater, akpm, sergey.senozhatsky, Hui Zhu

In function obj_malloc:
	if (!class->huge)
		/* record handle in the header of allocated chunk */
		link->handle = handle;
	else
		/* record handle in first_page->private */
		set_page_private(first_page, handle);
The huge's page save handle to private directly.

But in obj_to_head:
	if (class->huge) {
		VM_BUG_ON(!is_first_page(page));
		return *(unsigned long *)page_private(page);
	} else
		return *(unsigned long *)obj;
It is used as a pointer.

The reason why there is no problem until now is huge-class page is
born with ZS_FULL so it couldn't be migrated.
Therefore, it shouldn't be real bug in practice.
However, we need this patch for future-work "VM-aware zsmalloced
page migration" to reduce external fragmentation.

Signed-off-by: Hui Zhu <zhuhui@xiaomi.com>
Acked-by: Minchan Kim <minchan@kernel.org>
---
 mm/zsmalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index f135b1b..e881d4f 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -824,7 +824,7 @@ static unsigned long obj_to_head(struct size_class *class, struct page *page,
 {
 	if (class->huge) {
 		VM_BUG_ON(!is_first_page(page));
-		return *(unsigned long *)page_private(page);
+		return page_private(page);
 	} else
 		return *(unsigned long *)obj;
 }
-- 
1.9.1


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

end of thread, other threads:[~2015-10-07  4:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-05  8:23 [PATCH] zsmalloc: fix obj_to_head use page_private(page) as value but not pointer Hui Zhu
2015-10-06 10:59 ` Sergey Senozhatsky
2015-10-06 13:54 ` Minchan Kim
2015-10-07  4:44   ` Hui Zhu
2015-10-07  4:45   ` [PATCH v2] " Hui Zhu

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).