Re: [PATCH] vmstat: don't auto expand the sysfs files

From: Pasha Tatashin
Date: Mon Dec 11 2023 - 12:10:40 EST


On Mon, Dec 11, 2023 at 12:00 PM Matthew Wilcox <willy@xxxxxxxxxxxxx> wrote:
>
> On Mon, Dec 11, 2023 at 03:46:44PM +0000, Pasha Tatashin wrote:
> > +++ b/drivers/base/node.c
> > @@ -520,26 +520,34 @@ static ssize_t node_read_vmstat(struct device *dev,
> > int i;
> > int len = 0;
> >
> > - for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
> > - len += sysfs_emit_at(buf, len, "%s %lu\n",
> > - zone_stat_name(i),
> > - sum_zone_node_page_state(nid, i));
> > + for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++) {
> > + if (vmstat_text[ZONE_STAT_NAME_IDX(i)].flags & VMSTAT_SHOW_SYSFS) {
> > + len += sysfs_emit_at(buf, len, "%s %lu\n",
> > + zone_stat_name(i),
> > + sum_zone_node_page_state(nid, i));
> > + }
> > + }
>
> This seems overly complicated. Why not do:
>
> for (i = 0; i < NR_VM_ZONE_STAT_SYSFS_ITEMS; i++)
>
> and have assertions that this number doesn't change (and require people
> to add to the list after that point)?

This is what I wanted to do at the beginning. But, the problem is that
vmstat_text[] contains names from a number of different structs of
stats: zone_stat, numa_stat, node_stat, lru_list, writeback_stat,
vm_even. Therefore, we can't simply count the number of
NR_VM_ZONE_STAT_SYSFS_ITEMS, as the new items can be added in the
middle of vmstat_text[] when for example numa_stat is expanded.

Pasha