Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp46823pxb; Mon, 13 Sep 2021 12:32:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxP/Kte5eJvS7co5TNCc+Wv5jRLzAnWGcDR7w8jO03cD1ABF/I+P6mB2aI5tO7RuWjF5aPw X-Received: by 2002:a17:907:7755:: with SMTP id kx21mr14585413ejc.463.1631561528764; Mon, 13 Sep 2021 12:32:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631561528; cv=none; d=google.com; s=arc-20160816; b=Vzn19WUaYScDgsmq+g8Sx3/CePdM0cy7Cte78Pu1A9DnF9QQxl1wZ+IkgqHL7ptsz7 7zbdvKxP2YA+gGRaX1FZcsTRJw+0rUmuv7epo85zcEXFlaWzHUEiZaZZTbHFp1G6Er3M h73Mv+RY4fJuZR6rTVgmSNuXB5XK+KxrrSST6H7a1AJOB/Lo6vmlzRZWdwf3StfdJX49 sjh3+LkQv9b3MUzmrR8X5VssEPgmYXNs1jvAmyHZck4ImOPa8JUecaYvSixrNLboLsRN eYTVcWgpXVrFcrbWJYnuR1Y6BNxE+lWCUBpg0QYLtcW1cIyUL6JREz7Hwc8V0RtMV4iu aJ6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tAZB8fNIocj2sTIe0/ZRzWCTgm64iaLJzMGo0tTJz7s=; b=Nu2u5jYP2qc/2cNhGel0C4ZfLZR3yQWAskyKQDuKwbpBRq8TQYSeVQhldHKjqfUCny wpSlGPcbl970Xf9xQdCZArImOUhZ1WyAb6FY6dapNSowJtnHByXViRTVASCUEEJjeeHt w8cHa3jqlowQsh0YUJ8qZ0nkJ8PdXB6khaRXWci2xy55RmngdfQM7KbOmhyAJfPNP6PP E+m9RiOiuipyfGyMtBOoN15mTQGPlb+SYQHeUNkEfxg4SkSoeMHNouQP7gq7Y7Oy7s6b PhPnb1jufL4UzS1XUN6ch0/rJv33SI9Pj0mVY/yAiQUDGbQcQz8V1tjm/FAY6vIU6mX2 7mXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="sHXMG/0d"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q19si10200738edv.125.2021.09.13.12.31.45; Mon, 13 Sep 2021 12:32:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="sHXMG/0d"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238240AbhIMNfV (ORCPT + 99 others); Mon, 13 Sep 2021 09:35:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:58346 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241743AbhIMNa4 (ORCPT ); Mon, 13 Sep 2021 09:30:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9111961108; Mon, 13 Sep 2021 13:24:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539500; bh=wv1Y4mrKh+5yXEcKtaJVPZYqAzJ6UYaNjiylbSyYrnI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sHXMG/0ddOe+xa99odVlLSuhz8ealSQWsHenmBJA0qBskMIpAFtqRAOxVHy/mbaTN onlTNQ5dEzefuymw+dXBCcs4SVa9Bmzyn2VZ+vKeh3GZ0rnKFywrW+w3l67B1dzITM dtw/lmlZTXICOBW5xGrBX+UXfaWb/lrupKAs5wjM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oleksandr Natalenko , Ming Lei , Jens Axboe , Sasha Levin Subject: [PATCH 5.10 048/236] block: return ELEVATOR_DISCARD_MERGE if possible Date: Mon, 13 Sep 2021 15:12:33 +0200 Message-Id: <20210913131101.987232905@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ming Lei [ Upstream commit 866663b7b52d2da267b28e12eed89ee781b8fed1 ] When merging one bio to request, if they are discard IO and the queue supports multi-range discard, we need to return ELEVATOR_DISCARD_MERGE because both block core and related drivers(nvme, virtio-blk) doesn't handle mixed discard io merge(traditional IO merge together with discard merge) well. Fix the issue by returning ELEVATOR_DISCARD_MERGE in this situation, so both blk-mq and drivers just need to handle multi-range discard. Reported-by: Oleksandr Natalenko Signed-off-by: Ming Lei Tested-by: Oleksandr Natalenko Fixes: 2705dfb20947 ("block: fix discard request merge") Link: https://lore.kernel.org/r/20210729034226.1591070-1-ming.lei@redhat.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/bfq-iosched.c | 3 +++ block/blk-merge.c | 16 ---------------- block/elevator.c | 3 +++ block/mq-deadline.c | 2 ++ include/linux/blkdev.h | 16 ++++++++++++++++ 5 files changed, 24 insertions(+), 16 deletions(-) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index c91dca641eb4..8ea37328ca84 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -2251,6 +2251,9 @@ static int bfq_request_merge(struct request_queue *q, struct request **req, __rq = bfq_find_rq_fmerge(bfqd, bio, q); if (__rq && elv_bio_merge_ok(__rq, bio)) { *req = __rq; + + if (blk_discard_mergable(__rq)) + return ELEVATOR_DISCARD_MERGE; return ELEVATOR_FRONT_MERGE; } diff --git a/block/blk-merge.c b/block/blk-merge.c index 110db636d230..26f4bcc10de9 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -702,22 +702,6 @@ static void blk_account_io_merge_request(struct request *req) } } -/* - * 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; -} - static enum elv_merge blk_try_req_merge(struct request *req, struct request *next) { diff --git a/block/elevator.c b/block/elevator.c index 293c5c81397a..2a525863d4e9 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -336,6 +336,9 @@ enum elv_merge elv_merge(struct request_queue *q, struct request **req, __rq = elv_rqhash_find(q, bio->bi_iter.bi_sector); if (__rq && elv_bio_merge_ok(__rq, bio)) { *req = __rq; + + if (blk_discard_mergable(__rq)) + return ELEVATOR_DISCARD_MERGE; return ELEVATOR_BACK_MERGE; } diff --git a/block/mq-deadline.c b/block/mq-deadline.c index 2b9635d0dcba..e4e90761eab3 100644 --- a/block/mq-deadline.c +++ b/block/mq-deadline.c @@ -454,6 +454,8 @@ static int dd_request_merge(struct request_queue *q, struct request **rq, if (elv_bio_merge_ok(__rq, bio)) { *rq = __rq; + if (blk_discard_mergable(__rq)) + return ELEVATOR_DISCARD_MERGE; return ELEVATOR_FRONT_MERGE; } } diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 542471b76f41..8aae375864b6 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1534,6 +1534,22 @@ static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector return offset << SECTOR_SHIFT; } +/* + * 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; +} + static inline int bdev_discard_alignment(struct block_device *bdev) { struct request_queue *q = bdev_get_queue(bdev); -- 2.30.2