Skip to contentSkip to conversation

blk-mq: Fix blk_mq_tagset_busy_iter() for shared tags

PATCH Superseded John Garry 2 participants 10 messages Oct 13, 2021 – Oct 18, 2021 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

John Garry

author
#0 lore raw

PATCH 1/1 blk-mq: Fix blk_mq_tagset_busy_iter() for shared tags

Since it is now possible for a tagset to share a single set of tags, the iter function should not re-iter the tags for the count of #hw queues in that case. Rather it should just iter once.

Fixes e0fdf846c7bb ("blk-mq: Use shared tags for shared sbitmap support")
block/blk-mq-tag.c +5 -2
index 72a2724a4eee..c943b6529619 100644
@@ -378,9 +378,12 @@ void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
 void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
 		busy_tag_iter_fn *fn, void *priv)
 {
-	int i;
+	unsigned int flags = tagset->flags;
+	int i, nr_tags;
+
+	nr_tags = blk_mq_is_shared_tags(flags) ? 1 : tagset->nr_hw_queues;
 
-	for (i = 0; i < tagset->nr_hw_queues; i++) {
+	for (i = 0; i < nr_tags; i++) {
 		if (tagset->tags && tagset->tags[i])
 			__blk_mq_all_tag_iter(tagset->tags[i], fn, priv,
 					      BT_TAG_ITER_STARTED);
Signature · 1 line
2.26.2
#1 lore raw
Quoted 17 lines · John Garry

Since it is now possible for a tagset to share a single set of tags, the iter function should not re-iter the tags for the count of #hw queues in that case. Rather it should just iter once.

Fixes e0fdf846c7bb ("blk-mq: Use shared tags for shared sbitmap support")
block/blk-mq-tag.c +0 -1
index 72a2724a4eee..c943b6529619 100644
@@ -378,9 +378,12 @@ void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
 void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
 		busy_tag_iter_fn *fn, void *priv)
 {
-	int i;

block/blk-mq-tag.c void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn, · line 389

Quoted 10 lines
block/blk-mq-tag.c +5 -1
+	unsigned int flags = tagset->flags;
+	int i, nr_tags;
+
+	nr_tags = blk_mq_is_shared_tags(flags) ? 1 : tagset->nr_hw_queues;
 
-	for (i = 0; i < tagset->nr_hw_queues; i++) {
+	for (i = 0; i < nr_tags; i++) {
 		if (tagset->tags && tagset->tags[i])
 			__blk_mq_all_tag_iter(tagset->tags[i], fn, priv,
 					      BT_TAG_ITER_STARTED);

blk_mq_queue_tag_busy_iter() needn't such change?

Thanks,
Ming

author
#2 lore raw
Quoted 23 lines · Ming Lei
Quoted 22 lines · John Garry

Since it is now possible for a tagset to share a single set of tags, the iter function should not re-iter the tags for the count of #hw queues in that case. Rather it should just iter once.

Fixes e0fdf846c7bb ("blk-mq: Use shared tags for shared sbitmap support")
block/blk-mq-tag.c +4 -1
index 72a2724a4eee..c943b6529619 100644
@@ -378,9 +378,12 @@ void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
  void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
  		busy_tag_iter_fn *fn, void *priv)
  {
-	int i;
+	unsigned int flags = tagset->flags;
+	int i, nr_tags;
+
+	nr_tags = blk_mq_is_shared_tags(flags) ? 1 : tagset->nr_hw_queues;
 
Quoted 6 lines

block/blk-mq-tag.c void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn, · line 389

Quoted 5 lines
block/blk-mq-tag.c +1 -1
-	for (i = 0; i < tagset->nr_hw_queues; i++) {
+	for (i = 0; i < nr_tags; i++) {
  		if (tagset->tags && tagset->tags[i])
  			__blk_mq_all_tag_iter(tagset->tags[i], fn, priv,
  					      BT_TAG_ITER_STARTED);

blk_mq_queue_tag_busy_iter() needn't such change?

I didn't think so.

blk_mq_queue_tag_busy_iter() will indeed re-iter the tags per hctx. However in bt_iter(), we check rq->mq_hctx == hctx for calling the iter callback:

static bool bt_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)

{
	...

	if (rq->q == hctx->queue && rq->mq_hctx == hctx)
		ret = iter_data->fn(hctx, rq, iter_data->data, reserved);

And this would only pass for the correct hctx which we're iter'ing for. Indeed, it would be nice not to iter excessive times, but I didn't see a straightforward way to change that.

There is also blk_mq_all_tag_iter():

void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
void *priv)

{
	__blk_mq_all_tag_iter(tags, fn, priv, BT_TAG_ITER_STATIC_RQS);
}

But then the only user is blk_mq_hctx_has_requests():

static bool blk_mq_hctx_has_requests(struct blk_mq_hw_ctx *hctx)

{
	struct blk_mq_tags *tags = hctx->sched_tags ?
			hctx->sched_tags : hctx->tags;
	struct rq_iter_data data = {
		.hctx	= hctx,
	};

	blk_mq_all_tag_iter(tags, blk_mq_has_request, &data);
	return data.has_rq;
}

But, again like bt_iter(), blk_mq_has_request() will check the hctx matches:

static bool blk_mq_has_request(struct request *rq, void *data, bool reserved)

{
	struct rq_iter_data *iter_data = data;

	if (rq->mq_hctx != iter_data->hctx)
		return true;
	iter_data->has_rq = true;
	return false;
}

Thanks,
John

#3 lore raw
Quoted 35 lines · John Garry
Quoted 20 lines · Ming Lei
Quoted 19 lines · John Garry

Since it is now possible for a tagset to share a single set of tags, the iter function should not re-iter the tags for the count of #hw queues in that case. Rather it should just iter once.

Fixes e0fdf846c7bb ("blk-mq: Use shared tags for shared sbitmap support")
block/blk-mq-tag.c +2 -1
index 72a2724a4eee..c943b6529619 100644
@@ -378,9 +378,12 @@ void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
  void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
  		busy_tag_iter_fn *fn, void *priv)
  {
-	int i;
+	unsigned int flags = tagset->flags;
+	int i, nr_tags;
Quoted 8 lines

block/blk-mq-tag.c void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn, · line 389

Quoted 7 lines
block/blk-mq-tag.c +3 -1
+
+	nr_tags = blk_mq_is_shared_tags(flags) ? 1 : tagset->nr_hw_queues;
-	for (i = 0; i < tagset->nr_hw_queues; i++) {
+	for (i = 0; i < nr_tags; i++) {
  		if (tagset->tags && tagset->tags[i])
  			__blk_mq_all_tag_iter(tagset->tags[i], fn, priv,
  					      BT_TAG_ITER_STARTED);

blk_mq_queue_tag_busy_iter() needn't such change?

I didn't think so.

blk_mq_queue_tag_busy_iter() will indeed re-iter the tags per hctx. However in bt_iter(), we check rq->mq_hctx == hctx for calling the iter callback:

Quoted 8 lines

static bool bt_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)

{
	...

	if (rq->q == hctx->queue && rq->mq_hctx == hctx)
		ret = iter_data->fn(hctx, rq, iter_data->data, reserved);

And this would only pass for the correct hctx which we're iter'ing for.

It is true for both shared and non-shared sbitmap since we don't share hctx, so what does matter? With single shared tags, you can iterate over all requests originated from all hw queues, right?

Quoted 2 lines

Indeed, it would be nice not to iter excessive times, but I didn't see a straightforward way to change that.

In Kashyap's report, the lock contention is actually from blk_mq_queue_tag_busy_iter(), see:

https://lore.kernel.org/linux-block/[email protected]/

Quoted 12 lines

There is also blk_mq_all_tag_iter():

void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
void *priv)

{
	__blk_mq_all_tag_iter(tags, fn, priv, BT_TAG_ITER_STATIC_RQS);
}

But then the only user is blk_mq_hctx_has_requests():

static bool blk_mq_hctx_has_requests(struct blk_mq_hw_ctx *hctx)

Quoted 10 lines
{
	struct blk_mq_tags *tags = hctx->sched_tags ?
			hctx->sched_tags : hctx->tags;
	struct rq_iter_data data = {
		.hctx	= hctx,
	};

	blk_mq_all_tag_iter(tags, blk_mq_has_request, &data);
	return data.has_rq;
}

This above one only iterates over the specified hctx/tags, it won't be affected.

Quoted 2 lines

But, again like bt_iter(), blk_mq_has_request() will check the hctx matches:

Not see what matters wrt. checking hctx.

Thanks,
Ming

author
#4 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line

blk_mq_queue_tag_busy_iter() needn't such change? >> I didn't think so.>>>> blk_mq_queue_tag_busy_iter() will indeed

re-iter the tags per hctx. However

Quoted 6 lines
Quoted 6 lines

in bt_iter(), we check rq->mq_hctx == hctx for calling the iter callback:

static bool bt_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)

{
	...
Quoted 6 lines
Quoted 4 lines
	if (rq->q == hctx->queue && rq->mq_hctx == hctx)
		ret = iter_data->fn(hctx, rq, iter_data->data, reserved);

And this would only pass for the correct hctx which we're iter'ing for.

It is true for both shared and non-shared sbitmap since we don't share hctx, so what does matter?

It matters that we are doing the right thing for shared tags. My point is we iter but don't call the callback unless the correct hctx.

As I see, this has not changed in transitioning from shared sbitmap to shared tags.

Quoted 3 lines

With single shared tags, you can iterate over all requests originated from all hw queues, right?

Right, for the same request queue, we should do that.

Quoted 9 lines
Quoted 2 lines

Indeed, it would be nice not to iter excessive times, but I didn't see a straightforward way to change that.

In Kashyap's report, the lock contention is actually from blk_mq_queue_tag_busy_iter(), see:

https://lore.kernel.org/linux-block/[email protected]/

As I understand, Kashyap mentioned no throughput regression with my series, but just higher cpu usage in blk_mq_find_and_get_req().

I'll see if I can see such a thing in my setup.

But could it be that since we only have a single sets of requests per tagset, and not a set of requests per HW queue, there is more contention on the common set of requests in the refcount_inc_not_zero() call ***, below:

static struct request *blk_mq_find_and_get_req(struct blk_mq_tags *tags, unsigned int bitnr)

{
	...

	rq = tags->rqs[bitnr];
	if (... || !refcount_inc_not_zero(&rq->ref)) ***
	...
}

But I wonder why this function is even called often...

Quoted 18 lines
Quoted 18 lines

There is also blk_mq_all_tag_iter():

void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
void *priv)

{
	__blk_mq_all_tag_iter(tags, fn, priv, BT_TAG_ITER_STATIC_RQS);
}

But then the only user is blk_mq_hctx_has_requests():

static bool blk_mq_hctx_has_requests(struct blk_mq_hw_ctx *hctx)

{
	struct blk_mq_tags *tags = hctx->sched_tags ?
			hctx->sched_tags : hctx->tags;
	struct rq_iter_data data = {
		.hctx	= hctx,
	};
Quoted 8 lines
Quoted 3 lines
	blk_mq_all_tag_iter(tags, blk_mq_has_request, &data);
	return data.has_rq;
}

This above one only iterates over the specified hctx/tags, it won't be affected.

Quoted 1 line

But, again like bt_iter(), blk_mq_has_request() will check the hctx matches:

Not see what matters wrt. checking hctx.

I'm just saying that something like the following would be broken for shared tags:

static bool blk_mq_has_request(struct request *rq, void *data, bool reserved)

{
	struct rq_iter_data *iter_data = data;

	iter_data->has_rq = true;
	return true;
}

static bool blk_mq_hctx_has_requests(struct blk_mq_hw_ctx *hctx)

{
	struct rq_iter_data data = {
	};

	blk_mq_all_tag_iter(tags, blk_mq_has_request, &data);
	return data.has_rq;
}

As it ignores that we want to check for a specific hctx.

Thanks,
John

#5 lore raw
Quoted 48 lines · John Garry
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

blk_mq_queue_tag_busy_iter() needn't such change? >> I didn't think so.>>>> blk_mq_queue_tag_busy_iter() will indeed

re-iter the tags per hctx. However

Quoted 6 lines
Quoted 6 lines

in bt_iter(), we check rq->mq_hctx == hctx for calling the iter callback:

static bool bt_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)

{
	...
Quoted 6 lines
Quoted 4 lines
	if (rq->q == hctx->queue && rq->mq_hctx == hctx)
		ret = iter_data->fn(hctx, rq, iter_data->data, reserved);

And this would only pass for the correct hctx which we're iter'ing for.

It is true for both shared and non-shared sbitmap since we don't share hctx, so what does matter?

It matters that we are doing the right thing for shared tags. My point is we iter but don't call the callback unless the correct hctx.

As I see, this has not changed in transitioning from shared sbitmap to shared tags.

Quoted 3 lines

With single shared tags, you can iterate over all requests originated from all hw queues, right?

Right, for the same request queue, we should do that.

Quoted 9 lines
Quoted 2 lines

Indeed, it would be nice not to iter excessive times, but I didn't see a straightforward way to change that.

In Kashyap's report, the lock contention is actually from blk_mq_queue_tag_busy_iter(), see:

https://lore.kernel.org/linux-block/[email protected]/

As I understand, Kashyap mentioned no throughput regression with my series, but just higher cpu usage in blk_mq_find_and_get_req().

I'll see if I can see such a thing in my setup.

But could it be that since we only have a single sets of requests per tagset, and not a set of requests per HW queue, there is more contention on the common set of requests in the refcount_inc_not_zero() call ***, below:

static struct request *blk_mq_find_and_get_req(struct blk_mq_tags *tags, unsigned int bitnr)

Quoted 7 lines
{
	...

	rq = tags->rqs[bitnr];
	if (... || !refcount_inc_not_zero(&rq->ref)) ***
	...
}

Kashyap's log shows that contention on tags->lock is increased, that should be caused by nr_hw_queues iterating. blk_mq_find_and_get_req() will be run nr_hw_queue times compared with pre-shared-sbitmap, since it is done before checking rq->mq_hctx.

Quoted 51 lines

But I wonder why this function is even called often...

Quoted 18 lines
Quoted 18 lines

There is also blk_mq_all_tag_iter():

void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
void *priv)

{
	__blk_mq_all_tag_iter(tags, fn, priv, BT_TAG_ITER_STATIC_RQS);
}

But then the only user is blk_mq_hctx_has_requests():

static bool blk_mq_hctx_has_requests(struct blk_mq_hw_ctx *hctx)

{
	struct blk_mq_tags *tags = hctx->sched_tags ?
			hctx->sched_tags : hctx->tags;
	struct rq_iter_data data = {
		.hctx	= hctx,
	};
Quoted 8 lines
Quoted 3 lines
	blk_mq_all_tag_iter(tags, blk_mq_has_request, &data);
	return data.has_rq;
}

This above one only iterates over the specified hctx/tags, it won't be affected.

Quoted 1 line

But, again like bt_iter(), blk_mq_has_request() will check the hctx matches:

Not see what matters wrt. checking hctx.

I'm just saying that something like the following would be broken for shared tags:

static bool blk_mq_has_request(struct request *rq, void *data, bool reserved)

{
	struct rq_iter_data *iter_data = data;

	iter_data->has_rq = true;
	return true;
}

static bool blk_mq_hctx_has_requests(struct blk_mq_hw_ctx *hctx)

{
	struct rq_iter_data data = {
	};

	blk_mq_all_tag_iter(tags, blk_mq_has_request, &data);
	return data.has_rq;
}
Quoted 1 line

As it ignores that we want to check for a specific hctx.

No, that isn't what I meant, follows the change I suggested:

block/blk-mq-tag.c +6 -2
index 72a2724a4eee..2a2ad6dfcc33 100644
@@ -232,8 +232,9 @@ static bool bt_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)
 	if (!rq)
 		return true;
 
-	if (rq->q == hctx->queue && rq->mq_hctx == hctx)
-		ret = iter_data->fn(hctx, rq, iter_data->data, reserved);
+	if (rq->q == hctx->queue && (rq->mq_hctx == hctx ||
+				blk_mq_is_shared_tags(hctx->flags)))
+		ret = iter_data->fn(rq->mq_hctx, rq, iter_data->data, reserved);
 	blk_mq_put_rq_ref(rq);
 	return ret;
 }
@@ -460,6 +461,9 @@ void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_iter_fn *fn,
 		if (tags->nr_reserved_tags)
 			bt_for_each(hctx, &tags->breserved_tags, fn, priv, true);
 		bt_for_each(hctx, &tags->bitmap_tags, fn, priv, false);
+
+		if (blk_mq_is_shared_tags(hctx->flags))
+			break;
 	}
 	blk_queue_exit(q);
 }

Thanks,
Ming

author
#6 lore raw
Quoted 14 lines · Ming Lei
Quoted 14 lines

As I understand, Kashyap mentioned no throughput regression with my series, but just higher cpu usage in blk_mq_find_and_get_req().

I'll see if I can see such a thing in my setup.

But could it be that since we only have a single sets of requests per tagset, and not a set of requests per HW queue, there is more contention on the common set of requests in the refcount_inc_not_zero() call ***, below:

static struct request *blk_mq_find_and_get_req(struct blk_mq_tags *tags, unsigned int bitnr)

{
	...
Quoted 6 lines
Quoted 4 lines
	rq = tags->rqs[bitnr];
	if (... || !refcount_inc_not_zero(&rq->ref)) ***
	...
}

Kashyap's log shows that contention on tags->lock is increased, that should be caused by nr_hw_queues iterating.

If the lock contention increases on tags->lock then I am not totally surprised. For shared sbitmap, each HW queue had its own tags (and tags lock). Now with shared tags, we have a single lock over the tagset, and so we would have more contention. That's on the basis that we have many parallel callers to blk_mq_queue_tag_busy_iter().

Quoted 3 lines

blk_mq_find_and_get_req()
will be run nr_hw_queue times compared with pre-shared-sbitmap, since it is done before checking rq->mq_hctx.

Isn't shared sitmap older than blk_mq_find_and_get_req()?

Anyway, for 5.14 shared sbitmap support, we iter nr_hw_queue times. And now, for shared tags, we still do that. I don't see what's changed in that regard.

Quoted 46 lines
Quoted 46 lines

But I wonder why this function is even called often...

Quoted 18 lines
Quoted 18 lines

There is also blk_mq_all_tag_iter():

void blk_mq_all_tag_iter(struct blk_mq_tags *tags, busy_tag_iter_fn *fn,
void *priv)

{
	__blk_mq_all_tag_iter(tags, fn, priv, BT_TAG_ITER_STATIC_RQS);
}

But then the only user is blk_mq_hctx_has_requests():

static bool blk_mq_hctx_has_requests(struct blk_mq_hw_ctx *hctx)

{
	struct blk_mq_tags *tags = hctx->sched_tags ?
			hctx->sched_tags : hctx->tags;
	struct rq_iter_data data = {
		.hctx	= hctx,
	};
Quoted 8 lines
Quoted 3 lines
	blk_mq_all_tag_iter(tags, blk_mq_has_request, &data);
	return data.has_rq;
}

This above one only iterates over the specified hctx/tags, it won't be affected.

Quoted 1 line

But, again like bt_iter(), blk_mq_has_request() will check the hctx matches:

Not see what matters wrt. checking hctx.

I'm just saying that something like the following would be broken for shared tags:

static bool blk_mq_has_request(struct request *rq, void *data, bool reserved)

{
	struct rq_iter_data *iter_data = data;

	iter_data->has_rq = true;
	return true;
}

static bool blk_mq_hctx_has_requests(struct blk_mq_hw_ctx *hctx)

{
	struct rq_iter_data data = {
	};
Quoted 6 lines
Quoted 5 lines
	blk_mq_all_tag_iter(tags, blk_mq_has_request, &data);
	return data.has_rq;
}

As it ignores that we want to check for a specific hctx.

No, that isn't what I meant, follows the change I suggested:

I didn't mean that this was your suggestion. I am just saying that we need to be careful iter'ing tags for shared tags now, as in that example.

Quoted 20 lines
block/blk-mq-tag.c +3 -2
index 72a2724a4eee..2a2ad6dfcc33 100644
@@ -232,8 +232,9 @@ static bool bt_iter(struct sbitmap *bitmap, unsigned int bitnr, void *data)
  	if (!rq)
  		return true;
 
-	if (rq->q == hctx->queue && rq->mq_hctx == hctx)
-		ret = iter_data->fn(hctx, rq, iter_data->data, reserved);
+	if (rq->q == hctx->queue && (rq->mq_hctx == hctx ||
+				blk_mq_is_shared_tags(hctx->flags)))
+		ret = iter_data->fn(rq->mq_hctx, rq, iter_data->data, reserved);
  	blk_mq_put_rq_ref(rq);
  	return ret;
  }

