diff mbox

[QEMU,5/5] migration: Add the interface for cache drop control

Message ID 1461075643-3668-6-git-send-email-liang.z.li@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Liang Li April 19, 2016, 2:20 p.m. UTC
Whether drop the cache and drop what kind of cache depend on the
user, add the related qmp and hmp interface to query and set the
cache control value.

Signed-off-by: Liang Li <liang.z.li@intel.com>
---
 hmp.c                         |  8 ++++++++
 include/migration/migration.h |  1 +
 migration/migration.c         | 31 ++++++++++++++++++++++++++++++-
 migration/ram.c               | 10 ++--------
 qapi-schema.json              | 25 ++++++++++++++++++++++---
 5 files changed, 63 insertions(+), 12 deletions(-)

Comments

Eric Blake April 19, 2016, 2:52 p.m. UTC | #1
On 04/19/2016 08:20 AM, Liang Li wrote:
> Whether drop the cache and drop what kind of cache depend on the

Whether to drop the cache, and what kind of cache drop to perform,
depend ...

> user, add the related qmp and hmp interface to query and set the
> cache control value.
> 
> Signed-off-by: Liang Li <liang.z.li@intel.com>
> ---

> +++ b/qapi-schema.json
> @@ -612,11 +612,21 @@
>  # @x-cpu-throttle-increment: throttle percentage increase each time
>  #                            auto-converge detects that migration is not making
>  #                            progress. The default value is 10. (Since 2.5)
> +# @x-drop-cache: drop guest's page cache during live migration, the value can
> +#         be set to 0, 1, 2, 3. 1 means drop the clean page cache, 2 means
> +#         drop the slab cache, 3 means to drop both clean page cache, 0 means
> +#         do not drop any cache. Drop cache can speed up live migration
> +#         process and reduce the network traffic, the side affect is the
> +#         performance impact to the guest, 1 is the recommended value for
> +#         proper balance between speed and performance. The value only takes
> +#         affect when the virtio-balloon device are enabled and the guest
> +#         has the related driver. The default value is 0. (Since 2.7)

Absolutely not this interface.  Make this an enum type, not a raw
magic-number integer type, where the user requests
"x-drop-cache":"clean", "x-drop-cache":"slab", and so on.
Liang Li April 19, 2016, 2:59 p.m. UTC | #2
PiBTZW50OiBUdWVzZGF5LCBBcHJpbCAxOSwgMjAxNiAxMDo1MiBQTQ0KPiBUbzogTGksIExpYW5n
IFo7I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ICsjICAgICAgICAgcGVyZm9y
bWFuY2UgaW1wYWN0IHRvIHRoZSBndWVzdCwgMSBpcyB0aGUgcmVjb21tZW5kZWQgdmFsdWUgZm9y
DQo+ID4gKyMgICAgICAgICBwcm9wZXIgYmFsYW5jZSBiZXR3ZWVuIHNwZWVkIGFuZCBwZXJmb3Jt
YW5jZS4gVGhlIHZhbHVlIG9ubHkNCj4gdGFrZXMNCj4gPiArIyAgICAgICAgIGFmZmVjdCB3aGVu
IHRoZSB2aXJ0aW8tYmFsbG9vbiBkZXZpY2UgYXJlIGVuYWJsZWQgYW5kIHRoZSBndWVzdA0KPiA+
ICsjICAgICAgICAgaGFzIHRoZSByZWxhdGVkIGRyaXZlci4gVGhlIGRlZmF1bHQgdmFsdWUgaXMg
MC4gKFNpbmNlIDIuNykNCj4gDQo+IEFic29sdXRlbHkgbm90IHRoaXMgaW50ZXJmYWNlLiAgTWFr
ZSB0aGlzIGFuIGVudW0gdHlwZSwgbm90IGEgcmF3IG1hZ2ljLQ0KPiBudW1iZXIgaW50ZWdlciB0
eXBlLCB3aGVyZSB0aGUgdXNlciByZXF1ZXN0cyAieC1kcm9wLWNhY2hlIjoiY2xlYW4iLCAieC0N
Cj4gZHJvcC1jYWNoZSI6InNsYWIiLCBhbmQgc28gb24uDQo+IA0KDQpUaGUgZW51bSB0eXBlIGxv
b2tzIGJldHRlciwgdGhhbmtzIQ0KDQpMaWFuZw0KPiAtLQ0KPiBFcmljIEJsYWtlICAgZWJsYWtl
IHJlZGhhdCBjb20gICAgKzEtOTE5LTMwMS0zMjY2DQo+IExpYnZpcnQgdmlydHVhbGl6YXRpb24g
bGlicmFyeSBodHRwOi8vbGlidmlydC5vcmcNCg0K
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/hmp.c b/hmp.c
index d510236..17f418e 100644
--- a/hmp.c
+++ b/hmp.c
@@ -286,6 +286,9 @@  void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, " %s: %" PRId64,
             MigrationParameter_lookup[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT],
             params->x_cpu_throttle_increment);
+        monitor_printf(mon, " %s: %" PRId64,
+            MigrationParameter_lookup[MIGRATION_PARAMETER_X_DROP_CACHE],
+            params->x_drop_cache);
         monitor_printf(mon, "\n");
     }
 
@@ -1242,6 +1245,7 @@  void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     bool has_decompress_threads = false;
     bool has_x_cpu_throttle_initial = false;
     bool has_x_cpu_throttle_increment = false;
+    bool has_x_drop_cache = false;
     int i;
 
     for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
@@ -1262,12 +1266,16 @@  void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
             case MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT:
                 has_x_cpu_throttle_increment = true;
                 break;
+            case MIGRATION_PARAMETER_X_DROP_CACHE:
+                has_x_drop_cache = true;
+                break;
             }
             qmp_migrate_set_parameters(has_compress_level, value,
                                        has_compress_threads, value,
                                        has_decompress_threads, value,
                                        has_x_cpu_throttle_initial, value,
                                        has_x_cpu_throttle_increment, value,
+                                       has_x_drop_cache, value,
                                        &err);
             break;
         }
diff --git a/include/migration/migration.h b/include/migration/migration.h
index ac2c12c..873e3bc 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -283,6 +283,7 @@  bool migrate_use_compression(void);
 int migrate_compress_level(void);
 int migrate_compress_threads(void);
 int migrate_decompress_threads(void);
+int migrate_drop_cache(void);
 bool migrate_use_events(void);
 
 /* Sending on the return path - generic and then for each message type */
diff --git a/migration/migration.c b/migration/migration.c
index 991313a..ecd07b8 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -52,6 +52,13 @@ 
 /* Define default autoconverge cpu throttle migration parameters */
 #define DEFAULT_MIGRATE_X_CPU_THROTTLE_INITIAL 20
 #define DEFAULT_MIGRATE_X_CPU_THROTTLE_INCREMENT 10
+/* Default cache drop control
+ * 0: no drop
+ * 1: drop clean page cache
+ * 2: drop slab cache
+ * 3: drop both clean and slab cache
+ */
+#define DEFAULT_MIGRATE_X_DROP_CACHE 0
 
 /* Migration XBZRLE default cache size */
 #define DEFAULT_MIGRATE_CACHE_SIZE (64 * 1024 * 1024)
@@ -91,6 +98,8 @@  MigrationState *migrate_get_current(void)
                 DEFAULT_MIGRATE_X_CPU_THROTTLE_INITIAL,
         .parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT] =
                 DEFAULT_MIGRATE_X_CPU_THROTTLE_INCREMENT,
+        .parameters[MIGRATION_PARAMETER_X_DROP_CACHE] =
+                DEFAULT_MIGRATE_X_DROP_CACHE,
     };
 
     if (!once) {
@@ -525,6 +534,7 @@  MigrationParameters *qmp_query_migrate_parameters(Error **errp)
             s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INITIAL];
     params->x_cpu_throttle_increment =
             s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT];
+    params->x_drop_cache = s->parameters[MIGRATION_PARAMETER_X_DROP_CACHE];
 
     return params;
 }
@@ -721,7 +731,9 @@  void qmp_migrate_set_parameters(bool has_compress_level,
                                 bool has_x_cpu_throttle_initial,
                                 int64_t x_cpu_throttle_initial,
                                 bool has_x_cpu_throttle_increment,
-                                int64_t x_cpu_throttle_increment, Error **errp)
+                                int64_t x_cpu_throttle_increment,
+                                bool has_x_drop_cache,
+                                int64_t x_drop_cache, Error **errp)
 {
     MigrationState *s = migrate_get_current();
 
@@ -756,6 +768,11 @@  void qmp_migrate_set_parameters(bool has_compress_level,
                    "x_cpu_throttle_increment",
                    "an integer in the range of 1 to 99");
     }
+    if (has_x_drop_cache && (x_drop_cache < 0 || x_drop_cache > 3)) {
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+                   "x_drop_cache",
+                   "an integer in the range of 0 to 3");
+    }
 
     if (has_compress_level) {
         s->parameters[MIGRATION_PARAMETER_COMPRESS_LEVEL] = compress_level;
@@ -776,6 +793,9 @@  void qmp_migrate_set_parameters(bool has_compress_level,
         s->parameters[MIGRATION_PARAMETER_X_CPU_THROTTLE_INCREMENT] =
                                                     x_cpu_throttle_increment;
     }
+    if (has_x_drop_cache) {
+        s->parameters[MIGRATION_PARAMETER_X_DROP_CACHE] = x_drop_cache;
+    }
 }
 
 void qmp_migrate_start_postcopy(Error **errp)
