mm/vmstat: make MEMCG select VM_EVENT_COUNTERS

JIRA: https://redhat.atlassian.net/browse/RHEL-145695

commit fdc5001b002eaca9989b5f3563245662fd1e4d40
Author: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Date:   Wed Jun 4 12:51:11 2025 +0300

    mm/vmstat: make MEMCG select VM_EVENT_COUNTERS

    The vmstat_text array contains labels for counters displayed in
    /proc/vmstat.  It is important to keep the labels in sync with the
    counters.

    There is a BUILD_BUG_ON() check in vmstat_start() that ensures the size of
    the vmstat_text is not smaller than VM_EVENT_COUNTERS.  This helps to
    catch cases where a new counter is added but the label is not.  However,
    it does not help if a counter is removed but the label remains.

    It would be nice to make the BUILD_BUG_ON() check more strict to catch
    such cases.  However, when compiling with MEMCG enabled but
    VM_EVENT_COUNTERS disabled, the vmstat_text array is larger than
    NR_VMSTAT_ITEMS.

    This issue arises because some elements of the vmstat_text array are
    present when either MEMCG or VM_EVENT_COUNTERS is enabled, but
    NR_VMSTAT_ITEMS only accounts for these elements if VM_EVENT_COUNTERS is
    enabled.

    Instead of adjusting the NR_VMSTAT_ITEMS definition to account for MEMCG,
    make MEMCG select VM_EVENT_COUNTERS.  VM_EVENT_COUNTERS is enabled in most
    configurations anyway.

    Link: https://lkml.kernel.org/r/20250604095111.533783-1-kirill.shutemov@linux.intel.com
    Fixes: ebc5d83d04 ("mm/memcontrol: use vmstat names for printing statistics")
    Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
    Reported-by: Randy Dunlap <rdunlap@infradead.org>
    Acked-by: Vlastimil Babka <vbabka@suse.cz>
    Tested-by: Randy Dunlap <rdunlap@infradead.org>
    Acked-by: Randy Dunlap <rdunlap@infradead.org>
    Acked-by: Shakeel Butt <shakeel.butt@linux.dev>
    Cc: Konstantin Khlebnikov <koct9i@gmail.com>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: Johannes Weiner <hannes@cmpxchg.org>
    Cc: Liam Howlett <liam.howlett@oracle.com>
    Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
    Cc: Michal Hocko <mhocko@suse.com>
    Cc: Mike Rapoport <rppt@kernel.org>
    Cc: Muchun Song <muchun.song@linux.dev>
    Cc: Suren Baghdasaryan <surenb@google.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Rafael Aquini <raquini@redhat.com>
This commit is contained in:
Rafael Aquini
2026-07-31 14:50:35 -04:00
parent d69f4c994a
commit b67b04d9bb
3 changed files with 5 additions and 4 deletions
+2 -2
View File
@@ -507,7 +507,7 @@ static inline const char *lru_list_name(enum lru_list lru)
return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
}
#if defined(CONFIG_VM_EVENT_COUNTERS) || defined(CONFIG_MEMCG)
#if defined(CONFIG_VM_EVENT_COUNTERS)
static inline const char *vm_event_name(enum vm_event_item item)
{
return vmstat_text[NR_VM_ZONE_STAT_ITEMS +
@@ -516,7 +516,7 @@ static inline const char *vm_event_name(enum vm_event_item item)
NR_VM_STAT_ITEMS +
item];
}
#endif /* CONFIG_VM_EVENT_COUNTERS || CONFIG_MEMCG */
#endif /* CONFIG_VM_EVENT_COUNTERS */
#ifdef CONFIG_MEMCG
+1
View File
@@ -995,6 +995,7 @@ config MEMCG
select PAGE_COUNTER
select EVENTFD
select SLAB_OBJ_EXT
select VM_EVENT_COUNTERS
help
Provides control over the memory footprint of tasks in a cgroup.
+2 -2
View File
@@ -1288,7 +1288,7 @@ const char * const vmstat_text[] = {
"nr_memmap_pages",
"nr_memmap_boot_pages",
#if defined(CONFIG_VM_EVENT_COUNTERS) || defined(CONFIG_MEMCG)
#if defined(CONFIG_VM_EVENT_COUNTERS)
/* enum vm_event_item counters */
"pgpgin",
"pgpgout",
@@ -1476,7 +1476,7 @@ const char * const vmstat_text[] = {
"kstack_rest",
#endif
#endif
#endif /* CONFIG_VM_EVENT_COUNTERS || CONFIG_MEMCG */
#endif /* CONFIG_VM_EVENT_COUNTERS */
};
#endif /* CONFIG_PROC_FS || CONFIG_SYSFS || CONFIG_NUMA || CONFIG_MEMCG */