Skip to contentSkip to conversation

fs/resctrl: Use kvzalloc_objs() for large allocations

PATCH New Ben Horgan 1 participant 4 messages Nov 25 RDT - resource allocation

lore
Share & tools
lore

Ben Horgan

author
#0 lore raw

v3 cover fs/resctrl: Use kvzalloc_objs() for large allocations

When running an MPAM model with lots of PARTIDs and PMGs I hit an allocation failure in rmid_ptrs[]. Such failures are unlikely to be seen on a real system but addressing them helps testing. Patch 3 open codes a kvzalloc_objs() based allocation of a bitmap as I didn't think this was sufficient justification to add the proper helpers in the bitmap code. Please let me know if this is the right way to go. I made this the last patch so that it doesn't need to hold up the other two patches.

Changes since v2:
Patch 1 unchanged
Pathes 2 and 3 are new to address other large allocations (Reinette)

v2: https://lore.kernel.org/lkml/[email protected]/

Ben Horgan (3):
fs/resctrl: Allocate rmid_ptrs[] using kvzalloc_objs() fs/resctrl: Allocate the arrays in struct rdt_l3_mon_domain using
kvzalloc_objs()
fs/resctrl: Allocate rdt_l3_mon_domain::rmid_busy_llc using
kvzalloc_objs()

 fs/resctrl/monitor.c  |  4 ++--
 fs/resctrl/rdtgroup.c | 18 ++++++++----------
 2 files changed, 10 insertions(+), 12 deletions(-)

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v3 1/3 fs/resctrl: Allocate rmid_ptrs[] using kvzalloc_objs()

On an MPAM system the number of entries in rmid_ptrs[] 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 pushing the limits of the MPAM specification this can be large enough to consistently fail the kzalloc_objs() allocation and hence fail to mount the resctrl filesystem.

Switch to allocating rmid_ptrs[] using kvzalloc_objs() so that large allocations fall back to vmalloc().

Fixes 264c285999fc ("arm_mpam: resctrl: Add monitor initialisation and domain boilerplate")

---
I found this by testing the extremes of a software model and don't expect this to effect real systems.

---
 fs/resctrl/monitor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/resctrl/monitor.c +2 -2
index 04e4ea612b7c..9c383abfbbe0 100644
@@ -979,7 +979,7 @@ int setup_rmid_lru_list(void)
 		return 0;
 
 	idx_limit = resctrl_arch_system_num_rmid_idx();
-	rmid_ptrs = kzalloc_objs(struct rmid_entry, idx_limit);
+	rmid_ptrs = kvzalloc_objs(struct rmid_entry, idx_limit);
 	if (!rmid_ptrs)
 		return -ENOMEM;
 
@@ -1010,7 +1010,7 @@ void free_rmid_lru_list(void)
 		return;
 
 	mutex_lock(&rdtgroup_mutex);
-	kfree(rmid_ptrs);
+	kvfree(rmid_ptrs);
 	rmid_ptrs = NULL;
 	mutex_unlock(&rdtgroup_mutex);
 }
Signature · 1 line
2.43.0
author
#2 lore raw

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

In reply to 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")
---
 fs/resctrl/rdtgroup.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
fs/resctrl/rdtgroup.c +5 -7
index 57ab090072c2..c55f125ce9a1 100644
@@ -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);
 		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;
 	}
 
Signature · 1 line
2.43.0
author
#3 lore raw

PATCH v3 3/3 fs/resctrl: Allocate rdt_l3_mon_domain::rmid_busy_llc using kvzalloc_objs()

In reply to Ben Horgan

The bitmap rdt_l3_mon_domain::rmid_busy_llc 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.

As there is no equivalent to bitmap_zalloc() that uses kvmalloc() or vmalloc(), open code the allocation of rmid_busy_llc using kvzalloc_objs() so that large allocations fall back to vmalloc().

Fixes 264c285999fc ("arm_mpam: resctrl: Add monitor initialisation and domain boilerplate")
---
 fs/resctrl/rdtgroup.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/resctrl/rdtgroup.c +3 -3
index c55f125ce9a1..a8eebb5a5c4b 100644
@@ -4503,7 +4503,7 @@ static void domain_destroy_l3_mon_state(struct rdt_l3_mon_domain *d)
 	int idx;
 
 	kvfree(d->cntr_cfg);
-	bitmap_free(d->rmid_busy_llc);
+	kvfree(d->rmid_busy_llc);
 	for_each_mbm_idx(idx) {
 		kvfree(d->mbm_states[idx]);
 		d->mbm_states[idx] = NULL;
@@ -4624,7 +4624,7 @@ static int domain_setup_l3_mon_state(struct rdt_resource *r, struct rdt_l3_mon_d
 	int idx;
 
 	if (resctrl_is_mon_event_enabled(QOS_L3_OCCUP_EVENT_ID)) {
-		d->rmid_busy_llc = bitmap_zalloc(idx_limit, GFP_KERNEL);
+		d->rmid_busy_llc = kvzalloc_objs(unsigned long, BITS_TO_LONGS(idx_limit));
 		if (!d->rmid_busy_llc)
 			return -ENOMEM;
 	}
@@ -4646,7 +4646,7 @@ static int domain_setup_l3_mon_state(struct rdt_resource *r, struct rdt_l3_mon_d
 
 	return 0;
 cleanup:
-	bitmap_free(d->rmid_busy_llc);
+	kvfree(d->rmid_busy_llc);
 	for_each_mbm_idx(idx) {
 		kvfree(d->mbm_states[idx]);
 		d->mbm_states[idx] = NULL;
Signature · 1 line
2.43.0