Skip to content

Commit 4f68728

Browse files
yosrym93akpm00
authored andcommitted
mm: do not update memcg stats for NR_{FILE/SHMEM}_PMDMAPPED
Previously, all NR_VM_EVENT_ITEMS stats were maintained per-memcg, although some of those fields are not exposed anywhere. Commit 14e0f6c ("memcg: reduce memory for the lruvec and memcg stats") changed this such that we only maintain the stats we actually expose per-memcg via a translation table. Additionally, commit 514462b ("memcg: warn for unexpected events and stats") added a warning if a per-memcg stat update is attempted for a stat that is not in the translation table. The warning started firing for the NR_{FILE/SHMEM}_PMDMAPPED stat updates in the rmap code. These stats are not maintained per-memcg, and hence are not in the translation table. Do not use __lruvec_stat_mod_folio() when updating NR_FILE_PMDMAPPED and NR_SHMEM_PMDMAPPED. Use __mod_node_page_state() instead, which updates the global per-node stats only. Link: https://lkml.kernel.org/r/20240506192924.271999-1-yosryahmed@google.com Fixes: 514462b ("memcg: warn for unexpected events and stats") Signed-off-by: Yosry Ahmed <yosryahmed@google.com> Reported-by: syzbot+9319a4268a640e26b72b@syzkaller.appspotmail.com Closes: https://lore.kernel.org/lkml/0000000000001b9d500617c8b23c@google.com Acked-by: Shakeel Butt <shakeel.butt@linux.dev> Acked-by: David Hildenbrand <david@redhat.com> Reviewed-by: Roman Gushchin <roman.gushchin@linux.dev> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Muchun Song <muchun.song@linux.dev> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent e6b331a commit 4f68728

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

mm/rmap.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,13 +1435,14 @@ static __always_inline void __folio_add_file_rmap(struct folio *folio,
14351435
struct page *page, int nr_pages, struct vm_area_struct *vma,
14361436
enum rmap_level level)
14371437
{
1438+
pg_data_t *pgdat = folio_pgdat(folio);
14381439
int nr, nr_pmdmapped = 0;
14391440

14401441
VM_WARN_ON_FOLIO(folio_test_anon(folio), folio);
14411442

14421443
nr = __folio_add_rmap(folio, page, nr_pages, level, &nr_pmdmapped);
14431444
if (nr_pmdmapped)
1444-
__lruvec_stat_mod_folio(folio, folio_test_swapbacked(folio) ?
1445+
__mod_node_page_state(pgdat, folio_test_swapbacked(folio) ?
14451446
NR_SHMEM_PMDMAPPED : NR_FILE_PMDMAPPED, nr_pmdmapped);
14461447
if (nr)
14471448
__lruvec_stat_mod_folio(folio, NR_FILE_MAPPED, nr);
@@ -1493,6 +1494,7 @@ static __always_inline void __folio_remove_rmap(struct folio *folio,
14931494
enum rmap_level level)
14941495
{
14951496
atomic_t *mapped = &folio->_nr_pages_mapped;
1497+
pg_data_t *pgdat = folio_pgdat(folio);
14961498
int last, nr = 0, nr_pmdmapped = 0;
14971499
bool partially_mapped = false;
14981500
enum node_stat_item idx;
@@ -1540,13 +1542,14 @@ static __always_inline void __folio_remove_rmap(struct folio *folio,
15401542
}
15411543

15421544
if (nr_pmdmapped) {
1545+
/* NR_{FILE/SHMEM}_PMDMAPPED are not maintained per-memcg */
15431546
if (folio_test_anon(folio))
1544-
idx = NR_ANON_THPS;
1545-
else if (folio_test_swapbacked(folio))
1546-
idx = NR_SHMEM_PMDMAPPED;
1547+
__lruvec_stat_mod_folio(folio, NR_ANON_THPS, -nr_pmdmapped);
15471548
else
1548-
idx = NR_FILE_PMDMAPPED;
1549-
__lruvec_stat_mod_folio(folio, idx, -nr_pmdmapped);
1549+
__mod_node_page_state(pgdat,
1550+
folio_test_swapbacked(folio) ?
1551+
NR_SHMEM_PMDMAPPED : NR_FILE_PMDMAPPED,
1552+
-nr_pmdmapped);
15501553
}
15511554
if (nr) {
15521555
idx = folio_test_anon(folio) ? NR_ANON_MAPPED : NR_FILE_MAPPED;

0 commit comments

Comments
 (0)