qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH QEMU 5/5] migration: Add the interface for cache dro


From: Liang Li
Subject: [Qemu-devel] [PATCH QEMU 5/5] migration: Add the interface for cache drop control
Date: Tue, 19 Apr 2016 22:20:43 +0800

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 <address@hidden>
---
 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(-)

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
 #
-- 
1.8.3.1




reply via email to

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