block/blk-mq-tag.c void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_iter_fn *fn, · line 469

Quoted 9 lines
block/blk-mq-tag.c +3 -0
@@ -460,6 +461,9 @@ void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_iter_fn *fn,
  		if (tags->nr_reserved_tags)
  			bt_for_each(hctx, &tags->breserved_tags, fn, priv, true);
  		bt_for_each(hctx, &tags->bitmap_tags, fn, priv, false);
+
+		if (blk_mq_is_shared_tags(hctx->flags))
+			break;
  	}
  	blk_queue_exit(q);
  }

I suppose that is ok, and means that we iter once.

However, I have to ask, where is the big user of blk_mq_queue_tag_busy_iter() coming from? I saw this from Kashyap's mail:

Quoted 4 lines

1.31% 1.31% kworker/57:1H-k [kernel.vmlinux]
native_queued_spin_lock_slowpath
ret_from_fork
kthread

Quoted 8 lines

worker_thread
process_one_work
blk_mq_timeout_work
blk_mq_queue_tag_busy_iter
bt_iter
blk_mq_find_and_get_req
_raw_spin_lock_irqsave
native_queued_spin_lock_slowpath

How or why blk_mq_timeout_work()?

Thanks,
john

author
#7 lore raw
Quoted 46 lines · John Garry
Quoted 26 lines
block/blk-mq-tag.c +6 -2
index 72a2724a4eee..2a2ad6dfcc33 100644
@@ -232,8 +232,9 @@ static bool bt_iter(struct sbitmap *bitmap, 
 unsigned int bitnr, void *data)
       if (!rq)
           return true;
