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

From: Matthew Wilcox
Date: Mon Dec 11 2023 - 12:00:53 EST


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)?