* [PATCH] mm/vmstat: do not use size of vmstat_text as count of /proc/vmstat items
@ 2019-10-19 21:45 Konstantin Khlebnikov
2019-10-20 2:07 ` Randy Dunlap
0 siblings, 1 reply; 2+ messages in thread
From: Konstantin Khlebnikov @ 2019-10-19 21:45 UTC (permalink / raw)
To: linux-mm, Andrew Morton, linux-kernel; +Cc: Randy Dunlap
Strings from vmstat_text[] will be used for printing memory cgroup
statistics which exists even if CONFIG_VM_EVENT_COUNTERS=n.
This should be applied before patch "mm/memcontrol: use vmstat names
for printing statistics".
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Link: https://lore.kernel.org/linux-mm/cd1c42ae-281f-c8a8-70ac-1d01d417b2e1@infradead.org/T/#u
---
mm/vmstat.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 590aeca27cab..13e36da70f3c 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1638,25 +1638,23 @@ static const struct seq_operations zoneinfo_op = {
.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_file *m, loff_t *pos)
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;
}
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mm/vmstat: do not use size of vmstat_text as count of /proc/vmstat items
2019-10-19 21:45 [PATCH] mm/vmstat: do not use size of vmstat_text as count of /proc/vmstat items Konstantin Khlebnikov
@ 2019-10-20 2:07 ` Randy Dunlap
0 siblings, 0 replies; 2+ messages in thread
From: Randy Dunlap @ 2019-10-20 2:07 UTC (permalink / raw)
To: Konstantin Khlebnikov, linux-mm, Andrew Morton, linux-kernel
On 10/19/19 2:45 PM, Konstantin Khlebnikov wrote:
> Strings from vmstat_text[] will be used for printing memory cgroup
> statistics which exists even if CONFIG_VM_EVENT_COUNTERS=n.
>
> This should be applied before patch "mm/memcontrol: use vmstat names
> for printing statistics".
>
> Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
> Link: https://lore.kernel.org/linux-mm/cd1c42ae-281f-c8a8-70ac-1d01d417b2e1@infradead.org/T/#u
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
Thanks.
> ---
> mm/vmstat.c | 26 ++++++++++++--------------
> 1 file changed, 12 insertions(+), 14 deletions(-)
>
> diff --git a/mm/vmstat.c b/mm/vmstat.c
> index 590aeca27cab..13e36da70f3c 100644
> --- a/mm/vmstat.c
> +++ b/mm/vmstat.c
> @@ -1638,25 +1638,23 @@ static const struct seq_operations zoneinfo_op = {
> .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_file *m, loff_t *pos)
> 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;
> }
>
--
~Randy
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-10-20 2:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-19 21:45 [PATCH] mm/vmstat: do not use size of vmstat_text as count of /proc/vmstat items Konstantin Khlebnikov
2019-10-20 2:07 ` Randy Dunlap
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).