From: Ming Lei <ming.lei@redhat.com>
To: Sumanesh Samanta <sumanesh.samanta@broadcom.com>
Cc: axboe@kernel.dk, linux-block@vger.kernel.org, jejb@linux.ibm.com,
martin.petersen@oracle.com, linux-scsi@vger.kernel.org,
sathya.prakash@broadcom.com, chaitra.basappa@broadcom.com,
suganath-prabu.subramani@broadcom.com,
kashyap.desai@broadcom.com, sumit.saxena@broadcom.com,
shivasharan.srikanteshwara@broadcom.com, emilne@redhat.com,
hch@lst.de, hare@suse.de, bart.vanassche@wdc.com
Subject: Re: [PATCH 1/1] scsi core: limit overhead of device_busy counter for SSDs
Date: Wed, 20 Nov 2019 15:29:19 +0800 [thread overview]
Message-ID: <20191120072919.GB3664@ming.t460p> (raw)
In-Reply-To: <1574194079-27363-2-git-send-email-sumanesh.samanta@broadcom.com>
On Tue, Nov 19, 2019 at 12:07:59PM -0800, Sumanesh Samanta wrote:
> From: root <sumanesh.samanta@broadcom.com>
>
> Recently a patch was delivered to remove host_busy counter from SCSI mid layer. That was a major bottleneck, and helped improve SCSI stack performance.
> With that patch, bottle neck moved to the scsi_device device_busy counter. The performance issue with this counter is seen more in cases where a single device can produce very high IOPs, for example h/w RAID devices where OS sees one device, but there are many drives behind it, thus being capable of very high IOPs. The effect is also visible when cores from multiple NUMA nodes send IO to the same device or same controller.
> The device_busy counter is not needed by controllers which can manage as many IO as submitted to it. Rotating media still uses it for merging IO, but for non-rotating SSD drives it becomes a major bottleneck as described above.
>
> A few weeks back, a patch was provided to address the device_busy counter also but unfortunately that had some issues:
> 1. There was a functional issue discovered:
> https://lists.01.org/hyperkitty/list/lkp@lists.01.org/thread/VFKDTG4XC4VHWX5KKDJJI7P36EIGK526/
> 2. There was some concern about existing drivers using the device_busy counter.
There are only two drivers(mpt3sas and megaraid_sas) which uses this
counter. And there are two types of usage:
1) both use .device_busy to balance interrupt load among LUNs in
fast path
2) mpt3sas uses .device_busy in its device reset handler(slow path), and
this kind of usage can be replaced by blk_mq_queue_tag_busy_iter()
easily.
IMO, blk-mq has already considered IO load balance, see
hctx_may_queue(), meantime managed IRQ can balance IO completion load
among each IRQ vectors, not see obvious reason for driver to do that
any more.
However, if the two drivers still want to do that, I'd suggest to implement
it inside the driver, and no reason to re-invent generic wheels just for
two drivers.
That is why I replace .device_busy uses in the two drivers with private
counters in the patches posted days ago:
https://lore.kernel.org/linux-scsi/20191118103117.978-1-ming.lei@redhat.com/T/#t
And if drivers thought the private counter isn't good enough, they can
improve it in any way, such as this percpu approach, or even kill them.
>
> This patch is an attempt to address both the above issues.
> For this patch to be effective, LLDs need to set a specific flag use_per_cpu_device_busy in the scsi_host_template. For other drivers ( who does not set the flag), this patch would be a no-op, and should not affect their performance or functionality at all.
>
> Also, this patch does not fundamentally change any logic or functionality of the code. All it does is replace device_busy with a per CPU counter. In fast path, all cpu increment/decrement their own counter. In relatively slow path. they call scsi_device_busy function to get the total no of IO outstanding on a device. Only functional aspect it changes is that for non-rotating media, the number of IO to a device is not restricted. Controllers which can handle that, can set the use_per_cpu_device_busy flag in scsi_host_template to take advantage of this patch. Other controllers need not modify any code and would work as usual.
> Since the patch does not modify any other functional aspects, it should not have any side effects even for drivers that do set the use_per_cpu_device_busy flag.
> ---
> drivers/scsi/scsi_lib.c | 151 ++++++++++++++++++++++++++++++++++---
> drivers/scsi/scsi_scan.c | 16 ++++
> drivers/scsi/scsi_sysfs.c | 9 ++-
> drivers/scsi/sg.c | 2 +-
> include/scsi/scsi_device.h | 15 ++++
> include/scsi/scsi_host.h | 16 ++++
> 6 files changed, 197 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index 2563b061f56b..5dc392914f9e 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -52,6 +52,12 @@
> #define SCSI_INLINE_SG_CNT 2
> #endif
>
> +#define MAX_PER_CPU_COUNTER_ABSOLUTE_VAL (0xFFFFFFFFFFF)
> +#define PER_CPU_COUNTER_OK_VAL (MAX_PER_CPU_COUNTER_ABSOLUTE_VAL>>16)
> +#define USE_DEVICE_BUSY(sdev) (!(sdev)->host->hostt->use_per_cpu_device_busy \
> + || !blk_queue_nonrot((sdev)->request_queue))
> +
> +
> static struct kmem_cache *scsi_sdb_cache;
> static struct kmem_cache *scsi_sense_cache;
> static struct kmem_cache *scsi_sense_isadma_cache;
> @@ -65,6 +71,111 @@ scsi_select_sense_cache(bool unchecked_isa_dma)
> return unchecked_isa_dma ? scsi_sense_isadma_cache : scsi_sense_cache;
> }
>
> +/*
> + *Generic helper function to decrement per cpu io counter.
> + *@per_cpu_counter: The per cpu counter array. Current cpu counter will be
> + * decremented
> + */
> +
> +static inline void dec_per_cpu_io_counter(atomic64_t __percpu *per_cpu_counter)
> +{
> + atomic64_t __percpu *io_count = get_cpu_ptr(per_cpu_counter);
> +
> + if (unlikely(abs(atomic64_dec_return(io_count)) >
> + MAX_PER_CPU_COUNTER_ABSOLUTE_VAL))
> + scsi_rebalance_per_cpu_io_counters(per_cpu_counter, io_count);
> + put_cpu_ptr(per_cpu_counter);
> +}
> +/*
> + *Generic helper function to increment per cpu io counter.
> + *@per_cpu_counter: The per cpu counter array. Current cpu counter will be
> + * incremented
> + */
> +static inline void inc_per_cpu_io_counter(atomic64_t __percpu *per_cpu_counter)
> +{
> + atomic64_t __percpu *io_count = get_cpu_ptr(per_cpu_counter);
> +
> + if (unlikely(abs(atomic64_inc_return(io_count)) >
> + MAX_PER_CPU_COUNTER_ABSOLUTE_VAL))
> + scsi_rebalance_per_cpu_io_counters(per_cpu_counter, io_count);
> + put_cpu_ptr(per_cpu_counter);
> +}
> +
> +
> +/**
> + * scsi_device_busy - Return the device_busy counter
> + * @sdev: Pointer to scsi_device to get busy counter.
> + **/
> +int scsi_device_busy(struct scsi_device *sdev)
> +{
> + long long total = 0;
> + int i;
> +
> + if (USE_DEVICE_BUSY(sdev))
As Ewan and Bart commented, you can't use the NONROT queue flag simply
in IO path, given it may be changed somewhere.
Thanks,
Ming
next prev parent reply other threads:[~2019-11-20 7:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-19 20:07 [PATCH 0/1] : limit overhead of device_busy counter for SSDs Sumanesh Samanta
2019-11-19 20:07 ` [PATCH 1/1] scsi core: " Sumanesh Samanta
2019-11-19 21:01 ` Ewan D. Milne
2019-11-19 23:22 ` Bart Van Assche
2019-11-19 23:35 ` Sumanesh Samanta
2019-11-20 7:29 ` Ming Lei [this message]
2019-11-20 19:59 ` Sumanesh Samanta
2019-11-21 1:34 ` Ming Lei
2019-11-21 1:59 ` Sumanesh Samanta
2019-11-21 2:29 ` Ming Lei
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=20191120072919.GB3664@ming.t460p \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=bart.vanassche@wdc.com \
--cc=chaitra.basappa@broadcom.com \
--cc=emilne@redhat.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=jejb@linux.ibm.com \
--cc=kashyap.desai@broadcom.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=sathya.prakash@broadcom.com \
--cc=shivasharan.srikanteshwara@broadcom.com \
--cc=suganath-prabu.subramani@broadcom.com \
--cc=sumanesh.samanta@broadcom.com \
--cc=sumit.saxena@broadcom.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