From patchwork Thu Feb 1 04:56:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 10195059 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D850960247 for ; Thu, 1 Feb 2018 04:53:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C0F94288E6 for ; Thu, 1 Feb 2018 04:53:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2B86288EA; Thu, 1 Feb 2018 04:53:03 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 58B11288E6 for ; Thu, 1 Feb 2018 04:53:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751324AbeBAExB (ORCPT ); Wed, 31 Jan 2018 23:53:01 -0500 Received: from mga01.intel.com ([192.55.52.88]:56289 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751190AbeBAExA (ORCPT ); Wed, 31 Jan 2018 23:53:00 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jan 2018 20:53:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,443,1511856000"; d="scan'208";a="197780417" Received: from unknown (HELO localhost.localdomain) ([10.232.112.44]) by orsmga005.jf.intel.com with ESMTP; 31 Jan 2018 20:52:59 -0800 Date: Wed, 31 Jan 2018 21:56:45 -0700 From: Keith Busch To: Jens Axboe Cc: "jianchao.wang" , "linux-block@vger.kernel.org" , Christoph Hellwig , "linux-nvme@lists.infradead.org" , Ming Lei Subject: Re: WARNING: CPU: 2 PID: 207 at drivers/nvme/host/core.c:527 nvme_setup_cmd+0x3d3 Message-ID: <20180201045645.GF27735@localhost.localdomain> References: <45f93661-da0d-94c5-1740-85242df8776e@kernel.dk> <0872b361-157b-a876-20af-3d7a4ee7ff31@kernel.dk> <8fd916ab-42d7-c654-5a01-8f1eb4be730e@oracle.com> <0b7686b3-f716-49ba-c7c4-929d84905569@kernel.dk> <7459ffed-c63c-38a9-84f5-456c2a5c4fe0@oracle.com> <0f6c248b-eb67-9b02-a4b9-0366d476e70d@kernel.dk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <0f6c248b-eb67-9b02-a4b9-0366d476e70d@kernel.dk> User-Agent: Mutt/1.9.1 (2017-09-22) 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 On Wed, Jan 31, 2018 at 08:07:41PM -0700, Jens Axboe wrote: > if (total_phys_segments > queue_max_segments(q)) > - return 0; > + return 0; This perhaps unintended change happens to point out another problem: queue_max_segments is the wrong limit for discards, which require queue_max_discard_segments. It might be easier to merge discard requests special, like how merging a discard bio is handled (untested). --- -- diff --git a/block/blk-merge.c b/block/blk-merge.c index 8452fc7164cc..01671e1373ff 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -550,6 +550,28 @@ static bool req_no_special_merge(struct request *req) return !q->mq_ops && req->special; } +static bool req_attempt_discard_merge(struct request_queue *q, struct request *req, + struct request *next) +{ + unsigned short segments = blk_rq_nr_discard_segments(req); + + if (segments >= queue_max_discard_segments(q)) + goto no_merge; + if (blk_rq_sectors(req) + bio_sectors(next->bio) > + blk_rq_get_max_sectors(req, blk_rq_pos(req))) + goto no_merge; + + req->biotail->bi_next = next->bio; + req->biotail = next->biotail; + req->nr_phys_segments = segments + blk_rq_nr_discard_segments(next); + next->bio = NULL; + return true; + +no_merge: + req_set_nomerge(q, req); + return false; +} + static int ll_merge_requests_fn(struct request_queue *q, struct request *req, struct request *next) { @@ -679,6 +701,15 @@ static struct request *attempt_merge(struct request_queue *q, if (req->write_hint != next->write_hint) return NULL; + /* + * Discards are ... special. + */ + if (req_op(req) == REQ_OP_DISCARD) { + if (req_attempt_discard_merge(q, req, next)) + return next; + return NULL; + } + /* * If we are allowed to merge, then append bio list * from next to rq and release next. merge_requests_fn