qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 4/4] block: Add iops_sector _count to do the iops ac


From: Benoît Canet
Subject: [Qemu-devel] [PATCH 4/4] block: Add iops_sector _count to do the iops accounting for a given io size .
Date: Mon, 22 Jul 2013 14:33:26 +0200

This feature can be used in case where users are avoiding the iops limit by
doing jumbo I/Os hammering the storage backend.

Signed-off-by: Benoit Canet <address@hidden>
---
 block.c                   |    8 +++++++-
 block/qapi.c              |    4 ++++
 blockdev.c                |   22 +++++++++++++++++++++-
 hmp.c                     |    8 ++++++--
 include/block/block_int.h |    1 +
 qapi-schema.json          |   10 ++++++++--
 qemu-options.hx           |    2 +-
 qmp-commands.hx           |    8 ++++++--
 8 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/block.c b/block.c
index 2d6e9b4..cfa890d 100644
--- a/block.c
+++ b/block.c
@@ -337,6 +337,12 @@ static bool 
bdrv_is_any_threshold_exceeded(BlockDriverState *bs, int nb_sectors,
                                            bool is_write)
 {
     bool bps_ret, iops_ret;
+    double   ios = 1.0;
+
+    if (bs->io_limits.iops_sector_count) {
+        ios = ((double) nb_sectors) / bs->io_limits.iops_sector_count;
+        ios = MAX(ios, 1.0);
+    }
 
     /* check if any bandwith or per IO threshold has been exceeded */
     bps_ret = bdrv_is_bps_threshold_exceeded(bs, is_write);
@@ -360,7 +366,7 @@ static bool bdrv_is_any_threshold_exceeded(BlockDriverState 
*bs, int nb_sectors,
     /* the IO is authorized so do the accounting and return false */
     bs->leaky_buckets.bytes[is_write] += (int64_t)nb_sectors *
                                          BDRV_SECTOR_SIZE;
-    bs->leaky_buckets.ios[is_write]++;
+    bs->leaky_buckets.ios[is_write] += ios;
 
     return false;
 }
diff --git a/block/qapi.c b/block/qapi.c
index 03f1604..f81081c 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -259,6 +259,10 @@ void bdrv_query_info(BlockDriverState *bs,
                            bs->io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE];
             info->inserted->iops_wr_threshold =
                            bs->io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE];
+            info->inserted->has_iops_sector_count =
+                           bs->io_limits.iops_sector_count;
+            info->inserted->iops_sector_count =
+                           bs->io_limits.iops_sector_count;
         }
 
         bs0 = bs;
diff --git a/blockdev.c b/blockdev.c
index 9bda359..8ddd710 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -352,6 +352,11 @@ static bool do_check_io_limits(BlockIOLimit *io_limits, 
Error **errp)
         return false;
     }
 
+    if (io_limits->iops_sector_count < 0) {
+        error_setg(errp, "iops_sector_count must be 0 or greater");
+        return false;
+    }
+
     return true;
 }
 
@@ -563,6 +568,10 @@ DriveInfo *drive_init(QemuOpts *all_opts, 
BlockInterfaceType block_default_type)
         qemu_opt_get_number(opts, "iops_wr_threshold",
                             io_limits.iops[BLOCK_IO_LIMIT_WRITE] / 
THROTTLE_HZ);
 