-    if (rq->q == hctx->queue && rq->mq_hctx == hctx)
-        ret = iter_data->fn(hctx, rq, iter_data->data, reserved);
+    if (rq->q == hctx->queue && (rq->mq_hctx == hctx ||
+                blk_mq_is_shared_tags(hctx->flags)))
+        ret = iter_data->fn(rq->mq_hctx, rq, iter_data->data, reserved);
       blk_mq_put_rq_ref(rq);
       return ret;
   }
@@ -460,6 +461,9 @@ void blk_mq_queue_tag_busy_iter(struct 
 request_queue *q, busy_iter_fn *fn,
           if (tags->nr_reserved_tags)
               bt_for_each(hctx, &tags->breserved_tags, fn, priv, true);
           bt_for_each(hctx, &tags->bitmap_tags, fn, priv, false);
+
+        if (blk_mq_is_shared_tags(hctx->flags))
+            break;
       }
       blk_queue_exit(q);
Quoted 2 lines

  }

I suppose that is ok, and means that we iter once.

However, I have to ask, where is the big user of blk_mq_queue_tag_busy_iter() coming from? I saw this from Kashyap's mail:

Quoted 4 lines

1.31%     1.31%  kworker/57:1H-k  [kernel.vmlinux] native_queued_spin_lock_slowpath ret_from_fork
       kthread

