linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hugh Dickins <hughd@google.com>
To: David Rientjes <rientjes@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Andrea Arcangeli <aarcange@redhat.com>,
	Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Michel Lespinasse <walken@google.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	stable@vger.kernel.org
Subject: Re: [patch] mm, thp: fix mlock statistics
Date: Thu, 27 Sep 2012 18:32:33 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LSU.2.00.1209271814340.2107@eggly.anvils> (raw)
In-Reply-To: <alpine.DEB.2.00.1209261929270.8567@chino.kir.corp.google.com>

On Wed, 26 Sep 2012, David Rientjes wrote:

> NR_MLOCK is only accounted in single page units: there's no logic to
> handle transparent hugepages.  This patch checks the appropriate number
> of pages to adjust the statistics by so that the correct amount of memory
> is reflected.
> 
> Currently:
> 
> 		$ grep Mlocked /proc/meminfo
> 		Mlocked:           19636 kB
> 
> 	#define MAP_SIZE	(4 << 30)	/* 4GB */
> 
> 	void *ptr = mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE,
> 			 MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
> 	mlock(ptr, MAP_SIZE);
> 
> 		$ grep Mlocked /proc/meminfo
> 		Mlocked:           29844 kB
> 
> 	munlock(ptr, MAP_SIZE);
> 
> 		$ grep Mlocked /proc/meminfo
> 		Mlocked:           19636 kB
> 
> And with this patch:
> 
> 		$ grep Mlock /proc/meminfo
> 		Mlocked:           19636 kB
> 
> 	mlock(ptr, MAP_SIZE);
> 
> 		$ grep Mlock /proc/meminfo
> 		Mlocked:         4213664 kB
> 
> 	munlock(ptr, MAP_SIZE);
> 
> 		$ grep Mlock /proc/meminfo
> 		Mlocked:           19636 kB
> 
> Reported-by: Hugh Dickens <hughd@google.com>

I do prefer         Dickins :)

> Signed-off-by: David Rientjes <rientjes@google.com>

Acked-by: Hugh Dickins <hughd@google.com>

Yes, this now seems to be working nicely, thanks.

I would have preferred you to omit the free_page_mlock() part, since
that sets me wondering about what flags might be set to mean what at
that point; but since it should never get there anyway, and we'll be
removing it entirely from v3.7, never mind.  (In doing that, I shall
need to consider whether clear_page_mlock() then needs hpage_nr_pages,
but your patch below is perfectly correct to omit it.)

If I understand aright, in another (thp: avoid VM_BUG_ON) thread,
Linus remarks that he's noticed this and your matching Unevictable
patch (that I had thought too late for v3.6), and is hoping for Acks
so that he can put them into v3.6 after all.

So despite my earlier reluctance, please take this as an Ack on that
one too (I was testing them together): it'll be odd if one of them goes
to stable and the other not, but we can sort that out with GregKH later.

Hugh

> ---
>  mm/internal.h   |    3 ++-
>  mm/mlock.c      |    6 ++++--
>  mm/page_alloc.c |    2 +-
>  3 files changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/mm/internal.h b/mm/internal.h
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -180,7 +180,8 @@ static inline int mlocked_vma_newpage(struct vm_area_struct *vma,
>  		return 0;
>  
>  	if (!TestSetPageMlocked(page)) {
> -		inc_zone_page_state(page, NR_MLOCK);
> +		mod_zone_page_state(page_zone(page), NR_MLOCK,
> +				    hpage_nr_pages(page));
>  		count_vm_event(UNEVICTABLE_PGMLOCKED);
>  	}
>  	return 1;
> diff --git a/mm/mlock.c b/mm/mlock.c
> --- a/mm/mlock.c
> +++ b/mm/mlock.c
> @@ -81,7 +81,8 @@ void mlock_vma_page(struct page *page)
>  	BUG_ON(!PageLocked(page));
>  
>  	if (!TestSetPageMlocked(page)) {
> -		inc_zone_page_state(page, NR_MLOCK);
> +		mod_zone_page_state(page_zone(page), NR_MLOCK,
> +				    hpage_nr_pages(page));
>  		count_vm_event(UNEVICTABLE_PGMLOCKED);
>  		if (!isolate_lru_page(page))
>  			putback_lru_page(page);
> @@ -108,7 +109,8 @@ void munlock_vma_page(struct page *page)
>  	BUG_ON(!PageLocked(page));
>  
>  	if (TestClearPageMlocked(page)) {
> -		dec_zone_page_state(page, NR_MLOCK);
> +		mod_zone_page_state(page_zone(page), NR_MLOCK,
> +				    -hpage_nr_pages(page));
>  		if (!isolate_lru_page(page)) {
>  			int ret = SWAP_AGAIN;
>  
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -604,7 +604,7 @@ out:
>   */
>  static inline void free_page_mlock(struct page *page)
>  {
> -	__dec_zone_page_state(page, NR_MLOCK);
> +	__mod_zone_page_state(page_zone(page), NR_MLOCK, -hpage_nr_pages(page));
>  	__count_vm_event(UNEVICTABLE_MLOCKFREED);
>  }
>  
> 

--
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:[~2012-09-28  1:33 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-20  1:19 [patch for-3.6] mm, thp: fix mapped pages avoiding unevictable list on mlock David Rientjes
2012-09-20  4:01 ` Hugh Dickins
2012-09-27  1:40   ` David Rientjes
2012-09-27  1:54     ` Hugh Dickins
2012-09-27  2:29     ` [patch] mm, thp: fix mlock statistics David Rientjes
2012-09-28  1:32       ` Hugh Dickins [this message]
2012-10-03 20:10         ` Andrew Morton
2012-10-03 21:10           ` [patch -mm] mm, thp: fix mlock statistics fix David Rientjes
2012-10-03 21:25             ` Andrew Morton
2012-10-03 21:46               ` Hugh Dickins
2012-10-03 21:29             ` Hugh Dickins
2012-09-28 13:51       ` [patch] mm, thp: fix mlock statistics Andrea Arcangeli
2012-09-29  0:11       ` Michel Lespinasse
2012-10-01 15:22     ` [patch for-3.6] mm, thp: fix mapped pages avoiding unevictable list on mlock Linus Torvalds
2012-09-28 13:30 ` Andrea Arcangeli

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=alpine.LSU.2.00.1209271814340.2107@eggly.anvils \
    --to=hughd@google.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=n-horiguchi@ah.jp.nec.com \
    --cc=rientjes@google.com \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=walken@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox