Re: [libvirt] [PATCH v6 0/2] Add support for qcow2 cache

2017-09-27 Thread Liu Qing
On Wed, Sep 27, 2017 at 02:07:02PM -0400, John Ferlan wrote:
> 
> 
> On 09/27/2017 08:42 AM, Pavel Hrdina wrote:
> > On Wed, Sep 27, 2017 at 02:24:12PM +0200, Pavel Hrdina wrote:
> >> On Tue, Sep 26, 2017 at 05:06:37PM -0400, John Ferlan wrote:
> >>>
> >>>
> >>> On 09/18/2017 11:45 PM, Liu Qing wrote:
> >>>> Qcow2 small IO random write performance will drop dramatically if the l2
> >>>> cache table could not cover the whole disk. This will be a lot of l2
> >>>> cache table RW operations if cache miss happens frequently.
> >>>>  
> >>>> This patch exports the qcow2 driver parameter
> >>>> l2-cache-size/refcount-cache-size, first added in Qemu 2.2, and
> >>>> cache-clean-interval, first added in Qemu 2.5, in libvirt.
> >>>>
> >>>> change since v4: removed unnecessary cache error check
> >>>>
> >>>> Liu Qing (2):
> >>>>   conf, docs: Add qcow2 cache configuration support
> >>>
> >>> According to what you added for the v5 - there's an upstream bz that
> >>> could be associated with this work.  Is this something that should be
> >>> added to the commit message so that we can "track" where the idea comes
> >>> from?
> >>>
> >>> Beyond that - I agree setting policy is not the business we want to be
> >>> in. I just figured I'd throw it out there. I didn't read all of the qemu
> >>> links from the bz about thoughts on this - too many links too much to
> >>> follow not enough time/desire to think about it.
> >>>
> >>> I'm not against pushing these patches, but would like to at least make
> >>> sure Peter isn't 100% against them. I agree the attributes are really
> >>> painful to understand, but it's not the first time we've added some
> >>> attribute that comes with a beware of using this unless you know what
> >>> you're doing.
> >>
> >> I'm still not convinced that this is something we would like to expose
> >> to users.  It's way too low-level for libvirt XML.  I like the idea to
> >> allow 'max' as possible value in QEMU and that could be reused by
> >> libvirt.
> >>
> >> One may argue that having two options as "max storage" or
> >> "max performace" isn't good enough and they would like to be able to
> >> tune it for they exact needs.  Most of the users don't care about the
> >> specifics and they just need a performance or not.
> >>
> >> I attempted to introduce "polling" feature [1] for iothreads but that
> >> was a bad idea and too low-level for libvirt users and configuring exact
> >> values for qcow2 cache seems to be the same case.
> >>
> >> Adding an element/attribute into XML where you would specify whether you
> >> care about performance or not isn't a policy.  Libvirt will simply use
> >> some defaults or configure the maximum performance.  For fine-grained
> >> tuning you can use  like it was suggested for
> >> "polling" feature.
> >>
> >> Pavel
> > 
> > Ehm, I forgot to include the link to the "polling" discussion:
> > 
> > [1] 
> > <https://www.redhat.com/archives/libvir-list/2017-February/msg01084.html>
> > 
> 
> I scanned the .1 discussion... it seems as though there were adjustments
> made to the default iothreads to make them useful or at least enabled by
> default a better set of values which could be disabled via some
>  setting.
> 
> From the discussion thus far for qcow2 cache the difference here is that
> the default values QEMU uses have been inadequate for real world type
> usages and it doesn't appear convergence is possible because the
> possible adjustments has vary degrees of issues. I think it's nicely
> summed up here :
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=1377735#c2 and
> https://bugzilla.redhat.com/show_bug.cgi?id=1377735#c3
> 
> Following the link in the bz from comment 5 to the qemu patches shows
> only a couple of attempts at trying something before the idea was
> seemingly dropped. I looked forward and only recently was the idea
> resurrected, but perhaps in perhaps a bit different format.
> 
> https://lists.gnu.org/archive/html/qemu-block/2017-09/msg00635.html
Looked into the thread, not sure whether the author will change the originial
qcow2 cache configuration. Personally I don't think so, he may add a new
parameter which could be used to configure how much memory will be consumed
for each "slice" as you suggested.

If the cache is separated to size smaller than cluster, this will lead
to more frequent IO access. Athough memory could be used more
efficiently. Mmm... this should not be in this thread.
> 
> In any case, I've sent an email to the author of those patches to get
> insights regarding adding exposure from libvirt is a good or not and to
> determine if the new proposal somehow overrides any settins that would
> be made. It'd be awful if a value was provided, but how that value is
> used gets changed...
> 
> John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v6 0/2] Add support for qcow2 cache

2017-09-26 Thread Liu Qing
On Tue, Sep 26, 2017 at 05:06:37PM -0400, John Ferlan wrote:
> 
> 
> On 09/18/2017 11:45 PM, Liu Qing wrote:
> > Qcow2 small IO random write performance will drop dramatically if the l2
> > cache table could not cover the whole disk. This will be a lot of l2
> > cache table RW operations if cache miss happens frequently.
> >  
> > This patch exports the qcow2 driver parameter
> > l2-cache-size/refcount-cache-size, first added in Qemu 2.2, and
> > cache-clean-interval, first added in Qemu 2.5, in libvirt.
> > 
> > change since v4: removed unnecessary cache error check
> > 
> > Liu Qing (2):
> >   conf, docs: Add qcow2 cache configuration support
> 
> According to what you added for the v5 - there's an upstream bz that
> could be associated with this work.  Is this something that should be
> added to the commit message so that we can "track" where the idea comes
> from?
John could you help to add the bz in the commit message while pushing the
patch, of course, with Peter's support on pushing. The bz link is:
https://bugzilla.redhat.com/show_bug.cgi?id=1377735
If you need me to do the change, just let me know. Thanks.
> 
> Beyond that - I agree setting policy is not the business we want to be
> in. I just figured I'd throw it out there. I didn't read all of the qemu
> links from the bz about thoughts on this - too many links too much to
> follow not enough time/desire to think about it.
Thanks for the understanding.
> 
> I'm not against pushing these patches, but would like to at least make
> sure Peter isn't 100% against them. I agree the attributes are really
> painful to understand, but it's not the first time we've added some
> attribute that comes with a beware of using this unless you know what
> you're doing.
> 
> John
> 
> >   qemu: add capability checking for qcow2 cache configuration
> > 
> >  docs/formatdomain.html.in  | 41 +
> >  docs/schemas/domaincommon.rng  | 35 
> >  src/conf/domain_conf.c | 97 
> > --
> >  src/qemu/qemu_capabilities.c   | 11 +++
> >  src/qemu/qemu_capabilities.h   |  5 ++
> >  src/qemu/qemu_command.c| 33 
> >  src/qemu/qemu_driver.c |  5 ++
> >  src/util/virstoragefile.c  |  3 +
> >  src/util/virstoragefile.h  |  6 ++
> >  tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml   |  3 +
> >  .../caps_2.6.0-gicv2.aarch64.xml   |  3 +
> >  .../caps_2.6.0-gicv3.aarch64.xml   |  3 +
> >  tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml  |  3 +
> >  tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml   |  3 +
> >  tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml|  3 +
> >  tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml   |  3 +
> >  tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml|  3 +
> >  tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml   |  3 +
> >  tests/qemucapabilitiesdata/caps_2.9.0.ppc64le.xml  |  3 +
> >  tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml|  3 +
> >  tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   |  3 +
> >  .../qemuxml2argv-disk-drive-qcow2-cache.args   | 28 +++
> >  .../qemuxml2argv-disk-drive-qcow2-cache.xml| 43 ++
> >  tests/qemuxml2argvtest.c   |  4 +
> >  .../qemuxml2xmlout-disk-drive-qcow2-cache.xml  | 43 ++
> >  tests/qemuxml2xmltest.c|  1 +
> >  26 files changed, 384 insertions(+), 7 deletions(-)
> >  create mode 100644 
> > tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.args
> >  create mode 100644 
> > tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.xml
> >  create mode 100644 
> > tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-cache.xml
> > 
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v6 2/2] qemu: add capability checking for qcow2 cache configuration

2017-09-18 Thread Liu Qing
Add qemu capabilities QEMU_CAPS_L2_CACHE_SIZE,
QEMU_CAPS_REFCOUNT_CACHE_SIZE, QEMU_CAPS_CACHE_CLEAN_INTERVAL.
Add testing for the above qemu capabilities.

Signed-off-by: Liu Qing 
---
 src/qemu/qemu_capabilities.c   | 11 
 src/qemu/qemu_capabilities.h   |  5 
 src/qemu/qemu_command.c| 33 ++
 tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml   |  3 ++
 .../caps_2.6.0-gicv2.aarch64.xml   |  3 ++
 .../caps_2.6.0-gicv3.aarch64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml  |  3 ++
 tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.ppc64le.xml  |  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   |  3 ++
 .../qemuxml2argv-disk-drive-qcow2-cache.args   | 28 ++
 tests/qemuxml2argvtest.c   |  4 +++
 17 files changed, 117 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.args

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index e7ea6f4..2db6af1 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -439,6 +439,11 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
   "virtio-net.tx_queue_size",
   "chardev-reconnect",
   "virtio-gpu.max_outputs",
+
+  /* 270 */
+  "drive.qcow2.l2-cache-size",
+  "drive.qcow2.refcount-cache-size",
+  "drive.qcow2.cache-clean-interval",
 );
 
 