Quoted 8 lines

       worker_thread
       process_one_work
       blk_mq_timeout_work
       blk_mq_queue_tag_busy_iter
       bt_iter
       blk_mq_find_and_get_req
       _raw_spin_lock_irqsave
       native_queued_spin_lock_slowpath

Quoted 1 line

How or why blk_mq_timeout_work()?

Just some update: I tried hisi_sas with 10x SAS SSDs, megaraid sas with 1x SATA HDD (that's all I have), and null blk with lots of devices, and I still can't see high usage of blk_mq_queue_tag_busy_iter().

So how about we get this patch processed (to fix blk_mq_tagset_busy_iter()), as it is independent of blk_mq_queue_tag_busy_iter()? And then wait for some update or some more info from Kashyap regarding blk_mq_queue_tag_busy_iter()

Thanks,
John

Reviewed-by
#8 lore raw
Quoted 49 lines · John Garry
Quoted 48 lines · John Garry
Quoted 26 lines
block/blk-mq-tag.c +6 -2
index 72a2724a4eee..2a2ad6dfcc33 100644
@@ -232,8 +232,9 @@ static bool bt_iter(struct sbitmap *bitmap,
 unsigned int bitnr, void *data)
       if (!rq)
           return true;
-    if (rq->q == hctx->queue && rq->mq_hctx == hctx)
-        ret = iter_data->fn(hctx, rq, iter_data->data, reserved);
+    if (rq->q == hctx->queue && (rq->mq_hctx == hctx ||
+                blk_mq_is_shared_tags(hctx->flags)))
+        ret = iter_data->fn(rq->mq_hctx, rq, iter_data->data, reserved);
       blk_mq_put_rq_ref(rq);
       return ret;
   }
