Skip to content

Commit

Permalink
mm, thp: fix mlock statistics
Browse files Browse the repository at this point in the history
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

Signed-off-by: David Rientjes <[email protected]>
Reported-by: Hugh Dickens <[email protected]>
Acked-by: Hugh Dickins <[email protected]>
Reviewed-by: Andrea Arcangeli <[email protected]>
Cc: Naoya Horiguchi <[email protected]>
Cc: KAMEZAWA Hiroyuki <[email protected]>
Cc: Johannes Weiner <[email protected]>
Reviewed-by: Michel Lespinasse <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
rientjes authored and torvalds committed Oct 9, 2012
1 parent b676b29 commit 8449d21
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion mm/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions mm/mlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ void clear_page_mlock(struct page *page)
if (!TestClearPageMlocked(page))
return;

dec_zone_page_state(page, NR_MLOCK);
mod_zone_page_state(page_zone(page), NR_MLOCK,
-hpage_nr_pages(page));
count_vm_event(UNEVICTABLE_PGCLEARED);
if (!isolate_lru_page(page)) {
putback_lru_page(page);
Expand All @@ -78,7 +79,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);
Expand All @@ -105,7 +107,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;

Expand Down

0 comments on commit 8449d21

Please sign in to comment.