> On 30 Dec 2024, at 19:53, Rik van Riel <riel@xxxxxxxxxxx> wrote: > > +/* > + * Figure out whether to assign a broadcast (global) ASID to a process. > + * We vary the threshold by how empty or full broadcast ASID space is. > + * 1/4 full: >= 4 active threads > + * 1/2 full: >= 8 active threads > + * 3/4 full: >= 16 active threads > + * 7/8 full: >= 32 active threads > + * etc > + * > + * This way we should never exhaust the broadcast ASID space, even on very > + * large systems, and the processes with the largest number of active > + * threads should be able to use broadcast TLB invalidation. > + */ > +#define HALFFULL_THRESHOLD 8 > +static bool meets_broadcast_asid_threshold(struct mm_struct *mm) > +{ > + int avail = broadcast_asid_available; > + int threshold = HALFFULL_THRESHOLD; > + > + if (!avail) > + return false; > + > + if (avail > MAX_ASID_AVAILABLE * 3 / 4) { > + threshold = HALFFULL_THRESHOLD / 4; > + } else if (avail > MAX_ASID_AVAILABLE / 2) { > + threshold = HALFFULL_THRESHOLD / 2; > + } else if (avail < MAX_ASID_AVAILABLE / 3) { > + do { > + avail *= 2; > + threshold *= 2; > + } while ((avail + threshold) < MAX_ASID_AVAILABLE / 2); > + } > + > + return mm_active_cpus_exceeds(mm, threshold); > +} Rik, I thought about it further and I am not sure this approach is so great. It reminds me the technique of eating chocolate forever: each day eat half of the previous day. It works in theory, but less in practice. IOW, I mean it seems likely that early processes would get and hog all broadcast ASIDs. It seems necessary to be able to revoke broadcast ASIDs, although I understand it can be complicated. Do you have any other resource in mind that Linux manages in a similar way (avoids revoking)?