The patch titled Subject: mm/vmstat: do not use size of vmstat_text as count of /proc/vmstat items has been added to the -mm tree. Its filename is mm-vmstat-do-not-use-size-of-vmstat_text-as-count-of-proc-vmstat-items.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-vmstat-do-not-use-size-of-vmstat_text-as-count-of-proc-vmstat-items.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-vmstat-do-not-use-size-of-vmstat_text-as-count-of-proc-vmstat-items.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Konstantin Khlebnikov <khlebnikov@xxxxxxxxxxxxxx> Subject: mm/vmstat: do not use size of vmstat_text as count of /proc/vmstat items Strings from vmstat_text[] will be used for printing memory cgroup statistics which exists even if CONFIG_VM_EVENT_COUNTERS=n. Link: http://lkml.kernel.org/r/157152151769.4139.15423465513138349343.stgit@buzz Link: https://lore.kernel.org/linux-mm/cd1c42ae-281f-c8a8-70ac-1d01d417b2e1@xxxxxxxxxxxxx/T/#u Signed-off-by: Konstantin Khlebnikov <khlebnikov@xxxxxxxxxxxxxx> Reported-by: Randy Dunlap <rdunlap@xxxxxxxxxxxxx> Acked-by: Randy Dunlap <rdunlap@xxxxxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxxxx> Cc: Vladimir Davydov <vdavydov.dev@xxxxxxxxx> Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: YueHaibing <yuehaibing@xxxxxxxxxx> Cc: Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/vmstat.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) --- a/mm/vmstat.c~mm-vmstat-do-not-use-size-of-vmstat_text-as-count-of-proc-vmstat-items +++ a/mm/vmstat.c @@ -1638,25 +1638,23 @@ static const struct seq_operations zonei .show = zoneinfo_show, }; +#define NR_VMSTAT_ITEMS (NR_VM_ZONE_STAT_ITEMS + \ + NR_VM_NUMA_STAT_ITEMS + \ + NR_VM_NODE_STAT_ITEMS + \ + NR_VM_WRITEBACK_STAT_ITEMS + \ + (IS_ENABLED(CONFIG_VM_EVENT_COUNTERS) ? \ + NR_VM_EVENT_ITEMS : 0)) + static void *vmstat_start(struct seq_file *m, loff_t *pos) { unsigned long *v; - int i, stat_items_size; + int i; - if (*pos >= ARRAY_SIZE(vmstat_text)) + if (*pos >= NR_VMSTAT_ITEMS) return NULL; - stat_items_size = NR_VM_ZONE_STAT_ITEMS * sizeof(unsigned long) + - NR_VM_NUMA_STAT_ITEMS * sizeof(unsigned long) + - NR_VM_NODE_STAT_ITEMS * sizeof(unsigned long) + - NR_VM_WRITEBACK_STAT_ITEMS * sizeof(unsigned long); - -#ifdef CONFIG_VM_EVENT_COUNTERS - stat_items_size += sizeof(struct vm_event_state); -#endif - BUILD_BUG_ON(stat_items_size != - ARRAY_SIZE(vmstat_text) * sizeof(unsigned long)); - v = kmalloc(stat_items_size, GFP_KERNEL); + BUILD_BUG_ON(ARRAY_SIZE(vmstat_text) < NR_VMSTAT_ITEMS); + v = kmalloc_array(NR_VMSTAT_ITEMS, sizeof(unsigned long), GFP_KERNEL); m->private = v; if (!v) return ERR_PTR(-ENOMEM); @@ -1689,7 +1687,7 @@ static void *vmstat_start(struct seq_fil static void *vmstat_next(struct seq_file *m, void *arg, loff_t *pos) { (*pos)++; - if (*pos >= ARRAY_SIZE(vmstat_text)) + if (*pos >= NR_VMSTAT_ITEMS) return NULL; return (unsigned long *)m->private + *pos; } _ Patches currently in -mm which might be from khlebnikov@xxxxxxxxxxxxxx are mm-swap-piggyback-lru_add_drain_all-calls.patch mm-vmstat-add-helpers-to-get-vmstat-item-names-for-each-enum-type.patch mm-vmstat-do-not-use-size-of-vmstat_text-as-count-of-proc-vmstat-items.patch mm-memcontrol-use-vmstat-names-for-printing-statistics.patch