@@ -1811,6 +1816,12 @@ static struct virQEMUCapsStringFlags 
virQEMUCapsObjectPropsIntelIOMMU[] = {
 static struct virQEMUCapsStringFlags virQEMUCapsQMPSchemaQueries[] = {
 { "blockdev-add/arg-type/options/+gluster/debug-level", 
QEMU_CAPS_GLUSTER_DEBUG_LEVEL},
 { "blockdev-add/arg-type/+gluster/debug", QEMU_CAPS_GLUSTER_DEBUG_LEVEL},
+{ "blockdev-add/arg-type/options/+qcow2/l2-cache-size", 
QEMU_CAPS_DRIVE_QCOW2_L2_CACHE_SIZE},
+{ "blockdev-add/arg-type/options/+qcow2/refcount-cache-size", 
QEMU_CAPS_DRIVE_QCOW2_REFCOUNT_CACHE_SIZE},
+{ "blockdev-add/arg-type/options/+qcow2/cache-clean-interval", 
QEMU_CAPS_DRIVE_QCOW2_CACHE_CLEAN_INTERVAL},
+{ "blockdev-add/arg-type/+qcow2/l2-cache-size", 
QEMU_CAPS_DRIVE_QCOW2_L2_CACHE_SIZE},
+{ "blockdev-add/arg-type/+qcow2/refcount-cache-size", 
QEMU_CAPS_DRIVE_QCOW2_REFCOUNT_CACHE_SIZE},
+{ "blockdev-add/arg-type/+qcow2/cache-clean-interval", 
QEMU_CAPS_DRIVE_QCOW2_CACHE_CLEAN_INTERVAL},
 };
 
 struct virQEMUCapsObjectTypeProps {
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index f32687d..021297e 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -426,6 +426,11 @@ typedef enum {
 QEMU_CAPS_CHARDEV_RECONNECT, /* -chardev reconnect */
 QEMU_CAPS_VIRTIO_GPU_MAX_OUTPUTS, /* -device 
virtio-(vga|gpu-*),max-outputs= */
 
+/* 270 */
+QEMU_CAPS_DRIVE_QCOW2_L2_CACHE_SIZE, /* -drive support qcow2 l2 cache size 
*/
+QEMU_CAPS_DRIVE_QCOW2_REFCOUNT_CACHE_SIZE, /* -drive support qcow2 
refcount cache size */
+QEMU_CAPS_DRIVE_QCOW2_CACHE_CLEAN_INTERVAL, /* -drive qcow2 cache clean 
interval */
+
 QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d553df5..da91059 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1434,6 +1434,39 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
 virBufferAsprintf(buf, "format=%s,", qemuformat);
 }
 
+if (disk->src->l2_cache_size > 0) {
+if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_QCOW2_L2_CACHE_SIZE)) {
+virBufferAsprintf(buf, "l2-cache-size=%llu,",
+  disk->src->l2_cache_size);
+} else {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("l2-cache-size is not supported by this QEMU"));
+goto cleanup;
+}
+}
+
+if (disk->src->refcount_cache_size > 0) {
+if (virQEMUCapsGet(qemuCaps, 
QEMU_CAPS_DRIVE_QCOW2_REFCOUNT_CACHE_SIZE)) {
+virBufferAsprintf(buf, "refcount-cache-size=%llu,",
+  disk->src->refcount_cache_size);
+} else {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _(&q

[libvirt] [PATCH v6 0/2] Add support for qcow2 cache

2017-09-18 Thread Liu Qing
Qcow2 small IO random write performance will drop dramatically if the l2
cache table could not cover the whole disk. This will be a lot of l2
cache table RW operations if cache miss happens frequently.
 
This patch exports the qcow2 driver parameter
l2-cache-size/refcount-cache-size, first added in Qemu 2.2, and
cache-clean-interval, first added in Qemu 2.5, in libvirt.

change since v4: removed unnecessary cache error check

Liu Qing (2):
  conf, docs: Add qcow2 cache configuration support
  qemu: add capability checking for qcow2 cache configuration

 docs/formatdomain.html.in  | 41 +
 docs/schemas/domaincommon.rng  | 35 
 src/conf/domain_conf.c | 97 --
 src/qemu/qemu_capabilities.c   | 11 +++
 src/qemu/qemu_capabilities.h   |  5 ++
 src/qemu/qemu_command.c| 33 
 src/qemu/qemu_driver.c |  5 ++
 src/util/virstoragefile.c  |  3 +
 src/util/virstoragefile.h  |  6 ++
 tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml   |  3 +
 .../caps_2.6.0-gicv2.aarch64.xml   |  3 +
 .../caps_2.6.0-gicv3.aarch64.xml   |  3 +
 tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml  |  3 +
 tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml   |  3 +
 tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml|  3 +
 tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml   |  3 +
 tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml|  3 +
 tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml   |  3 +
 tests/qemucapabilitiesdata/caps_2.9.0.ppc64le.xml  |  3 +
 tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml|  3 +
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   |  3 +
 .../qemuxml2argv-disk-drive-qcow2-cache.args   | 28 +++
 .../qemuxml2argv-disk-drive-qcow2-cache.xml| 43 ++
 tests/qemuxml2argvtest.c   |  4 +
 .../qemuxml2xmlout-disk-drive-qcow2-cache.xml  | 43 ++
 tests/qemuxml2xmltest.c|  1 +
 26 files changed, 384 insertions(+), 7 deletions(-)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-cache.xml

-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v6 1/2] conf, docs: Add qcow2 cache configuration support

2017-09-18 Thread Liu Qing
Random write IOPS will drop dramatically if qcow2 l2 cache could not
cover the whole disk. This patch gives libvirt user a chance to adjust
the qcow2 cache configuration.

Three new qcow2 driver parameters (l2-cache-size, refcount-cache-size
and cache-clean-interval) are added as attributes to a new 
subelement for a  of a 
element. The QEMU source docs/qcow2-cache.txt provides the guidelines
for defining/configuring values for each.

Signed-off-by: Liu Qing 
---

change since v4: removed unnecessary cache error check

 docs/formatdomain.html.in  | 41 +
 docs/schemas/domaincommon.rng  | 35 
 src/conf/domain_conf.c | 97 --
 src/qemu/qemu_driver.c |  5 ++
 src/util/virstoragefile.c  |  3 +
 src/util/virstoragefile.h  |  6 ++
 .../qemuxml2argv-disk-drive-qcow2-cache.xml| 43 ++
 .../qemuxml2xmlout-disk-drive-qcow2-cache.xml  | 43 ++
 tests/qemuxml2xmltest.c|  1 +
 9 files changed, 267 insertions(+), 7 deletions(-)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-cache.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 8ca7637..4574e3a 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3036,6 +3036,47 @@
   set. (Since 3.5.0)
   
 
+The driver element may contain a qcow2 sub
+element, which to specifying further details related to a qcow2 disk.
+For recommended setting guidelines refer to the QEMU source file
+docs/qcow2-cache.txt.
+Since 3.8.0
+
+  
+The optional l2_cache_size attribute controls how much
+memory will be consumed by qcow2 l2 table cache in bytes. This
+option is only valid when the driver type is qcow2. The default
+size is 2097152.
+Since 3.8.0
+
+In general you should leave this option alone, unless you
+are very certain you know what you are doing.
+  
+  
+The optional refcount_cache_size attribute controls
+how much memory will be consumed by qcow2 reference count table
+cache in bytes. This option is only valid when the driver type is
+qcow2. The default size is 262144.
+Since 3.8.0
+
+In general you should leave this option alone, unless you
+are very certain you know what you are doing.
+  
+  
+The optional cache_clean_interval attribute defines
+an interval (in seconds). All cache entries that haven't been
+accessed during that interval are removed from memory. This option
+is only valid when the driver type is qcow2. The default
+value is 0, which disables this feature. If the interval is too
+short, it will cause frequent cache write back and load, which
+impact performance. If the interval is too long, unused cache
+will still consume memory until it's been written back to disk.
+Since 3.8.0
+
+In general you should leave this option alone, unless you
+are very certain you know what you are doing.
+  
+
   
   backenddomain
   The optional backenddomain element allows specifying a
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index c9a4f7a..0e25f44 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1756,6 +1756,23 @@
 
   
   
+  
+
+  
+
+  
+  
+
+  
+  
+
+  
+
+  
+
+  
   
@@ -1794,6 +1811,9 @@
 
   
   
+  
+
+  
   
 
   
@@ -1889,6 +1909,21 @@
   
 
   
+  
+
+  
+
+  
+  
+
+  
+
+  
+  
+
+  
+
+  
   
 
   
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a43b25c..f225a7f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5734,6 +5734,30 @@ virDomainDeviceLoadparmIsValid(const char *loadparm)
 
 
 static void
+virDomainQcow2CacheOptionsFormat(virBufferPtr buf,
+ virDomainDiskDefPtr def)
+{
+if (def->src->l2_cache_size == 0 &&
+def->src->refcount_cache_size == 0 &&
+def->src->cache_clean_interval == 0)
+return;
+
+virBufferAddLit(buf, "src->l2_cache_size > 0)
+virBufferAsprintf(buf, " l2_cache_size='%llu'",
+  def->src->l2_cache_size);
+if (def->src->refcount_cache_size > 0)
+virBufferAsprintf(bu

Re: [libvirt] [PATCH v5 1/2] conf, docs: Add qcow2 cache configuration support

2017-09-18 Thread Liu Qing
On Mon, Sep 18, 2017 at 09:49:36AM -0400, John Ferlan wrote:
> 
> 
> On 09/14/2017 01:08 AM, Liu Qing wrote:
> > Random write IOPS will drop dramatically if qcow2 l2 cache could not
> > cover the whole disk. This patch gives libvirt user a chance to adjust
> > the qcow2 cache configuration.
> > 
> > Three new qcow2 driver parameters (l2-cache-size, refcount-cache-size
> > and cache-clean-interval) are added as attributes to a new 
> > subelement for a  of a 
> > element. The QEMU source docs/qcow2-cache.txt provides the guidelines
> > for defining/configuring values for each.
> > 
> > Signed-off-by: Liu Qing 
> > ---
> >  docs/formatdomain.html.in  | 41 +
> >  docs/schemas/domaincommon.rng  | 35 
> >  src/conf/domain_conf.c | 96 
> > --
> >  src/qemu/qemu_driver.c |  5 ++
> >  src/util/virstoragefile.c  |  3 +
> >  src/util/virstoragefile.h  |  6 ++
> >  .../qemuxml2argv-disk-drive-qcow2-cache.xml| 43 ++
> >  .../qemuxml2xmlout-disk-drive-qcow2-cache.xml  | 43 ++
> >  tests/qemuxml2xmltest.c|  1 +
> >  9 files changed, 268 insertions(+), 5 deletions(-)
> >  create mode 100644 
> > tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.xml
> >  create mode 100644 
> > tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-cache.xml
> > 
> 
> OK - so I had my head in other code during the v4 review comments from
> Peter. So I'll just "restart" that a bit here. If I can summarize the
> comments... There's a concern that we're creating a very specific set of
> parameters for which there isn't great guidance available other than
> going to a source file in the qemu tree and attempting to decipher it.
> Something I did note at one time as a possible issue and why I also
> asked for the "qcow2" subelement. It makes it painfully obvious that
> there was something very specific. I figure seeing a "qcow2" element
> name would fairly easily point out to anyone that specificity.
> 
> So, based on what I read in the responses it seems that the purpose of
> the values is to provide a mechanism to "allow" qemu to use a couple of
> different algorithms to perform operations, but qemu wants the user to
> decide whether they are willing to sacrifice one thing over another. If
> you want high IOPS, then you have to sacrifice something else; whereas,
> if you don't care about performance, then you sacrifice something else.
> 
> In any case, I think what could be useful is to determine if there is a
> way to "automate" something such that the "dials" would be automatically
> set based on the algorithms. That is - rather than supplying the
> specific values, supply a named attribute that would then perform the
> calculations and set the values, such as "high_performance="yes" or
> "large_capacity=yes". Where you cannot set both, but can set one or the
> other.  Or can you set both? Is there value in partially turning a knob?
>  If so maybe the attribute is "performance={default, ..., best}" and
> "capacity={default, ..., large}". Then based on the value of the
> attribute, code you add to libvirt would perform the calculations.
> 
> Or do you really think that's something some supplier (such as what
> you're trying to do) would want to have - the ability to control the
> algorithm for the various knobs.
I googled the qcow2 cache and there are already some discussion about
how to give a user friendly interface, even in the qemu community.
https://bugzilla.redhat.com/show_bug.cgi?id=1377735
I don't what to involve this, as this is hard to lead to an all win
result. A high level policy configuration would be enough for us.
If a policy configuration on libvirt level is necessary, I think a new patch
could be made. For example adding new attribute in the  element
which controls how the cache is automatically configured. But this may lead to
another discussion about what's a good policy. A policy way and the knob
way could both be available on libvirt level.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v4 1/2] conf, docs: Add qcow2 cache configuration support

2017-09-14 Thread Liu Qing
On Thu, Sep 14, 2017 at 12:56:30PM +0200, Peter Krempa wrote:
> On Thu, Sep 14, 2017 at 16:37:03 +0800, Liu Qing wrote:
> > On Thu, Sep 14, 2017 at 10:02:40AM +0200, Peter Krempa wrote:
> > > On Thu, Sep 14, 2017 at 09:29:28 +0200, Peter Krempa wrote:
> 
> [...]
> 
> > > One more thing. The design you've proposed is really not user friendly.
> > > The user has to read a lenghty document, then inquire the parameters for
> > > every single qcow2 image, do the calculations and set it in the XML.
> > > This might be okay for higher level management tools, but not for users
> > > who use libvirt directly.
> > I agree this is not user friendly. I only give the user a choice, maybe
> > not the best, right now. Any suggestion will be greatly appreicated.
> > For our company, this feature will be an add-on to Openstack.
> 
> This means that you will have to deal with everything that I've pointed
> out. How are you planning to expose this to the user? And which
> calculations are you going to use?
We will not expose this to the user on Openstack level.
We have different volume types like performance and capacity. For
performance volumes we will cache as much space as possible. Free memory
left in the host will be counted in. For capacity volume we will set a
max cache size.
The cache setting strategy be implemented in a higher level management
tool seems much resaonable to me. As this will be much more flexible.


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v4 1/2] conf, docs: Add qcow2 cache configuration support

2017-09-14 Thread Liu Qing
On Thu, Sep 14, 2017 at 10:02:40AM +0200, Peter Krempa wrote:
> On Thu, Sep 14, 2017 at 09:29:28 +0200, Peter Krempa wrote:
> > On Thu, Sep 14, 2017 at 13:02:46 +0800, Liu Qing wrote:
> > > On Wed, Sep 13, 2017 at 01:20:03PM +0200, Peter Krempa wrote:
> > > > On Wed, Sep 13, 2017 at 17:21:23 +0800, Liu Qing wrote:
> > 
> > [...]
> > 
> > > > [1] There's discussion I can link to for other tuning parameters. The
> > > > gist is that allowing users to set something withoug giving them
> > > > guidance is pointless since they might not use it. Also if the guidance
> > > > is strict (e.g. a formula, libvirt or qemu should set the defaults
> > > > properly and not force users to do the calculation)
> > > The guidance could be found in doc/qcow2-cache.txt in qemu source code.
> > > As John Ferlan suggested I have added the file locaton in 
> > > formatdomain.html.in. 
> > 
> > Well, if the guidance is absolute (use this cache size and it's okay)
> > then we should implement it automatically (don't allow users
> > to set it.)
> 
> One more thing. The design you've proposed is really not user friendly.
> The user has to read a lenghty document, then inquire the parameters for
> every single qcow2 image, do the calculations and set it in the XML.
> This might be okay for higher level management tools, but not for users
> who use libvirt directly.
I agree this is not user friendly. I only give the user a choice, maybe
not the best, right now. Any suggestion will be greatly appreicated.
For our company, this feature will be an add-on to Openstack.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v4 1/2] conf, docs: Add qcow2 cache configuration support

2017-09-14 Thread Liu Qing
On Thu, Sep 14, 2017 at 09:29:28AM +0200, Peter Krempa wrote:
> On Thu, Sep 14, 2017 at 13:02:46 +0800, Liu Qing wrote:
> > On Wed, Sep 13, 2017 at 01:20:03PM +0200, Peter Krempa wrote:
> > > On Wed, Sep 13, 2017 at 17:21:23 +0800, Liu Qing wrote:
> 
> [...]
> 
> > > [1] There's discussion I can link to for other tuning parameters. The
> > > gist is that allowing users to set something withoug giving them
> > > guidance is pointless since they might not use it. Also if the guidance
> > > is strict (e.g. a formula, libvirt or qemu should set the defaults
> > > properly and not force users to do the calculation)
> > The guidance could be found in doc/qcow2-cache.txt in qemu source code.
> > As John Ferlan suggested I have added the file locaton in 
> > formatdomain.html.in. 
> 
> Well, if the guidance is absolute (use this cache size and it's okay)
> then we should implement it automatically (don't allow users
> to set it.)
> 
> I'm asking whether there are some catches why not to do it automatically.
> E.g whether there's an possibility that users would do something *else*
> as described by the document and what would be the reasons for it.
I think there is some trade off between the cache size and performance.
Otherwise qemu does not need to export these parameters to user, they
could do the automation in qemu. The guidance only let the user know how
much disk space is coverred by caches, and how much memory will be
needed to cover all disk spaces. User should do their own decision to
choose a right size. But if the user is using the current version of
libvirt, they could not set the value even if they know what's the
proper value.

For example if the user may need a LUN which need high IOPS, he could
set the cache to cover all disk spaces. And in another situation, he
needs a large capacity,for example 4T, but low perfermance LUN, then he
could set the l2 cache size to a value much less than 512M.

> 
> One of the reasons might be memory consumption of the cache as it
> looks like you need 1 MiB of memory to fully cover a 8GiB image.
Yes, as I said above.
> 
> Also the problem is that those parameters are qemu-isms so we should be
> aware when modelling them in the XML since they can change and may not
> map well to any other technology.
Currently the new element is added as a child elemnt of driver, and the
driver type needs to be qcow2. Also add this kind information in the
doc.
> 
> Also how does the cache impact read-performance from the backing layers?
> We might need to set the cache for the backing layers as well.
I have a peek at the latest qemu code and the backing layers will have
the same cache size value as the top volume. And this will reduce metadata read
count if the table is already in the memory. Also more memory will
consumed.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v5 1/2] conf, docs: Add qcow2 cache configuration support

2017-09-13 Thread Liu Qing
Random write IOPS will drop dramatically if qcow2 l2 cache could not
cover the whole disk. This patch gives libvirt user a chance to adjust
the qcow2 cache configuration.

Three new qcow2 driver parameters (l2-cache-size, refcount-cache-size
and cache-clean-interval) are added as attributes to a new 
subelement for a  of a 
element. The QEMU source docs/qcow2-cache.txt provides the guidelines
for defining/configuring values for each.

Signed-off-by: Liu Qing 
---
 docs/formatdomain.html.in  | 41 +
 docs/schemas/domaincommon.rng  | 35 
 src/conf/domain_conf.c | 96 --
 src/qemu/qemu_driver.c |  5 ++
 src/util/virstoragefile.c  |  3 +
 src/util/virstoragefile.h  |  6 ++
 .../qemuxml2argv-disk-drive-qcow2-cache.xml| 43 ++
 .../qemuxml2xmlout-disk-drive-qcow2-cache.xml  | 43 ++
 tests/qemuxml2xmltest.c|  1 +
 9 files changed, 268 insertions(+), 5 deletions(-)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-cache.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 8ca7637..4574e3a 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3036,6 +3036,47 @@
   set. (Since 3.5.0)
   
 
+The driver element may contain a qcow2 sub
+element, which to specifying further details related to a qcow2 disk.
+For recommended setting guidelines refer to the QEMU source file
+docs/qcow2-cache.txt.
+Since 3.8.0
+
+  
+The optional l2_cache_size attribute controls how much
+memory will be consumed by qcow2 l2 table cache in bytes. This
+option is only valid when the driver type is qcow2. The default
+size is 2097152.
+Since 3.8.0
+
+In general you should leave this option alone, unless you
+are very certain you know what you are doing.
+  
+  
+The optional refcount_cache_size attribute controls
+how much memory will be consumed by qcow2 reference count table
+cache in bytes. This option is only valid when the driver type is
+qcow2. The default size is 262144.
+Since 3.8.0
+
+In general you should leave this option alone, unless you
+are very certain you know what you are doing.
+  
+  
+The optional cache_clean_interval attribute defines
+an interval (in seconds). All cache entries that haven't been
+accessed during that interval are removed from memory. This option
+is only valid when the driver type is qcow2. The default
+value is 0, which disables this feature. If the interval is too
+short, it will cause frequent cache write back and load, which
+impact performance. If the interval is too long, unused cache
+will still consume memory until it's been written back to disk.
+Since 3.8.0
+
+In general you should leave this option alone, unless you
+are very certain you know what you are doing.
+  
+
   
   backenddomain
   The optional backenddomain element allows specifying a
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index c9a4f7a..0e25f44 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1756,6 +1756,23 @@
 
   
   
+  
+
+  
+
+  
+  
+
+  
+  
+
+  
+
+  
+
+  
   
@@ -1794,6 +1811,9 @@
 
   
   
+  
+
+  
   
 
   
@@ -1889,6 +1909,21 @@
   
 
   
+  
+
+  
+
+  
+  
+
+  
+
+  
+  
+
+  
+
+  
   
 
   
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a43b25c..e29ecb5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5734,6 +5734,30 @@ virDomainDeviceLoadparmIsValid(const char *loadparm)
 
 
 static void
+virDomainQcow2CacheOptionsFormat(virBufferPtr buf,
+ virDomainDiskDefPtr def)
+{
+if (def->src->l2_cache_size == 0 &&
+def->src->refcount_cache_size == 0 &&
+def->src->cache_clean_interval == 0)
+return;
+
+virBufferAddLit(buf, "src->l2_cache_size > 0)
+virBufferAsprintf(buf, " l2_cache_size='%llu'",
+  def->src->l2_cache_size);
+if (def->src->refcount_cache_size > 0)
+virBufferAsprintf(buf, " refcount_cache_size='%llu'

[libvirt] [PATCH v5 2/2] qemu: add capability checking for qcow2 cache configuration

2017-09-13 Thread Liu Qing
Add qemu capabilities QEMU_CAPS_L2_CACHE_SIZE,
QEMU_CAPS_REFCOUNT_CACHE_SIZE, QEMU_CAPS_CACHE_CLEAN_INTERVAL.
Add testing for the above qemu capabilities.

Signed-off-by: Liu Qing 
---
 src/qemu/qemu_capabilities.c   | 11 
 src/qemu/qemu_capabilities.h   |  5 
 src/qemu/qemu_command.c| 33 ++
 tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml   |  3 ++
 .../caps_2.6.0-gicv2.aarch64.xml   |  3 ++
 .../caps_2.6.0-gicv3.aarch64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml  |  3 ++
 tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.ppc64le.xml  |  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   |  3 ++
 .../qemuxml2argv-disk-drive-qcow2-cache.args   | 28 ++
 tests/qemuxml2argvtest.c   |  4 +++
 17 files changed, 117 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.args

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index e7ea6f4..2db6af1 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -439,6 +439,11 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
   "virtio-net.tx_queue_size",
   "chardev-reconnect",
   "virtio-gpu.max_outputs",
+
+  /* 270 */
+  "drive.qcow2.l2-cache-size",
+  "drive.qcow2.refcount-cache-size",
+  "drive.qcow2.cache-clean-interval",
 );
 
 
@@ -1811,6 +1816,12 @@ static struct virQEMUCapsStringFlags 
virQEMUCapsObjectPropsIntelIOMMU[] = {
 static struct virQEMUCapsStringFlags virQEMUCapsQMPSchemaQueries[] = {
 { "blockdev-add/arg-type/options/+gluster/debug-level", 
QEMU_CAPS_GLUSTER_DEBUG_LEVEL},
 { "blockdev-add/arg-type/+gluster/debug", QEMU_CAPS_GLUSTER_DEBUG_LEVEL},
+{ "blockdev-add/arg-type/options/+qcow2/l2-cache-size", 
QEMU_CAPS_DRIVE_QCOW2_L2_CACHE_SIZE},
+{ "blockdev-add/arg-type/options/+qcow2/refcount-cache-size", 
QEMU_CAPS_DRIVE_QCOW2_REFCOUNT_CACHE_SIZE},
+{ "blockdev-add/arg-type/options/+qcow2/cache-clean-interval", 
QEMU_CAPS_DRIVE_QCOW2_CACHE_CLEAN_INTERVAL},
+{ "blockdev-add/arg-type/+qcow2/l2-cache-size", 
QEMU_CAPS_DRIVE_QCOW2_L2_CACHE_SIZE},
+{ "blockdev-add/arg-type/+qcow2/refcount-cache-size", 
QEMU_CAPS_DRIVE_QCOW2_REFCOUNT_CACHE_SIZE},
+{ "blockdev-add/arg-type/+qcow2/cache-clean-interval", 
QEMU_CAPS_DRIVE_QCOW2_CACHE_CLEAN_INTERVAL},
 };
 
 struct virQEMUCapsObjectTypeProps {
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index f32687d..021297e 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -426,6 +426,11 @@ typedef enum {
 QEMU_CAPS_CHARDEV_RECONNECT, /* -chardev reconnect */
 QEMU_CAPS_VIRTIO_GPU_MAX_OUTPUTS, /* -device 
virtio-(vga|gpu-*),max-outputs= */
 
+/* 270 */
+QEMU_CAPS_DRIVE_QCOW2_L2_CACHE_SIZE, /* -drive support qcow2 l2 cache size 
*/
+QEMU_CAPS_DRIVE_QCOW2_REFCOUNT_CACHE_SIZE, /* -drive support qcow2 
refcount cache size */
+QEMU_CAPS_DRIVE_QCOW2_CACHE_CLEAN_INTERVAL, /* -drive qcow2 cache clean 
interval */
+
 QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d553df5..da91059 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1434,6 +1434,39 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
 virBufferAsprintf(buf, "format=%s,", qemuformat);
 }
 
+if (disk->src->l2_cache_size > 0) {
+if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_QCOW2_L2_CACHE_SIZE)) {
+virBufferAsprintf(buf, "l2-cache-size=%llu,",
+  disk->src->l2_cache_size);
+} else {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("l2-cache-size is not supported by this QEMU"));
+goto cleanup;
+}
+}
+
+if (disk->src->refcount_cache_size > 0) {
+if (virQEMUCapsGet(qemuCaps, 
QEMU_CAPS_DRIVE_QCOW2_REFCOUNT_CACHE_SIZE)) {
+virBufferAsprintf(buf, "refcount-cache-size=%llu,",
+  disk->src->refcount_cache_size);
+} else {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _(&q

[libvirt] [PATCH v5 0/2] Add support for qcow2 cache

2017-09-13 Thread Liu Qing
Qcow2 small IO random write performance will drop dramatically if the l2
cache table could not cover the whole disk. This will be a lot of l2
cache table RW operations if cache miss happens frequently.
 
This patch exports the qcow2 driver parameter
l2-cache-size/refcount-cache-size, first added in Qemu 2.2, and
cache-clean-interval, first added in Qemu 2.5, in libvirt.

change since v4: updated doc and did code adjustment based on John
Ferlan's review.

Liu Qing (2):
  conf, docs: Add qcow2 cache configuration support
  qemu: add capability checking for qcow2 cache configuration

 docs/formatdomain.html.in  | 41 +
 docs/schemas/domaincommon.rng  | 35 
 src/conf/domain_conf.c | 96 --
 src/qemu/qemu_capabilities.c   | 11 +++
 src/qemu/qemu_capabilities.h   |  5 ++
 src/qemu/qemu_command.c| 33 
 src/qemu/qemu_driver.c |  5 ++
 src/util/virstoragefile.c  |  3 +
 src/util/virstoragefile.h  |  6 ++
 tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml   |  3 +
 .../caps_2.6.0-gicv2.aarch64.xml   |  3 +
 .../caps_2.6.0-gicv3.aarch64.xml   |  3 +
 tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml  |  3 +
 tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml   |  3 +
 tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml|  3 +
 tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml   |  3 +
 tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml|  3 +
 tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml   |  3 +
 tests/qemucapabilitiesdata/caps_2.9.0.ppc64le.xml  |  3 +
 tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml|  3 +
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   |  3 +
 .../qemuxml2argv-disk-drive-qcow2-cache.args   | 28 +++
 .../qemuxml2argv-disk-drive-qcow2-cache.xml| 43 ++
 tests/qemuxml2argvtest.c   |  4 +
 .../qemuxml2xmlout-disk-drive-qcow2-cache.xml  | 43 ++
 tests/qemuxml2xmltest.c|  1 +
 26 files changed, 385 insertions(+), 5 deletions(-)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-cache.xml

-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v4 1/2] conf, docs: Add qcow2 cache configuration support

2017-09-13 Thread Liu Qing
On Wed, Sep 13, 2017 at 01:20:03PM +0200, Peter Krempa wrote:
> On Wed, Sep 13, 2017 at 17:21:23 +0800, Liu Qing wrote:
> > Random write IOPS will drop dramatically if qcow2 l2 cache could not
> > cover the whole disk. This patch gives libvirt user a chance to adjust
> > the qcow2 cache configuration.
> > 
> > Three new qcow2 driver parameters are added. They are l2-cache-size,
> > refcount-cache-size and cache-clean-interval.
> > 
> > The following are from qcow2-cache.txt.
> > The amount of virtual disk that can be mapped by the L2 and refcount
> > caches (in bytes) is:
> > disk_size = l2_cache_size * cluster_size / 8
> > disk_size = refcount_cache_size * cluster_size * 8 / refcount_bits
> > 
> > The parameter "cache-clean-interval" defines an interval (in seconds).
> > All cache entries that haven't been accessed during that interval are
> > removed from memory.
> > 
> > Signed-off-by: Liu Qing 
> > ---
> > Change since v3: a) copy qcow2 cache configurion from source to backing$
> > to backing file source.$
> 
> This looks like one of the tuning parameters which really is hard for
> users to set and thus it should be justified properly if we need it. [1]
> 
> From the commit message above it looks like that there are guidelines
> how to set them. Can't we just make them implicit and not expose
> anything to tune the settings? Does it make sense to do so? Are there
> any drawbacks?
> 
> If any of them need to be configured by the user, please describe that
> in detail why it's necessary.
> 
> Peter
> 
> [1] There's discussion I can link to for other tuning parameters. The
> gist is that allowing users to set something withoug giving them
> guidance is pointless since they might not use it. Also if the guidance
> is strict (e.g. a formula, libvirt or qemu should set the defaults
> properly and not force users to do the calculation)
The guidance could be found in doc/qcow2-cache.txt in qemu source code.
As John Ferlan suggested I have added the file locaton in formatdomain.html.in. 


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/2] conf, docs: Add qcow2 cache configuration support

2017-09-13 Thread Liu Qing
On Tue, Sep 12, 2017 at 05:21:53PM -0400, John Ferlan wrote:
> 
> 
> On 09/07/2017 02:09 AM, Liu Qing wrote:
> > Random write IOPS will drop dramatically if qcow2 l2 cache could not
> > cover the whole disk. This patch gives libvirt user a chance to adjust
> > the qcow2 cache configuration.
> > 
> > Three new qcow2 driver parameters are added. They are l2-cache-size,
> > refcount-cache-size and cache-clean-interval.
> > 
> > The following are from qcow2-cache.txt.
> > The amount of virtual disk that can be mapped by the L2 and refcount
> > caches (in bytes) is:
> > disk_size = l2_cache_size * cluster_size / 8
> > disk_size = refcount_cache_size * cluster_size * 8 / refcount_bits
> > 
> > The parameter "cache-clean-interval" defines an interval (in seconds).
> > All cache entries that haven't been accessed during that interval are
> > removed from memory.
> 
> Suggestion, rewrite a bit:
> 
> Three new qcow2 driver parameters (l2-cache-size, refcount-cache-size
> and cache-clean-interval) are added as attributes to a new 
> subelement for a  of a 
> element. The QEMU source docs/qcow2-cache.txt provides the guidelines
> for defining/configuring values for each.
> 
> ...
> 
> That is - let's not bother with repeating what's in the document since
> it can change, but provide enough information that someone with
> curiosity would know where to look.
I am thinking add a web link but afraid of 404 error when the link is
not accessable.
A indirect link like docs/qcow2-cache.txt is a good idea.
> 
> Question from me: does "cache='none'" need to be set in the 
> element for this to work properly? Do any of the cache values make
> sense?  If it must be none, then we need to check that. If something
> doesn't make ense, we need to check that too.
The cache attribute in driver element is how qemu will deals with page
cache of qcow2 file on the host. When opening a qcow2 file on host, the
oflag will be dertimined by cache.

L2 and refcount tables are metadatas of qcow2.

So cache='xxx' determines how the guest data will be cached, and
l2/refcount table cache controls the metadata cache.

> >  if (def->src->auth) {
> > diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> > index ed8cb6e..391aaba 100644
> > --- a/src/qemu/qemu_command.c
> > +++ b/src/qemu/qemu_command.c
> > @@ -1433,6 +1433,12 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
> >  qemuformat = "luks";
> >  virBufferAsprintf(buf, "format=%s,", qemuformat);
> >  }
> > +if (disk->src->l2_cache_size > 0)
> > +virBufferAsprintf(buf, "l2-cache-size=%llu,", 
> > disk->src->l2_cache_size);
> > +if (disk->src->refcount_cache_size > 0)
> > +virBufferAsprintf(buf, "refcount-cache-size=%llu,", 
> > disk->src->refcount_cache_size);
> > +if (disk->src->cache_clean_interval > 0)
> > +virBufferAsprintf(buf, "cache-clean-interval=%llu,", 
> > disk->src->cache_clean_interval);
> 
> These  don't belong in this patch, they belong in the next patch. We're
> not adding the .args here.
> 
> 
> I can make all the above changes for you - not a problem.  But please
> let me know your thoughts on whether we should keep the sizing
> recommendation in formatdomain.html.in or just point at the qemu source
> document. It's a fine line - I like the example, but I also see the
> downside.
A point to source document is fine. I have done all the modifications in
v5. If any missing please let me know. Thanks.
Qing
> 
> John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v4 0/2] Add support for qcow2 cache

2017-09-13 Thread Liu Qing
On Wed, Sep 13, 2017 at 06:51:35AM -0400, John Ferlan wrote:
> 
> 
> On 09/13/2017 05:21 AM, Liu Qing wrote:
> > Qcow2 small IO random write performance will drop dramatically if the l2
> > cache table could not cover the whole disk. This will be a lot of l2
> > cache table RW operations if cache miss happens frequently.
> >  
> > This patch exports the qcow2 driver parameter
> > l2-cache-size/refcount-cache-size, first added in Qemu 2.2, and
> > cache-clean-interval, first added in Qemu 2.5, in libvirt.
> > 
> > Change since v3: a) copy qcow2 cache configurion from source to backing
> > to backing file source.
> 
> 
> The difference you list doesn't make any sense. The only difference
> between this an V3 is removing the qemu_command.c from patch1.  I did a
> git diff between the two trees I have from your patches:
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index c3b81e138..e95683965 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -14318,11 +14318,6 @@
> qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver,
>  if (!(dd->src = virStorageSourceCopy(snap->def->disks[i].src,
> false)))
>  goto error;
> 
> -/* keep the qcow2 cache configuration */
> -dd->src->l2_cache_size = vm->def->disks[i]->src->l2_cache_size;
> -dd->src->refcount_cache_size =
> vm->def->disks[i]->src->refcount_cache_size;
> -dd->src->cache_clean_interval =
> vm->def->disks[i]->src->cache_clean_interval;
If these three lines are not added, the qcow2 element(child of driver
element) will be missed after a external disk snapshot. This is due to the
values of the three parameters will be set to 0.
> -
>      if (virStorageSourceInitChainElement(dd->src, dd->disk->src,
> false) < 0)
>  goto error;
> 
> 
> I'll stick with the v3 version and adjustments from comments that I made.
> 
> John
> > Liu Qing (2):
> >   conf, docs: Add qcow2 cache configuration support
> >   qemu: add capability checking for qcow2 cache configuration
> > 
> >  docs/formatdomain.html.in  | 43 ++
> >  docs/schemas/domaincommon.rng  | 35 
> >  src/conf/domain_conf.c | 95 
> > +-
> >  src/qemu/qemu_capabilities.c   |  9 ++
> >  src/qemu/qemu_capabilities.h   |  3 +
> >  src/qemu/qemu_command.c| 33 
> >  src/qemu/qemu_driver.c |  5 ++
> >  src/util/virstoragefile.c  |  3 +
> >  src/util/virstoragefile.h  |  6 ++
> >  tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml   |  3 +
> >  .../caps_2.6.0-gicv2.aarch64.xml   |  3 +
> >  .../caps_2.6.0-gicv3.aarch64.xml   |  3 +
> >  tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml  |  3 +
> >  tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml   |  3 +
> >  tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml|  3 +
> >  tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml   |  3 +
> >  tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml|  3 +
> >  tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml   |  3 +
> >  tests/qemucapabilitiesdata/caps_2.9.0.ppc64le.xml  |  3 +
> >  tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml|  3 +
> >  tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   |  3 +
> >  .../qemuxml2argv-disk-drive-qcow2-cache.args   | 28 +++
> >  .../qemuxml2argv-disk-drive-qcow2-cache.xml| 43 ++
> >  tests/qemuxml2argvtest.c   |  4 +
> >  .../qemuxml2xmlout-disk-drive-qcow2-cache.xml  | 43 ++
> >  tests/qemuxml2xmltest.c|  1 +
> >  26 files changed, 386 insertions(+), 1 deletion(-)
> >  create mode 100644 
> > tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.args
> >  create mode 100644 
> > tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.xml
> >  create mode 100644 
> > tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-cache.xml
> > 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v4 2/2] qemu: add capability checking for qcow2 cache configuration

2017-09-13 Thread Liu Qing
Add qemu capabilities QEMU_CAPS_L2_CACHE_SIZE,
QEMU_CAPS_REFCOUNT_CACHE_SIZE, QEMU_CAPS_CACHE_CLEAN_INTERVAL.
Add testing for the above qemu capabilities.

Signed-off-by: Liu Qing 
---
 src/qemu/qemu_capabilities.c   |  9 +
 src/qemu/qemu_capabilities.h   |  3 ++
 src/qemu/qemu_command.c| 39 ++
 tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml   |  3 ++
 .../caps_2.6.0-gicv2.aarch64.xml   |  3 ++
 .../caps_2.6.0-gicv3.aarch64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml  |  3 ++
 tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.ppc64le.xml  |  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   |  3 ++
 .../qemuxml2argv-disk-drive-qcow2-cache.args   | 28 
 tests/qemuxml2argvtest.c   |  4 +++
 17 files changed, 113 insertions(+), 6 deletions(-)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.args

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index e7ea6f4..e8cce38 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -439,6 +439,9 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
   "virtio-net.tx_queue_size",
   "chardev-reconnect",
   "virtio-gpu.max_outputs",
+  "drive.qcow2.l2-cache-size",
+  "drive.qcow2.refcount-cache-size",
+  "drive.qcow2.cache-clean-interval",
 );
 
 
