Skip to content

Commit bf9ecea

Browse files
songmuchuntorvalds
authored andcommitted
mm: memcontrol: convert NR_FILE_THPS account to pages
Currently we use struct per_cpu_nodestat to cache the vmstat counters, which leads to inaccurate statistics especially THP vmstat counters. In the systems with if hundreds of processors it can be GBs of memory. For example, for a 96 CPUs system, the threshold is the maximum number of 125. And the per cpu counters can cache 23.4375 GB in total. The THP page is already a form of batched addition (it will add 512 worth of memory in one go) so skipping the batching seems like sensible. Although every THP stats update overflows the per-cpu counter, resorting to atomic global updates. But it can make the statistics more accuracy for the THP vmstat counters. So we convert the NR_FILE_THPS account to pages. This patch is consistent with 8f18227 ("mm/swap.c: flush lru pvecs on compound page arrival"). Doing this also can make the unit of vmstat counters more unified. Finally, the unit of the vmstat counters are pages, kB and bytes. The B/KB suffix can tell us that the unit is bytes or kB. The rest which is without suffix are pages. Link: https://lkml.kernel.org/r/20201228164110.2838-4-songmuchun@bytedance.com Signed-off-by: Muchun Song <songmuchun@bytedance.com> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: Feng Tang <feng.tang@intel.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Hugh Dickins <hughd@google.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Michal Hocko <mhocko@suse.com> Cc: NeilBrown <neilb@suse.de> Cc: Pankaj Gupta <pankaj.gupta@cloud.ionos.com> Cc: Rafael. J. Wysocki <rafael@kernel.org> Cc: Randy Dunlap <rdunlap@infradead.org> Cc: Roman Gushchin <guro@fb.com> Cc: Sami Tolvanen <samitolvanen@google.com> Cc: Shakeel Butt <shakeelb@google.com> Cc: Vladimir Davydov <vdavydov.dev@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 69473e5 commit bf9ecea

7 files changed

Lines changed: 14 additions & 10 deletions

File tree

‎drivers/base/node.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,7 @@ static ssize_t node_read_meminfo(struct device *dev,
466466
HPAGE_PMD_NR),
467467
nid, K(node_page_state(pgdat, NR_SHMEM_PMDMAPPED) *
468468
HPAGE_PMD_NR),
469-
nid, K(node_page_state(pgdat, NR_FILE_THPS) *
470-
HPAGE_PMD_NR),
469+
nid, K(node_page_state(pgdat, NR_FILE_THPS)),
471470
nid, K(node_page_state(pgdat, NR_FILE_PMDMAPPED) *
472471
HPAGE_PMD_NR)
473472
#endif

‎fs/proc/meminfo.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
135135
show_val_kb(m, "ShmemPmdMapped: ",
136136
global_node_page_state(NR_SHMEM_PMDMAPPED) * HPAGE_PMD_NR);
137137
show_val_kb(m, "FileHugePages: ",
138-
global_node_page_state(NR_FILE_THPS) * HPAGE_PMD_NR);
138+
global_node_page_state(NR_FILE_THPS));
139139
show_val_kb(m, "FilePmdMapped: ",
140140
global_node_page_state(NR_FILE_PMDMAPPED) * HPAGE_PMD_NR);
141141
#endif

‎include/linux/mmzone.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ static __always_inline bool vmstat_item_print_in_thp(enum node_stat_item item)
219219
if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE))
220220
return false;
221221

222-
return item == NR_ANON_THPS;
222+
return item == NR_ANON_THPS ||
223+
item == NR_FILE_THPS;
223224
}
224225

225226
/*

‎mm/filemap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static void unaccount_page_cache_page(struct address_space *mapping,
208208
if (PageTransHuge(page))
209209
__dec_lruvec_page_state(page, NR_SHMEM_THPS);
210210
} else if (PageTransHuge(page)) {
211-
__dec_lruvec_page_state(page, NR_FILE_THPS);
211+
__mod_lruvec_page_state(page, NR_FILE_THPS, -nr);
212212
filemap_nr_thps_dec(mapping);
213213
}
214214

‎mm/huge_memory.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2752,10 +2752,13 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)
27522752
}
27532753
spin_unlock(&ds_queue->split_queue_lock);
27542754
if (mapping) {
2755+
int nr = thp_nr_pages(head);
2756+
27552757
if (PageSwapBacked(head))
27562758
__dec_lruvec_page_state(head, NR_SHMEM_THPS);
27572759
else
2758-
__dec_lruvec_page_state(head, NR_FILE_THPS);
2760+
__mod_lruvec_page_state(head, NR_FILE_THPS,
2761+
-nr);
27592762
}
27602763

27612764
__split_huge_page(page, list, end);

‎mm/khugepaged.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,7 @@ static void collapse_file(struct mm_struct *mm,
16431643
XA_STATE_ORDER(xas, &mapping->i_pages, start, HPAGE_PMD_ORDER);
16441644
int nr_none = 0, result = SCAN_SUCCEED;
16451645
bool is_shmem = shmem_file(file);
1646+
int nr;
16461647

16471648
VM_BUG_ON(!IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !is_shmem);
16481649
VM_BUG_ON(start & (HPAGE_PMD_NR - 1));
@@ -1854,11 +1855,12 @@ static void collapse_file(struct mm_struct *mm,
18541855
put_page(page);
18551856
goto xa_unlocked;
18561857
}
1858+
nr = thp_nr_pages(new_page);
18571859

18581860
if (is_shmem)
18591861
__inc_lruvec_page_state(new_page, NR_SHMEM_THPS);
18601862
else {
1861-
__inc_lruvec_page_state(new_page, NR_FILE_THPS);
1863+
__mod_lruvec_page_state(new_page, NR_FILE_THPS, nr);
18621864
filemap_nr_thps_inc(mapping);
18631865
}
18641866

‎mm/memcontrol.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ static struct memory_stat memory_stats[] = {
15341534
* constant(e.g. powerpc).
15351535
*/
15361536
{ "anon_thp", PAGE_SIZE, NR_ANON_THPS },
1537-
{ "file_thp", 0, NR_FILE_THPS },
1537+
{ "file_thp", PAGE_SIZE, NR_FILE_THPS },
15381538
{ "shmem_thp", 0, NR_SHMEM_THPS },
15391539
#endif
15401540
{ "inactive_anon", PAGE_SIZE, NR_INACTIVE_ANON },
@@ -1566,8 +1566,7 @@ static int __init memory_stats_init(void)
15661566

15671567
for (i = 0; i < ARRAY_SIZE(memory_stats); i++) {
15681568
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
1569-
if (memory_stats[i].idx == NR_FILE_THPS ||
1570-
memory_stats[i].idx == NR_SHMEM_THPS)
1569+
if (memory_stats[i].idx == NR_SHMEM_THPS)
15711570
memory_stats[i].ratio = HPAGE_PMD_SIZE;
15721571
#endif
15731572
VM_BUG_ON(!memory_stats[i].ratio);

0 commit comments

Comments
 (0)