+    io_limits.iops_sector_count =
+                           qemu_opt_get_number(opts, "iops_sector_count", 0);
+ 
+
     if (!do_check_io_limits(&io_limits, &error)) {
         error_report("%s", error_get_pretty(error));
         error_free(error);
@@ -1260,7 +1269,9 @@ void qmp_block_set_io_throttle(const char *device, 
int64_t bps, int64_t bps_rd,
                                bool has_iops_rd_threshold,
                                int64_t iops_rd_threshold,
                                bool has_iops_wr_threshold,
-                               int64_t iops_wr_threshold, Error **errp)
+                               int64_t iops_wr_threshold,
+                               bool has_iops_sector_count,
+                               int64_t iops_sector_count, Error **errp)
 {
     BlockIOLimit io_limits;
     BlockDriverState *bs;
@@ -1283,6 +1294,7 @@ void qmp_block_set_io_throttle(const char *device, 
int64_t bps, int64_t bps_rd,
     io_limits.iops_threshold[BLOCK_IO_LIMIT_TOTAL] = iops / THROTTLE_HZ;
     io_limits.iops_threshold[BLOCK_IO_LIMIT_READ]  = iops_rd / THROTTLE_HZ;
     io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE] = iops_wr / THROTTLE_HZ;
+    io_limits.iops_sector_count = 0;
 
     /* override them with givens values if present */
     if (has_bps_threshold) {
@@ -1304,6 +1316,10 @@ void qmp_block_set_io_throttle(const char *device, 
int64_t bps, int64_t bps_rd,
         io_limits.iops_threshold[BLOCK_IO_LIMIT_WRITE] = iops_wr_threshold;
     }
 
+    if (has_iops_sector_count) {
+        io_limits.iops_sector_count = iops_sector_count;
+    }
+
     if (!do_check_io_limits(&io_limits, errp)) {
         return;
     }
@@ -2007,6 +2023,10 @@ QemuOptsList qemu_common_drive_opts = {
             .type = QEMU_OPT_NUMBER,
             .help = "write bytes threshold",
         },{
+            .name = "iops_sector_count",
+            .type = QEMU_OPT_NUMBER,
+            .help = "when limiting by iops max size of an I/O in sector",
+        },{
             .name = "copy-on-read",
             .type = QEMU_OPT_BOOL,
             .help = "copy read data from backing file into image file",
diff --git a/hmp.c b/hmp.c
index d75aa99..3912305 100644
--- a/hmp.c
+++ b/hmp.c
@@ -347,7 +347,8 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
                             " iops_wr=%" PRId64
                             " iops_threshold=%" PRId64
                             " iops_rd_threshold=%" PRId64
-                            " iops_wr_threshold=%" PRId64 "\n",
+                            " iops_wr_threshold=%" PRId64
+                            " iops_sector_count=%" PRId64 "\n",
                             info->value->inserted->bps,
                             info->value->inserted->bps_rd,
                             info->value->inserted->bps_wr,
@@ -359,7 +360,8 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
                             info->value->inserted->iops_wr,
                             info->value->inserted->iops_threshold,
                             info->value->inserted->iops_rd_threshold,
-                            info->value->inserted->iops_wr_threshold);
+                            info->value->inserted->iops_wr_threshold,
+                            info->value->inserted->iops_sector_count);
         } else {
             monitor_printf(mon, " [not inserted]");
         }
@@ -1120,6 +1122,8 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict 
*qdict)
                               false,
                               0,
                               false,
+                              0,
+                              false, /* No default I/O size */
                               0, &err);
     hmp_handle_error(mon, &err);
 }
diff --git a/include/block/block_int.h b/include/block/block_int.h
index e32ad1f..74d7503 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -76,6 +76,7 @@ typedef struct BlockIOLimit {
     int64_t iops[3];
     int64_t bps_threshold[3];
     int64_t iops_threshold[3];
+    int64_t iops_sector_count;
 } BlockIOLimit;
 
 typedef struct BlockIOBaseValue {
diff --git a/qapi-schema.json b/qapi-schema.json
index a6f3792..d579fda 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -781,6 +781,8 @@
 #
 # @iops_wr_threshold: #optional write I/O operations threshold (Since 1.6)
 #
+# @iops_sector_count: #optional an I/O size in sector (Since 1.6)
+#
 # Since: 0.14.0
 #
 # Notes: This interface is only found in @BlockInfo.
@@ -794,7 +796,8 @@
             'image': 'ImageInfo',
             '*bps_threshold': 'int', '*bps_rd_threshold': 'int',
             '*bps_wr_threshold': 'int', '*iops_threshold': 'int',
-            '*iops_rd_threshold': 'int', '*iops_wr_threshold': 'int' }}
+            '*iops_rd_threshold': 'int', '*iops_wr_threshold': 'int',
+            '*iops_sector_count': 'int' } }
 
 ##
 # @BlockDeviceIoStatus:
@@ -2185,6 +2188,8 @@
 #
 # @iops_wr_threshold: #optional write I/O operations threshold (Since 1.6)
 #
+# @iops_sector_count: #optional an I/O size in sector (Since 1.6)
+#
 # Returns: Nothing on success
 #          If @device is not a valid block device, DeviceNotFound
 #
@@ -2195,7 +2200,8 @@
             'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
             '*bps_threshold': 'int', '*bps_rd_threshold': 'int',
             '*bps_wr_threshold': 'int', '*iops_threshold': 'int',
-            '*iops_rd_threshold': 'int', '*iops_wr_threshold': 'int' }}
+            '*iops_rd_threshold': 'int', '*iops_wr_threshold': 'int',
+            '*iops_sector_count': 'int' }}
 
 ##
 # @block-stream:
diff --git a/qemu-options.hx b/qemu-options.hx
index 4d5ee66..2f417b8 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -409,7 +409,7 @@ DEF("drive", HAS_ARG, QEMU_OPTION_drive,
     "       
[,cache=writethrough|writeback|none|directsync|unsafe][,format=f]\n"
     "       [,serial=s][,addr=A][,id=name][,aio=threads|native]\n"
     "       [,readonly=on|off][,copy-on-read=on|off]\n"
-    "       
[[,bps=b]|[[,bps_rd=r][,bps_wr=w]]][[,iops=i]|[[,iops_rd=r][,iops_wr=w][,bps_threshold=bt]|[[,bps_rd_threshold=rt][,bps_wr_threshold=wt]]][[,iops_threshold=it]|[[,iops_rd_threshold=rt][,iops_wr_threshold=wt]]\n"
+    "       
[[,bps=b]|[[,bps_rd=r][,bps_wr=w]]][[,iops=i]|[[,iops_rd=r][,iops_wr=w][,bps_threshold=bt]|[[,bps_rd_threshold=rt][,bps_wr_threshold=wt]]][[,iops_threshold=it]|[[,iops_rd_threshold=rt][,iops_wr_threshold=wt][,iops_sector_count=cnt]]\n"
     "                use 'file' as a drive image\n", QEMU_ARCH_ALL)
 STEXI
 @item -drive @var{option}[,@var{option}[,@var{option}[,...]]]
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 11c638a..b40db2f 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1385,7 +1385,7 @@ EQMP
 
     {
         .name       = "block_set_io_throttle",
-        .args_type  = 
"device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l,bps_threshold:l?,bps_rd_threshold:l?,bps_wr_threshold:l?,iops_threshold:l?,iops_rd_threshold:l?,iops_wr_threshold:l?",
+        .args_type  = 
"device:B,bps:l,bps_rd:l,bps_wr:l,iops:l,iops_rd:l,iops_wr:l,bps_threshold:l?,bps_rd_threshold:l?,bps_wr_threshold:l?,iops_threshold:l?,iops_rd_threshold:l?,iops_wr_threshold:l?,iops_sector_count:l?",
         .mhandler.cmd_new = qmp_marshal_input_block_set_io_throttle,
     },
 
@@ -1410,6 +1410,7 @@ Arguments:
 - "iops_threshold":  total I/O operations threshold(json-int)
 - "iops_rd_threshold":  read I/O operations threshold(json-int)
 - "iops_wr_threshold":  write I/O operations threshold(json-int)
+- "iops_sector_count":  I/O sector count when limiting(json-int)
 
 Example:
 
@@ -1425,7 +1426,8 @@ Example:
                                                "bps_wr_threshold": "0",
                                                "iops_threshold": "0",
                                                "iops_rd_threshold": "0",
-                                               "iops_wr_threshold": "0" } }
+                                               "iops_wr_threshold": "0",
+                                               "iops_sector_count": "0" } }
 <- { "return": {} }
 
 EQMP
@@ -1772,6 +1774,7 @@ Each json-object contain the following:
          - "iops_threshold":  total I/O operations threshold(json-int)
          - "iops_rd_threshold":  read I/O operations threshold(json-int)
          - "iops_wr_threshold":  write I/O operations threshold(json-int)
+         - "iops_sector_count":  I/O sector count when limiting(json-int)
          - "image": the detail of the image, it is a json-object containing
             the following:
              - "filename": image file name (json-string)
@@ -1847,6 +1850,7 @@ Example:
                "iops_threshold": "0",
                "iops_rd_threshold": "0",
                "iops_wr_threshold": "0",
+               "iops_sector_count": "0",
                "image":{
                   "filename":"disks/test.qcow2",
                   "format":"qcow2",
-- 
1.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]