On 2020-05-14 18:41, Ming Lei wrote: > + /* Prevent new request from being allocated on the current hctx/cpu */ > + set_bit(BLK_MQ_S_INACTIVE, &hctx->state); What guarantees that this change has been observed by all CPUs before the blk_mq_tags_has_request() loop finishes? > + /* > + * Grab one refcount for avoiding scheduler switch, and > + * return immediately if queue has been frozen. > + */ > + if (!percpu_ref_tryget(&q->q_usage_counter)) > + return 0; If percpu_ref_tryget(&q->q_usage_counter) fails that means either that request queue freezing is in progress or that a request queue has been frozen. I don't think that it is safe to return immediately if request queue freezing is still in progress. > + /* wait until all requests in this hctx are gone */ > + while (blk_mq_tags_has_request(hctx)) > + msleep(5); > + > + percpu_ref_put(&q->q_usage_counter); > + return 0; > +} Thanks, Bart.