Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp732457imm; Thu, 13 Sep 2018 06:59:57 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbi9T4SEbLumQPfqEZ64kZuuPjkbr3KB59BWHJdt6Suk+uPDAhl1RLdnEBi9kbZlOFFSOHd X-Received: by 2002:a62:e08b:: with SMTP id d11-v6mr7657061pfm.214.1536847197578; Thu, 13 Sep 2018 06:59:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847197; cv=none; d=google.com; s=arc-20160816; b=TumDQqjoBOzs7ngKPoKQjC72rieqxip5VrYCbkmxklxWA0vHXAUJ24/0sG78fygQBW IQmh18uhK4O20bLqhF66oXNY2VHJrp4xEgVGXac2GJiaTR4Qg89tqeiFrPWbmiW7muIG APHLcYli6nDvtIE2VZMb61ahLuefBG2mvcKvtkPAwkNH1woICR1envr1aD+pZa42vsfu qdACTkPwtr4fXmwsQ3L4CiHjZYK4scclV1cYIt8rZVPTOHbL2SCAFyXh6io5N8ACXhjV tkXA76Lvkm7mKzJgXPmSPG+TEbEN7Hw6zvPqDKu2DR+tBQg7lGWo0Ws20flEJ9DhXhFC pCMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=DOkjwmLx+NYCUhFzXG9tfSdZiGjCdCYrW3xrMF98psI=; b=ajcGDopWto8uNwZadtm8aEOIJeBvYiYGSAZoMTZgk5jpTWX8ssIzMpUdZ9fsm63wiu UrLuytKbltZVXiXXnR9wggTUk4NuB9K3LWw6OpTgSd7V0HthQrVRdO+gww9jTiS5xXmQ anFn5HGM7UIeJGCmTE8jUWD9BjYrDIFVO0z4zaZODiLl/xjMjBtY1Se5xqF0E66i/ZB5 sPNogHr6PIKatM4sr9FCuFkvD8ndF29ZUb3kBiYEvCDToDI74p/8yEmA0L827QhEO+fe 2CnkOnjB81re5O+ZwmVzAux2lQbP6W0sdPI9RGpP35B6i3+Sq/a35jHYuNqQ+6x4CJuH 8GBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 14-v6si4400033plb.230.2018.09.13.06.59.42; Thu, 13 Sep 2018 06:59:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731369AbeIMTHy (ORCPT + 99 others); Thu, 13 Sep 2018 15:07:54 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34482 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728566AbeIMTHx (ORCPT ); Thu, 13 Sep 2018 15:07:53 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 089CAD0E; Thu, 13 Sep 2018 13:58:15 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ming Lei , Jianchao Wang , Jens Axboe , Sasha Levin Subject: [PATCH 4.18 106/197] blk-mq: count the hctx as active before allocating tag Date: Thu, 13 Sep 2018 15:30:55 +0200 Message-Id: <20180913131845.790670295@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jianchao Wang [ Upstream commit d263ed9926823c462f99a7679e18f0c9e5b8550d ] Currently, we count the hctx as active after allocate driver tag successfully. If a previously inactive hctx try to get tag first time, it may fails and need to wait. However, due to the stale tag ->active_queues, the other shared-tags users are still able to occupy all driver tags while there is someone waiting for tag. Consequently, even if the previously inactive hctx is waked up, it still may not be able to get a tag and could be starved. To fix it, we count the hctx as active before try to allocate driver tag, then when it is waiting the tag, the other shared-tag users will reserve budget for it. Reviewed-by: Ming Lei Signed-off-by: Jianchao Wang Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- block/blk-mq-tag.c | 3 +++ block/blk-mq.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) --- a/block/blk-mq-tag.c +++ b/block/blk-mq-tag.c @@ -23,6 +23,9 @@ bool blk_mq_has_free_tags(struct blk_mq_ /* * If a previously inactive queue goes active, bump the active user count. + * We need to do this before try to allocate driver tag, then even if fail + * to get tag when first time, the other shared-tag users could reserve + * budget for it. */ bool __blk_mq_tag_busy(struct blk_mq_hw_ctx *hctx) { --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -285,7 +285,7 @@ static struct request *blk_mq_rq_ctx_ini rq->tag = -1; rq->internal_tag = tag; } else { - if (blk_mq_tag_busy(data->hctx)) { + if (data->hctx->flags & BLK_MQ_F_TAG_SHARED) { rq_flags = RQF_MQ_INFLIGHT; atomic_inc(&data->hctx->nr_active); } @@ -367,6 +367,8 @@ static struct request *blk_mq_get_reques if (!op_is_flush(op) && e->type->ops.mq.limit_depth && !(data->flags & BLK_MQ_REQ_RESERVED)) e->type->ops.mq.limit_depth(op, data); + } else { + blk_mq_tag_busy(data->hctx); } tag = blk_mq_get_tag(data); @@ -970,6 +972,7 @@ bool blk_mq_get_driver_tag(struct reques .hctx = blk_mq_map_queue(rq->q, rq->mq_ctx->cpu), .flags = wait ? 0 : BLK_MQ_REQ_NOWAIT, }; + bool shared; might_sleep_if(wait); @@ -979,9 +982,10 @@ bool blk_mq_get_driver_tag(struct reques if (blk_mq_tag_is_reserved(data.hctx->sched_tags, rq->internal_tag)) data.flags |= BLK_MQ_REQ_RESERVED; + shared = blk_mq_tag_busy(data.hctx); rq->tag = blk_mq_get_tag(&data); if (rq->tag >= 0) { - if (blk_mq_tag_busy(data.hctx)) { + if (shared) { rq->rq_flags |= RQF_MQ_INFLIGHT; atomic_inc(&data.hctx->nr_active); }