All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhouping Liu <zliu@redhat.com>
To: David Rientjes <rientjes@google.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>,
	Hugh Dickins <hughd@google.com>, Mel Gorman <mgorman@suse.de>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Amos Kong <akong@redhat.com>
Subject: Re: THP: AnonHugePages in /proc/[pid]/smaps is correct or not?
Date: Tue, 02 Apr 2013 11:09:05 +0800	[thread overview]
Message-ID: <515A4BD1.1020407@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1304011512490.17714@chino.kir.corp.google.com>

On 04/02/2013 06:23 AM, David Rientjes wrote:
> On Mon, 1 Apr 2013, Zhouping Liu wrote:
>
>> Hi all,
>>
>> I found THP can't correctly distinguish one anonymous hugepage map.
>>
>> 1. when /sys/kernel/mm/transparent_hugepage/enabled is 'always', the
>>     amount of THP always is one less.
>>
> It's not a problem with identifying an anonymous mapping as a hugepage,
> setting thp enabled to "always" does not guarantee that they will always
> be allocatable or that your mmap() will be 2MB aligned.  Your sample code
> is using mmap() instead of posix_memalign() so you'll probably only get
> 100% hugepages only 1/512th of the time.

I don't understand clearly the last sentence 'you'll probably only get 
100% hugepages only 1/512th of the time.'
could you please explain more details about 'only 1/512th of the time'?

