Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5255899ybl; Tue, 4 Feb 2020 10:27:49 -0800 (PST) X-Google-Smtp-Source: APXvYqww7OGJP+I+kjjLjx5KasLrMeQgLIzwp9XmPIiluIVDDH+vUio/Xe2Zu3WVTXDx7jHQaoXP X-Received: by 2002:aca:f487:: with SMTP id s129mr229104oih.75.1580840869697; Tue, 04 Feb 2020 10:27:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580840869; cv=none; d=google.com; s=arc-20160816; b=N0MNKhP5O4OT1dZiuQq4D7cND9sei9WYbV18tupsuBdHN6swIx6VVOxKEhtGxcojOD y/col14AitQCOjaWcUr5JKZR4pROOISCFD3ixc+yJvKCAkKT1E0Qd0Mt7LM6l2nuXDI/ P/qE5mXqlMmCc0RGDhUDRh+ploXRW9PhJ9Rr5BzEXSVtUygsSOmu8fxYMMBjnH8triQH jwgA0439tmgpLUNO9Ygt2bFQXGcsoEZx8uMeY2fJ3kJlE2tkJSrsUndj6v7C0ZFiSAeE RxDuNI6DhVGnIjqjxLMxutuZybidvvUOPEm+zz44h0kAr5U4Cmog81rXtb5pHDkut5m5 Vi5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=vXW19wXJC3hVKT8Q66ZK6uUNSfw5Qexl8aHI+Ttvtxs=; b=xdQUnUffEZ+jJSvesG/nafEJAUGb17q85m0Is3Ipakz1Ip+y6uXO4dPGez+bi7Cyol 6j+B3EzND9N6y4lFliOX0xDIvdaxOAwQkWasj8+PCRDqXZVRlokETQRjeuhfDTgz7IoL bCrKhd0ss8kGXUbFZnUPdDK5smOlw3IZkZq6G3KtRPoAjdHH6pofqkuC4Yv32T5/fThn 66XmxAlR2gnV3L7VEyJwUkUJTAInADXnh/Ls1w57TCD2ss4wWhLd02LNLMlYCM+u2J8u TZAAogjrEVSLnBlTrLqNjjxJayeLcZpqPkYBV8gVExSRHOTeAke7wYyYTYdL7VGpiS50 oK0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=WHBqARzU; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i7si10038073oib.63.2020.02.04.10.27.36; Tue, 04 Feb 2020 10:27:49 -0800 (PST) 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; dkim=pass header.i=@google.com header.s=20161025 header.b=WHBqARzU; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727455AbgBDS0n (ORCPT + 99 others); Tue, 4 Feb 2020 13:26:43 -0500 Received: from mail-il1-f195.google.com ([209.85.166.195]:41236 "EHLO mail-il1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727415AbgBDS0n (ORCPT ); Tue, 4 Feb 2020 13:26:43 -0500 Received: by mail-il1-f195.google.com with SMTP id f10so16718240ils.8 for ; Tue, 04 Feb 2020 10:26:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vXW19wXJC3hVKT8Q66ZK6uUNSfw5Qexl8aHI+Ttvtxs=; b=WHBqARzUWFjo+MMe3akW5up70rA/ST5BWP8DO296nQBjZJ4mNrYdyCelzTgqa3aDt1 pUmZOE5j+5GS7tEjY22hT/hcjlyEI/hBQgEMbEX9bUDk+/TU68QF8NQky2ZwkjT3ouio kEREvuPj90Q9fkwac5nGf/66rjfMk0ANG1/jPZeIOaccvYa6k6SkfRJYD5Jro35nOB21 CtR2qo1S5SudrdMHwsvJXklMjL34qvYuvfSZC9Ry1cGLb/QWeJhuJq6kzgugG7sMLhEC vdZyg2mcdBnYCsc5O7qDg53GB0OT9qIN44HTAefcAaSzCBYikoEu/pL0UnDZVEIh23g4 vPRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vXW19wXJC3hVKT8Q66ZK6uUNSfw5Qexl8aHI+Ttvtxs=; b=DEriGf7Oh6oDm6wn4uskC8hY2mPBz9TOXgY0zhrSA9VsmQxcMsM4zRkChec7eqIiGd K8bh5MR/kqVhOxXH2pNWlJeLxZa9wf1cOm4EUsTc+sfrIdita41xHD52bjxk9r6DLq4o r+tPN8xrkqQEJEoVpYrDbh7Lw8PTsngAoYJ2FZ2XiUJwPQRYayS3/ZpQ06k5MKX2epVL Wy+yJds8qxMBbHAwGVZC4kCJSTJ6eGJsA71zlwoN9Pdax2HDWMkSXt8dJMMso+otkHc/ Qv3QCVow1o43W1/N6xKtvdAKZk/AVfstZMfJj4/xn+O5CgMytqW/IySauNdbl23rwdts r8xA== X-Gm-Message-State: APjAAAVl0aVs2tF03878/ubsOs+fLuR1tnSPlt2mvbDd2TpOmwiV9GSi Pdx5TBNBvLkzURqG4q4S/QBHp6KD4mZE+oDsZHksqA== X-Received: by 2002:a05:6e02:df2:: with SMTP id m18mr28041600ilj.56.1580840801910; Tue, 04 Feb 2020 10:26:41 -0800 (PST) MIME-Version: 1.0 References: <20200203205950.127629-1-sqazi@google.com> <20200204092004.GB19922@ming.t460p> In-Reply-To: <20200204092004.GB19922@ming.t460p> From: Salman Qazi Date: Tue, 4 Feb 2020 10:26:29 -0800 Message-ID: Subject: Re: [PATCH] block: Limit number of items taken from the I/O scheduler in one go To: Ming Lei Cc: Bart Van Assche , Jens Axboe , linux-block@vger.kernel.org, Linux Kernel Mailing List , Jesse Barnes , Gwendal Grignou Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 4, 2020 at 1:20 AM Ming Lei wrote: > > On Mon, Feb 03, 2020 at 12:59:50PM -0800, Salman Qazi wrote: > > We observed that it is possible for a flush to bypass the I/O > > scheduler and get added to hctx->dispatch in blk_mq_sched_bypass_insert. > > We always bypass io scheduler for flush request. > > > This can happen while a kworker is running blk_mq_do_dispatch_sched call > > in blk_mq_sched_dispatch_requests. > > > > However, the blk_mq_do_dispatch_sched call doesn't end in bounded time. > > As a result, the flush can sit there indefinitely, as the I/O scheduler > > feeds an arbitrary number of requests to the hardware. > > blk-mq supposes to handle requests in hctx->dispatch with higher > priority, see blk_mq_sched_dispatch_requests(). > > However, there is single hctx->run_work, so async run queue for dispatching > flush request can only be run until another async run queue from scheduler > is done. > > > > > The solution is to periodically poll hctx->dispatch in > > blk_mq_do_dispatch_sched, to put a bound on the latency of the commands > > sitting there. > > > > Signed-off-by: Salman Qazi > > --- > > block/blk-mq-sched.c | 6 ++++++ > > block/blk-mq.c | 4 ++++ > > block/blk-sysfs.c | 33 +++++++++++++++++++++++++++++++++ > > include/linux/blkdev.h | 2 ++ > > 4 files changed, 45 insertions(+) > > > > diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c > > index ca22afd47b3d..75cdec64b9c7 100644 > > --- a/block/blk-mq-sched.c > > +++ b/block/blk-mq-sched.c > > @@ -90,6 +90,7 @@ static void blk_mq_do_dispatch_sched(struct blk_mq_hw_ctx *hctx) > > struct request_queue *q = hctx->queue; > > struct elevator_queue *e = q->elevator; > > LIST_HEAD(rq_list); > > + int count = 0; > > > > do { > > struct request *rq; > > @@ -97,6 +98,10 @@ static void blk_mq_do_dispatch_sched(struct blk_mq_hw_ctx *hctx) > > if (e->type->ops.has_work && !e->type->ops.has_work(hctx)) > > break; > > > > + if (count > 0 && count % q->max_sched_batch == 0 && > > + !list_empty_careful(&hctx->dispatch)) > > + break; > > q->max_sched_batch may not be needed, and it is reasonable to always > disaptch requests in hctx->dispatch first. > > Also such trick is missed in dispatch from sw queue. I will update the commit message, drop max_sched_batch and just turn it into a simple check and add the same thing to the dispatch from the sw queue. > > > Thanks, > Ming >