Skip to contentSkip to conversation

Block: Give option to force io polling

PATCH In review Jon Derrick 5 participants 15 messages Mar 31, 2016 – May 12, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Block: Give option to force io polling

In 4.6, enabling io polling in direct-io was switched to a per-io flag. This had an unintended result of giving a significant difference when doing benchmarks between 4.5 and 4.6, using fio's sync engine.

I was able to regain the performance by getting the pvsync2 engine working with the new p{read,write}v2 syscalls, but this patchset allows polling to be tried in the direct-io path with the other syscalls.

Rather than having to convert applications to prwv2 syscalls, users can enable this knob that let's them see the same performance as they may have seen in 4.5 when it always polled.

Jon Derrick (2):
block: add queue flag to always poll
block: add forced polling sysfs controls

 block/blk-core.c       |  8 ++++++++
 block/blk-sysfs.c      | 38 ++++++++++++++++++++++++++++++++++++++
 fs/direct-io.c         |  7 ++++++-
 include/linux/blkdev.h |  2 ++
 4 files changed, 54 insertions(+), 1 deletion(-)
Signature · 1 line
2.5.0
#1 lore raw

PATCH 1/2 block: add queue flag to always poll

This patch adds poll-by-default functionality back for 4.6 by adding a queue flag which specifies that it should always try polling, rather than only if the io specifies it.

Signed-off-by Jon Derrick <jonathan.derrick at intel.com>
---
 block/blk-core.c       | 8 ++++++++
 fs/direct-io.c         | 7 ++++++-
 include/linux/blkdev.h | 2 ++
 3 files changed, 16 insertions(+), 1 deletion(-)
block/blk-core.c +8 -0
index 827f8ba..d85f913 100644
@@ -3335,6 +3335,14 @@ void blk_finish_plug(struct blk_plug *plug)
 }
 EXPORT_SYMBOL(blk_finish_plug);
 
