Re: [PATCH v3 2/3] fs/resctrl: Allocate the arrays in struct rdt_l3_mon_domain using kvzalloc_objs()

From: Jinjie Ruan

Date: Thu Nov 26 2026 - 01:43:26 EST




在 2026/11/26 0:47, Ben Horgan 写道:
> Each element of rdt_l3_mon_domain::mbm_states[] has
> resctrl_arch_system_num_rmid_idx() entries. On an MPAM system this is the
> number of PARTIDs multiplied by the number of PMGs. The maximum possible number
> of PARTIDs is 0x10000 and the maximum number of PMGs is 0x100. On a system
> approaching these limits the kmalloc() based allocation will consistently fail
> and hence fail to bring the monitor domain online.
>
> The number of entries of rdt_l3_mon_domain::cntr_cfg is equal to the number of
> counters. On an MPAM system the maximum number of counters is 0x1000 and so
> potentially larger than a 4K page. Allocations of this size can benefit from the
> fallback to vmalloc() in kvmalloc().
>
> Switch to allocating cntr_cfg and the elements of mbm_states[] using
> kvzalloc_objs() so that large allocations fall back to vmalloc().
>
> Fixes: 264c285999fc ("arm_mpam: resctrl: Add monitor initialisation and domain boilerplate")
> Signed-off-by: Ben Horgan <ben.horgan@xxxxxxx>
> ---
> fs/resctrl/rdtgroup.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
> index 57ab090072c2..c55f125ce9a1 100644
> --- a/fs/resctrl/rdtgroup.c
> +++ b/fs/resctrl/rdtgroup.c
> @@ -4502,10 +4502,10 @@ static void domain_destroy_l3_mon_state(struct rdt_l3_mon_domain *d)
> {
> int idx;
>
> - kfree(d->cntr_cfg);
> + kvfree(d->cntr_cfg);
> bitmap_free(d->rmid_busy_llc);
> for_each_mbm_idx(idx) {
> - kfree(d->mbm_states[idx]);
> + kvfree(d->mbm_states[idx]);
> d->mbm_states[idx] = NULL;
> }
> }
> @@ -4620,7 +4620,6 @@ void resctrl_offline_mon_domain(struct rdt_resource *r, struct rdt_domain_hdr *h
> static int domain_setup_l3_mon_state(struct rdt_resource *r, struct rdt_l3_mon_domain *d)
> {
> u32 idx_limit = resctrl_arch_system_num_rmid_idx();
> - size_t tsize = sizeof(*d->mbm_states[0]);
> enum resctrl_event_id eventid;
> int idx;
>
> @@ -4634,14 +4633,13 @@ static int domain_setup_l3_mon_state(struct rdt_resource *r, struct rdt_l3_mon_d
> if (!resctrl_is_mon_event_enabled(eventid))
> continue;
> idx = MBM_STATE_IDX(eventid);
> - d->mbm_states[idx] = kcalloc(idx_limit, tsize, GFP_KERNEL);
> + d->mbm_states[idx] = kvzalloc_objs(struct mbm_state, idx_limit);
> if (!d->mbm_states[idx])
> goto cleanup;
> }
>
> if (resctrl_is_mbm_enabled() && r->mon.mbm_cntr_assignable) {
> - tsize = sizeof(*d->cntr_cfg);
> - d->cntr_cfg = kcalloc(r->mon.num_mbm_cntrs, tsize, GFP_KERNEL);
> + d->cntr_cfg = kvzalloc_objs(struct mbm_cntr_cfg, r->mon.num_mbm_cntrs);

LGTM
Reviewed-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>

> if (!d->cntr_cfg)
> goto cleanup;
> }
> @@ -4650,7 +4648,7 @@ static int domain_setup_l3_mon_state(struct rdt_resource *r, struct rdt_l3_mon_d
> cleanup:
> bitmap_free(d->rmid_busy_llc);
> for_each_mbm_idx(idx) {
> - kfree(d->mbm_states[idx]);
> + kvfree(d->mbm_states[idx]);
> d->mbm_states[idx] = NULL;
> }
>