Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1637504

Re: Large latency on blk_queue_enter

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!news.servidellagleba.it!bofh.it!news.nic.it!robomod
From Jens Axboe <axboe@kernel.dk>
Newsgroups linux.kernel
Subject Re: Large latency on blk_queue_enter
Date Mon, 08 May 2017 17:20:02 +0200
Message-ID <tESC6-5Ad-27@gated-at.bofh.it> (permalink)
References <tEPuy-3tj-21@gated-at.bofh.it> <tEPXz-3RJ-5@gated-at.bofh.it> <tERd0-4yE-13@gated-at.bofh.it> <tERPH-51Z-13@gated-at.bofh.it> <tERPH-51Z-11@gated-at.bofh.it> <tES94-59R-15@gated-at.bofh.it> <tES94-59R-13@gated-at.bofh.it> <tESsp-5wT-17@gated-at.bofh.it> <tESsp-5wT-15@gated-at.bofh.it> <tESC6-5Ad-29@gated-at.bofh.it>
X-Original-To Javier González <jg@lightnvm.io>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=cwzsX9wPs7uY37X0lO9IL1jzTjO09AYmrsIDmBSy44U=; b=ELpChK0W7f8mKU/A4UI+LUjpq2rsnZ06wtWOEhnmfFIUjUsdEOT+JZE+QIC4Rn2Ii4 C00Q6VbCxr4KuroihIYFcryQScpyBWCvB56dWE7diNy4zrPGYGnpF7g6i/Rj0AsEZU6Z 2tdbWVlNXitbgcbQMYh8Wgtfps/vWsd1uiHlqZfsOJYw1UcpZjSEtUGJmgEePhYgJR+x B8kZ0c1VsFlfXj1+4XTJn0KstR//HkEpUCFEWX0puMAxsgYH5Z/6eFQ0wdk4P6CWczed qPJ18f3tGDSlT2ZM3B020dN1q3W/XIVNwCODBTrjyDjoVP0FQkDOj2TD1pYLdquvsdTh 745A==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=cwzsX9wPs7uY37X0lO9IL1jzTjO09AYmrsIDmBSy44U=; b=e9oibRjNjBXP6CO3+KaH52p4HOZtwmHpCJ015VlTyrozrw/FkUBofbTqPt8/zgsxpl 4guxCnCEqiOolecvVB85V2DGUtFVABeM5tp/eia/4mCxYJuz/zVyibC2tHuhnrKsxGzE 5MAmm05CnKITD3aGMtQ3GNUiQq6uxUJ3PBOKuzQJP/0P2K/PvLSrKQ9qIqFXznNX0GIq hMabgDQ5xr05VNQYkq0xNhtFwInffqaBNqodIO7D+A8knRepNpOnj8ffhI7JbXwCdx9w WkqcFbendEu8NWIM1hbG3aJUpE84R0mPSjfcAI0oy+6LFUNnAbv1DUtzlc7yTC/BM/Hc 5Bxg==
X-Gm-Message-State AN3rC/6OIQZv2SrhbFcZz/S/SsUBimgmuK1w0Mc71JiloVlyzEl+uszb VieJqB8st/vUng==
X-Received by 10.107.6.69 with SMTP id 66mr25065516iog.163.1494256463714; Mon, 08 May 2017 08:14:23 -0700 (PDT)
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 129
Organization linux.* mail to news gateway
X-Original-Cc Ming Lei <ming.lei@redhat.com>, Christoph Hellwig <hch@lst.de>, Dan Williams <dan.j.williams@intel.com>, linux-block@vger.kernel.org, Linux Kernel Mailing List <linux-kernel@vger.kernel.org>, Matias Bjørling <mb@lightnvm.io>
X-Original-Date Mon, 8 May 2017 09:14:22 -0600
X-Original-Message-ID <991bbc1d-1849-94d9-5787-69a630e7e10d@kernel.dk>
X-Original-References <1656B440-3ECA-4F2B-B95C-418CF0F347E9@lightnvm.io> <20170508122738.GC5696@ming.t460p> <76E35BA3-FEC9-46D6-B36F-554F464FA9ED@lightnvm.io> <bbe256c2-f9ff-e594-45c9-7f9ac233ee7a@fb.com> <E169E488-53EC-468A-9221-DF11F0944298@lightnvm.io> <661d4b67-cf0c-a703-331b-ce24d75e782d@fb.com> <C6ED0F6F-EEC2-4F2A-A498-34B0882BA924@lightnvm.io> <a088cc3d-7d85-98bf-e7a4-93368cadd238@fb.com> <375D00C3-8B76-40FA-BB81-69829270BF5A@lightnvm.io> <576f9601-b0de-c636-8195-07e12fe99734@fb.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1637504

Show key headers only | View raw


On 05/08/2017 09:08 AM, Jens Axboe wrote:
> On 05/08/2017 09:02 AM, Javier González wrote:
>>> On 8 May 2017, at 16.52, Jens Axboe <axboe@fb.com> wrote:
>>>
>>> On 05/08/2017 08:46 AM, Javier González wrote:
>>>>> On 8 May 2017, at 16.23, Jens Axboe <axboe@fb.com> wrote:
>>>>>
>>>>> On 05/08/2017 08:20 AM, Javier González wrote:
>>>>>>> On 8 May 2017, at 16.13, Jens Axboe <axboe@fb.com> wrote:
>>>>>>>
>>>>>>> On 05/08/2017 07:44 AM, Javier González wrote:
>>>>>>>>> On 8 May 2017, at 14.27, Ming Lei <ming.lei@redhat.com> wrote:
>>>>>>>>>
>>>>>>>>> On Mon, May 08, 2017 at 01:54:58PM +0200, Javier González wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I find an unusual added latency(~20-30ms) on blk_queue_enter when
>>>>>>>>>> allocating a request directly from the NVMe driver through
>>>>>>>>>> nvme_alloc_request. I could use some help confirming that this is a bug
>>>>>>>>>> and not an expected side effect due to something else.
>>>>>>>>>>
>>>>>>>>>> I can reproduce this latency consistently on LightNVM when mixing I/O
>>>>>>>>>> from pblk and I/O sent through an ioctl using liblightnvm, but I don't
>>>>>>>>>> see anything on the LightNVM side that could impact the request
>>>>>>>>>> allocation.
>>>>>>>>>>
>>>>>>>>>> When I have a 100% read workload sent from pblk, the max. latency is
>>>>>>>>>> constant throughout several runs at ~80us (which is normal for the media
>>>>>>>>>> we are using at bs=4k, qd=1). All pblk I/Os reach the nvme_nvm_submit_io
>>>>>>>>>> function on lightnvm.c., which uses nvme_alloc_request. When we send a
>>>>>>>>>> command from user space through an ioctl, then the max latency goes up
>>>>>>>>>> to ~20-30ms. This happens independently from the actual command
>>>>>>>>>> (IN/OUT). I tracked down the added latency down to the call
>>>>>>>>>> percpu_ref_tryget_live in blk_queue_enter. Seems that the queue
>>>>>>>>>> reference counter is not released as it should through blk_queue_exit in
>>>>>>>>>> blk_mq_alloc_request. For reference, all ioctl I/Os reach the
>>>>>>>>>> nvme_nvm_submit_user_cmd on lightnvm.c
>>>>>>>>>>
>>>>>>>>>> Do you have any idea about why this might happen? I can dig more into
>>>>>>>>>> it, but first I wanted to make sure that I am not missing any obvious
>>>>>>>>>> assumption, which would explain the reference counter to be held for a
>>>>>>>>>> longer time.
>>>>>>>>>
>>>>>>>>> You need to check if the .q_usage_counter is working at atomic mode.
>>>>>>>>> This counter is initialized as atomic mode, and finally switchs to
>>>>>>>>> percpu mode via percpu_ref_switch_to_percpu() in blk_register_queue().
>>>>>>>>
>>>>>>>> Thanks for commenting Ming.
>>>>>>>>
>>>>>>>> The .q_usage_counter is not working on atomic mode. The queue is
>>>>>>>> initialized normally through blk_register_queue() and the counter is
>>>>>>>> switched to percpu mode, as you mentioned. As I understand it, this is
>>>>>>>> how it should be, right?
>>>>>>>
>>>>>>> That is how it should be, yes. You're not running with any heavy
>>>>>>> debugging options, like lockdep or anything like that?
>>>>>>
>>>>>> No lockdep, KASAN, kmemleak or any of the other usual suspects.
>>>>>>
>>>>>> What's interesting is that it only happens when one of the I/Os comes
>>>>>> from user space through the ioctl. If I have several pblk instances on
>>>>>> the same device (which would end up allocating a new request in
>>>>>> parallel, potentially on the same core), the latency spike does not
>>>>>> trigger.
>>>>>>
>>>>>> I also tried to bind the read thread and the liblightnvm thread issuing
>>>>>> the ioctl to different cores, but it does not help...
>>>>>
>>>>> How do I reproduce this? Off the top of my head, and looking at the code,
>>>>> I have no idea what is going on here.
>>>>
>>>> Using LightNVM and liblightnvm [1] you can reproduce it by:
>>>>
>>>> 1. Instantiate a pblk instance on the first channel (luns 0 - 7):
>>>>        sudo nvme lnvm create -d nvme0n1 -n test0 -t pblk -b 0 -e 7 -f
>>>> 2. Write 5GB to the test0 block device with a normal fio script
>>>> 3. Read 5GB to verify that latencies are good (max. ~80-90us at bs=4k, qd=1)
>>>> 4. Re-run 3. and in parallel send a command through liblightnvm to a
>>>> different channel. A simple command is an erase (erase block 900 on
>>>> channel 2, lun 0):
>>>> 	sudo nvm_vblk line_erase /dev/nvme0n1 2 2 0 0 900
>>>>
>>>> After 4. you should see a ~25-30ms latency on the read workload.
>>>>
>>>> I tried to reproduce the ioctl in a more generic way to reach
>>>> __nvme_submit_user_cmd(), but SPDK steals the whole device. Also, qemu
>>>> is not reliable for this kind of performance testing.
>>>>
>>>> If you have a suggestion on how I can mix an ioctl with normal block I/O
>>>> read on a standard NVMe device, I'm happy to try it and see if I can
>>>> reproduce the issue.
>>>
>>> Just to rule out this being any hardware related delays in processing
>>> IO:
>>>
>>> 1) Does it reproduce with a simpler command, anything close to a no-op
>>>   that you can test?
>>
>> Yes. I tried with a 4KB read and with a fake command I drop right after
>> allocation.
>>
>>> 2) What did you use to time the stall being blk_queue_enter()?
>>>
>>
>> I have some debug code measuring time with ktime_get() in different
>> places in the stack, and among other places, around blk_queue_enter(). I
>> use them then to measure max latency and expose it through sysfs. I can
>> see that the latency peak is recorded in the probe before
>> blk_queue_enter() and not in the one after.
>>
>> I also did an experiment, where the normal I/O path allocates the
>> request with BLK_MQ_REQ_NOWAIT. When running the experiment above, the
>> read test fails since we reach:
>> 	if (nowait)
>> 	  return -EBUSY;
>>
>> in blk_queue_enter.
> 
> OK, that's starting to make more sense, that indicates that there is indeed
> something wrong with the refs. Does the below help?

No, that can't be right, it does look balanced to begin with.
blk_mq_alloc_request() always grabs a queue ref, and always drops it. If
we return with a request succesfully allocated, then we have an extra
ref on it, which is dropped when it is later freed. Something smells
fishy, I'll dig a bit.

-- 
Jens Axboe

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Large latency on blk_queue_enter Javier González <jg@lightnvm.io> - 2017-05-08 14:00 +0200
  Re: Large latency on blk_queue_enter Ming Lei <ming.lei@redhat.com> - 2017-05-08 14:30 +0200
    Re: Large latency on blk_queue_enter Javier González <jg@lightnvm.io> - 2017-05-08 15:50 +0200
      Re: Large latency on blk_queue_enter Javier González <jg@lightnvm.io> - 2017-05-08 16:30 +0200
        Re: Large latency on blk_queue_enter Javier González <jg@lightnvm.io> - 2017-05-08 16:50 +0200
          Re: Large latency on blk_queue_enter Javier González <jg@lightnvm.io> - 2017-05-08 17:10 +0200
            Re: Large latency on blk_queue_enter Jens Axboe <axboe@kernel.dk> - 2017-05-08 17:20 +0200
              Re: Large latency on blk_queue_enter Jens Axboe <axboe@kernel.dk> - 2017-05-08 17:30 +0200
                Re: Large latency on blk_queue_enter Javier González <jg@lightnvm.io> - 2017-05-08 17:40 +0200
                Re: Large latency on blk_queue_enter Javier González <jg@lightnvm.io> - 2017-05-08 17:50 +0200
                Re: Large latency on blk_queue_enter Jens Axboe <axboe@kernel.dk> - 2017-05-08 18:10 +0200
                Re: Large latency on blk_queue_enter Javier González <jg@lightnvm.io> - 2017-05-08 18:40 +0200
                Re: Large latency on blk_queue_enter Javier González <jg@lightnvm.io> - 2017-05-09 12:40 +0200
                Re: Large latency on blk_queue_enter Ming Lei <ming.lei@redhat.com> - 2017-05-09 13:00 +0200
                Re: Large latency on blk_queue_enter Javier González <jg@lightnvm.io> - 2017-05-09 13:30 +0200
                Re: Large latency on blk_queue_enter Javier González <jg@lightnvm.io> - 2017-05-09 16:30 +0200
                Re: Large latency on blk_queue_enter Jens Axboe <axboe@kernel.dk> - 2017-05-08 17:50 +0200
              Re: Large latency on blk_queue_enter Javier González <jg@lightnvm.io> - 2017-05-08 17:30 +0200

csiph-web