@@ -1811,6 +1814,12 @@ static struct virQEMUCapsStringFlags 
virQEMUCapsObjectPropsIntelIOMMU[] = {
 static struct virQEMUCapsStringFlags virQEMUCapsQMPSchemaQueries[] = {
 { "blockdev-add/arg-type/options/+gluster/debug-level", 
QEMU_CAPS_GLUSTER_DEBUG_LEVEL},
 { "blockdev-add/arg-type/+gluster/debug", QEMU_CAPS_GLUSTER_DEBUG_LEVEL},
+{ "blockdev-add/arg-type/options/+qcow2/l2-cache-size", 
QEMU_CAPS_DRIVE_QCOW2_L2_CACHE_SIZE},
+{ "blockdev-add/arg-type/options/+qcow2/refcount-cache-size", 
QEMU_CAPS_DRIVE_QCOW2_REFCOUNT_CACHE_SIZE},
+{ "blockdev-add/arg-type/options/+qcow2/cache-clean-interval", 
QEMU_CAPS_DRIVE_QCOW2_CACHE_CLEAN_INTERVAL},
+{ "blockdev-add/arg-type/+qcow2/l2-cache-size", 
QEMU_CAPS_DRIVE_QCOW2_L2_CACHE_SIZE},
+{ "blockdev-add/arg-type/+qcow2/refcount-cache-size", 
QEMU_CAPS_DRIVE_QCOW2_REFCOUNT_CACHE_SIZE},
+{ "blockdev-add/arg-type/+qcow2/cache-clean-interval", 
QEMU_CAPS_DRIVE_QCOW2_CACHE_CLEAN_INTERVAL},
 };
 
 struct virQEMUCapsObjectTypeProps {
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index f32687d..81fb759 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -425,6 +425,9 @@ typedef enum {
 QEMU_CAPS_VIRTIO_NET_TX_QUEUE_SIZE, /* virtio-net-*.tx_queue_size */
 QEMU_CAPS_CHARDEV_RECONNECT, /* -chardev reconnect */
 QEMU_CAPS_VIRTIO_GPU_MAX_OUTPUTS, /* -device 
virtio-(vga|gpu-*),max-outputs= */
+QEMU_CAPS_DRIVE_QCOW2_L2_CACHE_SIZE, /* -drive support qcow2 l2 cache size 
*/
+QEMU_CAPS_DRIVE_QCOW2_REFCOUNT_CACHE_SIZE, /* -drive support qcow2 
refcount cache size */
+QEMU_CAPS_DRIVE_QCOW2_CACHE_CLEAN_INTERVAL, /* -drive qcow2 cache clean 
interval */
 
 QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index ba81525..da91059 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1433,12 +1433,39 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
 qemuformat = "luks";
 virBufferAsprintf(buf, "format=%s,", qemuformat);
 }
-if (disk->src->l2_cache_size > 0)
-virBufferAsprintf(buf, "l2-cache-size=%llu,", 
disk->src->l2_cache_size);
-if (disk->src->refcount_cache_size > 0)
-virBufferAsprintf(buf, "refcount-cache-size=%llu,", 
disk->src->refcount_cache_size);
-if (disk->src->cache_clean_interval > 0)
-virBufferAsprintf(buf, "cache-clean-interval=%llu,", 
disk->src->cache_clean_interval);
+
+if (disk->src->l2_cache_size > 0) {
+if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_QCOW2_L2_CACHE_SIZE)) {
+virBufferAsprintf(buf, "l2-cache-size=%llu,",
+  disk->src->l2_cache_size);
+} else {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,

[libvirt] [PATCH v4 0/2] Add support for qcow2 cache

2017-09-13 Thread Liu Qing
Qcow2 small IO random write performance will drop dramatically if the l2
cache table could not cover the whole disk. This will be a lot of l2
cache table RW operations if cache miss happens frequently.
 
This patch exports the qcow2 driver parameter
l2-cache-size/refcount-cache-size, first added in Qemu 2.2, and
cache-clean-interval, first added in Qemu 2.5, in libvirt.

Change since v3: a) copy qcow2 cache configurion from source to backing
to backing file source.
Liu Qing (2):
  conf, docs: Add qcow2 cache configuration support
  qemu: add capability checking for qcow2 cache configuration

 docs/formatdomain.html.in  | 43 ++
 docs/schemas/domaincommon.rng  | 35 
 src/conf/domain_conf.c | 95 +-
 src/qemu/qemu_capabilities.c   |  9 ++
 src/qemu/qemu_capabilities.h   |  3 +
 src/qemu/qemu_command.c| 33 
 src/qemu/qemu_driver.c |  5 ++
 src/util/virstoragefile.c  |  3 +
 src/util/virstoragefile.h  |  6 ++
 tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml   |  3 +
 .../caps_2.6.0-gicv2.aarch64.xml   |  3 +
 .../caps_2.6.0-gicv3.aarch64.xml   |  3 +
 tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml  |  3 +
 tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml   |  3 +
 tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml|  3 +
 tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml   |  3 +
 tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml|  3 +
 tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml   |  3 +
 tests/qemucapabilitiesdata/caps_2.9.0.ppc64le.xml  |  3 +
 tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml|  3 +
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   |  3 +
 .../qemuxml2argv-disk-drive-qcow2-cache.args   | 28 +++
 .../qemuxml2argv-disk-drive-qcow2-cache.xml| 43 ++
 tests/qemuxml2argvtest.c   |  4 +
 .../qemuxml2xmlout-disk-drive-qcow2-cache.xml  | 43 ++
 tests/qemuxml2xmltest.c|  1 +
 26 files changed, 386 insertions(+), 1 deletion(-)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-cache.xml

-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v4 1/2] conf, docs: Add qcow2 cache configuration support

2017-09-13 Thread Liu Qing
Random write IOPS will drop dramatically if qcow2 l2 cache could not
cover the whole disk. This patch gives libvirt user a chance to adjust
the qcow2 cache configuration.

Three new qcow2 driver parameters are added. They are l2-cache-size,
refcount-cache-size and cache-clean-interval.

The following are from qcow2-cache.txt.
The amount of virtual disk that can be mapped by the L2 and refcount
caches (in bytes) is:
disk_size = l2_cache_size * cluster_size / 8
disk_size = refcount_cache_size * cluster_size * 8 / refcount_bits

The parameter "cache-clean-interval" defines an interval (in seconds).
All cache entries that haven't been accessed during that interval are
removed from memory.

Signed-off-by: Liu Qing 
---
Change since v3: a) copy qcow2 cache configurion from source to backing$
to backing file source.$

 docs/formatdomain.html.in  | 43 ++
 docs/schemas/domaincommon.rng  | 35 
 src/conf/domain_conf.c | 95 +-
 src/qemu/qemu_command.c|  6 ++
 src/qemu/qemu_driver.c |  5 ++
 src/util/virstoragefile.c  |  3 +
 src/util/virstoragefile.h  |  6 ++
 .../qemuxml2argv-disk-drive-qcow2-cache.xml| 43 ++
 .../qemuxml2xmlout-disk-drive-qcow2-cache.xml  | 43 ++
 tests/qemuxml2xmltest.c|  1 +
 10 files changed, 279 insertions(+), 1 deletion(-)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-cache.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 8ca7637..245d5c4 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3036,6 +3036,49 @@
   set. (Since 3.5.0)
   
 
+The drive element may contain a qcow2 sub element, which
+allows to specifying further details related to qcow2 driver type.
+Since 3.8.0
+
+  
+The optional l2_cache_size attribute controls how much
+memory will be consumed by qcow2 l2 table cache in bytes. This
+option is only valid when the driver type is qcow2. The default
+size is 2097152. The amount of virtual disk that can be mapped by
+the L2 caches (in bytes) is:
+  disk_size = l2_cache_size * cluster_size / 8
+Since 3.8.0
+
+In general you should leave this option alone, unless you
+are very certain you know what you are doing.
+  
+  
+The optional refcount_cache_size attribute controls
+how much memory will be consumed by qcow2 reference count table
+cache in bytes. This option is only valid when the driver type is
+qcow2. The default size is 262144. The amount of virtual disk that
+can be mapped by the refcount caches (in bytes) is:
+  disk_size = refcount_cache_size * cluster_size * 8 / 
refcount_bits
+Since 3.8.0
+
+In general you should leave this option alone, unless you
+are very certain you know what you are doing.
+  
+  
+The optional cache_clean_interval attribute defines
+an interval (in seconds). All cache entries that haven't been
+accessed during that interval are removed from memory. This option
+is only valid when the driver type is qcow2. The default
+value is 0, which disables this feature. If the interval is too
+short, it will cause frequent cache write back and load, which
+impact performance. If the interval is too long, unused cache
+will still consume memory until it's been written back to disk.
+Since 3.8.0
+
+In general you should leave this option alone, unless you
+are very certain you know what you are doing.
+  
+
   
   backenddomain
   The optional backenddomain element allows specifying a
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index c9a4f7a..e4200fe 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1756,6 +1756,23 @@
 
   
   
+  
+
+  
+
+  
+  
+
+  
+  
+
+  
+
+  
+
+  
   
@@ -1794,6 +1811,9 @@
 
   
   
+  
+
+  
   
 
   
@@ -1889,6 +1909,21 @@
   
 
   
+  
+
+  
+
+  
+  
+
+  
+
+  
+  
+
+  
+
+  
   
 
   
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a43b25c..4949e8b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5734,6 +5734,28 @@ virDomainDeviceLoadparmIsV

[libvirt] [PATCH v3 0/2] Add support for qcow2 cache

2017-09-06 Thread Liu Qing
changes since v2:
Patch 1 - a) add new element qcow2 as drive's child, if any qcow2
 specific configuration exists.
  b) merge the three test cases to one.
  c) update docs. cache size only support bytes.
  d) move the parameters checking to virDomainDiskDefParseValidate 

Patch 2 - a) use QMP instead of qemu version to identify qemu capabilities.
  b) change capablity names with prefix drive.qcow2.
  c) merge the three test cases to one.

Liu Qing (2):
  conf, docs: Add qcow2 cache configuration support
  qemu: add capability checking for qcow2 cache configuration

 docs/formatdomain.html.in  | 43 ++
 docs/schemas/domaincommon.rng  | 35 
 src/conf/domain_conf.c | 95 +-
 src/qemu/qemu_capabilities.c   |  9 ++
 src/qemu/qemu_capabilities.h   |  3 +
 src/qemu/qemu_command.c| 33 
 src/util/virstoragefile.c  |  3 +
 src/util/virstoragefile.h  |  6 ++
 tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml   |  3 +
 .../caps_2.6.0-gicv2.aarch64.xml   |  3 +
 .../caps_2.6.0-gicv3.aarch64.xml   |  3 +
 tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml  |  3 +
 tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml   |  3 +
 tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml|  3 +
 tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml   |  3 +
 tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml|  3 +
 tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml   |  3 +
 tests/qemucapabilitiesdata/caps_2.9.0.ppc64le.xml  |  3 +
 tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml|  3 +
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   |  3 +
 .../qemuxml2argv-disk-drive-qcow2-cache.args   | 28 +++
 .../qemuxml2argv-disk-drive-qcow2-cache.xml| 43 ++
 tests/qemuxml2argvtest.c   |  4 +
 .../qemuxml2xmlout-disk-drive-qcow2-cache.xml  | 43 ++
 tests/qemuxml2xmltest.c|  1 +
 25 files changed, 381 insertions(+), 1 deletion(-)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-cache.xml

-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/2] conf, docs: Add qcow2 cache configuration support

2017-09-06 Thread Liu Qing
Random write IOPS will drop dramatically if qcow2 l2 cache could not
cover the whole disk. This patch gives libvirt user a chance to adjust
the qcow2 cache configuration.

Three new qcow2 driver parameters are added. They are l2-cache-size,
refcount-cache-size and cache-clean-interval.

The following are from qcow2-cache.txt.
The amount of virtual disk that can be mapped by the L2 and refcount
caches (in bytes) is:
disk_size = l2_cache_size * cluster_size / 8
disk_size = refcount_cache_size * cluster_size * 8 / refcount_bits

The parameter "cache-clean-interval" defines an interval (in seconds).
All cache entries that haven't been accessed during that interval are
removed from memory.

Signed-off-by: Liu Qing 
---

a) add new element qcow2 as drive's child, if any qcow2
   specific configuration exists.
b) merge the three test cases to one.
c) update docs. cache size only support bytes.
d) move the parameters checking to virDomainDiskDefParseValidate 

 docs/formatdomain.html.in  | 43 ++
 docs/schemas/domaincommon.rng  | 35 
 src/conf/domain_conf.c | 95 +-
 src/qemu/qemu_command.c|  6 ++
 src/util/virstoragefile.c  |  3 +
 src/util/virstoragefile.h  |  6 ++
 .../qemuxml2argv-disk-drive-qcow2-cache.xml| 43 ++
 .../qemuxml2xmlout-disk-drive-qcow2-cache.xml  | 43 ++
 tests/qemuxml2xmltest.c|  1 +
 9 files changed, 274 insertions(+), 1 deletion(-)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-cache.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 8ca7637..245d5c4 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3036,6 +3036,49 @@
   set. (Since 3.5.0)
   
 
+The drive element may contain a qcow2 sub element, which
+allows to specifying further details related to qcow2 driver type.
+Since 3.8.0
+
+  
+The optional l2_cache_size attribute controls how much
+memory will be consumed by qcow2 l2 table cache in bytes. This
+option is only valid when the driver type is qcow2. The default
+size is 2097152. The amount of virtual disk that can be mapped by
+the L2 caches (in bytes) is:
+  disk_size = l2_cache_size * cluster_size / 8
+Since 3.8.0
+
+In general you should leave this option alone, unless you
+are very certain you know what you are doing.
+  
+  
+The optional refcount_cache_size attribute controls
+how much memory will be consumed by qcow2 reference count table
+cache in bytes. This option is only valid when the driver type is
+qcow2. The default size is 262144. The amount of virtual disk that
+can be mapped by the refcount caches (in bytes) is:
+  disk_size = refcount_cache_size * cluster_size * 8 / 
refcount_bits
+Since 3.8.0
+
+In general you should leave this option alone, unless you
+are very certain you know what you are doing.
+  
+  
+The optional cache_clean_interval attribute defines
+an interval (in seconds). All cache entries that haven't been
+accessed during that interval are removed from memory. This option
+is only valid when the driver type is qcow2. The default
+value is 0, which disables this feature. If the interval is too
+short, it will cause frequent cache write back and load, which
+impact performance. If the interval is too long, unused cache
+will still consume memory until it's been written back to disk.
+Since 3.8.0
+
+In general you should leave this option alone, unless you
+are very certain you know what you are doing.
+  
+
   
   backenddomain
   The optional backenddomain element allows specifying a
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 06c5a91..ec44e58 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1762,6 +1762,23 @@
 
   
   
+  
+
+  
+
+  
+  
+
+  
+  
+
+  
+
+  
+
+  
   
@@ -1800,6 +1817,9 @@
 
   
   
+  
+
+  
   
 
   
@@ -1895,6 +1915,21 @@
   
 
   
+  
+
+  
+
+  
+  
+
+  
+
+  
+  
+
+  
+
+  
   
 
   
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2fc1fc3..c7d4b9b 100644
--- a/src/conf/domain_conf.c
+++ b/src

[libvirt] [PATCH 2/2] qemu: add capability checking for qcow2 cache configuration

2017-09-06 Thread Liu Qing
Add qemu capabilities QEMU_CAPS_L2_CACHE_SIZE,
QEMU_CAPS_REFCOUNT_CACHE_SIZE, QEMU_CAPS_CACHE_CLEAN_INTERVAL.
Add testing for the above qemu capabilities.

Signed-off-by: Liu Qing 
---

Patch 2 - a) use QMP instead of qemu version to identify qemu capabilities.
  b) change capablity names with prefix drive.qcow2.
  c) merge the three test cases to one.

 src/qemu/qemu_capabilities.c   |  9 +
 src/qemu/qemu_capabilities.h   |  3 ++
 src/qemu/qemu_command.c| 39 ++
 tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml   |  3 ++
 .../caps_2.6.0-gicv2.aarch64.xml   |  3 ++
 .../caps_2.6.0-gicv3.aarch64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml  |  3 ++
 tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.ppc64le.xml  |  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   |  3 ++
 .../qemuxml2argv-disk-drive-qcow2-cache.args   | 28 
 tests/qemuxml2argvtest.c   |  4 +++
 17 files changed, 113 insertions(+), 6 deletions(-)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache.args

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index e7ea6f4..e8cce38 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -439,6 +439,9 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
   "virtio-net.tx_queue_size",
   "chardev-reconnect",
   "virtio-gpu.max_outputs",
+  "drive.qcow2.l2-cache-size",
+  "drive.qcow2.refcount-cache-size",
+  "drive.qcow2.cache-clean-interval",
 );
 
 
@@ -1811,6 +1814,12 @@ static struct virQEMUCapsStringFlags 
virQEMUCapsObjectPropsIntelIOMMU[] = {
 static struct virQEMUCapsStringFlags virQEMUCapsQMPSchemaQueries[] = {
 { "blockdev-add/arg-type/options/+gluster/debug-level", 
QEMU_CAPS_GLUSTER_DEBUG_LEVEL},
 { "blockdev-add/arg-type/+gluster/debug", QEMU_CAPS_GLUSTER_DEBUG_LEVEL},
+{ "blockdev-add/arg-type/options/+qcow2/l2-cache-size", 
QEMU_CAPS_DRIVE_QCOW2_L2_CACHE_SIZE},
+{ "blockdev-add/arg-type/options/+qcow2/refcount-cache-size", 
QEMU_CAPS_DRIVE_QCOW2_REFCOUNT_CACHE_SIZE},
+{ "blockdev-add/arg-type/options/+qcow2/cache-clean-interval", 
QEMU_CAPS_DRIVE_QCOW2_CACHE_CLEAN_INTERVAL},
+{ "blockdev-add/arg-type/+qcow2/l2-cache-size", 
QEMU_CAPS_DRIVE_QCOW2_L2_CACHE_SIZE},
+{ "blockdev-add/arg-type/+qcow2/refcount-cache-size", 
QEMU_CAPS_DRIVE_QCOW2_REFCOUNT_CACHE_SIZE},
+{ "blockdev-add/arg-type/+qcow2/cache-clean-interval", 
QEMU_CAPS_DRIVE_QCOW2_CACHE_CLEAN_INTERVAL},
 };
 
 struct virQEMUCapsObjectTypeProps {
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index f32687d..81fb759 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -425,6 +425,9 @@ typedef enum {
 QEMU_CAPS_VIRTIO_NET_TX_QUEUE_SIZE, /* virtio-net-*.tx_queue_size */
 QEMU_CAPS_CHARDEV_RECONNECT, /* -chardev reconnect */
 QEMU_CAPS_VIRTIO_GPU_MAX_OUTPUTS, /* -device 
virtio-(vga|gpu-*),max-outputs= */
+QEMU_CAPS_DRIVE_QCOW2_L2_CACHE_SIZE, /* -drive support qcow2 l2 cache size 
*/
+QEMU_CAPS_DRIVE_QCOW2_REFCOUNT_CACHE_SIZE, /* -drive support qcow2 
refcount cache size */
+QEMU_CAPS_DRIVE_QCOW2_CACHE_CLEAN_INTERVAL, /* -drive qcow2 cache clean 
interval */
 
 QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 391aaba..e2592e0 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1433,12 +1433,39 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
 qemuformat = "luks";
 virBufferAsprintf(buf, "format=%s,", qemuformat);
 }
-if (disk->src->l2_cache_size > 0)
-virBufferAsprintf(buf, "l2-cache-size=%llu,", 
disk->src->l2_cache_size);
-if (disk->src->refcount_cache_size > 0)
-virBufferAsprintf(buf, "refcount-cache-size=%llu,", 
disk->src->refcount_cache_size);
-if (disk->src->cache_clean_interval > 0)
-virBufferAsprintf(buf, "cache-clean-interval=%llu,", 
disk->src->cache_clean_interval);
+
+if (disk->src->l2_cache_size > 0) {
+if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_QCOW2_L2_CACHE_SIZE)) {
+virBuffer

[libvirt] [PATCH v2 1/2] conf, docs: Add qcow2 cache configuration support

2017-09-03 Thread Liu Qing
Random write IOPS will drop dramatically if qcow2 l2 cache could not
cover the whole disk. This patch gives libvirt user a chance to adjust
the qcow2 cache configuration.

Three new qcow2 driver paramters are added. They are l2-cache-size,
refcount-cache-size and cache-clean-interval.

The following are from qcow2-cache.txt.
The amount of virtual disk that can be mapped by the L2 and refcount
caches (in bytes) is:
disk_size = l2_cache_size * cluster_size / 8
disk_size = refcount_cache_size * cluster_size * 8 / refcount_bits

The parameter "cache-clean-interval" defines an interval (in seconds).
All cache entries that haven't been accessed during that interval are
removed from memory.

Signed-off-by: Liu Qing 
---
 docs/formatdomain.html.in  | 21 +++
 docs/schemas/domaincommon.rng  | 24 +
 src/conf/domain_conf.c | 30 
 src/qemu/qemu_command.c|  6 
 src/util/virstoragefile.c  |  3 ++
 src/util/virstoragefile.h  |  4 +++
 ...2argv-disk-drive-qcow2-cache-clean-interval.xml | 37 +++
 ...qemuxml2argv-disk-drive-qcow2-l2-cache-size.xml | 37 +++
 ...l2argv-disk-drive-qcow2-refcount-cache-size.xml | 37 +++
 ...mlout-disk-drive-qcow2-cache-clean-interval.xml | 41 ++
 ...muxml2xmlout-disk-drive-qcow2-l2-cache-size.xml | 41 ++
 ...xmlout-disk-drive-qcow2-refcount-cache-size.xml | 41 ++
 tests/qemuxml2xmltest.c|  3 ++
 13 files changed, 325 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache-clean-interval.xml
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-l2-cache-size.xml
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-refcount-cache-size.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-cache-clean-interval.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-l2-cache-size.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-refcount-cache-size.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 8ca7637..8f093b5 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3035,6 +3035,27 @@
   Virtio-specific options can also be
   set. (Since 3.5.0)
   
+  
+The optional l2_cache_size attribute controls how much
+memory will be consumed by qcow2 l2 table cache. This option is
+only valid when the driver type is qcow2. The default size is 1MB.
+Since 3.7.0
+  
+  
+The optional refcount_cache_size attribute controls
+how much memory will be consumed by qcow2 reference count table
+cache. This option is only valid when the driver type is qcow2.
+The default size is 256KB.
+Since 3.7.0
+  
+  
+The optional cache_clean_interval attribute defines
+an interval (in seconds). All cache entries that haven't been
+accessed during that interval are removed from memory. This option
+is only valid when the driver type is qcow2. The defaut value is 0,
+which disables this feature.
+Since 3.7.0
+  
 
   
   backenddomain
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 06c5a91..5545179 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1797,6 +1797,15 @@
 
   
   
+
+  
+  
+
+  
+  
+
+  
+  
 
   
   
@@ -1895,6 +1904,21 @@
   
 
   
+  
+
+  
+
+  
+  
+
+  
+
+  
+  
+
+  
+
+  
   
 
   
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f7574d7..f07ab72 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8600,6 +8600,30 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def,
 VIR_FREE(tmp);
 }
 
+if ((tmp = virXMLPropString(cur, "l2_cache_size")) &&
+(virStrToLong_ui(tmp, NULL, 10, &def->src->l2_cache_size) < 0)) {
+virReportError(VIR_ERR_XML_ERROR,
+   _("Invalid l2_cache_size attribute in disk driver 
element: %s"),
+   tmp);
+goto cleanup;
+}
+
+if ((tmp = virXMLPropString(cur, "refcount_cache_size")) &&
+(virStrToLong_ui(tmp, NULL, 10, &def->src->refcount_cache_size) < 0)) {
+virReportError(VIR_ERR_XML_ERROR,
+   _("Invalid refcount_cache_size attribute in disk d

[libvirt] [PATCH v2 0/2] Add support for qcow2 cache

2017-09-03 Thread Liu Qing
Qcow2 small IO random write performance will drop dramatically if the l2
cache table could not cover the whole disk. This will be a lot of l2
cache table RW operations if cache miss happens frequently.

This patch exports the qcow2 driver parameter
l2-cache-size/refcount-cache-size, first added in Qemu 2.2, and
cache-clean-interval, first added in Qemu 2.5, in libvirt.

*** BLURB HERE ***

Liu Qing (2):
  conf, docs: Add qcow2 cache configuration support
  qemu: add capability checking for qcow2 cache configuration

 docs/formatdomain.html.in  | 21 ++
 docs/schemas/domaincommon.rng  | 24 +++
 src/conf/domain_conf.c | 30 ++
 src/qemu/qemu_capabilities.c   | 15 +++
 src/qemu/qemu_capabilities.h   |  3 ++
 src/qemu/qemu_command.c| 47 ++
 src/util/virstoragefile.c  |  3 ++
 src/util/virstoragefile.h  |  4 ++
 tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml   |  2 +
 tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml   |  3 ++
 .../caps_2.6.0-gicv2.aarch64.xml   |  3 ++
 .../caps_2.6.0-gicv3.aarch64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml  |  3 ++
 tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.ppc64le.xml  |  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   |  3 ++
 ...argv-disk-drive-qcow2-cache-clean-interval.args | 27 +
 ...2argv-disk-drive-qcow2-cache-clean-interval.xml | 37 +
 ...emuxml2argv-disk-drive-qcow2-l2-cache-size.args | 27 +
 ...qemuxml2argv-disk-drive-qcow2-l2-cache-size.xml | 37 +
 ...2argv-disk-drive-qcow2-refcount-cache-size.args | 27 +
 ...l2argv-disk-drive-qcow2-refcount-cache-size.xml | 37 +
 tests/qemuxml2argvtest.c   |  6 +++
 ...mlout-disk-drive-qcow2-cache-clean-interval.xml | 41 +++
 ...muxml2xmlout-disk-drive-qcow2-l2-cache-size.xml | 41 +++
 ...xmlout-disk-drive-qcow2-refcount-cache-size.xml | 41 +++
 tests/qemuxml2xmltest.c|  3 ++
 32 files changed, 509 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache-clean-interval.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache-clean-interval.xml
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-l2-cache-size.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-l2-cache-size.xml
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-refcount-cache-size.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-refcount-cache-size.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-cache-clean-interval.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-l2-cache-size.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-qcow2-refcount-cache-size.xml

-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 2/2] qemu: add capability checking for qcow2 cache configuration

2017-09-03 Thread Liu Qing
Add qemu capabilities QEMU_CAPS_L2_CACHE_SIZE,
QEMU_CAPS_REFCOUNT_CACHE_SIZE, QEMU_CAPS_CACHE_CLEAN_INTERVAL.
Add testing for the above qemu capabilities.

Signed-off-by: Liu Qing 
---
 src/qemu/qemu_capabilities.c   | 15 +++
 src/qemu/qemu_capabilities.h   |  3 ++
 src/qemu/qemu_command.c| 47 --
 tests/qemucapabilitiesdata/caps_2.4.0.x86_64.xml   |  2 +
 tests/qemucapabilitiesdata/caps_2.5.0.x86_64.xml   |  3 ++
 .../caps_2.6.0-gicv2.aarch64.xml   |  3 ++
 .../caps_2.6.0-gicv3.aarch64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.6.0.ppc64le.xml  |  3 ++
 tests/qemucapabilitiesdata/caps_2.6.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.7.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.8.0.x86_64.xml   |  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.ppc64le.xml  |  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.s390x.xml|  3 ++
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   |  3 ++
 ...argv-disk-drive-qcow2-cache-clean-interval.args | 27 +
 ...emuxml2argv-disk-drive-qcow2-l2-cache-size.args | 27 +
 ...2argv-disk-drive-qcow2-refcount-cache-size.args | 27 +
 tests/qemuxml2argvtest.c   |  6 +++
 20 files changed, 187 insertions(+), 3 deletions(-)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-cache-clean-interval.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-l2-cache-size.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-drive-qcow2-refcount-cache-size.args

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index e7ea6f4..619735d 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -376,6 +376,8 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
   "nec-usb-xhci-ports",
   "virtio-scsi-pci.iothread",
   "name-guest",
+  "l2-cache-size",
+  "refcount-cache-size",
 
   /* 225 */
   "qxl.max_outputs",
@@ -418,6 +420,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
   "query-named-block-nodes",
   "cpu-cache",
   "qemu-xhci",
+  "cache-clean-interval",
 
   /* 255 */
   "kernel-irqchip",
@@ -4753,6 +4756,14 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
 if (qemuCaps->version >= 2002000)
 virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_VMPORT_OPT);
 
+/* qcow2 l2-cache-size option is supported v2.2.0 onwards */
+if (qemuCaps->version >= 2002000)
+virQEMUCapsSet(qemuCaps, QEMU_CAPS_L2_CACHE_SIZE);
+
+/* qcow2 refcount_cache_size option is supported v2.2.0 onwards */
+if (qemuCaps->version >= 2002000)
+virQEMUCapsSet(qemuCaps, QEMU_CAPS_REFCOUNT_CACHE_SIZE);
+
 /* -cpu ...,aarch64=off supported in v2.3.0 and onwards. But it
isn't detectable via qmp at this point */
 if (qemuCaps->arch == VIR_ARCH_AARCH64 &&
@@ -4772,6 +4783,10 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
 if (qemuCaps->version >= 2004050)
 virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACH_VIRT_GIC_VERSION);
 
+/* qcow2 cache_clean_interval option is supported v2.5.0 onwards */
+if (qemuCaps->version >= 2005000)
+virQEMUCapsSet(qemuCaps, QEMU_CAPS_CACHE_CLEAN_INTERVAL);
+
 /* no way to query if -machine kernel_irqchip supports split */
 if (qemuCaps->version >= 2006000)
 virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_KERNEL_IRQCHIP_SPLIT);
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index f32687d..f1302ee 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -362,6 +362,8 @@ typedef enum {
 QEMU_CAPS_NEC_USB_XHCI_PORTS, /* -device nec-usb-xhci.p3 ports setting */
 QEMU_CAPS_VIRTIO_SCSI_IOTHREAD, /* virtio-scsi-{pci,ccw}.iothread */
 QEMU_CAPS_NAME_GUEST, /* -name guest= */
+QEMU_CAPS_L2_CACHE_SIZE, /* -drive support qcow2 l2 cache size */
+QEMU_CAPS_REFCOUNT_CACHE_SIZE, /* -drive support qcow2 refcount cache size 
*/
 
 /* 225 */
 QEMU_CAPS_QXL_MAX_OUTPUTS, /* -device qxl,max-outputs= */
@@ -404,6 +406,7 @@ typedef enum {
 QEMU_CAPS_QUERY_NAMED_BLOCK_NODES, /* qmp query-named-block-nodes */
 QEMU_CAPS_CPU_CACHE, /* -cpu supports host-cache-info and l3-cache 
properties */
 QEMU_CAPS_DEVICE_QEMU_XHCI, /* -device qemu-xhci */
+QEMU_CAPS_CACHE_CLEAN_INTERVAL, /* -drive qcow2 cache clean interval */
 
 /* 255 */
 QEMU_CAPS_MACHINE_KERNEL_IRQCHIP, /* -machine kernel_irqchip */
diff --git 

Re: [libvirt] [PATCH] Add qcow2 cache configuration

2017-08-30 Thread Liu Qing
On Wed, Aug 30, 2017 at 11:12:02AM +0200, Martin Kletzander wrote:
> On Wed, Aug 30, 2017 at 04:07:16PM +0800, Liu Qing wrote:
> >Random write IOPS will drop dramatically if qcow2 l2 cache could not
> >cover the whole disk. This patch give libvirt user a chance to adjust
> >the qcow2 cache configuration.
> >
> 
> Thanks for the patch, but it has no documentation, no capability
> checking, no RNG schema adjustments and no tests.  Ideally the patch
> should be a series of patches, each introducing part of the
> functionality.  For example:
> 
>  [PATCH 1/3] conf, docs: Add support for bla bla bla
> 
>Add stuff to docs/schemas/*.rng, docs/*.html.in, src/conf/*.c, add
>parsing tests to tests/qemuxml2xmltest.c (and possibly
>qemuxml2argvtest.c if there is some negative test that should fail
>parsing).  Code needs to compile cleanly and tests need to pass after
>this patch.  Documentation should cleanly state the reasoning and
>rules for the possible values so that users know *if* and *why* they
>need to set this up and to *what* values.  It is also good to think
>about why QEMU doesn't use such values as default and whether or not
>(or why/not) libvirt should default to such values without making
>the user do so.
> 
>  [PATCH 2/3] qemu: Add capability checking for bla bla bla
> 
>Here you would check that we properly probe qemu for the possibility
>of setting such tunables in src/qemu/qemu_capabilities.[hc].  Code
>needs to compile cleanly and tests need to pass after this patch.
> 
>  [PATCH 3/3] qemu: Add support for bla bla bla
> 
>Here you would check if the emulator has the required capabilities,
>format them on the command line and add positive tests to
>tests/qemuxml2argvtest.c.  Code needs to compile cleanly and tests
>need to pass after this patch.
> 
> In rare cases where the functionality and required tests are minimal,
> patches [2/3] and [3/3] could be merged together, but they can always be
> separate, IMHO.
> 
> All of this ^^ is only about the way the patch is supposed to be sent.
> Whether or not it makes sense to expose such tunables is left as an
> exercise to all readers (and possibly a discussion on v2 of this patch).
Thanks for the guide, I will take time to complete these.
> 
> Have a nice day,
> Martin


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] Add qcow2 cache configuration

2017-08-30 Thread Liu Qing
Random write IOPS will drop dramatically if qcow2 l2 cache could not
cover the whole disk. This patch give libvirt user a chance to adjust
the qcow2 cache configuration.

Signed-off-by: Liu Qing 
---
 src/conf/domain_conf.c| 30 ++
 src/qemu/qemu_command.c   |  6 ++
 src/util/virstoragefile.c |  3 +++
 src/util/virstoragefile.h |  4 
 4 files changed, 43 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d97aab4..06ca1de 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8590,6 +8590,30 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def,
 VIR_FREE(tmp);
 }
 
+if ((tmp = virXMLPropString(cur, "l2-cache-size")) &&
+(virStrToLong_ui(tmp, NULL, 10, &def->src->l2_cache_size) < 0)) {
+virReportError(VIR_ERR_XML_ERROR,
+   _("Invalid l2-cache-size attribute in disk driver 
element: %s"),
+   tmp);
+goto cleanup;
+}
+
+if ((tmp = virXMLPropString(cur, "refcount-cache-size")) &&
+(virStrToLong_ui(tmp, NULL, 10, &def->src->refcount_cache_size) < 0)) {
+virReportError(VIR_ERR_XML_ERROR,
+   _("Invalid refcount-cache-size attribute in disk driver 
element: %s"),
+   tmp);
+goto cleanup;
+}
+
+if ((tmp = virXMLPropString(cur, "cache-clean-interval")) &&
+(virStrToLong_ui(tmp, NULL, 10, &def->src->cache_clean_interval) < 0)) 
{
+virReportError(VIR_ERR_XML_ERROR,
+   _("Invalid cache-clean-interval attribute in disk 
driver element: %s"),
+   tmp);
+goto cleanup;
+}
+
 if ((tmp = virXMLPropString(cur, "detect_zeroes")) &&
 (def->detect_zeroes = virDomainDiskDetectZeroesTypeFromString(tmp)) <= 
0) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -21887,6 +21911,12 @@ virDomainDiskDefFormat(virBufferPtr buf,
 virBufferAsprintf(&driverBuf, " iothread='%u'", def->iothread);
 if (def->detect_zeroes)
 virBufferAsprintf(&driverBuf, " detect_zeroes='%s'", detect_zeroes);
+if (def->src->l2_cache_size > 0)
+virBufferAsprintf(&driverBuf, " l2-cache-size='%u'", 
def->src->l2_cache_size);
+if (def->src->refcount_cache_size > 0)
+virBufferAsprintf(&driverBuf, " refcount-cache-size='%u'", 
def->src->refcount_cache_size);
+if (def->src->cache_clean_interval > 0)
+virBufferAsprintf(&driverBuf, " cache-clean-interval='%u'", 
def->src->cache_clean_interval);
 
 virDomainVirtioOptionsFormat(&driverBuf, def->virtio);
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 9a27987..7996eed 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1430,6 +1430,12 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
 qemuformat = "luks";
 virBufferAsprintf(buf, "format=%s,", qemuformat);
 }
+if (disk->src->format == VIR_STORAGE_FILE_QCOW2 && 
disk->src->l2_cache_size > 0)
+virBufferAsprintf(buf, "l2-cache-size=%u,", disk->src->l2_cache_size);
+if (disk->src->format == VIR_STORAGE_FILE_QCOW2 && 
disk->src->refcount_cache_size > 0)
+virBufferAsprintf(buf, "refcount-cache-size=%u,", 
disk->src->refcount_cache_size);
+if (disk->src->format == VIR_STORAGE_FILE_QCOW2 && 
disk->src->cache_clean_interval > 0)
+virBufferAsprintf(buf, "cache-clean-interval=%u,", 
disk->src->cache_clean_interval);
 
 ret = 0;
 
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index fbc8245..c685331 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -2038,6 +2038,9 @@ virStorageSourceCopy(const virStorageSource *src,
 ret->physical = src->physical;
 ret->readonly = src->readonly;
 ret->shared = src->shared;
+ret->l2_cache_size = src->l2_cache_size;
+ret->refcount_cache_size = src->refcount_cache_size;
+ret->cache_clean_interval = src->cache_clean_interval;
 
 /* storage driver metadata are not copied */
 ret->drv = NULL;
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 6c388b1..e7889d9 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -280,6 +280,10 @@ struct _virStorageSource {
 /* metadata that allows identifying given storage source */
 char *nodeformat;  /* name of the format handler object */
 char *nodestorage; /* name of the storage object */
+
+unsigned l2_cache_size; /* qcow2 l2 cache size */
+unsigned refcount_cache_size; /* qcow2 reference count table cache size */
+unsigned cache_clean_interval; /* clean unused cache entries interval */
 };
 
 
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2] BlockCopy support rbd external destination file

2016-11-14 Thread Liu Qing
Currently qemuDomainBlockCopy only support local file. This patch make
the rbd external destination file could be passed to qemu driver_mirror.
If the flag VIR_DOMAIN_BLOCK_COPY_REUSE_EXT is not set for rbd protocol,
qemuDomainBlockCopy will report an error.

Signed-off-by: Liu Qing 
---
 src/qemu/qemu_driver.c | 119 ++---
 1 file changed, 82 insertions(+), 37 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a82e58b..c0b7fda 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -16609,6 +16609,12 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
 virQEMUDriverConfigPtr cfg = NULL;
 const char *format = NULL;
 int desttype = virStorageSourceGetActualType(mirror);
+char *mirr_path = NULL;
+qemuDomainSecretInfoPtr tmp_secinfo = NULL;
+qemuDomainSecretInfoPtr mirr_secinfo = NULL;
+qemuDomainSecretInfoPtr tmp_encinfo = NULL;
+virStorageSourcePtr tmp_src = NULL;
+qemuDomainDiskPrivatePtr diskPriv = NULL;
 
 /* Preliminaries: find the disk we are editing, sanity checks */
 virCheckFlags(VIR_DOMAIN_BLOCK_COPY_SHALLOW |
@@ -16629,6 +16635,8 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
 if (!(disk = qemuDomainDiskByName(vm->def, path)))
 goto endjob;
 
+diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+
 if (!(device = qemuAliasFromDisk(disk)))
 goto endjob;
 
@@ -16675,51 +16683,67 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
 }
 
 /* Prepare the destination file.  */
-/* XXX Allow non-file mirror destinations */
-if (!virStorageSourceIsLocalStorage(mirror)) {
+if (!virStorageSourceIsLocalStorage(mirror) &&
+(mirror->type != VIR_STORAGE_TYPE_NETWORK ||
+ mirror->protocol != VIR_STORAGE_NET_PROTOCOL_RBD)) {
 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("non-file destination not supported yet"));
 goto endjob;
 }
-if (stat(mirror->path, &st) < 0) {
-if (errno != ENOENT) {
-virReportSystemError(errno, _("unable to stat for disk %s: %s"),
- disk->dst, mirror->path);
-goto endjob;
-} else if (flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT ||
-   desttype == VIR_STORAGE_TYPE_BLOCK) {
-virReportSystemError(errno,
- _("missing destination file for disk %s: %s"),
- disk->dst, mirror->path);
-goto endjob;
-}
-} else if (!S_ISBLK(st.st_mode)) {
-if (st.st_size && !(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("external destination file for disk %s already "
- "exists and is not a block device: %s"),
-   disk->dst, mirror->path);
-goto endjob;
-}
-if (desttype == VIR_STORAGE_TYPE_BLOCK) {
-virReportError(VIR_ERR_INVALID_ARG,
-   _("blockdev flag requested for disk %s, but file "
- "'%s' is not a block device"),
-   disk->dst, mirror->path);
-goto endjob;
+if (virStorageSourceIsLocalStorage(mirror)) {
+if (stat(mirror->path, &st) < 0) {
+if (errno != ENOENT) {
+virReportSystemError(errno, _("unable to stat for disk %s: 
%s"),
+ disk->dst, mirror->path);
+goto endjob;
+} else if (flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT ||
+   desttype == VIR_STORAGE_TYPE_BLOCK) {
+virReportSystemError(errno,
+ _("missing destination file for disk %s: 
%s"),
+ disk->dst, mirror->path);
+goto endjob;
+}
+} else if (!S_ISBLK(st.st_mode)) {
+if (st.st_size && !(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("external destination file for disk %s 
already "
+ "exists and is not a block device: %s"),
+   disk->dst, mirror->path);
+goto endjob;
+}
+if (desttype == VIR_STORAGE_TYPE_BLOCK) {
+virReportError(VIR_ERR_INVALID_ARG,
+   _("blockdev flag requested for disk %s, but 
file "
+ "'%s' is not a block device"),
+   disk->dst, mirror-&

[libvirt] [PATCH] BlockCopy support rbd external destination file

2016-11-08 Thread Liu Qing
Currently qemuDomainBlockCopy only support local file. This patch make
the rbd external destination file could be passed to qemu driver_mirror.
If the external rbd file is not exist, qemuDomainBlockCopy will report
an error.

Signed-off-by: Liu Qing 
---
 src/qemu/qemu_driver.c | 82 +++---
 1 file changed, 51 insertions(+), 31 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 38c8414..ee8db69 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -16609,6 +16609,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
 virQEMUDriverConfigPtr cfg = NULL;
 const char *format = NULL;
 int desttype = virStorageSourceGetActualType(mirror);
+char *mirr_path = NULL;
 
 /* Preliminaries: find the disk we are editing, sanity checks */
 virCheckFlags(VIR_DOMAIN_BLOCK_COPY_SHALLOW |
@@ -16675,42 +16676,50 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
 }
 
 /* Prepare the destination file.  */
-/* XXX Allow non-file mirror destinations */
-if (!virStorageSourceIsLocalStorage(mirror)) {
+if (!virStorageSourceIsLocalStorage(mirror) &&
+(mirror->type != VIR_STORAGE_TYPE_NETWORK ||
+ mirror->protocol != VIR_STORAGE_NET_PROTOCOL_RBD)) {
 virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("non-file destination not supported yet"));
 goto endjob;
 }
-if (stat(mirror->path, &st) < 0) {
-if (errno != ENOENT) {
-virReportSystemError(errno, _("unable to stat for disk %s: %s"),
- disk->dst, mirror->path);
-goto endjob;
-} else if (flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT ||
-   desttype == VIR_STORAGE_TYPE_BLOCK) {
-virReportSystemError(errno,
- _("missing destination file for disk %s: %s"),
- disk->dst, mirror->path);
-goto endjob;
-}
-} else if (!S_ISBLK(st.st_mode)) {
-if (st.st_size && !(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-   _("external destination file for disk %s already "
- "exists and is not a block device: %s"),
-   disk->dst, mirror->path);
-goto endjob;
-}
-if (desttype == VIR_STORAGE_TYPE_BLOCK) {
-virReportError(VIR_ERR_INVALID_ARG,
-   _("blockdev flag requested for disk %s, but file "
- "'%s' is not a block device"),
-   disk->dst, mirror->path);
-goto endjob;
+if (virStorageSourceIsLocalStorage(mirror)) {
+if (stat(mirror->path, &st) < 0) {
+if (errno != ENOENT) {
+virReportSystemError(errno, _("unable to stat for disk %s: 
%s"),
+ disk->dst, mirror->path);
+goto endjob;
+} else if (flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT ||
+   desttype == VIR_STORAGE_TYPE_BLOCK) {
+virReportSystemError(errno,
+ _("missing destination file for disk %s: 
%s"),
+ disk->dst, mirror->path);
+goto endjob;
+}
+} else if (!S_ISBLK(st.st_mode)) {
+if (st.st_size && !(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("external destination file for disk %s 
already "
+ "exists and is not a block device: %s"),
+   disk->dst, mirror->path);
+goto endjob;
+}
+if (desttype == VIR_STORAGE_TYPE_BLOCK) {
+virReportError(VIR_ERR_INVALID_ARG,
+   _("blockdev flag requested for disk %s, but 
file "
+ "'%s' is not a block device"),
+   disk->dst, mirror->path);
+goto endjob;
+}
 }
+} else if (!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)) {
+virReportError(VIR_ERR_INVALID_ARG,
+   _("only external destination file is supported for "
+ "rbd protocol"));
+goto endjob;
 }
 
-if (!mirror->format) {
+if (!mirror->format && virStorageSourceIsLocalStorage(mirror)) {
 if (!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)) {
 mirror-