From patchwork Mon Jan 16 15:51:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9519029 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E9C3B60209 for ; Mon, 16 Jan 2017 16:06:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D807F28339 for ; Mon, 16 Jan 2017 16:06:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCE6428387; Mon, 16 Jan 2017 16:06:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 15A9A28339 for ; Mon, 16 Jan 2017 16:06:28 +0000 (UTC) Received: from localhost ([::1]:57937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cT9nf-0001DC-F6 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 16 Jan 2017 11:06:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cT9nE-0001C7-NA for qemu-devel@nongnu.org; Mon, 16 Jan 2017 11:06:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cT9n9-0007Mu-3t for qemu-devel@nongnu.org; Mon, 16 Jan 2017 11:06:00 -0500 Received: from mail-db5eur01on0096.outbound.protection.outlook.com ([104.47.2.96]:19763 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cT9n8-0007M6-9Z for qemu-devel@nongnu.org; Mon, 16 Jan 2017 11:05:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=xKq0BuWDzYbq4//eVQYlbD0YCWt0/kaa8pfr4GQr07s=; b=Lz1CQL7cMKpr+sn197D9ajNOnJ49C7tsLx58MpnUGIwC+u8NCkyMnyGz+/AyYFc+bAR7VjoipH9B0uBa6wrIwq7gSzDAvuh6OdE5zpV8DBuxMe4xI/b2kwM1gbd3C6mq03tLOiyB1PDrI4xSIpHb4mvJSFyejSqT3nDQySGwWq8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pbutsykin@virtuozzo.com; Received: from pavelb-Z68P-DS3.sw.ru (195.214.232.6) by VI1PR0802MB2557.eurprd08.prod.outlook.com (10.172.255.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.845.12; Mon, 16 Jan 2017 15:51:36 +0000 From: Pavel Butsykin To: Date: Mon, 16 Jan 2017 18:51:13 +0300 Message-ID: <20170116155113.21034-3-pbutsykin@virtuozzo.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170116155113.21034-1-pbutsykin@virtuozzo.com> References: <20170116155113.21034-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: VI1PR0501CA0012.eurprd05.prod.outlook.com (10.172.9.150) To VI1PR0802MB2557.eurprd08.prod.outlook.com (10.172.255.135) X-MS-Office365-Filtering-Correlation-Id: 200b49a5-6e6c-4f47-771b-08d43e278dc1 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:VI1PR0802MB2557; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0802MB2557; 3:JFCM5RNWy0rfe+IW76y3AE4OcZ9O0hlNcmmjCYV0yBppKf6ssY9Joho7KneTMG0kAE2nDtKBKfqOQ2Ha3F1NmFwpZn5/0mpS3/RiocnCnPo+YJ/AoeUo6KCut8Fh1oXUJ08Izyz9mHvlW0+fLmRzLdLeJe4mZGkMQveNksNekgptXcRkRo/Qhw/3NZrM4DheBMeF9ZBULzSfnYYwi2RKv1CjJnBiwJcmg0baterkj+ahI3bfjkqqpxrOY4x6gJIicuqglrLLwljJuD1RnWw0vg== X-Microsoft-Exchange-Diagnostics: 1; VI1PR0802MB2557; 25:xzaH9P/YnaHqnd0d9TLiqjKv7EXcJbGAAL1dUw8578eI2OWVlAq0T1ZTesRyCMViDfnlwHrAXbrAoYdVuO+vhf8b8QxOpiFmrgf0pkrxXXBpC7aStqiKbmAPFzcmrqrXSzo/5jwceRQndMLg7zsED50s1ifwlAv+FwxQxnlfTNg0JWzK+UGynQjLRvxz3S3KhEsm5A9IFfkpcNLu+k6sWfI8mF0ObQwe09WrT1LFZ3gVRPrvwakUk40sNI8VxiGRL3UUT9WWfuTt3yAoweSHGS3LwZbZ/agkWNE47yV8Erxjw6EJ7SpgRbRKGgmDRHyvne/TQTstLZSOoxVyBOW7Vl+WyDw9W82aTlSietCbSlZl06wlRRSQQ91p4co09Wkuu5HDbFZw5Eb3oVNGZKAvoNwPmNAVyqkhmOvnCQ5+ZIXqPdeoRr/lIQjh/PcCAe+ybGPWo/dWve2z8uIRwtu08H4AAHxma+7MWCYghwHw37UZtPrRwTTS313qGycbhqHpcRG3tjJKZv204N50OLCw6eTHD/u/Qsz1IE7Jtk+1UstZCWUa3yGYsK4WR4YRi2RI2ZLJnYZn/9kka948tCozbt+utqktwifhaPGTKv9+y6nfBMW0JbGdETGp9oCCL71XakGZW7quVGTrmgBxuchi5hv9kYLbIsb6fLpk8/KaM/ObrS5LV/8U5CJXm8RbRvN+oCMX1pLn/xotbEwTvblT9ARB6VgFoQ2aL+mHozMMSNvX42SL4nnVWSj9pV5w4JSx X-Microsoft-Exchange-Diagnostics: 1; VI1PR0802MB2557; 31:yhvS8+927ODdwMc9LH1+FjByy5mmsqjOzyACLpJ+FSCb/AEAVocjJXgPllvghQUYSSO82QBXicLcRZQsPSgTCr+Np09v6PQAvHuym4Puuy2bOqW3VQE6SvX98xigyqbWTGbFuYmu8pmYglWN2Unz7giYNR9rPMhcsFOB4glBYeOLNdZa5MnXKQaFppjxrTD0J008DcKARaVtL8knNKu97+UXTBzkLrtVZp+GEP5SnWDc9HTBINDiC03iXpKt3z4fHnFk22JazPKwyU9Co5rfoA==; 20:NSmUhow42vf8U0nNz62hf9tnycv0XNEGIvuCXWcqCaGeDf0kRelsRAdXtRJHCnzTXqbSTcYwpG8kDJg4NotCCR8fxRZnYzvIIrRrknR8/o+t5FMoLSIosAO8fQrA7k8YfuSmmVIEp1dDGla73mN6+AarteGfcT7I5ogqXNOTfKAEgZ6mvUYcITu4KZ7c+03SOIFjf80CZPRG6TUde+veNcRGd4CetQUp6Ac8a4fNN1+TjNpk6hjNw9S0Zr+oy38w X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041248)(20161123560025)(20161123558021)(20161123555025)(20161123562025)(20161123564025)(6072148); SRVR:VI1PR0802MB2557; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0802MB2557; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0802MB2557; 4:MgkQTlHr/lo4JCpvfjrlMPEAytBnghrEZY4PQE2SW8hCGRcju/jLT2lhnSv8TpXFhnixgQdBxeG9ty/V3ccY/XPuA+x/78NWBCuLmIWPLUtNbYlWM9tgOjiqFn7sct8SSGMA7Zov5xWMtNtVg3yyK57z8cr6dP4Ak0PSrrkvzGW6w570zcwMPmPyd1I8XC+pnW93WRZyVdhwp6TgbN7Ml/vWX6iyPSJoRkhDD7aG+rgQ7uCRC5hiWEK2Oehy4zvGuDMFP5rq/hmyxwRqYo/ooGhq3dXvRUuZBLHvx1hPtsEn6uHGgycGFB7bdKTUXgOBwdYuqkEnwom6pWVMgxAo9iZOMkPt8mmFC/z3M/OxfWXOvWYi6ZHAKmSoh/j7Q0bFMeYYI/Gnm2kownWiUMqbZRRAFaSBoD+MsZY2umSqpWS3pUsryWZxzamJUecETwH3chKKQi+Dmb/ktMuqinOzaP4nu1nWj7A2OZe2jBe9dxvjfLv5Tb2az3k4zaRkbPxAhNhvSq08SqsAc7r++HLGk/wlRCAC3bPatearekEAzIWsXozcCd+Z2vvqNm3XForXmNbNcanfoApq8YD+AJmjfETmY4eNO2urg4bEKm7ZRLc= X-Forefront-PRVS: 01894AD3B8 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(39450400003)(39830400002)(39410400002)(189002)(199003)(50226002)(5003940100001)(36756003)(54906002)(305945005)(8676002)(6506006)(105586002)(81156014)(81166006)(42186005)(2351001)(7736002)(53416004)(48376002)(97736004)(27001)(6916009)(2950100002)(110136003)(4001430100002)(92566002)(47776003)(69596002)(1076002)(68736007)(6116002)(3846002)(107886002)(4326007)(2906002)(101416001)(189998001)(5660300001)(33646002)(6486002)(106356001)(66066001)(6512007)(6666003)(50466002)(86362001)(575784001)(50986999)(76176999)(25786008)(38730400001)(14143004); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0802MB2557; H:pavelb-Z68P-DS3.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0802MB2557; 23:a2L9lOxuHVqRua13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AXC51wws0FZuJShKM7UgtVu7pRDtg2k6r8Annzll/hf2FEzaJbbMl6Y4YDT60pPTzdyO55ezEH7bgDVLQTlCKMzQFQpAyl5iceCTg==; 24:pNzQ6nfWb5gqtWQsOxUS52g8Z/s/dtWPmtluCvTJNpULhutOb/C4ZtfFPSEbb/b7iVYsKZNOb8vIf0noyN+j/cPoOXM8o3ARg7UXjDTsUqE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0802MB2557; 7:ejuwkFjfDANVoBM7FHYtOamgaPMcORVHhlwezVxA/GISfwBg3EeI+c7fuGQ+wPM3uxJiSdjBuoZTbquBrCKlBbb39APhMRNV9V0nEu0mXUzXzGnNDFw8RwV0DPHfarr82ORZjNBx4WbjS9h3AyFgJWgKlNT7MuF2aYHkwkkdbeepyfNLT2VF0vNzn1KB7WlL6xN0R/aEZF/LSxqo/llylFvlftkYyUj7A4FarDa1H/9BzGbjxee6g9iLh6kC+PSquWwvA3ADkG1CrY8jU4QkZc7O0lYeUlM3Cjwc5CQHw71SyKA/SPtwv3pRuK+XAi+8ScOHzZxHsBYSBYg0RjAvUBaoMVRAvzL5DuiGbxUlGb83qE7M/K4zrBZ3e+r1vmFoD9WT0H3+caYeuWuRd7433ykXdZViPezahXLiipV4ZqmvBmiESVYNXOspg236a9rb4Jn0uk7bXzf8qoADXeso0Q==; 20:Vj+q52EFa9CJKD+qFNk910/iSdz/pf+eVh9TrigFtHggCj1IUqpo6XACl8orQTcmkK1rOPepKLHqqRzvh4p7LVvxqQb+wEZNVQWGNbWQFy6zRi5KepACx1wXcGivHZn4mVIOwcdZTPXrc4pLkrjK1PDiE4f571yxqyg8niDF33U= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2017 15:51:36.3911 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2557 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.96 Subject: [Qemu-devel] [PATCH 2/2] migration: discard non-dirty ram pages after the start of postcopy 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: pbutsykin@virtuozzo.com, quintela@redhat.com, armbru@redhat.com, amit.shah@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP After the start of postcopy migration there are some non-dirty pages which have already been migrated. These pages are no longer needed on the source vm so that we can free them and it doen't hurt to complete the migration. Signed-off-by: Pavel Butsykin --- include/migration/migration.h | 1 + migration/migration.c | 2 ++ migration/ram.c | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/include/migration/migration.h b/include/migration/migration.h index d7bd404365..0d9b81545c 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -279,6 +279,7 @@ int ram_postcopy_send_discard_bitmap(MigrationState *ms); int ram_discard_range(MigrationIncomingState *mis, const char *block_name, uint64_t start, size_t length); int ram_postcopy_incoming_init(MigrationIncomingState *mis); +void ram_postcopy_migrated_memory_discard(MigrationState *ms); /** * @migrate_add_blocker - prevent migration from proceeding diff --git a/migration/migration.c b/migration/migration.c index 391db6f28b..20490ed020 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1662,6 +1662,8 @@ static int postcopy_start(MigrationState *ms, bool *old_vm_running) */ qemu_savevm_send_ping(ms->to_dst_file, 4); + ram_postcopy_migrated_memory_discard(ms); + ret = qemu_file_get_error(ms->to_dst_file); if (ret) { error_report("postcopy_start: Migration stream errored"); diff --git a/migration/ram.c b/migration/ram.c index b0322a0b5c..8a6b614b0d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1546,6 +1546,31 @@ void ram_debug_dump_bitmap(unsigned long *todump, bool expected) /* **** functions for postcopy ***** */ +void ram_postcopy_migrated_memory_discard(MigrationState *ms) +{ + struct RAMBlock *block; + unsigned long *bitmap = atomic_rcu_read(&migration_bitmap_rcu)->bmap; + + QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { + unsigned long first = block->offset >> TARGET_PAGE_BITS; + unsigned long range = first + (block->used_length >> TARGET_PAGE_BITS); + unsigned long run_start = find_next_zero_bit(bitmap, range, first); + + while (run_start < range) { + unsigned long run_end = find_next_bit(bitmap, range, run_start + 1); + uint8_t *addr = block->host + (run_start << TARGET_PAGE_BITS); + size_t chunk_size = (run_end - run_start) << TARGET_PAGE_BITS; + + if (qemu_madvise(addr, chunk_size, QEMU_MADV_DONTNEED) < 0) { + error_report("migrate: madvise DONTNEED failed %p %ld: %s", + addr, chunk_size, strerror(errno)); + } + + run_start = find_next_zero_bit(bitmap, range, run_end + 1); + } + } +} + /* * Callback from postcopy_each_ram_send_discard for each RAMBlock * Note: At this point the 'unsentmap' is the processed bitmap combined