[PATCH] smaps should deal with huge zero page exactly same as normal zero page.

From: Fengwei Yin
Date: Thu Oct 09 2014 - 10:20:58 EST


Signed-off-by: Fengwei Yin <yfw.kernel@xxxxxxxxx>
---
fs/proc/task_mmu.c | 6 ++++--
include/linux/huge_mm.h | 2 ++
mm/huge_memory.c | 5 +++++
mm/memory.c | 4 ++++
4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index c341568..fb19c0c 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -471,8 +471,11 @@ static void smaps_pte_entry(pte_t ptent, unsigned long addr,
if (!page)
return;

- if (PageAnon(page))
+ if (PageAnon(page)) {
mss->anonymous += ptent_size;
+ if (PageTransHuge(page))
+ mss->anonymous_thp += HPAGE_PMD_SIZE;
+ }

if (page->index != pgoff)
mss->nonlinear += ptent_size;
@@ -508,7 +511,6 @@ static int smaps_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
if (pmd_trans_huge_lock(pmd, vma, &ptl) == 1) {
smaps_pte_entry(*(pte_t *)pmd, addr, HPAGE_PMD_SIZE, walk);
spin_unlock(ptl);
- mss->anonymous_thp += HPAGE_PMD_SIZE;
return 0;
}

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 63579cb..9bf6263 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -34,6 +34,8 @@ extern int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
unsigned long addr, pgprot_t newprot,
int prot_numa);

+extern bool is_huge_zero_pfn(unsigned long pfn);
+
enum transparent_hugepage_flag {
TRANSPARENT_HUGEPAGE_FLAG,
TRANSPARENT_HUGEPAGE_REQ_MADV_FLAG,
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index f8ffd94..71ca4ed 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -183,6 +183,11 @@ static inline bool is_huge_zero_pmd(pmd_t pmd)
return is_huge_zero_page(pmd_page(pmd));
}

+inline bool is_huge_zero_pfn(unsigned long pfn)
+{
+ return is_huge_zero_page(pfn_to_page(pfn));
+}
+
static struct page *get_huge_zero_page(void)
{
struct page *zero_page;
diff --git a/mm/memory.c b/mm/memory.c
index e229970..5f5ecbc 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -41,6 +41,7 @@
#include <linux/kernel_stat.h>
#include <linux/mm.h>
#include <linux/hugetlb.h>
+#include <linux/huge_mm.h>
#include <linux/mman.h>
#include <linux/swap.h>
#include <linux/highmem.h>
@@ -787,6 +788,9 @@ check_pfn:
return NULL;
}

+ if (is_huge_zero_pfn(pfn))
+ return NULL;
+
/*
* NOTE! We still have PageReserved() pages in the page tables.
* eg. VDSO mappings can cause them to exist.
--
2.0.1


--GID0FwUMdk1T2AWN--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/