On Fri, 30 Jun 2023, NeilBrown wrote: > > I agree that an a priori cap on number of threads is not ideal. > Have you considered using the xarray to only store busy threads? > I think its lookup mechanism mostly relies on a bitmap of present > entries, but I'm not completely sure. It might be event better to use xa_set_mark() and xa_clear_mark() to manage the busy state. These are not atomic so you would need an atomic operation in the rqst. #define XA_MARK_IDLE XA_MARK_1 do { rqstp = xa_find(xa, ..., XA_MARK_IDLE); if (test_and_set_bit(RQ_BUSY, &rqstp->rq_flags)) { xa_clear_mark(xa, rqstp->xa_index, XA_MARK_IDLE); break; } } while {rqstp); xa_find() should be nearly as fast at find_next_bit() NeilBrown