+bool blk_force_poll(struct request_queue *q)
+{
+	if (!q->mq_ops || !q->mq_ops->poll ||
+	    !test_bit(QUEUE_FLAG_POLL_FORCE, &q->queue_flags))
+		return false;
+	return true;
+}
+
 bool blk_poll(struct request_queue *q, blk_qc_t cookie)
 {
 	struct blk_plug *plug;
fs/direct-io.c +6 -1
index 476f1ec..2775552 100644
@@ -450,7 +450,12 @@ static struct bio *dio_await_one(struct dio *dio)
 		__set_current_state(TASK_UNINTERRUPTIBLE);
 		dio->waiter = current;
 		spin_unlock_irqrestore(&dio->bio_lock, flags);
-		if (!(dio->iocb->ki_flags & IOCB_HIPRI) ||
+		/*
+		 * Polling must be enabled explicitly on a per-IO basis,
+		 * or through the queue's sysfs io_poll_force control
+		 */
+		if (!((dio->iocb->ki_flags & IOCB_HIPRI) ||
+		      (blk_force_poll(bdev_get_queue(dio->bio_bdev)))) ||
 		    !blk_poll(bdev_get_queue(dio->bio_bdev), dio->bio_cookie))
 			io_schedule();
 		/* wake up sets us TASK_RUNNING */
include/linux/blkdev.h +2 -0
index 7e5d7e0..e87ef17 100644
@@ -491,6 +491,7 @@ struct request_queue {
 #define QUEUE_FLAG_INIT_DONE   20	/* queue is initialized */
 #define QUEUE_FLAG_NO_SG_MERGE 21	/* don't attempt to merge SG segments*/
 #define QUEUE_FLAG_POLL	       22	/* IO polling enabled if set */
+#define QUEUE_FLAG_POLL_FORCE  23	/* IO polling forced if set */
 
 #define QUEUE_FLAG_DEFAULT	((1 << QUEUE_FLAG_IO_STAT) |		\
 				 (1 << QUEUE_FLAG_STACKABLE)	|	\
@@ -824,6 +825,7 @@ extern int blk_execute_rq(struct request_queue *, struct gendisk *,
 extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *,
 				  struct request *, int, rq_end_io_fn *);
 
+bool blk_force_poll(struct request_queue *q);
 bool blk_poll(struct request_queue *q, blk_qc_t cookie);
 
 static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
Signature · 1 line
2.5.0
#2 lore raw

PATCH 1/2 block: add queue flag to always poll

Quoted 3 lines · Jon Derrick

This patch adds poll-by-default functionality back for 4.6 by adding a queue flag which specifies that it should always try polling, rather than only if the io specifies it.

I'm not against the functionality, but it somehow feels like you've implemented this at the wrong layer. I'd much rather polling be forced on for the file or the mountpoint, and then all requests would come down with RWF_HIPRI and there would be no special casing in the direct I/O code.

In case others disagree, I've provided a couple of comments below. Really, though, I think this is implemented upside-down.

-Jeff

Quoted 12 lines
Signed-off-by Jon Derrick <jonathan.derrick at intel.com>
---
 block/blk-core.c       | 8 ++++++++
 fs/direct-io.c         | 7 ++++++-
 include/linux/blkdev.h | 2 ++
 3 files changed, 16 insertions(+), 1 deletion(-)
block/blk-core.c +0 -0
index 827f8ba..d85f913 100644

block/blk-core.c void blk_finish_plug(struct blk_plug *plug) · line 3344

Quoted 10 lines
block/blk-core.c +7 -0
@@ -3335,6 +3335,14 @@ void blk_finish_plug(struct blk_plug *plug)
 }
 EXPORT_SYMBOL(blk_finish_plug);
 
+bool blk_force_poll(struct request_queue *q)
+{
+	if (!q->mq_ops || !q->mq_ops->poll ||
+	    !test_bit(QUEUE_FLAG_POLL_FORCE, &q->queue_flags))
+		return false;
+	return true;
+}

The flag shouldn't be set if it doesn't make sense, and these checks are re-done inside blk_poll, anyway. Just do the test bit:

	return test_bit(QUEUE_FLAG_POLL_FORCE, &q->queue_flags);
Quoted 9 lines
block/blk-core.c +0 -0
 bool blk_poll(struct request_queue *q, blk_qc_t cookie)
 {
 	struct blk_plug *plug;
fs/direct-io.c +0 -0
index 476f1ec..2775552 100644
@@ -450,7 +450,12 @@ static struct bio *dio_await_one(struct dio *dio)
 		__set_current_state(TASK_UNINTERRUPTIBLE);

fs/direct-io.c static struct bio *dio_await_one(struct dio *dio) · line 459

Quoted 10 lines
fs/direct-io.c +6 -1
 		dio->waiter = current;
 		spin_unlock_irqrestore(&dio->bio_lock, flags);
-		if (!(dio->iocb->ki_flags & IOCB_HIPRI) ||
+		/*
+		 * Polling must be enabled explicitly on a per-IO basis,
+		 * or through the queue's sysfs io_poll_force control
+		 */
+		if (!((dio->iocb->ki_flags & IOCB_HIPRI) ||
+		      (blk_force_poll(bdev_get_queue(dio->bio_bdev)))) ||
 		    !blk_poll(bdev_get_queue(dio->bio_bdev), dio->bio_cookie))

Make a local variable for the queue, please.

-Jeff

#3 lore raw

PATCH 1/2 block: add queue flag to always poll

Quoted 11 lines · Jeff Moyer
Quoted 3 lines · Jon Derrick

This patch adds poll-by-default functionality back for 4.6 by adding a queue flag which specifies that it should always try polling, rather than only if the io specifies it.

I'm not against the functionality, but it somehow feels like you've implemented this at the wrong layer. I'd much rather polling be forced on for the file or the mountpoint, and then all requests would come down with RWF_HIPRI and there would be no special casing in the direct I/O code.

It was mainly grouped with common code.

I'll look into your suggestion of tagging HIPRI on file or mountpoint.

Quoted 32 lines

In case others disagree, I've provided a couple of comments below. Really, though, I think this is implemented upside-down.

-Jeff

Quoted 12 lines
Signed-off-by Jon Derrick <jonathan.derrick at intel.com>
---
 block/blk-core.c       | 8 ++++++++
 fs/direct-io.c         | 7 ++++++-
 include/linux/blkdev.h | 2 ++
 3 files changed, 16 insertions(+), 1 deletion(-)
block/blk-core.c +0 -0
index 827f8ba..d85f913 100644

block/blk-core.c void blk_finish_plug(struct blk_plug *plug) · line 3344

Quoted 10 lines
block/blk-core.c +7 -0
@@ -3335,6 +3335,14 @@ void blk_finish_plug(struct blk_plug *plug)
 }
 EXPORT_SYMBOL(blk_finish_plug);
 
+bool blk_force_poll(struct request_queue *q)
+{
+	if (!q->mq_ops || !q->mq_ops->poll ||
+	    !test_bit(QUEUE_FLAG_POLL_FORCE, &q->queue_flags))
+		return false;
+	return true;
+}

The flag shouldn't be set if it doesn't make sense, and these checks are re-done inside blk_poll, anyway. Just do the test bit:

Quoted 2 lines
	return test_bit(QUEUE_FLAG_POLL_FORCE, &q->queue_flags);

Yeah I noticed that too after posting v1, but I didn't get much interest into proposing v2. Thanks for catching that and reminding me of it.

Quoted 13 lines
Quoted 13 lines
block/blk-core.c +0 -0
 bool blk_poll(struct request_queue *q, blk_qc_t cookie)
 {
 	struct blk_plug *plug;
fs/direct-io.c +1 -1
index 476f1ec..2775552 100644
@@ -450,7 +450,12 @@ static struct bio *dio_await_one(struct dio *dio)
 		__set_current_state(TASK_UNINTERRUPTIBLE);
 		dio->waiter = current;
 		spin_unlock_irqrestore(&dio->bio_lock, flags);
-		if (!(dio->iocb->ki_flags & IOCB_HIPRI) ||
+		/*
Quoted 9 lines

fs/direct-io.c static struct bio *dio_await_one(struct dio *dio) · line 459

Quoted 6 lines
fs/direct-io.c +5 -0
+		 * Polling must be enabled explicitly on a per-IO basis,
+		 * or through the queue's sysfs io_poll_force control
+		 */
+		if (!((dio->iocb->ki_flags & IOCB_HIPRI) ||
+		      (blk_force_poll(bdev_get_queue(dio->bio_bdev)))) ||
 		    !blk_poll(bdev_get_queue(dio->bio_bdev), dio->bio_cookie))

Make a local variable for the queue, please.

Sounds good

Quoted 1 line

-Jeff

#4 lore raw

PATCH 2/2 block: add forced polling sysfs controls

In reply to Jon Derrick

This patch adds io polling force controls to sysfs. Setting this knob forces direct-io to always poll, even if the io does not specify the HIPRI flag.

Signed-off-by Jon Derrick <jonathan.derrick at intel.com>
---
 block/blk-sysfs.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
block/blk-sysfs.c +38 -0
index dd93763..e3af748 100644
@@ -347,6 +347,37 @@ static ssize_t queue_poll_store(struct request_queue *q, const char *page,
 	return ret;
 }
 
+static ssize_t queue_poll_force_show(struct request_queue *q, char *page)
+{
+	return queue_var_show(test_bit(QUEUE_FLAG_POLL_FORCE, &q->queue_flags),
+			      page);
+}
+
+static ssize_t queue_poll_force_store(struct request_queue *q, const char *page,
+				size_t count)
+{
+	unsigned long poll_force_on;
+	ssize_t ret;
+
+	if (!q->mq_ops || !q->mq_ops->poll ||
+	    !test_bit(QUEUE_FLAG_POLL, &q->queue_flags))
+		return -EINVAL;
+
+	ret = queue_var_store(&poll_force_on, page, count);
+	if (ret < 0)
+		return ret;
+
+	spin_lock_irq(q->queue_lock);
+	if (poll_force_on)
+		queue_flag_set(QUEUE_FLAG_POLL_FORCE, q);
+	else
+		queue_flag_clear(QUEUE_FLAG_POLL_FORCE, q);
+	spin_unlock_irq(q->queue_lock);
+
+	return ret;
+}
+
+
 static struct queue_sysfs_entry queue_requests_entry = {
 	.attr = {.name = "nr_requests", .mode = S_IRUGO | S_IWUSR },
 	.show = queue_requests_show,
@@ -478,6 +509,12 @@ static struct queue_sysfs_entry queue_poll_entry = {
 	.store = queue_poll_store,
 };
 
+static struct queue_sysfs_entry queue_poll_force_entry = {
+	.attr = {.name = "io_poll_force", .mode = S_IRUGO | S_IWUSR },
+	.show = queue_poll_force_show,
+	.store = queue_poll_force_store,
+};
+
 static struct attribute *default_attrs[] = {
 	&queue_requests_entry.attr,
 	&queue_ra_entry.attr,
@@ -503,6 +540,7 @@ static struct attribute *default_attrs[] = {
 	&queue_iostats_entry.attr,
 	&queue_random_entry.attr,
 	&queue_poll_entry.attr,
+	&queue_poll_force_entry.attr,
 	NULL,
 };
 
Signature · 1 line
2.5.0
#5 lore raw
In reply to Jon Derrick
Quoted 3 lines · Jon Derrick

In 4.6, enabling io polling in direct-io was switched to a per-io flag. This had an unintended result of giving a significant difference when doing benchmarks between 4.5 and 4.6, using fio's sync engine.

Only if you manually enabled polling beforehand. I really don't see how this is going to be useful for actual applications vs benchmarks, so I'll need more convincing arguments.

#6 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Jon Derrick

In 4.6, enabling io polling in direct-io was switched to a per-io flag. This had an unintended result of giving a significant difference when doing benchmarks between 4.5 and 4.6, using fio's sync engine.

Only if you manually enabled polling beforehand. I really don't see how this is going to be useful for actual applications vs benchmarks, so I'll need more convincing arguments.

I think it's more about providing opt-in control to make the low-latency benefit reachable to users with existing programs.

#7 lore raw
Quoted 2 lines · Keith Busch

I think it's more about providing opt-in control to make the low-latency benefit reachable to users with existing programs.

What program benefits from unconditional polling for all I/O on a given device?

#8 lore raw
Quoted 5 lines
Quoted 2 lines

I think it's more about providing opt-in control to make the low-latency benefit reachable to users with existing programs.

What program benefits from unconditional polling for all I/O on a given device?

End users who want to avail of the polling benefits for low latency NVMe devices without having to resort to rewriting their code would like to see something like what Jon is proposing. As I understand it this could be polling control per queue not per device but I can see caching applications where polling for the whole NVMe device would be desirable.

Stephen

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

Reviewed-by Tested-by on the v1 series
#9 lore raw
In reply to Jon Derrick
Quoted 17 lines

In 4.6, enabling io polling in direct-io was switched to a per-io flag. This had an unintended result of giving a significant difference when doing benchmarks between 4.5 and 4.6, using fio's sync engine.

I was able to regain the performance by getting the pvsync2 engine working with the new p{read,write}v2 syscalls, but this patchset allows polling to be tried in the direct-io path with the other syscalls.

Rather than having to convert applications to prwv2 syscalls, users can enable this knob that let's them see the same performance as they may have seen in 4.5 when it always polled.

Jon Derrick (2):
block: add queue flag to always poll
block: add forced polling sysfs controls

Quoted 6 lines
 block/blk-core.c       |  8 ++++++++
 block/blk-sysfs.c      | 38 ++++++++++++++++++++++++++++++++++++++
 fs/direct-io.c         |  7 ++++++-
 include/linux/blkdev.h |  2 ++
 4 files changed, 54 insertions(+), 1 deletion(-)

Hi

Revisiting this discussion from late March...

I am very interested in seeing this added. There are use cases involving super-low latency (non-NAND based) NVMe devices and they want the fastest possible IO response times for ALL IO to that device. They also have no desire to wait for the new system calls and glibc updates needed to tie their applications into polling or to rewrite their applications to avail of those new calls. I have done some testing on Jon's "big hammer" and it seems to work well for this use case and applied cleanly against v4.6-rc6.

For the series...

Cheers

Stephen

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#10 lore raw
Quoted 1 line · Stephen Bates

I am very interested in seeing this added. There are use cases involving super-low latency (non-NAND based) NVMe devices and they want the fastest possible IO response times for ALL IO to that device. They also have no desire to wait for the new system calls and glibc updates needed to tie their applications into polling or to rewrite their applications to avail of those new calls. I have done some testing on Jon's "big hammer" and it seems to work well for this use case and applied cleanly against v4.6-rc6.

Let's get the driver for those devices merged first, and if you can provide numbers that it's worth it we can add a tweak to always enable polling from the driver for those devices.

#11 lore raw
Quoted 9 lines · Stephen Bates
Quoted 1 line

I am very interested in seeing this added. There are use cases involving

super-low latency (non-NAND based) NVMe devices and they want the fastest possible IO response times for ALL IO to that device. They also have no desire to wait for the new system calls and glibc updates needed to tie their applications into polling or to rewrite their applications to avail of those new calls. I have done some testing on Jon's "big hammer" and it seems to work well for this use case and applied cleanly against v4.6-rc6.

Quoted 3 lines

Let's get the driver for those devices merged first, and if you can provide numbers that it's worth it we can add a tweak to always enable polling from the driver for those devices.

Christoph, this is a DRAM based NVMe device, the code for polling in NVMe was merged in 4.5 right? We are using the inbox NVMe driver. Here is some performance data:

QD=1, single thread, random 4KB reads

Polling Off: 12us Avg / 40us 99.99% ;
Polling On: 9.5us Avg / 25us 99.99%

Both the average and 99.99% reduction are of interest.

Cheers

Stephen

_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme

#12 lore raw
Quoted 8 lines · Stephen Bates

Christoph, this is a DRAM based NVMe device, the code for polling in NVMe was merged in 4.5 right? We are using the inbox NVMe driver. Here is some performance data:

QD=1, single thread, random 4KB reads

Polling Off: 12us Avg / 40us 99.99% ;
Polling On: 9.5us Avg / 25us 99.99%

Both the average and 99.99% reduction are of interest.

How does CPU usage look for common workloads with polling force enabled? If it's really an overall win we should just add a quirk to the NVMe driver to always force polling for this device based on the PCI ID.

#13 lore raw
Quoted 7 lines · Stephen Bates
Quoted 1 line

Christoph, this is a DRAM based NVMe device, the code for polling in

NVMe was merged in 4.5 right? We are using the inbox NVMe driver. Here is some performance data:

Quoted 1 line
Quoted 8 lines
Quoted 6 lines

QD=1, single thread, random 4KB reads

Polling Off: 12us Avg / 40us 99.99% ;
Polling On: 9.5us Avg / 25us 99.99%

Both the average and 99.99% reduction are of interest.

How does CPU usage look for common workloads with polling force enabled?

Christoph, CPU load added.

Polling Off: 12us Avg / 40us 99.99% ; CPU 0.39 H/W Threads Polling On: 9.5us Avg / 25us 99.99% ; CPU 0.98 H/W Threads

Quoted 2 lines

If it's really an overall win we should just add a quirk to the NVMe driver to always force polling for this device based on the PCI ID.

While I like the "big hammer" approach I think we have to have some control over when it is swung ;-). Always turning on polling for a specific device seems a bit too Mj?lnir [1] of a solution. The bonus of polling is only when QD and/or thread-count is low and not everyone will use the device that way. I also suspect other low latency NVMe devices are coming and having a quirk for each and every one of them does not make sense. We could use a module param or sysfs entry in the NVMe driver itself if we want to avoid having this control in the block layer?

Stephen

[1] Mj?lnir = Thor's Hammer ;-).

#14 lore raw

Hi Stephen,

I've got a patch I'm going to send out shortly which does it for a block-device file (as Jeff suggested). It's still Mj?lnir but seems to be more in the right place.

-----Original Message-----
From: Stephen Bates [mailto:[email protected]]
Sent: Thursday, May 12, 2016 11:28 AM
To: hch at infradead.org
Cc: axboe at fb.com; linux-block at vger.kernel.org; Busch, Keith <keith.busch at intel.com>; linux-nvme at lists.infradead.org; Derrick, Jonathan <jonathan.derrick at intel.com>
Subject: RE: [PATCH 0/2] Block: Give option to force io polling

Quoted 7 lines · Stephen Bates
Quoted 1 line

Christoph, this is a DRAM based NVMe device, the code for polling in

NVMe was merged in 4.5 right? We are using the inbox NVMe driver. Here is some performance data:

Quoted 1 line
Quoted 8 lines
Quoted 6 lines

QD=1, single thread, random 4KB reads

Polling Off: 12us Avg / 40us 99.99% ; Polling On: 9.5us Avg / 25us 99.99%

Both the average and 99.99% reduction are of interest.

How does CPU usage look for common workloads with polling force enabled?

Christoph, CPU load added.

Polling Off: 12us Avg / 40us 99.99% ; CPU 0.39 H/W Threads Polling On: 9.5us Avg / 25us 99.99% ; CPU 0.98 H/W Threads

Quoted 2 lines

If it's really an overall win we should just add a quirk to the NVMe driver to always force polling for this device based on the PCI ID.

While I like the "big hammer" approach I think we have to have some control over when it is swung ;-). Always turning on polling for a specific device seems a bit too Mj?lnir [1] of a solution. The bonus of polling is only when QD and/or thread-count is low and not everyone will use the device that way. I also suspect other low latency NVMe devices are coming and having a quirk for each and every one of them does not make sense. We could use a module param or sysfs entry in the NVMe driver itself if we want to avoid having this control in the block layer?

Stephen

[1] Mj?lnir = Thor's Hammer ;-).