Commit 65c45377 authored by Kirill A. Shutemov's avatar Kirill A. Shutemov Committed by Linus Torvalds

mm, rmap: account shmem thp pages

Let's add ShmemHugePages and ShmemPmdMapped fields into meminfo and
smaps.  It indicates how many times we allocate and map shmem THP.

NR_ANON_TRANSPARENT_HUGEPAGES is renamed to NR_ANON_THPS.

Link: http://lkml.kernel.org/r/1466021202-61880-27-git-send-email-kirill.shutemov@linux.intel.comSigned-off-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent fc127da0
...@@ -113,6 +113,8 @@ static ssize_t node_read_meminfo(struct device *dev, ...@@ -113,6 +113,8 @@ static ssize_t node_read_meminfo(struct device *dev,
"Node %d SUnreclaim: %8lu kB\n" "Node %d SUnreclaim: %8lu kB\n"
#ifdef CONFIG_TRANSPARENT_HUGEPAGE #ifdef CONFIG_TRANSPARENT_HUGEPAGE
"Node %d AnonHugePages: %8lu kB\n" "Node %d AnonHugePages: %8lu kB\n"
"Node %d ShmemHugePages: %8lu kB\n"
"Node %d ShmemPmdMapped: %8lu kB\n"
#endif #endif
, ,
nid, K(node_page_state(nid, NR_FILE_DIRTY)), nid, K(node_page_state(nid, NR_FILE_DIRTY)),
...@@ -131,10 +133,13 @@ static ssize_t node_read_meminfo(struct device *dev, ...@@ -131,10 +133,13 @@ static ssize_t node_read_meminfo(struct device *dev,
node_page_state(nid, NR_SLAB_UNRECLAIMABLE)), node_page_state(nid, NR_SLAB_UNRECLAIMABLE)),
nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE)), nid, K(node_page_state(nid, NR_SLAB_RECLAIMABLE)),
#ifdef CONFIG_TRANSPARENT_HUGEPAGE #ifdef CONFIG_TRANSPARENT_HUGEPAGE
nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE)) nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE)),
, nid, nid, K(node_page_state(nid, NR_ANON_THPS) *
K(node_page_state(nid, NR_ANON_TRANSPARENT_HUGEPAGES) * HPAGE_PMD_NR),
HPAGE_PMD_NR)); nid, K(node_page_state(nid, NR_SHMEM_THPS) *
HPAGE_PMD_NR),
nid, K(node_page_state(nid, NR_SHMEM_PMDMAPPED) *
HPAGE_PMD_NR));
#else #else
nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE))); nid, K(node_page_state(nid, NR_SLAB_UNRECLAIMABLE)));
#endif #endif
......
...@@ -105,6 +105,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v) ...@@ -105,6 +105,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
#endif #endif
#ifdef CONFIG_TRANSPARENT_HUGEPAGE #ifdef CONFIG_TRANSPARENT_HUGEPAGE
"AnonHugePages: %8lu kB\n" "AnonHugePages: %8lu kB\n"
"ShmemHugePages: %8lu kB\n"
"ShmemPmdMapped: %8lu kB\n"
#endif #endif
#ifdef CONFIG_CMA #ifdef CONFIG_CMA
"CmaTotal: %8lu kB\n" "CmaTotal: %8lu kB\n"
...@@ -162,8 +164,9 @@ static int meminfo_proc_show(struct seq_file *m, void *v) ...@@ -162,8 +164,9 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
, atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10) , atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
#endif #endif
#ifdef CONFIG_TRANSPARENT_HUGEPAGE #ifdef CONFIG_TRANSPARENT_HUGEPAGE
, K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) * , K(global_page_state(NR_ANON_THPS) * HPAGE_PMD_NR)
HPAGE_PMD_NR) , K(global_page_state(NR_SHMEM_THPS) * HPAGE_PMD_NR)
, K(global_page_state(NR_SHMEM_PMDMAPPED) * HPAGE_PMD_NR)
#endif #endif
#ifdef CONFIG_CMA #ifdef CONFIG_CMA
, K(totalcma_pages) , K(totalcma_pages)
......
...@@ -448,6 +448,7 @@ struct mem_size_stats { ...@@ -448,6 +448,7 @@ struct mem_size_stats {
unsigned long referenced; unsigned long referenced;
unsigned long anonymous; unsigned long anonymous;
unsigned long anonymous_thp; unsigned long anonymous_thp;
unsigned long shmem_thp;
unsigned long swap; unsigned long swap;
unsigned long shared_hugetlb; unsigned long shared_hugetlb;
unsigned long private_hugetlb; unsigned long private_hugetlb;
...@@ -576,7 +577,12 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, ...@@ -576,7 +577,12 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr,
page = follow_trans_huge_pmd(vma, addr, pmd, FOLL_DUMP); page = follow_trans_huge_pmd(vma, addr, pmd, FOLL_DUMP);
if (IS_ERR_OR_NULL(page)) if (IS_ERR_OR_NULL(page))
return; return;
mss->anonymous_thp += HPAGE_PMD_SIZE; if (PageAnon(page))
mss->anonymous_thp += HPAGE_PMD_SIZE;
else if (PageSwapBacked(page))
mss->shmem_thp += HPAGE_PMD_SIZE;
else
VM_BUG_ON_PAGE(1, page);
smaps_account(mss, page, true, pmd_young(*pmd), pmd_dirty(*pmd)); smaps_account(mss, page, true, pmd_young(*pmd), pmd_dirty(*pmd));
} }
#else #else
...@@ -770,6 +776,7 @@ static int show_smap(struct seq_file *m, void *v, int is_pid) ...@@ -770,6 +776,7 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
"Referenced: %8lu kB\n" "Referenced: %8lu kB\n"
"Anonymous: %8lu kB\n" "Anonymous: %8lu kB\n"
"AnonHugePages: %8lu kB\n" "AnonHugePages: %8lu kB\n"
"ShmemPmdMapped: %8lu kB\n"
"Shared_Hugetlb: %8lu kB\n" "Shared_Hugetlb: %8lu kB\n"
"Private_Hugetlb: %7lu kB\n" "Private_Hugetlb: %7lu kB\n"
"Swap: %8lu kB\n" "Swap: %8lu kB\n"
...@@ -787,6 +794,7 @@ static int show_smap(struct seq_file *m, void *v, int is_pid) ...@@ -787,6 +794,7 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
mss.referenced >> 10, mss.referenced >> 10,
mss.anonymous >> 10, mss.anonymous >> 10,
mss.anonymous_thp >> 10, mss.anonymous_thp >> 10,
mss.shmem_thp >> 10,
mss.shared_hugetlb >> 10, mss.shared_hugetlb >> 10,
mss.private_hugetlb >> 10, mss.private_hugetlb >> 10,
mss.swap >> 10, mss.swap >> 10,
......
...@@ -154,7 +154,9 @@ enum zone_stat_item { ...@@ -154,7 +154,9 @@ enum zone_stat_item {
WORKINGSET_REFAULT, WORKINGSET_REFAULT,
WORKINGSET_ACTIVATE, WORKINGSET_ACTIVATE,
WORKINGSET_NODERECLAIM, WORKINGSET_NODERECLAIM,
NR_ANON_TRANSPARENT_HUGEPAGES, NR_ANON_THPS,
NR_SHMEM_THPS,
NR_SHMEM_PMDMAPPED,
NR_FREE_CMA_PAGES, NR_FREE_CMA_PAGES,
NR_VM_ZONE_STAT_ITEMS }; NR_VM_ZONE_STAT_ITEMS };
......
...@@ -3067,7 +3067,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, ...@@ -3067,7 +3067,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
if (atomic_add_negative(-1, compound_mapcount_ptr(page))) { if (atomic_add_negative(-1, compound_mapcount_ptr(page))) {
/* Last compound_mapcount is gone. */ /* Last compound_mapcount is gone. */
__dec_zone_page_state(page, NR_ANON_TRANSPARENT_HUGEPAGES); __dec_zone_page_state(page, NR_ANON_THPS);
if (TestClearPageDoubleMap(page)) { if (TestClearPageDoubleMap(page)) {
/* No need in mapcount reference anymore */ /* No need in mapcount reference anymore */
for (i = 0; i < HPAGE_PMD_NR; i++) for (i = 0; i < HPAGE_PMD_NR; i++)
...@@ -3539,6 +3539,8 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) ...@@ -3539,6 +3539,8 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
pgdata->split_queue_len--; pgdata->split_queue_len--;
list_del(page_deferred_list(head)); list_del(page_deferred_list(head));
} }
if (mapping)
__dec_zone_page_state(page, NR_SHMEM_THPS);
spin_unlock(&pgdata->split_queue_lock); spin_unlock(&pgdata->split_queue_lock);
__split_huge_page(page, list, flags); __split_huge_page(page, list, flags);
ret = 0; ret = 0;
......
...@@ -4312,6 +4312,9 @@ void show_free_areas(unsigned int filter) ...@@ -4312,6 +4312,9 @@ void show_free_areas(unsigned int filter)
" unevictable:%lu dirty:%lu writeback:%lu unstable:%lu\n" " unevictable:%lu dirty:%lu writeback:%lu unstable:%lu\n"
" slab_reclaimable:%lu slab_unreclaimable:%lu\n" " slab_reclaimable:%lu slab_unreclaimable:%lu\n"
" mapped:%lu shmem:%lu pagetables:%lu bounce:%lu\n" " mapped:%lu shmem:%lu pagetables:%lu bounce:%lu\n"
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
" anon_thp: %lu shmem_thp: %lu shmem_pmdmapped: %lu\n"
#endif
" free:%lu free_pcp:%lu free_cma:%lu\n", " free:%lu free_pcp:%lu free_cma:%lu\n",
global_page_state(NR_ACTIVE_ANON), global_page_state(NR_ACTIVE_ANON),
global_page_state(NR_INACTIVE_ANON), global_page_state(NR_INACTIVE_ANON),
...@@ -4329,6 +4332,11 @@ void show_free_areas(unsigned int filter) ...@@ -4329,6 +4332,11 @@ void show_free_areas(unsigned int filter)
global_page_state(NR_SHMEM), global_page_state(NR_SHMEM),
global_page_state(NR_PAGETABLE), global_page_state(NR_PAGETABLE),
global_page_state(NR_BOUNCE), global_page_state(NR_BOUNCE),
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
global_page_state(NR_ANON_THPS) * HPAGE_PMD_NR,
global_page_state(NR_SHMEM_THPS) * HPAGE_PMD_NR,
global_page_state(NR_SHMEM_PMDMAPPED) * HPAGE_PMD_NR,
#endif
global_page_state(NR_FREE_PAGES), global_page_state(NR_FREE_PAGES),
free_pcp, free_pcp,
global_page_state(NR_FREE_CMA_PAGES)); global_page_state(NR_FREE_CMA_PAGES));
...@@ -4363,6 +4371,11 @@ void show_free_areas(unsigned int filter) ...@@ -4363,6 +4371,11 @@ void show_free_areas(unsigned int filter)
" writeback:%lukB" " writeback:%lukB"
" mapped:%lukB" " mapped:%lukB"
" shmem:%lukB" " shmem:%lukB"
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
" shmem_thp: %lukB"
" shmem_pmdmapped: %lukB"
" anon_thp: %lukB"
#endif
" slab_reclaimable:%lukB" " slab_reclaimable:%lukB"
" slab_unreclaimable:%lukB" " slab_unreclaimable:%lukB"
" kernel_stack:%lukB" " kernel_stack:%lukB"
...@@ -4395,6 +4408,12 @@ void show_free_areas(unsigned int filter) ...@@ -4395,6 +4408,12 @@ void show_free_areas(unsigned int filter)
K(zone_page_state(zone, NR_WRITEBACK)), K(zone_page_state(zone, NR_WRITEBACK)),
K(zone_page_state(zone, NR_FILE_MAPPED)), K(zone_page_state(zone, NR_FILE_MAPPED)),
K(zone_page_state(zone, NR_SHMEM)), K(zone_page_state(zone, NR_SHMEM)),
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
K(zone_page_state(zone, NR_SHMEM_THPS) * HPAGE_PMD_NR),
K(zone_page_state(zone, NR_SHMEM_PMDMAPPED)
* HPAGE_PMD_NR),
K(zone_page_state(zone, NR_ANON_THPS) * HPAGE_PMD_NR),
#endif
K(zone_page_state(zone, NR_SLAB_RECLAIMABLE)), K(zone_page_state(zone, NR_SLAB_RECLAIMABLE)),
K(zone_page_state(zone, NR_SLAB_UNRECLAIMABLE)), K(zone_page_state(zone, NR_SLAB_UNRECLAIMABLE)),
zone_page_state(zone, NR_KERNEL_STACK) * zone_page_state(zone, NR_KERNEL_STACK) *
......
...@@ -1212,10 +1212,8 @@ void do_page_add_anon_rmap(struct page *page, ...@@ -1212,10 +1212,8 @@ void do_page_add_anon_rmap(struct page *page,
* pte lock(a spinlock) is held, which implies preemption * pte lock(a spinlock) is held, which implies preemption
* disabled. * disabled.
*/ */
if (compound) { if (compound)
__inc_zone_page_state(page, __inc_zone_page_state(page, NR_ANON_THPS);
NR_ANON_TRANSPARENT_HUGEPAGES);
}
__mod_zone_page_state(page_zone(page), NR_ANON_PAGES, nr); __mod_zone_page_state(page_zone(page), NR_ANON_PAGES, nr);
} }
if (unlikely(PageKsm(page))) if (unlikely(PageKsm(page)))
...@@ -1253,7 +1251,7 @@ void page_add_new_anon_rmap(struct page *page, ...@@ -1253,7 +1251,7 @@ void page_add_new_anon_rmap(struct page *page,
VM_BUG_ON_PAGE(!PageTransHuge(page), page); VM_BUG_ON_PAGE(!PageTransHuge(page), page);
/* increment count (starts at -1) */ /* increment count (starts at -1) */
atomic_set(compound_mapcount_ptr(page), 0); atomic_set(compound_mapcount_ptr(page), 0);
__inc_zone_page_state(page, NR_ANON_TRANSPARENT_HUGEPAGES); __inc_zone_page_state(page, NR_ANON_THPS);
} else { } else {
/* Anon THP always mapped first with PMD */ /* Anon THP always mapped first with PMD */
VM_BUG_ON_PAGE(PageTransCompound(page), page); VM_BUG_ON_PAGE(PageTransCompound(page), page);
...@@ -1283,6 +1281,8 @@ void page_add_file_rmap(struct page *page, bool compound) ...@@ -1283,6 +1281,8 @@ void page_add_file_rmap(struct page *page, bool compound)
} }
if (!atomic_inc_and_test(compound_mapcount_ptr(page))) if (!atomic_inc_and_test(compound_mapcount_ptr(page)))
goto out; goto out;
VM_BUG_ON_PAGE(!PageSwapBacked(page), page);
__inc_zone_page_state(page, NR_SHMEM_PMDMAPPED);
} else { } else {
if (PageTransCompound(page)) { if (PageTransCompound(page)) {
VM_BUG_ON_PAGE(!PageLocked(page), page); VM_BUG_ON_PAGE(!PageLocked(page), page);
...@@ -1321,6 +1321,8 @@ static void page_remove_file_rmap(struct page *page, bool compound) ...@@ -1321,6 +1321,8 @@ static void page_remove_file_rmap(struct page *page, bool compound)
} }
if (!atomic_add_negative(-1, compound_mapcount_ptr(page))) if (!atomic_add_negative(-1, compound_mapcount_ptr(page)))
goto out; goto out;
VM_BUG_ON_PAGE(!PageSwapBacked(page), page);
__dec_zone_page_state(page, NR_SHMEM_PMDMAPPED);
} else { } else {
if (!atomic_add_negative(-1, &page->_mapcount)) if (!atomic_add_negative(-1, &page->_mapcount))
goto out; goto out;
...@@ -1354,7 +1356,7 @@ static void page_remove_anon_compound_rmap(struct page *page) ...@@ -1354,7 +1356,7 @@ static void page_remove_anon_compound_rmap(struct page *page)
if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE))
return; return;
__dec_zone_page_state(page, NR_ANON_TRANSPARENT_HUGEPAGES); __dec_zone_page_state(page, NR_ANON_THPS);
if (TestClearPageDoubleMap(page)) { if (TestClearPageDoubleMap(page)) {
/* /*
......
...@@ -733,6 +733,8 @@ const char * const vmstat_text[] = { ...@@ -733,6 +733,8 @@ const char * const vmstat_text[] = {
"workingset_activate", "workingset_activate",
"workingset_nodereclaim", "workingset_nodereclaim",
"nr_anon_transparent_hugepages", "nr_anon_transparent_hugepages",
"nr_shmem_hugepages",
"nr_shmem_pmdmapped",
"nr_free_cma", "nr_free_cma",
/* enum writeback_stat_item counters */ /* enum writeback_stat_item counters */
......
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