@@ -460,6 +461,9 @@ void blk_mq_queue_tag_busy_iter(struct
 request_queue *q, busy_iter_fn *fn,
           if (tags->nr_reserved_tags)
               bt_for_each(hctx, &tags->breserved_tags, fn, priv, true);
           bt_for_each(hctx, &tags->bitmap_tags, fn, priv, false);
+
+        if (blk_mq_is_shared_tags(hctx->flags))
+            break;
       }
       blk_queue_exit(q);
Quoted 2 lines

  }

I suppose that is ok, and means that we iter once.

However, I have to ask, where is the big user of blk_mq_queue_tag_busy_iter() coming from? I saw this from Kashyap's mail:

Quoted 12 lines

1.31%     1.31%  kworker/57:1H-k  [kernel.vmlinux] native_queued_spin_lock_slowpath ret_from_fork
       kthread
       worker_thread
       process_one_work blk_mq_timeout_work blk_mq_queue_tag_busy_iter
       bt_iter
       blk_mq_find_and_get_req _raw_spin_lock_irqsave native_queued_spin_lock_slowpath

Quoted 5 lines
Quoted 1 line

How or why blk_mq_timeout_work()?

Just some update: I tried hisi_sas with 10x SAS SSDs, megaraid sas with 1x SATA HDD (that's all I have), and null blk with lots of devices, and I still can't see high usage of blk_mq_queue_tag_busy_iter().

It should be triggered easily in case of heavy io accounting:

while true; do cat /proc/diskstats; done

Quoted 3 lines

So how about we get this patch processed (to fix blk_mq_tagset_busy_iter()), as it is independent of blk_mq_queue_tag_busy_iter()? And then wait for some update or some more info from Kashyap regarding blk_mq_queue_tag_busy_iter()

Looks fine:

Thanks,
Ming

author
#9 lore raw
Quoted 49 lines · Ming Lei
Quoted 48 lines · John Garry
Quoted 47 lines · John Garry
Quoted 26 lines
block/blk-mq-tag.c +6 -2
index 72a2724a4eee..2a2ad6dfcc33 100644
@@ -232,8 +232,9 @@ static bool bt_iter(struct sbitmap *bitmap,
 unsigned int bitnr, void *data)
       if (!rq)
           return true;
-    if (rq->q == hctx->queue && rq->mq_hctx == hctx)
-        ret = iter_data->fn(hctx, rq, iter_data->data, reserved);
+    if (rq->q == hctx->queue && (rq->mq_hctx == hctx ||
+                blk_mq_is_shared_tags(hctx->flags)))
+        ret = iter_data->fn(rq->mq_hctx, rq, iter_data->data, reserved);
       blk_mq_put_rq_ref(rq);
       return ret;
   }
@@ -460,6 +461,9 @@ void blk_mq_queue_tag_busy_iter(struct
 request_queue *q, busy_iter_fn *fn,
           if (tags->nr_reserved_tags)
               bt_for_each(hctx, &tags->breserved_tags, fn, priv, true);
           bt_for_each(hctx, &tags->bitmap_tags, fn, priv, false);
+
+        if (blk_mq_is_shared_tags(hctx->flags))
+            break;
       }
       blk_queue_exit(q);
Quoted 2 lines

  }

I suppose that is ok, and means that we iter once.

However, I have to ask, where is the big user of blk_mq_queue_tag_busy_iter() coming from? I saw this from Kashyap's mail:

Quoted 12 lines

1.31%     1.31%  kworker/57:1H-k  [kernel.vmlinux] native_queued_spin_lock_slowpath ret_from_fork
       kthread
       worker_thread
       process_one_work blk_mq_timeout_work blk_mq_queue_tag_busy_iter
       bt_iter
       blk_mq_find_and_get_req _raw_spin_lock_irqsave native_queued_spin_lock_slowpath

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

How or why blk_mq_timeout_work()?

Just some update: I tried hisi_sas with 10x SAS SSDs, megaraid sas with 1x SATA HDD (that's all I have), and null blk with lots of devices, and I still can't see high usage of blk_mq_queue_tag_busy_iter().

It should be triggered easily in case of heavy io accounting:

while true; do cat /proc/diskstats; done

Let me check that.

Quoted 7 lines
Quoted 4 lines

So how about we get this patch processed (to fix blk_mq_tagset_busy_iter()), as it is independent of blk_mq_queue_tag_busy_iter()? And then wait for some update or some more info from Kashyap regarding blk_mq_queue_tag_busy_iter()

Looks fine:

Thanks, I'll just send a v2 with your tag for clarity, as there has been much discussion here.

John