Skip to content

Commit 468c398

Browse files
hnaztorvalds
authored andcommitted
mm: memcontrol: switch to native NR_ANON_THPS counter
With rmap memcg locking already in place for NR_ANON_MAPPED, it's just a small step to remove the MEMCG_RSS_HUGE wart and switch memcg to the native NR_ANON_THPS accounting sites. [[email protected]: fixes] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Johannes Weiner <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Tested-by: Naresh Kamboju <[email protected]> Reviewed-by: Joonsoo Kim <[email protected]> Acked-by: Randy Dunlap <[email protected]> [build-tested] Cc: Alex Shi <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: Shakeel Butt <[email protected]> Cc: Balbir Singh <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Linus Torvalds <[email protected]>
1 parent be5d0a7 commit 468c398

File tree

4 files changed

+31
-29
lines changed

4 files changed

+31
-29
lines changed

include/linux/memcontrol.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ struct kmem_cache;
2929

3030
/* Cgroup-specific page state, on top of universal node page state */
3131
enum memcg_stat_item {
32-
MEMCG_RSS_HUGE = NR_VM_NODE_STAT_ITEMS,
33-
MEMCG_SWAP,
32+
MEMCG_SWAP = NR_VM_NODE_STAT_ITEMS,
3433
MEMCG_SOCK,
3534
/* XXX: why are these zone and not node counters? */
3635
MEMCG_KERNEL_STACK_KB,

mm/huge_memory.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2159,15 +2159,17 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
21592159
atomic_inc(&page[i]._mapcount);
21602160
}
21612161

2162+
lock_page_memcg(page);
21622163
if (atomic_add_negative(-1, compound_mapcount_ptr(page))) {
21632164
/* Last compound_mapcount is gone. */
2164-
__dec_node_page_state(page, NR_ANON_THPS);
2165+
__dec_lruvec_page_state(page, NR_ANON_THPS);
21652166
if (TestClearPageDoubleMap(page)) {
21662167
/* No need in mapcount reference anymore */
21672168
for (i = 0; i < HPAGE_PMD_NR; i++)
21682169
atomic_dec(&page[i]._mapcount);
21692170
}
21702171
}
2172+
unlock_page_memcg(page);
21712173

21722174
smp_wmb(); /* make pte visible before pmd */
21732175
pmd_populate(mm, pmd, pgtable);

mm/memcontrol.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -836,11 +836,6 @@ static void mem_cgroup_charge_statistics(struct mem_cgroup *memcg,
836836
struct page *page,
837837
int nr_pages)
838838
{
839-
if (abs(nr_pages) > 1) {
840-
VM_BUG_ON_PAGE(!PageTransHuge(page), page);
841-
__mod_memcg_state(memcg, MEMCG_RSS_HUGE, nr_pages);
842-
}
843-
844839
/* pagein of a big page is an event. So, ignore page size */
845840
if (nr_pages > 0)
846841
__count_memcg_events(memcg, PGPGIN, 1);
@@ -1406,15 +1401,11 @@ static char *memory_stat_format(struct mem_cgroup *memcg)
14061401
(u64)memcg_page_state(memcg, NR_WRITEBACK) *
14071402
PAGE_SIZE);
14081403

1409-
/*
1410-
* TODO: We should eventually replace our own MEMCG_RSS_HUGE counter
1411-
* with the NR_ANON_THP vm counter, but right now it's a pain in the
1412-
* arse because it requires migrating the work out of rmap to a place
1413-
* where the page->mem_cgroup is set up and stable.
1414-
*/
1404+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
14151405
seq_buf_printf(&s, "anon_thp %llu\n",
1416-
(u64)memcg_page_state(memcg, MEMCG_RSS_HUGE) *
1417-
PAGE_SIZE);
1406+
(u64)memcg_page_state(memcg, NR_ANON_THPS) *
1407+
HPAGE_PMD_SIZE);
1408+
#endif
14181409

14191410
for (i = 0; i < NR_LRU_LISTS; i++)
14201411
seq_buf_printf(&s, "%s %llu\n", lru_list_name(i),
@@ -3061,8 +3052,6 @@ void mem_cgroup_split_huge_fixup(struct page *head)
30613052

30623053
for (i = 1; i < HPAGE_PMD_NR; i++)
30633054
head[i].mem_cgroup = head->mem_cgroup;
3064-
3065-
__mod_memcg_state(head->mem_cgroup, MEMCG_RSS_HUGE, -HPAGE_PMD_NR);
30663055
}
30673056
#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
30683057

