public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Keith Busch <keith.busch@intel.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: "jianchao.wang" <jianchao.w.wang@oracle.com>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	Christoph Hellwig <hch@lst.de>,
	"linux-nvme@lists.infradead.org" <linux-nvme@lists.infradead.org>,
	Ming Lei <ming.lei@redhat.com>
Subject: Re: WARNING: CPU: 2 PID: 207 at drivers/nvme/host/core.c:527 nvme_setup_cmd+0x3d3
Date: Thu, 1 Feb 2018 11:12:09 -0700	[thread overview]
Message-ID: <20180201181208.GB24417@localhost.localdomain> (raw)
In-Reply-To: <7ec361a3-8900-d259-6842-e0b0b14a253a@kernel.dk>

On Thu, Feb 01, 2018 at 10:58:23AM -0700, Jens Axboe wrote:
> I was able to reproduce on a test box, pretty trivially in fact:
> 
> # echo mq-deadline > /sys/block/nvme2n1/queue/scheduler
> # mkfs.ext4 /dev/nvme2n1
> # mount /dev/nvme2n1 /data -o discard
> # dd if=/dev/zero of=/data/10g bs=1M count=10k
> # sync
> # rm /data/10g
> # sync <- triggered

Nice! Thanks, this recipe works for me too.
 
> Your patch still doesn't work, but mainly because we init the segments
> to 0 when setting up a discard. The below works for me, and cleans up
> the merge path a bit, since your patch was missing various adjustments
> on both the merged and freed request.

Yep, your update is very similiar to my real patch, but I'm missing one
thing (elv_merge_requests). If you're already testing successfully with
your patch, I don't mind if you want to move forward with yours.

 
> diff --git a/block/blk-core.c b/block/blk-core.c
> index a2005a485335..e4561c95fc23 100644
> --- a/block/blk-core.c
> +++ b/block/blk-core.c
> @@ -3282,6 +3282,8 @@ void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
>  {
>  	if (bio_has_data(bio))
>  		rq->nr_phys_segments = bio_phys_segments(q, bio);
> +	else if (bio_op(bio) == REQ_OP_DISCARD)
> +		rq->nr_phys_segments = 1;
>  
>  	rq->__data_len = bio->bi_iter.bi_size;
>  	rq->bio = rq->biotail = bio;
> diff --git a/block/blk-merge.c b/block/blk-merge.c
> index 8452fc7164cc..782940c65d8a 100644
> --- a/block/blk-merge.c
> +++ b/block/blk-merge.c
> @@ -550,6 +550,24 @@ 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->nr_phys_segments = segments + blk_rq_nr_discard_segments(next);
> +	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)
>  {
> @@ -683,9 +701,13 @@ 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.
> +	 * counts here. Handle DISCARDs separately, as they
> +	 * have separate settings.
>  	 */
> -	if (!ll_merge_requests_fn(q, req, next))
> +	if (req_op(req) == REQ_OP_DISCARD) {
> +		if (!req_attempt_discard_merge(q, req, next))
> +			return NULL;
> +	} else if (!ll_merge_requests_fn(q, req, next))
>  		return NULL;
>  
>  	/*
> @@ -715,7 +737,8 @@ static struct request *attempt_merge(struct request_queue *q,
>  
>  	req->__data_len += blk_rq_bytes(next);
>  
> -	elv_merge_requests(q, req, next);
> +	if (req_op(req) != REQ_OP_DISCARD)
> +		elv_merge_requests(q, req, next);
>  
>  	/*
>  	 * 'next' is going away, so update stats accordingly
> 
> -- 
> Jens Axboe
> 

  reply	other threads:[~2018-02-01 18:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-30 15:41 WARNING: CPU: 2 PID: 207 at drivers/nvme/host/core.c:527 nvme_setup_cmd+0x3d3 Jens Axboe
2018-01-30 15:57 ` Jens Axboe
2018-01-30 20:30   ` Keith Busch
2018-01-30 20:32     ` Jens Axboe
2018-01-30 20:49       ` Keith Busch
2018-01-30 20:55         ` Jens Axboe
2018-01-31  4:25   ` jianchao.wang
2018-01-31 15:29     ` Jens Axboe
2018-01-31 23:33       ` Keith Busch
2018-02-01  3:03         ` Jens Axboe
2018-02-01  3:03       ` jianchao.wang
2018-02-01  3:07         ` Jens Axboe
2018-02-01  3:33           ` jianchao.wang
2018-02-01  3:35             ` Jens Axboe
2018-02-01  4:56           ` Keith Busch
2018-02-01 15:26             ` Jens Axboe
2018-02-01 17:58               ` Jens Axboe
2018-02-01 18:12                 ` Keith Busch [this message]
2018-02-01 19:52                 ` Keith Busch
2018-02-01 20:55                   ` Jens Axboe
2018-02-01 18:01               ` Keith Busch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180201181208.GB24417@localhost.localdomain \
    --to=keith.busch@intel.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=jianchao.w.wang@oracle.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=ming.lei@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox