From patchwork Tue Apr 19 14:20:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liang Li X-Patchwork-Id: 8880891 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A85E29F1C1 for ; Tue, 19 Apr 2016 14:32:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B5C6A20279 for ; Tue, 19 Apr 2016 14:32:52 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 81EE72026F for ; Tue, 19 Apr 2016 14:32:51 +0000 (UTC) Received: from localhost ([::1]:59179 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asWhu-0006Po-T3 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Apr 2016 10:32:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asWfR-0001K4-Vr for qemu-devel@nongnu.org; Tue, 19 Apr 2016 10:30:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1asWfM-00035C-Lv for qemu-devel@nongnu.org; Tue, 19 Apr 2016 10:30:17 -0400 Received: from mga01.intel.com ([192.55.52.88]:37812) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asWfM-00034y-BI for qemu-devel@nongnu.org; Tue, 19 Apr 2016 10:30:12 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 19 Apr 2016 07:30:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,506,1455004800"; d="scan'208";a="961956155" Received: from ll.sh.intel.com (HELO localhost) ([10.239.13.27]) by fmsmga002.fm.intel.com with ESMTP; 19 Apr 2016 07:30:06 -0700 From: Liang Li To: mst@redhat.com, quintela@redhat.com, amit.shah@redhat.com, pbonzini@redhat.com, lcapitulino@redhat.com Date: Tue, 19 Apr 2016 22:20:43 +0800 Message-Id: <1461075643-3668-6-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461075643-3668-1-git-send-email-liang.z.li@intel.com> References: <1461075643-3668-1-git-send-email-liang.z.li@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.88 Subject: [Qemu-devel] [PATCH QEMU 5/5] migration: Add the interface for cache drop control X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, james.hogan@imgtec.com, ehabkost@redhat.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, Liang Li , armbru@redhat.com, agraf@suse.de, borntraeger@de.ibm.com, cornelia.huck@de.ibm.com, leon.alrae@imgtec.com, aurelien@aurel32.net, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 #