@@ -3818,7 +3807,9 @@ static int memcg_numa_stat_show(struct seq_file *m, void *v)
38183807
static const unsigned int memcg1_stats[] = {
38193808
NR_FILE_PAGES,
38203809
NR_ANON_MAPPED,
3821-
MEMCG_RSS_HUGE,
3810+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
3811+
NR_ANON_THPS,
3812+
#endif
38223813
NR_SHMEM,
38233814
NR_FILE_MAPPED,
38243815
NR_FILE_DIRTY,
@@ -3829,7 +3820,9 @@ static const unsigned int memcg1_stats[] = {
38293820
static const char *const memcg1_stat_names[] = {
38303821
"cache",
38313822
"rss",
3823+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
38323824
"rss_huge",
3825+
#endif
38333826
"shmem",
38343827
"mapped_file",
38353828
"dirty",
@@ -3855,11 +3848,16 @@ static int memcg_stat_show(struct seq_file *m, void *v)
38553848
BUILD_BUG_ON(ARRAY_SIZE(memcg1_stat_names) != ARRAY_SIZE(memcg1_stats));
38563849

38573850
for (i = 0; i < ARRAY_SIZE(memcg1_stats); i++) {
3851+
unsigned long nr;
3852+
38583853
if (memcg1_stats[i] == MEMCG_SWAP && !do_memsw_account())
38593854
continue;
3860-
seq_printf(m, "%s %lu\n", memcg1_stat_names[i],
3861-
memcg_page_state_local(memcg, memcg1_stats[i]) *
3862-
PAGE_SIZE);
3855+
nr = memcg_page_state_local(memcg, memcg1_stats[i]);
3856+
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
3857+
if (memcg1_stats[i] == NR_ANON_THPS)
3858+
nr *= HPAGE_PMD_NR;
3859+
#endif
3860+
seq_printf(m, "%s %lu\n", memcg1_stat_names[i], nr * PAGE_SIZE);
38633861
}
38643862

38653863
for (i = 0; i < ARRAY_SIZE(memcg1_events); i++)
@@ -5452,6 +5450,13 @@ static int mem_cgroup_move_account(struct page *page,
54525450
if (page_mapped(page)) {
54535451
__mod_lruvec_state(from_vec, NR_ANON_MAPPED, -nr_pages);
54545452
__mod_lruvec_state(to_vec, NR_ANON_MAPPED, nr_pages);
5453+
if (PageTransHuge(page)) {
5454+
__mod_lruvec_state(from_vec, NR_ANON_THPS,
5455+
-nr_pages);
5456+
__mod_lruvec_state(to_vec, NR_ANON_THPS,
5457+
nr_pages);
5458+
}
5459+
54555460
}
54565461
} else {
54575462
__mod_lruvec_state(from_vec, NR_FILE_PAGES, -nr_pages);
@@ -6671,7 +6676,6 @@ struct uncharge_gather {
66716676
unsigned long nr_pages;
66726677
unsigned long pgpgout;
66736678
unsigned long nr_kmem;
6674-
unsigned long nr_huge;
66756679
struct page *dummy_page;
66766680
};
66776681

@@ -6694,7 +6698,6 @@ static void uncharge_batch(const struct uncharge_gather *ug)
66946698
}
66956699

66966700
local_irq_save(flags);
6697-
__mod_memcg_state(ug->memcg, MEMCG_RSS_HUGE, -ug->nr_huge);
66986701
__count_memcg_events(ug->memcg, PGPGOUT, ug->pgpgout);
66996702
__this_cpu_add(ug->memcg->vmstats_percpu->nr_page_events, ug->nr_pages);
67006703
memcg_check_events(ug->memcg, ug->dummy_page);
@@ -6731,8 +6734,6 @@ static void uncharge_page(struct page *page, struct uncharge_gather *ug)
67316734
ug->nr_pages += nr_pages;
67326735

67336736
if (!PageKmemcg(page)) {
6734-
if (PageTransHuge(page))
6735-
ug->nr_huge += nr_pages;
67366737
ug->pgpgout++;
67376738
} else {
67386739
ug->nr_kmem += nr_pages;

mm/rmap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ void do_page_add_anon_rmap(struct page *page,
11381138
* disabled.
11391139
*/
11401140
if (compound)
1141-
__inc_node_page_state(page, NR_ANON_THPS);
1141+
__inc_lruvec_page_state(page, NR_ANON_THPS);
11421142
__mod_lruvec_page_state(page, NR_ANON_MAPPED, nr);
11431143
}
11441144

@@ -1180,7 +1180,7 @@ void page_add_new_anon_rmap(struct page *page,
11801180
if (hpage_pincount_available(page))
11811181
atomic_set(compound_pincount_ptr(page), 0);
11821182

1183-
__inc_node_page_state(page, NR_ANON_THPS);
1183+
__inc_lruvec_page_state(page, NR_ANON_THPS);
11841184
} else {
11851185
/* Anon THP always mapped first with PMD */
11861186
VM_BUG_ON_PAGE(PageTransCompound(page), page);
@@ -1286,7 +1286,7 @@ static void page_remove_anon_compound_rmap(struct page *page)
12861286
if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE))
12871287
return;
12881288

1289-
__dec_node_page_state(page, NR_ANON_THPS);
1289+
__dec_lruvec_page_state(page, NR_ANON_THPS);
12901290

12911291
if (TestClearPageDoubleMap(page)) {
12921292
/*

0 commit comments

Comments
 (0)