Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1022083yba; Thu, 4 Apr 2019 02:37:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLJPZbXyvKYR/LeD1lVgJz7pA/hIMYnPOszJtEXyCwJkGt6+w0a/QhQWEhpd2hVEY6bFbV X-Received: by 2002:a65:5106:: with SMTP id f6mr4714511pgq.253.1554370659109; Thu, 04 Apr 2019 02:37:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554370659; cv=none; d=google.com; s=arc-20160816; b=u4agRO554QqmSrsDQz/lQ3v6C2u5M0pvb+dT0s+IllIvXdMIVyFPM75dKQEd+hzc2i tS3Xo6nK9nCBwBp+2+79ap82zy9aGWnCPSbSc9beOVY6WelE2nki/7iYZHh5Xhk2m8rF IN2klj/zNz4rliIB42p9bHnF/ZNyVzl+C4JLAN4CAw3f779/agITk1yWk9XD3Nwm48ie sBEHVN9Z5Ff6HeXtDPHVNAwiIpRuSzNSi6Rz3XFY1gZIHmjflTzP5gq5f07Pb42Khp6F GFb0/gnqZ6/zmFgG0rCp/QKCfzZjKppZBsHdZovH6KJFKMRQhjMD2iYi7F7QumsD7NcG aEdw== 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:dkim-signature; bh=+T9rHbqwCftTLYwdu7U9XKWZH6WGV8zKZDLUkYAvGBw=; b=iLuE0QjcTyJNatc/C+yp1oA+pqftYtJ0mzj4blb8lUz1huyM2kHMXjoZcOOB1Xg2Xy yQnJEORAd35m4jmdvBMV1NEQutrfzA/Y76weN2j8EdMKKsB03X7tWd+pqD0RToKEcx3Q WHfEOL9WyjIYz9MnRU1UeAavk/MY3yxaW1GrB3oJoauG7Fwm47bQsDPEd0rBWL0Z9caW 34ksBiFDhaiCQT3E6RqQhZjBEcSn1aPijtI3tbkK66sBTMkF14UiTYTNc51nYT0qOXaG BRswouAYLwSLRVVQ9ZHmlr+Uw6+wFbXr2O2BEd7V3NAwPiSUIih1YgLdC+1go8A7+O1U Yj6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HYeSQTuu; 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 u6si15619490pfh.265.2019.04.04.02.37.24; Thu, 04 Apr 2019 02:37:39 -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; dkim=pass header.i=@kernel.org header.s=default header.b=HYeSQTuu; 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 S1732305AbfDDJGZ (ORCPT + 99 others); Thu, 4 Apr 2019 05:06:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:44804 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732284AbfDDJGX (ORCPT ); Thu, 4 Apr 2019 05:06:23 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E5BEC214AF; Thu, 4 Apr 2019 09:06:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368782; bh=32TWSW/ZvrlqYYaXjzABeW9LB7gb0nz4m9nGHeV+bJs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HYeSQTuuD4kEto6PcHDc73tDc/tGsdqfuiHuVHlsVlqHLX3rkEbr+AW8mPG0cXnV6 NlPKzcs0ZcHnl6wOMTZE68yf1gYfX3CvR7k6grZLi+XGbgLApFHfueHUp0IimuSAlI BQ6NT73avWDpCh9PPmGvZMSiOJgZgE3mZmCbjmM0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paolo Valente , Jens Axboe , Sasha Levin Subject: [PATCH 4.19 142/187] block, bfq: fix in-service-queue check for queue merging Date: Thu, 4 Apr 2019 10:47:59 +0200 Message-Id: <20190404084609.861344715@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 058fdecc6de7cdecbf4c59b851e80eb2d6c5295f ] When a new I/O request arrives for a bfq_queue, say Q, bfq checks whether that request is close to (a) the head request of some other queue waiting to be served, or (b) the last request dispatched for the in-service queue (in case Q itself is not the in-service queue) If a queue, say Q2, is found for which the above condition holds, then bfq merges Q and Q2, to hopefully get a more sequential I/O in the resulting merged queue, and thus a possibly higher throughput. Case (b) is checked by comparing the new request for Q with the last request dispatched, assuming that the latter necessarily belonged to the in-service queue. Unfortunately, this assumption is no longer always correct, since commit d0edc2473be9 ("block, bfq: inject other-queue I/O into seeky idle queues on NCQ flash"). When the assumption does not hold, queues that must not be merged may be merged, causing unexpected loss of control on per-queue service guarantees. This commit solves this problem by adding an extra field, which stores the actual last request dispatched for the in-service queue, and by using this new field to correctly check case (b). Signed-off-by: Paolo Valente Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/bfq-iosched.c | 5 ++++- block/bfq-iosched.h | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 653100fb719e..c5e2c5a01182 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -2215,7 +2215,8 @@ bfq_setup_cooperator(struct bfq_data *bfqd, struct bfq_queue *bfqq, if (in_service_bfqq && in_service_bfqq != bfqq && likely(in_service_bfqq != &bfqd->oom_bfqq) && - bfq_rq_close_to_sector(io_struct, request, bfqd->last_position) && + bfq_rq_close_to_sector(io_struct, request, + bfqd->in_serv_last_pos) && bfqq->entity.parent == in_service_bfqq->entity.parent && bfq_may_be_close_cooperator(bfqq, in_service_bfqq)) { new_bfqq = bfq_setup_merge(bfqq, in_service_bfqq); @@ -2755,6 +2756,8 @@ update_rate_and_reset: bfq_update_rate_reset(bfqd, rq); update_last_values: bfqd->last_position = blk_rq_pos(rq) + blk_rq_sectors(rq); + if (RQ_BFQQ(rq) == bfqd->in_service_queue) + bfqd->in_serv_last_pos = bfqd->last_position; bfqd->last_dispatch = now_ns; } diff --git a/block/bfq-iosched.h b/block/bfq-iosched.h index a8a2e5aca4d4..d5e9e60cb1a5 100644 --- a/block/bfq-iosched.h +++ b/block/bfq-iosched.h @@ -469,6 +469,9 @@ struct bfq_data { /* on-disk position of the last served request */ sector_t last_position; + /* position of the last served request for the in-service queue */ + sector_t in_serv_last_pos; + /* time of last request completion (ns) */ u64 last_completion; -- 2.19.1