From patchwork Sat Oct 20 14:29:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "jianchao.wang" X-Patchwork-Id: 10650555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A062B90 for ; Sat, 20 Oct 2018 14:27:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A80928622 for ; Sat, 20 Oct 2018 14:27:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7820B28630; Sat, 20 Oct 2018 14:27:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18E1E28622 for ; Sat, 20 Oct 2018 14:27:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727539AbeJTWig (ORCPT ); Sat, 20 Oct 2018 18:38:36 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:35272 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727373AbeJTWig (ORCPT ); Sat, 20 Oct 2018 18:38:36 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9KENrg3163460; Sat, 20 Oct 2018 14:27:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=dP7tKOQOVr2JK6GxTllAKeQzR7f0x1sxzeLDI1E8Wt4=; b=TbAw+hrVxEKe3+37oIKf4ALgjG8uF7alqBhsw6dJEYTAhhSzu7Hd6UQ/ntxkB2YlbQbS G8RatSoQ9Kfs2xw9zB3R0R67QtfeHJZj8+ZH2KnBnlBC6umHZ5KywWs39IOjbbdWShCK ZVYCK5vGDADIVvl/scc8Yai8MtIWobVBs8LEWn4X36deR90N+LWAz0gL0PUkcnxspW/d mwTDh8b8t6Bw2Kir5ycXBCX4JBJ1GEKe1nvlVb7RzUZ8XJsQOoA8ZC3Ug30ssdt8hbDQ jH84j6qrMaBhITVgFgxpOXkyTeMiBSJ678eqILZaaF5wWe0u/ascFfwYz7FNlTUZWi6H tA== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2n7w0q8vh9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 20 Oct 2018 14:27:51 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9KERpua003368 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 20 Oct 2018 14:27:51 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9KERoSb003749; Sat, 20 Oct 2018 14:27:50 GMT Received: from will-ThinkCentre-M910s.cn.oracle.com (/10.182.70.254) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 20 Oct 2018 07:27:27 -0700 From: Jianchao Wang To: axboe@kernel.dk Cc: martin.petersen@oracle.com, tom.leiming@gmail.com, hch@lst.de, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2] block: fix the DISCARD request merge Date: Sat, 20 Oct 2018 22:29:37 +0800 Message-Id: <1540045777-10290-1-git-send-email-jianchao.w.wang@oracle.com> X-Mailer: git-send-email 2.7.4 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9051 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=998 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810200135 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are two cases when handle DISCARD merge - max_discard_segments == 1 bios need to be contiguous - max_discard_segments > 1 Only nvme right now. 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. Signed-off-by: Jianchao Wang Reviewed-by: Ming Lei --- V2: - Add max_discard_segments > 1 checking in attempt_merge - Change patch title and comment - Add more comment in attempt_merge block/blk-merge.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/block/blk-merge.c b/block/blk-merge.c index 42a4674..8f22374 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -734,8 +734,15 @@ static struct request *attempt_merge(struct request_queue *q, /* * not contiguous */ - if (blk_rq_pos(req) + blk_rq_sectors(req) != blk_rq_pos(next)) - return NULL; + if (blk_rq_pos(req) + blk_rq_sectors(req) != blk_rq_pos(next)) { + /* + * When max_discard_segments is bigger than 1 (only nvme right + * now), needn't consider the contiguity. + */ + if (!(req_op(req) == REQ_OP_DISCARD && + queue_max_discard_segments(q) > 1)) + return NULL; + } if (rq_data_dir(req) != rq_data_dir(next) || req->rq_disk != next->rq_disk @@ -757,10 +764,17 @@ static struct request *attempt_merge(struct request_queue *q, * If we are allowed to merge, then append bio list * from next to rq and release next. merge_requests_fn * will have updated segment counts, update sector - * counts here. Handle DISCARDs separately, as they - * have separate settings. + * counts here. + * Two cases of Handling DISCARD: + * - max_discard_segments == 1 + * The bios need to be contiguous. + * - max_discard_segments > 1 + * Only nvme right now. It takes every bio as a + * range and send them to controller together. The ranges + * needn't to be contiguous. */ - if (req_op(req) == REQ_OP_DISCARD) { + if (req_op(req) == REQ_OP_DISCARD && + queue_max_discard_segments(q) > 1) { if (!req_attempt_discard_merge(q, req, next)) return NULL; } else if (!ll_merge_requests_fn(q, req, next))