@@ -1182,6 +1202,15 @@  int migrate_decompress_threads(void)
     return s->parameters[MIGRATION_PARAMETER_DECOMPRESS_THREADS];
 }
 
+int migrate_drop_cache(void)
+{
+    MigrationState *s;
+
+    s = migrate_get_current();
+
+    return s->parameters[MIGRATION_PARAMETER_X_DROP_CACHE];
+}
+
 bool migrate_use_events(void)
 {
     MigrationState *s;
diff --git a/migration/ram.c b/migration/ram.c
index 3944426..0d5fc97 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -229,7 +229,6 @@  static uint64_t migration_dirty_pages;
 static uint32_t last_version;
 static bool ram_bulk_stage;
 static bool ignore_freepage_rsp;
-static bool drop_page_cache;
 
 /* used by the search for pages to send */
 struct PageSearchStatus {
@@ -1520,12 +1519,7 @@  static void ram_request_free_page(unsigned long *bmap, unsigned long max_pfn)
 {
     FreePageStatus status;
 
-    /* drop_page_cache should be set by user, the related code will be
-     * added later, set it to ture temporarily.
-     */
-    drop_page_cache = true;
-
-    status = balloon_get_free_pages(bmap, max_pfn, drop_page_cache);
+    status = balloon_get_free_pages(bmap, max_pfn, migrate_drop_cache());
     switch (status) {
     case FREE_PAGE_REQ:
         ignore_freepage_rsp = false;
@@ -1546,7 +1540,7 @@  static void ram_handle_free_page(void)
     FreePageStatus status;
 
     status = balloon_get_free_pages(migration_bitmap_rcu->free_page_bmap,
-                                    get_guest_max_pfn(), drop_page_cache);
+                                    get_guest_max_pfn(), migrate_drop_cache());
     switch (status) {
     case FREE_PAGE_READY:
         rcu_read_lock();
diff --git a/qapi-schema.json b/qapi-schema.json
index 54634c4..8674d35 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -612,11 +612,21 @@ 
 # @x-cpu-throttle-increment: throttle percentage increase each time
 #                            auto-converge detects that migration is not making
 #                            progress. The default value is 10. (Since 2.5)
+# @x-drop-cache: drop guest's page cache during live migration, the value can
+#         be set to 0, 1, 2, 3. 1 means drop the clean page cache, 2 means
+#         drop the slab cache, 3 means to drop both clean page cache, 0 means
+#         do not drop any cache. Drop cache can speed up live migration
+#         process and reduce the network traffic, the side affect is the
+#         performance impact to the guest, 1 is the recommended value for
+#         proper balance between speed and performance. The value only takes
+#         affect when the virtio-balloon device are enabled and the guest
+#         has the related driver. The default value is 0. (Since 2.7)
 # Since: 2.4
 ##
 { 'enum': 'MigrationParameter',
   'data': ['compress-level', 'compress-threads', 'decompress-threads',
-           'x-cpu-throttle-initial', 'x-cpu-throttle-increment'] }
+           'x-cpu-throttle-initial', 'x-cpu-throttle-increment',
+           'x-drop-cache'] }
 
 #
 # @migrate-set-parameters
@@ -636,6 +646,10 @@ 
 # @x-cpu-throttle-increment: throttle percentage increase each time
 #                            auto-converge detects that migration is not making
 #                            progress. The default value is 10. (Since 2.5)
+#
+# @x-drop-cache: guest cache drop control, determine what kind of guest cache
+#       to drop during live migration. The default value is 0. (Since 2.7)
+#
 # Since: 2.4
 ##
 { 'command': 'migrate-set-parameters',
@@ -643,7 +657,8 @@ 
             '*compress-threads': 'int',
             '*decompress-threads': 'int',
             '*x-cpu-throttle-initial': 'int',
-            '*x-cpu-throttle-increment': 'int'} }
+            '*x-cpu-throttle-increment': 'int',
+            '*x-drop-cache': 'int'} }
 
 #
 # @MigrationParameters
@@ -662,6 +677,9 @@ 
 #                            auto-converge detects that migration is not making
 #                            progress. The default value is 10. (Since 2.5)
 #
+# @x-drop-cache: guest cache drop control, determine what kind of guest cache
+#       to drop during live migration. The default value is 0. (Since 2.7)
+#
 # Since: 2.4
 ##
 { 'struct': 'MigrationParameters',
@@ -669,7 +687,8 @@ 
             'compress-threads': 'int',
             'decompress-threads': 'int',
             'x-cpu-throttle-initial': 'int',
-            'x-cpu-throttle-increment': 'int'} }
+            'x-cpu-throttle-increment': 'int',
+            'x-drop-cache': 'int'} }
 ##
 # @query-migrate-parameters
 #