>
>> 2. when /sys/kernel/mm/transparent_hugepage/enabled is 'madvise', THP can't
>>     distinguish any one anonymous hugepage size:
>>
>>     Testing code:
>> -------- snip --------
>> unsigned long hugepagesize = (1UL << 21);
>>
>> int main()
>> {
>> 	void *addr;
>> 	int i;
>>
>> 	printf("pid is %d\n", getpid());
>>
>> 	for (i = 0; i < 5; i++) {
>> 		addr = mmap(NULL, hugepagesize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
>>
>> 		if (addr == MAP_FAILED) {
>> 			perror("mmap");
>> 			return -1;
>> 		}
>>
>> 		if (madvise(addr, hugepagesize, MADV_HUGEPAGE) == -1) {
>> 			perror("madvise");
>> 			return -1;
>> 		}
>>
>> 		memset(addr, i, hugepagesize);
>> 	}
>>
>> 	sleep(50);
>>
>> 	return 0;
>> }
>> --------- snip ----------
>>
>> The result is that it can't find any AnonHugePages from /proc/[pid]/smaps :
>> -------------- snip -------
>> 7f0b38cd0000-7f0b396d0000 rw-p 00000000 00:00 0
>> Size:              10240 kB
>> Rss:               10240 kB
>> Pss:               10240 kB
>> Shared_Clean:          0 kB
>> Shared_Dirty:          0 kB
>> Private_Clean:         0 kB
>> Private_Dirty:     10240 kB
>> Referenced:        10240 kB
>> Anonymous:         10240 kB
>> AnonHugePages:         0 kB
>> Swap:                  0 kB
>> KernelPageSize:        4 kB
>> MMUPageSize:           4 kB
>> Locked:                0 kB
>> VmFlags: rd wr mr mw me ac
> "hg" would be shown in VmFlags if your MADV_HUGEPAGE was successful, are
> you sure this is the right vma?

I think it's the same issue as the above, according to the sample code, 
it does mmap() five times in total,
and each time it map 2MB anonymous maps, as all the maps maybe aren't 
2MB aligned, so "AnonHugePages"
show 0 kB, and no "hg" VmFalgs.

so, again, if I understand correctly, thp should tune the naturally 
aligned maps, such as generated by mmap()/malloc(),
make such maps 'hugepagesize' aligned if the maps or vma is equal and 
greater than 'hugepagesize', doesn't it?

Thanks,
Zhouping

WARNING: multiple messages have this Message-ID (diff)
From: Zhouping Liu <zliu@redhat.com>
To: David Rientjes <rientjes@google.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>,
	Hugh Dickins <hughd@google.com>, Mel Gorman <mgorman@suse.de>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Amos Kong <akong@redhat.com>
Subject: Re: THP: AnonHugePages in /proc/[pid]/smaps is correct or not?
Date: Tue, 02 Apr 2013 11:09:05 +0800	[thread overview]
Message-ID: <515A4BD1.1020407@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1304011512490.17714@chino.kir.corp.google.com>

On 04/02/2013 06:23 AM, David Rientjes wrote:
> On Mon, 1 Apr 2013, Zhouping Liu wrote:
>
>> Hi all,
>>
>> I found THP can't correctly distinguish one anonymous hugepage map.
>>
>> 1. when /sys/kernel/mm/transparent_hugepage/enabled is 'always', the
>>     amount of THP always is one less.
>>
> It's not a problem with identifying an anonymous mapping as a hugepage,
> setting thp enabled to "always" does not guarantee that they will always
> be allocatable or that your mmap() will be 2MB aligned.  Your sample code
> is using mmap() instead of posix_memalign() so you'll probably only get
> 100% hugepages only 1/512th of the time.

I don't understand clearly the last sentence 'you'll probably only get 
100% hugepages only 1/512th of the time.'
could you please explain more details about 'only 1/512th of the time'?

>
>> 2. when /sys/kernel/mm/transparent_hugepage/enabled is 'madvise', THP can't
>>     distinguish any one anonymous hugepage size:
>>
>>     Testing code:
>> -------- snip --------
>> unsigned long hugepagesize = (1UL << 21);
>>
>> int main()
>> {
>> 	void *addr;
>> 	int i;
>>
>> 	printf("pid is %d\n", getpid());
>>
>> 	for (i = 0; i < 5; i++) {
>> 		addr = mmap(NULL, hugepagesize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0);
>>
>> 		if (addr == MAP_FAILED) {
>> 			perror("mmap");
>> 			return -1;
>> 		}
>>
>> 		if (madvise(addr, hugepagesize, MADV_HUGEPAGE) == -1) {
>> 			perror("madvise");
>> 			return -1;
>> 		}
>>
>> 		memset(addr, i, hugepagesize);
>> 	}
>>
>> 	sleep(50);
>>
>> 	return 0;
>> }
>> --------- snip ----------
>>
>> The result is that it can't find any AnonHugePages from /proc/[pid]/smaps :
>> -------------- snip -------
>> 7f0b38cd0000-7f0b396d0000 rw-p 00000000 00:00 0
>> Size:              10240 kB
>> Rss:               10240 kB
>> Pss:               10240 kB
>> Shared_Clean:          0 kB
>> Shared_Dirty:          0 kB
>> Private_Clean:         0 kB
>> Private_Dirty:     10240 kB
>> Referenced:        10240 kB
>> Anonymous:         10240 kB
>> AnonHugePages:         0 kB
>> Swap:                  0 kB
>> KernelPageSize:        4 kB
>> MMUPageSize:           4 kB
>> Locked:                0 kB
>> VmFlags: rd wr mr mw me ac
> "hg" would be shown in VmFlags if your MADV_HUGEPAGE was successful, are
> you sure this is the right vma?

I think it's the same issue as the above, according to the sample code, 
it does mmap() five times in total,
and each time it map 2MB anonymous maps, as all the maps maybe aren't 
2MB aligned, so "AnonHugePages"
show 0 kB, and no "hg" VmFalgs.

so, again, if I understand correctly, thp should tune the naturally 
aligned maps, such as generated by mmap()/malloc(),
make such maps 'hugepagesize' aligned if the maps or vma is equal and 
greater than 'hugepagesize', doesn't it?

Thanks,
Zhouping

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

  reply	other threads:[~2013-04-02  3:11 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1207916095.642011.1364800448075.JavaMail.root@redhat.com>
2013-04-01  8:00 ` THP: AnonHugePages in /proc/[pid]/smaps is correct or not? Zhouping Liu
2013-04-01  8:00   ` Zhouping Liu
2013-04-01 22:23   ` David Rientjes
2013-04-01 22:23     ` David Rientjes
2013-04-02  3:09     ` Zhouping Liu [this message]
2013-04-02  3:09       ` Zhouping Liu
2013-04-02  3:40       ` Lin Feng
2013-04-02  3:40         ` Lin Feng
2013-04-02  3:44         ` David Rientjes
2013-04-02  3:44           ` David Rientjes
2013-04-02  3:48         ` Zhouping Liu
2013-04-02  3:48           ` Zhouping Liu
2013-04-02 12:23     ` Simon Jeons
2013-04-02 12:23       ` Simon Jeons
2013-04-02 18:09       ` David Rientjes
2013-04-02 18:09         ` David Rientjes
2013-04-02 23:58         ` Simon Jeons
2013-04-02 23:58           ` Simon Jeons
2013-04-02 12:26     ` Simon Jeons
2013-04-02 12:26       ` Simon Jeons

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=515A4BD1.1020407@redhat.com \
    --to=zliu@redhat.com \
    --cc=aarcange@redhat.com \
    --cc=akong@redhat.com \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=rientjes@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.