Commit ad820c5d authored by Nick Piggin's avatar Nick Piggin Committed by Linus Torvalds

[PATCH] smaps: shared fix

The point of the smaps "shared" is to count the number of pages that are
mapped by more than one process, according to Mauricio Lin.  However, smaps
uses page_count for this, so it will return a false positive for every page
that is mapped by just that one process, which is also in pagecache or
swapcache.  There are false positive situations for anonymous pages not in
swapcache as well: - page reclaim, migration - get_user_pages (eg.
direct-io, ptrace)

Use page_mapcount instead, to count the number of mappings to the page.

Use vm_normal_page so that weird things like /dev/mem aren't counted either.
Signed-off-by: default avatarNick Piggin <npiggin@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 5ddfae16
...@@ -204,7 +204,6 @@ static void smaps_pte_range(struct vm_area_struct *vma, pmd_t *pmd, ...@@ -204,7 +204,6 @@ static void smaps_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
{ {
pte_t *pte, ptent; pte_t *pte, ptent;
spinlock_t *ptl; spinlock_t *ptl;
unsigned long pfn;
struct page *page; struct page *page;
pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl); pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
...@@ -214,12 +213,12 @@ static void smaps_pte_range(struct vm_area_struct *vma, pmd_t *pmd, ...@@ -214,12 +213,12 @@ static void smaps_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
continue; continue;
mss->resident += PAGE_SIZE; mss->resident += PAGE_SIZE;
pfn = pte_pfn(ptent);
if (!pfn_valid(pfn)) page = vm_normal_page(vma, addr, ptent);
if (!page)
continue; continue;
page = pfn_to_page(pfn); if (page_mapcount(page) >= 2) {
if (page_count(page) >= 2) {
if (pte_dirty(ptent)) if (pte_dirty(ptent))
mss->shared_dirty += PAGE_SIZE; mss->shared_dirty += PAGE_SIZE;
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment