linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hillf Danton <hdanton@sina.com>
To: linux-kernel <linux-kernel@vger.kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>, Ming Lin <ming.l@ssi.samsung.com>,
	Christoph Hellwig <hch@lst.de>,
	Keith Busch <keith.busch@intel.com>,
	linux-mm <linux-mm@kvack.org>, Hillf Danton <hdanton@sina.com>
Subject: [RFC PATCH] blk-mq: prefer local cpu on allocating request
Date: Thu,  2 Jan 2020 22:01:52 +0800	[thread overview]
Message-ID: <20200102140152.17088-1-hdanton@sina.com> (raw)


Use local cpu in order to avoid the risk of overloading the first mapped
one if completing requests has to be on the cpu where requests are
dispatched.

Signed-off-by: Hillf Danton <hdanton@sina.com>
---

--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -426,7 +426,6 @@ struct request *blk_mq_alloc_request_hct
 {
 	struct blk_mq_alloc_data alloc_data = { .flags = flags, .cmd_flags = op };
 	struct request *rq;
-	unsigned int cpu;
 	int ret;
 
 	/*
@@ -454,8 +453,14 @@ struct request *blk_mq_alloc_request_hct
 		blk_queue_exit(q);
 		return ERR_PTR(-EXDEV);
 	}
-	cpu = cpumask_first_and(alloc_data.hctx->cpumask, cpu_online_mask);
-	alloc_data.ctx = __blk_mq_get_ctx(q, cpu);
+
+	/* prefer local cpu if it's mapped to hw queue */
+	if (!cpumask_test_cpu(raw_smp_processor_id(), alloc_data.hctx->cpumask)) {
+		unsigned int cpu;
+		cpu = cpumask_first_and(alloc_data.hctx->cpumask, cpu_online_mask);
+		if (cpu < nr_cpu_ids)
+			alloc_data.ctx = __blk_mq_get_ctx(q, cpu);
+	}
 
 	rq = blk_mq_get_request(q, NULL, &alloc_data);
 	blk_queue_exit(q);



                 reply	other threads:[~2020-01-02 14:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200102140152.17088-1-hdanton@sina.com \
    --to=hdanton@sina.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=keith.busch@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ming.l@ssi.samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox