From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=3.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 174B4C2D0DC for ; Thu, 2 Jan 2020 14:02:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 997E3215A4 for ; Thu, 2 Jan 2020 14:02:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 997E3215A4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sina.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0367D8E0005; Thu, 2 Jan 2020 09:02:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F02678E0003; Thu, 2 Jan 2020 09:02:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA5338E0005; Thu, 2 Jan 2020 09:02:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0141.hostedemail.com [216.40.44.141]) by kanga.kvack.org (Postfix) with ESMTP id C02258E0003 for ; Thu, 2 Jan 2020 09:02:17 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 7D1AF2C8A for ; Thu, 2 Jan 2020 14:02:17 +0000 (UTC) X-FDA: 76332858714.26.plate14_6b16a31dd0e44 X-HE-Tag: plate14_6b16a31dd0e44 X-Filterd-Recvd-Size: 2045 Received: from r3-21.sinamail.sina.com.cn (r3-21.sinamail.sina.com.cn [202.108.3.21]) by imf39.hostedemail.com (Postfix) with SMTP for ; Thu, 2 Jan 2020 14:02:15 +0000 (UTC) Received: from unknown (HELO localhost.localdomain)([114.244.160.153]) by sina.com with ESMTP id 5E0DF7D9000161CB; Thu, 2 Jan 2020 22:02:04 +0800 (CST) X-Sender: hdanton@sina.com X-Auth-ID: hdanton@sina.com X-SMAIL-MID: 125472628753 From: Hillf Danton To: linux-kernel Cc: Jens Axboe , Ming Lin , Christoph Hellwig , Keith Busch , linux-mm , Hillf Danton Subject: [RFC PATCH] blk-mq: prefer local cpu on allocating request Date: Thu, 2 Jan 2020 22:01:52 +0800 Message-Id: <20200102140152.17088-1-hdanton@sina.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.003970, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 --- --- 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 =3D { .flags =3D flags, .cmd_flags = =3D op }; struct request *rq; - unsigned int cpu; int ret; =20 /* @@ -454,8 +453,14 @@ struct request *blk_mq_alloc_request_hct blk_queue_exit(q); return ERR_PTR(-EXDEV); } - cpu =3D cpumask_first_and(alloc_data.hctx->cpumask, cpu_online_mask); - alloc_data.ctx =3D __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 =3D cpumask_first_and(alloc_data.hctx->cpumask, cpu_online_mask); + if (cpu < nr_cpu_ids) + alloc_data.ctx =3D __blk_mq_get_ctx(q, cpu); + } =20 rq =3D blk_mq_get_request(q, NULL, &alloc_data); blk_queue_exit(q);