[RFC PATCH 30/31] fs/resctrl: Fix excessive padding in schemata output

From: Chen Yu

Date: Sun Aug 02 2026 - 12:18:15 EST


When a resource has several controls (such as the region-aware MBA
controls), the schemata and size files pad every line with a large
amount of leading whitespace and the control names no longer line up
into a table.

Compute the column width from the longest single control name and format
the full control name within that width so the output is aligned again.

Reported-by: Tony Luck <luck.tony@xxxxxxxxx>
Link: https://lore.kernel.org/all/aiB2oJFPF-sqUVQx@agluck-desk3/
Signed-off-by: Chen Yu <yu.c.chen@xxxxxxxxx>
---
fs/resctrl/ctrlmondata.c | 19 +++++++++++--------
fs/resctrl/rdtgroup.c | 11 ++++++-----
2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/fs/resctrl/ctrlmondata.c b/fs/resctrl/ctrlmondata.c
index d65036f7079e..66483c83e99d 100644
--- a/fs/resctrl/ctrlmondata.c
+++ b/fs/resctrl/ctrlmondata.c
@@ -405,16 +405,16 @@ static struct resctrl_ctrl *resctrl_resource_ctrl_get(struct rdt_resource *r,
size_t resctrl_resource_ctrl_max_len(struct rdt_resource *r)
{
struct resctrl_ctrl *ctrl;
- size_t total = 0;
+ size_t max = 0;
size_t len;

for_each_resource_ctrl(ctrl,r) {
len = strlen(resctrl_ctrl_name_str(ctrl->name));
if (len)
- total += 1 + len;
+ max = max_t(size_t, max, 1 + len);
}

- return total;
+ return max;
}

static int rdtgroup_parse_ctrl(char *ctrlname, char *tok,
@@ -522,6 +522,7 @@ static void show_doms(struct seq_file *s, struct rdt_resource_final *f,
bool print_ctrl, int closid, struct resctrl_ctrl *ctrl)
{
struct rdt_resource *r = f->res;
+ char ctrl_full_name[20];
struct rdt_ctrl_domain *dom;
bool sep = false;
u32 ctrl_val;
@@ -529,11 +530,13 @@ static void show_doms(struct seq_file *s, struct rdt_resource_final *f,
/* Walking r->domains, ensure it can't race with cpuhp */
lockdep_assert_cpus_held();

- if (print_ctrl)
- seq_printf(s, "%*s%s%s:", max_name_width, f->name,
- resctrl_ctrl_is_default(ctrl) ? "" : "_",
- resctrl_ctrl_is_default(ctrl) ?
- "" : resctrl_ctrl_name_str(ctrl->name));
+ if (print_ctrl) {
+ snprintf(ctrl_full_name, sizeof(ctrl_full_name), "%s%s%s", f->name,
+ resctrl_ctrl_is_default(ctrl) ? "" : "_",
+ resctrl_ctrl_is_default(ctrl) ?
+ "" : resctrl_ctrl_name_str(ctrl->name));
+ seq_printf(s, "%*s:", max_name_width, ctrl_full_name);
+ }
list_for_each_entry(dom, &ctrl->domains, hdr.list) {
if (sep)
seq_puts(s, ";");
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index 31bea5a9833b..7d615502a892 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -1653,6 +1653,7 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
struct resctrl_ctrl *ctrl;
struct rdtgroup *rdtgrp;
struct rdt_resource *r;
+ char ctrl_full_name[20];
unsigned int size;
u32 ctrl_val;
int ret = 0;
@@ -1693,11 +1694,11 @@ static int rdtgroup_size_show(struct kernfs_open_file *of,
type = f->conf_type;
for_each_resource_ctrl(ctrl, r) {
sep = false;
- seq_printf(s, "%*s", max_name_width, f->name);
- if (!resctrl_ctrl_is_default(ctrl))
- seq_printf(s, "_%s:", resctrl_ctrl_name_str(ctrl->name));
- else
- seq_putc(s, ':');
+ snprintf(ctrl_full_name, sizeof(ctrl_full_name), "%s%s%s", f->name,
+ resctrl_ctrl_is_default(ctrl) ? "" : "_",
+ resctrl_ctrl_is_default(ctrl) ?
+ "" : resctrl_ctrl_name_str(ctrl->name));
+ seq_printf(s, "%*s:", max_name_width, ctrl_full_name);
list_for_each_entry(d, &ctrl->domains, hdr.list) {
if (sep)
seq_putc(s, ';');
--
2.43.0