block: add event when disk usage exceeds threshold
PATCH v4 1/1 block: add event when disk usage exceeds threshold
Managing applications, like oVirt (http://www.ovirt.org), make extensive use of thin-provisioned disk images.
To let the guest run smoothly and be not unnecessarily paused, oVirt sets a disk usage threshold (so called 'high water mark') based on the occupation of the device, and automatically extends the image once the threshold is reached or exceeded.
In order to detect the crossing of the threshold, oVirt has no choice but aggressively polling the QEMU monitor using the query-blockstats command. This lead to unnecessary system load, and is made even worse under scale:
deployments with hundreds of VMs are no longer rare.
To fix this, this patch adds:
* A new monitor command to set a write threshold for a given block device.
* A new event to report if a block device usage exceeds the threshold.
This will allow the managing application to use smarter and more efficient monitoring, greatly reducing the need of polling.
A followup patch is planned to allow to add the write threshold at device creation.
--- block/Makefile.objs | 1 + block/qapi.c | 3 + block/write-threshold.c | 125 ++++++++++++++++++++++++++++++++++++++++ include/block/block_int.h | 4 ++ include/block/write-threshold.h | 64 ++++++++++++++++++++ qapi/block-core.json | 50 +++++++++++++++- qmp-commands.hx | 32 ++++++++++ tests/Makefile | 3 + tests/test-write-threshold.c | 119 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 400 insertions(+), 1 deletion(-) create mode 100644 block/write-threshold.c create mode 100644 include/block/write-threshold.h create mode 100644 tests/test-write-threshold.c
block/Makefile.objs +1 -0
@@ -20,6 +20,7 @@ block-obj-$(CONFIG_GLUSTERFS) += gluster.o block-obj-$(CONFIG_ARCHIPELAGO) += archipelago.o block-obj-$(CONFIG_LIBSSH2) += ssh.o block-obj-y += accounting.o +block-obj-y += write-threshold.o common-obj-y += stream.o common-obj-y += commit.o
block/qapi.c +3 -0
@@ -24,6 +24,7 @@#include "block/qapi.h" #include "block/block_int.h" +#include "block/write-threshold.h" #include "qmp-commands.h" #include "qapi-visit.h" #include "qapi/qmp-output-visitor.h"
@@ -82,6 +83,8 @@ BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs) info->iops_size = cfg.op_size; } + info->write_threshold =bdrv_write_threshold_get (bs); +return info; }
block/write-threshold.c new file +125 -0
125 lines not on this page · raw message
include/block/block_int.h +4 -0
@@ -409,6 +409,10 @@ struct BlockDriverState {/* The error object in use for blocking operations on backing_hd */ Error *backing_blocker; + +/* threshold limit for writes, in bytes. "High water mark". */ +uint64_t write_threshold_offset; +NotifierWithReturn write_threshold_notifier; };int get_tmp_filename (char *filename,int size);
include/block/write-threshold.h new file +64 -0
64 lines not on this page · raw message
qapi/block-core.json +49 -1
65 lines not on this page · raw message
qmp-commands.hx +32 -0
@@ -2104,6 +2104,8 @@ Each json-object contain the following: - "iops_size": I/O size when limiting by iops (json-int) - "detect_zeroes": detect and optimize zero writing (json-string) - Possible values: "off", "on", "unmap" + - "write_threshold": write offset threshold in bytes, a event will be + emitted if crossed. Zero if disabled (json-int) - "image": the detail of the image, it is a json-object containing the following: - "filename": image file name (json-string)
@@ -2181,6 +2183,7 @@ Example: "iops_wr_max": 0, "iops_size": 0, "detect_zeroes": "on", + "write_threshold": 0, "image":{ "filename":"disks/test.qcow2", "format":"qcow2",
@@ -3618,6 +3621,7 @@ Example: "iops_rd_max": 0, "iops_wr_max": 0, "iops_size": 0, + "write_threshold": 0, "image":{ "filename":"disks/test.qcow2", "format":"qcow2",
@@ -3854,3 +3858,31 @@ Move mouse pointer to absolute coordinates (20000, 400). <- { "return": {} } EQMP + + { + .name = "block-set-write-threshold", + .args_type = "node-name:s,write-threshold:l", + .mhandler.cmd_new = qmp_marshal_input_block_set_write_threshold, + }, + +SQMP +block-set-write-threshold +------------ + +Change the write threshold for a block drive. The threshold is an offset, +thus must be non-negative. Default is no write threshold. +Setting the threshold to zero disables it. + +Arguments: + +- "node-name": the node name in the block driver state graph (json-string) +- "write-threshold": the write threshold in bytes (json-int) + +Example: + +-> { "execute": "block-set-write-threshold", + "arguments": { "node-name": "mydev", + "write-threshold": 17179869184 } } +<- { "return": {} } + +EQMP
tests/Makefile +3 -0
@@ -64,6 +64,8 @@ gcov-files-check-qom-interface-y = qom/object.c check-unit-$(CONFIG_POSIX) += tests/test-vmstate$(EXESUF) check-unit-y += tests/test-qemu-opts$(EXESUF) gcov-files-test-qemu-opts-y = qom/test-qemu-opts.c +check-unit-y += tests/test-write-threshold$(EXESUF) +gcov-files-test-write-threshold-y = block/write-threshold.c check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
@@ -351,6 +353,7 @@ tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y) tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o $(qtest-obj-y) tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a libqemustub.a +tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(block-obj-y) libqemuutil.a libqemustub.a ifeq ($(CONFIG_POSIX),y) LIBS += -lutil
tests/test-write-threshold.c new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
1.9.3
----- Original Message -----
Quoted 6 lines
From: "Francesco Romani" <[email protected]>
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected], "Francesco Romani" <[email protected]>
Sent: Thursday, December 4, 2014 9:59:08 AM
Subject: [PATCH v4] block: add event when disk usage exceeds threshold
[...]
Changes since v3:
-----------------
addressed reviewers comments:
- dropped redundant cover letter
- improved commit message to reflect real intended use (polling is not going away completely)
- spelling fixes
- API consistency fixes
- kept 'uint64' in QAPI because it is mapped to C type uint64_t, where 'int' is mapped to 'int64_t'
- renamed for consistency everywhere:
'usage_threshold' => 'write_threshold'
Thanks and best regards
Signature · 4 lines
Francesco Romani RedHat Engineering Virtualization R & D Phone: 8261328 IRC: fromani
ping?
----- Original Message -----
Quoted 39 lines
From: "Francesco Romani" <[email protected]>
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Sent: Thursday, December 4, 2014 10:00:18 AM
Subject: Re: [Qemu-devel] [PATCH v4] block: add event when disk usage exceeds threshold----- Original Message -----
Quoted 7 lines
From: "Francesco Romani" <[email protected]>
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected],
"Francesco Romani" <[email protected]>
Sent: Thursday, December 4, 2014 9:59:08 AM
Subject: [PATCH v4] block: add event when disk usage exceeds threshold[...]
Changes since v3:
-----------------addressed reviewers comments:
- dropped redundant cover letter
- improved commit message to reflect real intended use (polling is not going away completely)
- spelling fixes
- API consistency fixes
- kept 'uint64' in QAPI because it is mapped to C typeuint64_t, where 'int' is mapped to 'int64_t'
- renamed for consistency everywhere:
'usage_threshold' => 'write_threshold'Thanks and best regards
--
Francesco Romani
RedHat Engineering Virtualization R & D
Phone: 8261328
IRC: fromani
Signature · 4 lines
Francesco Romani RedHat Engineering Virtualization R & D Phone: 8261328 IRC: fromani
ping
----- Original Message -----
Quoted 58 lines
From: "Francesco Romani" <[email protected]>
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Sent: Monday, December 15, 2014 12:19:44 PM
Subject: Re: [Qemu-devel] [PATCH v4] block: add event when disk usage exceeds thresholdping?
----- Original Message -----
Quoted 32 lines
From: "Francesco Romani" <[email protected]>
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Sent: Thursday, December 4, 2014 10:00:18 AM
Subject: Re: [Qemu-devel] [PATCH v4] block: add event when disk usage
exceeds threshold----- Original Message -----
Quoted 7 lines
From: "Francesco Romani" <[email protected]>
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected],
"Francesco Romani" <[email protected]>
Sent: Thursday, December 4, 2014 9:59:08 AM
Subject: [PATCH v4] block: add event when disk usage exceeds threshold[...]
Changes since v3:
-----------------addressed reviewers comments:
- dropped redundant cover letter
- improved commit message to reflect real intended use (polling is not going away completely)
- spelling fixes
- API consistency fixes
- kept 'uint64' in QAPI because it is mapped to C typeuint64_t, where 'int' is mapped to 'int64_t'
- renamed for consistency everywhere:
'usage_threshold' => 'write_threshold'Quoted 9 lines
Thanks and best regards
--
Francesco Romani
RedHat Engineering Virtualization R & D
Phone: 8261328
IRC: fromani--
Francesco Romani
RedHat Engineering Virtualization R & D
Phone: 8261328
IRC: fromani
Signature · 4 lines
Francesco Romani RedHat Engineering Virtualization R & D Phone: 8261328 IRC: fromani
Quoted 7 lines · Francesco Romani
Managing applications, like oVirt (http://www.ovirt.org), make extensive use of thin-provisioned disk images.
To let the guest run smoothly and be not unnecessarily paused, oVirt sets a disk usage threshold (so called 'high water mark') based on the occupation of the device, and automatically extends the image once the threshold is reached or exceeded.
Quoted 8 lines
In order to detect the crossing of the threshold, oVirt has no choice but aggressively polling the QEMU monitor using the query-blockstats command. This lead to unnecessary system load, and is made even worse under scale:
deployments with hundreds of VMs are no longer rare.To fix this, this patch adds:
* A new monitor command to set a write threshold for a given block device.
* A new event to report if a block device usage exceeds the threshold.
Please also mention the names of those two things in the commit message, to make it easier to find them when doing 'git log' archaeology.
Quoted 13 lines
This will allow the managing application to use smarter and more efficient monitoring, greatly reducing the need of polling.
A followup patch is planned to allow to add the write threshold at device creation.
Signed-off-by Francesco Romani <[email protected]>---
block/write-threshold.c line 4
Quoted 4 lines
block/write-threshold.c new file +4
-0@@ -0,0 +1,125 @@ +/* +* QEMU System Emulator block write threshold notification +* +* Copyright Red Hat, Inc. 2014
I've been so slow on the review that you may want to add 2015.
block/write-threshold.c line 28
Quoted 3 lines
block/write-threshold.c new file +3
-0+bool bdrv_write_threshold_is_set (const BlockDriverState *bs) +{ +return !!(bs->write_threshold_offset >0 );
The !! is spurious; use of > already guarantees a bool result.
Quoted 12 lines
block/write-threshold.c new file +4
-0+++ b/qapi/block-core.json@@ -239,6 +239,9 @@ # # @iops_size: #optional an I/O size in bytes (Since 1.7) # +# @write_threshold: configured write threshold for the device. +# 0 if disabled. (Since 2.3) +## Since : 0.14.0 # ##
block/write-threshold.c line 259
Quoted 5 lines
block/write-threshold.c new file +1
-1@@ -253,7 +256,7 @@ '*bps_max': 'int', '*bps_rd_max': 'int', '*bps_wr_max': 'int', '*iops_max': 'int', '*iops_rd_max': 'int', '*iops_wr_max': 'int', - '*iops_size': 'int' } } + '*iops_size': 'int', 'write_threshold': 'uint64' } }
'int' works as well as 'uint64'; since this is an output parameter, we aren't gaining any stricter input parsing by using a more-specific type.
My findings are minor, so I'm okay if you post a v5 that addresses them and includes:
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Hi,
thanks for the review!
----- Original Message -----
Quoted 20 lines
From: "Eric Blake" <[email protected]>
To: "Francesco Romani" <[email protected]>, [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Sent: Friday, January 9, 2015 5:54:40 PM
Subject: Re: [Qemu-devel] [PATCH v4] block: add event when disk usage exceeds thresholdQuoted 13 lines · Francesco Romani
Managing applications, like oVirt (http://www.ovirt.org), make extensive use of thin-provisioned disk images.
To let the guest run smoothly and be not unnecessarily paused, oVirt sets a disk usage threshold (so called 'high water mark') based on the occupation
of the device, and automatically extends the image once the threshold is reached or exceeded.In order to detect the crossing of the threshold, oVirt has no choice but aggressively polling the QEMU monitor using the query-blockstats command. This lead to unnecessary system load, and is made even worse under scale:
deployments with hundreds of VMs are no longer rare.
Quoted 6 lines
Quoted 3 lines
To fix this, this patch adds:
* A new monitor command to set a write threshold for a given block device.
* A new event to report if a block device usage exceeds the threshold.Please also mention the names of those two things in the commit message, to make it easier to find them when doing 'git log' archaeology.
Sure, will do.
Quoted 9 lines
Quoted 8 lines
This will allow the managing application to use smarter and more efficient monitoring, greatly reducing the need of polling.
A followup patch is planned to allow to add the write threshold at device creation.
Signed-off-by Francesco Romani <[email protected]>---
Quoted 9 lines
block/write-threshold.c line 4
Quoted 7 lines
block/write-threshold.c new file +4
-0@@ -0,0 +1,125 @@ +/* +* QEMU System Emulator block write threshold notification +* +* Copyright Red Hat, Inc. 2014 I've been so slow on the review that you may want to add 2015.
IANAL, but since most (~99%) of code was written in 2014, I'll just leave as that.
Quoted 5 lines
block/write-threshold.c line 28
Quoted 3 lines
block/write-threshold.c new file +3
-0+bool bdrv_write_threshold_is_set (const BlockDriverState *bs) +{ +return !!(bs->write_threshold_offset >0 );The !! is spurious; use of > already guarantees a bool result.
Will remove.
Quoted 12 lines
Quoted 12 lines
block/write-threshold.c new file +4
-0+++ b/qapi/block-core.json@@ -239,6 +239,9 @@ # # @iops_size: #optional an I/O size in bytes (Since 1.7) # +# @write_threshold: configured write threshold for the device. +# 0 if disabled. (Since 2.3) +## Since : 0.14.0 # ##@@ -253,7 +256,7 @@
Quoted 8 lines
block/write-threshold.c line 259
Quoted 5 lines
block/write-threshold.c new file +1
-1'*bps_max': 'int', '*bps_rd_max': 'int', '*bps_wr_max': 'int', '*iops_max': 'int', '*iops_rd_max': 'int', '*iops_wr_max': 'int', - '*iops_size': 'int' } } + '*iops_size': 'int', 'write_threshold': 'uint64' } }'int' works as well as 'uint64'; since this is an output parameter, we aren't gaining any stricter input parsing by using a more-specific type.
I found one case on which the usage 'int' vs 'uint64' made the code generator emit different code - and the one using uint64 was more correct. Can't recall if that is the case; I'll retry, and add a comment here to document the behaviour if I stumble on this again.
Quoted 3 lines
My findings are minor, so I'm okay if you post a v5 that addresses them and includes:
Reviewed-by Eric Blake <[email protected]>
Yep, will post ASAP.
Thanks and best regards.
Signature · 4 lines
Francesco Romani RedHat Engineering Virtualization R & D Phone: 8261328 IRC: fromani