Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5991646ybc; Wed, 27 Nov 2019 13:02:47 -0800 (PST) X-Google-Smtp-Source: APXvYqwtnNYeViIEsNrnfL12tC7VdHhd/3il8omXjfdZL/eIa/tupj9bsHV1LSZ2AKxonpIR8tCg X-Received: by 2002:a17:906:11cd:: with SMTP id o13mr50619279eja.272.1574888567666; Wed, 27 Nov 2019 13:02:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574888567; cv=none; d=google.com; s=arc-20160816; b=TRaOqVwrU7HjuXZPtbNEIIrbDhCkTqZpOnqU65wtfqbiubW1TfNaxi3O2ebNo6cUIx pKG8Y/7eVvrF0RNRjz8moctDNFL4ireY5KgHvTr+DNLl8WVplqca5TqwHJ4QLYbFppeA GI0BwILOH4JL2ykMLdCUms17WUmkc0jtYR7jaLQS47VNIHSz6mkOb/JgAzsLO/X4JSt2 xZ5OHtcRgpiMMPVV2zQVwwOl97o9yMpKwtDcdmmg08DrDNNeKIX0lYLos/wpCLeMxvTJ pwiaziUNSYw/+1wJZgaOWyYr1v1/lq+WgVUHsrQJtMSq6NZ3kvVPz7V+zH+pdHc8AugN 52/g== 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=kxIkDEBQWDnuaDv0JKtybBDJhmb65soJEKiGWsqrrog=; b=oFMucCaDntGqFs00YxOy1aij5oSVcmV7jhsK6LIrjJlmdWTcKskGDHjlDqr7rVSMqH MB2+ltB+NOmz12o4Fg1EgDj1snKk536UozFpW1whZh6pEBXhYPkRorrbLBkMh4rlkcHi UBPuY2v+cmN7Pop0GCUWxUgUAz5AVwZUCHLgSsnwj/712yQ9dTZhI9WmApk4FuR9O/lB TJK20BPyBy9DAP9BC6EW7nOKGGSYpIqVJgdR0UFagjUE1AezmFLz8+KSgmv0mfe6QpEV Xpz0tqhQ/7UZUzIwLelwve/u/nbkUIFHTrrwmaPk+E7KB33h1ftLQm++IFov+X2VBn6y gXvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tUKrMr+W; 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 g10si10167156ejh.271.2019.11.27.13.02.23; Wed, 27 Nov 2019 13:02:47 -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=@kernel.org header.s=default header.b=tUKrMr+W; 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 S1731171AbfK0VB3 (ORCPT + 99 others); Wed, 27 Nov 2019 16:01:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:53550 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727330AbfK0VBZ (ORCPT ); Wed, 27 Nov 2019 16:01:25 -0500 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 97DDA21556; Wed, 27 Nov 2019 21:01:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574888484; bh=mWW3zUmpWqa8PsbRflRCuBiivAf9/7lamvMNjRLzUvc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tUKrMr+WcGyhWl5Ofx6Ett7MCZco9ny75q/wfHJ2WzlKjijLHl+sgMAhsLTcel5eR or8ds8pIH65Cr78BfmJLaouU1Jpj22MD0bYIRpvNkcvi5YbrgPq0g87E/Ko01eZMKH HjkHclqMrD2xhS9BdlLI4F9IpnAfwVMaGF8itI9g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Ming Lei , Jianchao Wang , Jens Axboe , Sasha Levin Subject: [PATCH 4.19 153/306] block: fix the DISCARD request merge Date: Wed, 27 Nov 2019 21:30:03 +0100 Message-Id: <20191127203126.845809286@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203114.766709977@linuxfoundation.org> References: <20191127203114.766709977@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Jianchao Wang [ Upstream commit 69840466086d2248898020a08dda52732686c4e6 ] There are two cases when handle DISCARD merge. If max_discard_segments == 1, the bios/requests need to be contiguous to merge. If max_discard_segments > 1, it takes every bio as a range and different range needn't to be contiguous. But now, attempt_merge screws this up. It always consider contiguity for DISCARD for the case max_discard_segments > 1 and cannot merge contiguous DISCARD for the case max_discard_segments == 1, because rq_attempt_discard_merge always returns false in this case. This patch fixes both of the two cases above. Reviewed-by: Christoph Hellwig Reviewed-by: Ming Lei Signed-off-by: Jianchao Wang Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-merge.c | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 2e042190a4f1c..1dced51de1c6c 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -669,6 +669,31 @@ static void blk_account_io_merge(struct request *req) part_stat_unlock(); } } +/* + * Two cases of handling DISCARD merge: + * If max_discard_segments > 1, the driver takes every bio + * as a range and send them to controller together. The ranges + * needn't to be contiguous. + * Otherwise, the bios/requests will be handled as same as + * others which should be contiguous. + */ +static inline bool blk_discard_mergable(struct request *req) +{ + if (req_op(req) == REQ_OP_DISCARD && + queue_max_discard_segments(req->q) > 1) + return true; + return false; +} + +enum elv_merge blk_try_req_merge(struct request *req, struct request *next) +{ + if (blk_discard_mergable(req)) + return ELEVATOR_DISCARD_MERGE; + else if (blk_rq_pos(req) + blk_rq_sectors(req) == blk_rq_pos(next)) + return ELEVATOR_BACK_MERGE; + + return ELEVATOR_NO_MERGE; +} /* * For non-mq, this has to be called with the request spinlock acquired. @@ -686,12 +711,6 @@ static struct request *attempt_merge(struct request_queue *q, if (req_op(req) != req_op(next)) return NULL; - /* - * not contiguous - */ - if (blk_rq_pos(req) + blk_rq_sectors(req) != blk_rq_pos(next)) - return NULL; - if (rq_data_dir(req) != rq_data_dir(next) || req->rq_disk != next->rq_disk || req_no_special_merge(next)) @@ -715,11 +734,19 @@ static struct request *attempt_merge(struct request_queue *q, * counts here. Handle DISCARDs separately, as they * have separate settings. */ - if (req_op(req) == REQ_OP_DISCARD) { + + switch (blk_try_req_merge(req, next)) { + case ELEVATOR_DISCARD_MERGE: if (!req_attempt_discard_merge(q, req, next)) return NULL; - } else if (!ll_merge_requests_fn(q, req, next)) + break; + case ELEVATOR_BACK_MERGE: + if (!ll_merge_requests_fn(q, req, next)) + return NULL; + break; + default: return NULL; + } /* * If failfast settings disagree or any of the two is already @@ -843,8 +870,7 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio) enum elv_merge blk_try_merge(struct request *rq, struct bio *bio) { - if (req_op(rq) == REQ_OP_DISCARD && - queue_max_discard_segments(rq->q) > 1) + if (blk_discard_mergable(rq)) return ELEVATOR_DISCARD_MERGE; else if (blk_rq_pos(rq) + blk_rq_sectors(rq) == bio->bi_iter.bi_sector) return ELEVATOR_BACK_MERGE; -- 2.20.1