Skip to content

Commit

Permalink
pagemap: avoid splitting thp when reading /proc/pid/pagemap
Browse files Browse the repository at this point in the history
Thp split is not necessary if we explicitly check whether pmds are mapping
thps or not.  This patch introduces this check and adds code to generate
pagemap entries for pmds mapping thps, which results in less performance
impact of pagemap on thp.

Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Reviewed-by: Andi Kleen <ak@linux.intel.com>
Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Naoya Horiguchi authored and Linus Torvalds committed Mar 22, 2012
1 parent b716ad9 commit 5aaabe8
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions fs/proc/task_mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,9 @@ struct pagemapread {
u64 *buffer;
};

#define PAGEMAP_WALK_SIZE (PMD_SIZE)
#define PAGEMAP_WALK_MASK (PMD_MASK)

#define PM_ENTRY_BYTES sizeof(u64)
#define PM_STATUS_BITS 3
#define PM_STATUS_OFFSET (64 - PM_STATUS_BITS)
Expand Down Expand Up @@ -666,22 +669,65 @@ static u64 pte_to_pagemap_entry(pte_t pte)
return pme;
}

#ifdef CONFIG_TRANSPARENT_HUGEPAGE
static u64 thp_pmd_to_pagemap_entry(pmd_t pmd, int offset)
{
u64 pme = 0;
/*
* Currently pmd for thp is always present because thp can not be
* swapped-out, migrated, or HWPOISONed (split in such cases instead.)
* This if-check is just to prepare for future implementation.
*/
if (pmd_present(pmd))
pme = PM_PFRAME(pmd_pfn(pmd) + offset)
| PM_PSHIFT(PAGE_SHIFT) | PM_PRESENT;
return pme;
}
#else
static inline u64 thp_pmd_to_pagemap_entry(pmd_t pmd, int offset)
{
return 0;
}
#endif

static int pagemap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end,
struct mm_walk *walk)
{
struct vm_area_struct *vma;
struct pagemapread *pm = walk->private;
pte_t *pte;
int err = 0;
u64 pfn = PM_NOT_PRESENT;

split_huge_page_pmd(walk->mm, pmd);
if (pmd_trans_unstable(pmd))
return 0;

/* find the first VMA at or above 'addr' */
vma = find_vma(walk->mm, addr);
spin_lock(&walk->mm->page_table_lock);
if (pmd_trans_huge(*pmd)) {
if (pmd_trans_splitting(*pmd)) {
spin_unlock(&walk->mm->page_table_lock);
wait_split_huge_page(vma->anon_vma, pmd);
} else {
for (; addr != end; addr += PAGE_SIZE) {
unsigned long offset;

offset = (addr & ~PAGEMAP_WALK_MASK) >>
PAGE_SHIFT;
pfn = thp_pmd_to_pagemap_entry(*pmd, offset);
err = add_to_pagemap(addr, pfn, pm);
if (err)
break;
}
spin_unlock(&walk->mm->page_table_lock);
return err;
}
} else {
spin_unlock(&walk->mm->page_table_lock);
}

for (; addr != end; addr += PAGE_SIZE) {
u64 pfn = PM_NOT_PRESENT;

/* check to see if we've left 'vma' behind
* and need a new, higher one */
Expand Down Expand Up @@ -764,8 +810,6 @@ static int pagemap_hugetlb_range(pte_t *pte, unsigned long hmask,
* determine which areas of memory are actually mapped and llseek to
* skip over unmapped regions.
*/
#define PAGEMAP_WALK_SIZE (PMD_SIZE)
#define PAGEMAP_WALK_MASK (PMD_MASK)
static ssize_t pagemap_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
Expand Down

0 comments on commit 5aaabe8

Please sign in to comment.