Re: [PATCH v12 14/25] fs/resctrl: Rebuild free RMID list on each mount
From: Luck, Tony
Date: Tue Sep 22 2026 - 16:38:30 EST
On Mon, Sep 21, 2026 at 12:45:56PM -0500, Babu Moger wrote:
> Hi Tony,
Hi Babu,
Thanks for running tests to make sure that I didn't break any AMD
functionality, and for reviewing these patches.
>
> > int setup_rmid_lru_list(void)
> > {
> > - struct rmid_entry *entry = NULL;
> > - u32 idx_limit;
> > - u32 idx;
> > + struct rmid_entry *entry;
> > + u32 cur_idx_limit;
> > + u32 rsvd_idx;
> > int i;
> > if (!resctrl_mon_capable())
> > return 0;
> > /*
> > - * Called on every mount, but the number of RMIDs cannot change
> > - * after the first mount, so keep using the same set of rmid_ptrs[]
> > - * until resctrl_exit(). Note that the limbo handler continues to
> > - * access rmid_ptrs[] after resctrl is unmounted.
> > + * Allocate the largest number of RMIDs that this system will ever
> > + * need. These cannot be freed until resctrl_exit() because the limbo
> > + * handler continues to access rmid_ptrs[] after resctrl is unmounted.
> > */
> > - if (rmid_ptrs)
> > - return 0;
> > + if (!rmid_ptrs) {
> > + num_rmid_ptrs = resctrl_arch_system_max_rmid_idx();
> > + rmid_ptrs = kzalloc_objs(struct rmid_entry, num_rmid_ptrs);
> > + if (!rmid_ptrs) {
> > + num_rmid_ptrs = 0;
> > + return -ENOMEM;
> > + }
> > - idx_limit = resctrl_arch_system_max_rmid_idx();
> > - rmid_ptrs = kzalloc_objs(struct rmid_entry, idx_limit);
> > - if (!rmid_ptrs)
> > - return -ENOMEM;
> > + for (i = 0; i < num_rmid_ptrs; i++) {
> > + entry = &rmid_ptrs[i];
> > + INIT_LIST_HEAD(&entry->list);
> > - for (i = 0; i < idx_limit; i++) {
> > - entry = &rmid_ptrs[i];
> > - INIT_LIST_HEAD(&entry->list);
> > + resctrl_arch_rmid_idx_decode(i, &entry->closid, &entry->rmid);
> > + }
> > + }
> > - resctrl_arch_rmid_idx_decode(i, &entry->closid, &entry->rmid);
> > - list_add_tail(&entry->list, &rmid_free_lru);
> > + /* Find how many RMIDs are available for this mount */
> > + cur_idx_limit = resctrl_arch_system_num_rmid_idx();
> > + if (cur_idx_limit > num_rmid_ptrs) {
> > + pr_warn_once("RMID count %u exceeds allocated %u; capping\n",
> > + cur_idx_limit, num_rmid_ptrs);
> > + cur_idx_limit = num_rmid_ptrs;
> > }
> > + INIT_LIST_HEAD(&rmid_free_lru);
>
> It is possible the list is not empty at this point with difference in
> numbers from one mount to another? Should you check if the list is empty
> and clean it up?
After a clean unmount the free list will likely be mostly full as
resctrl_fs_teardown() calls rmdir_all_sub() which is going to free
up RMIDs as directories are removed. The only RMIDs missing will be
the ones in limbo waiting for LLC occupancy counts to decay.
But the free list may contain some RMIDs that are out of range for the
new mount. Simply rebuilding the free list from scratch is one option
to resolve this. Another would be to walk the list add remove any
RMIDs out of range for the new mount.
Except during validation tests mount/unmount/mount cycles are rare.
There doesn't seem to be any reason to take one approach over another.
>
> Thanks
> Babu
-Tony