• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修订版476ebf77fe8909ded10046edf26685bc28438162 (tree)
时间2022-01-28 23:38:23
作者Peter Xu <peterx@redh...>
CommiterJuan Quintela

Log Message

migration: Move temp page setup and cleanup into separate functions

Temp pages will need to grow if we want to have multiple channels for postcopy,
because each channel will need its own temp page to cache huge page data.

Before doing that, cleanup the related code. No functional change intended.

Since at it, touch up the errno handling a little bit on the setup side.

Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>

更改概述

差异

--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -523,6 +523,19 @@ int postcopy_ram_incoming_init(MigrationIncomingState *mis)
523523 return 0;
524524 }
525525
526+static void postcopy_temp_pages_cleanup(MigrationIncomingState *mis)
527+{
528+ if (mis->postcopy_tmp_page) {
529+ munmap(mis->postcopy_tmp_page, mis->largest_page_size);
530+ mis->postcopy_tmp_page = NULL;
531+ }
532+
533+ if (mis->postcopy_tmp_zero_page) {
534+ munmap(mis->postcopy_tmp_zero_page, mis->largest_page_size);
535+ mis->postcopy_tmp_zero_page = NULL;
536+ }
537+}
538+
526539 /*
527540 * At the end of a migration where postcopy_ram_incoming_init was called.
528541 */
@@ -564,14 +577,8 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis)
564577 }
565578 }
566579
567- if (mis->postcopy_tmp_page) {
568- munmap(mis->postcopy_tmp_page, mis->largest_page_size);
569- mis->postcopy_tmp_page = NULL;
570- }
571- if (mis->postcopy_tmp_zero_page) {
572- munmap(mis->postcopy_tmp_zero_page, mis->largest_page_size);
573- mis->postcopy_tmp_zero_page = NULL;
574- }
580+ postcopy_temp_pages_cleanup(mis);
581+
575582 trace_postcopy_ram_incoming_cleanup_blocktime(
576583 get_postcopy_total_blocktime());
577584
@@ -1082,6 +1089,40 @@ retry:
10821089 return NULL;
10831090 }
10841091
1092+static int postcopy_temp_pages_setup(MigrationIncomingState *mis)
1093+{
1094+ int err;
1095+
1096+ mis->postcopy_tmp_page = mmap(NULL, mis->largest_page_size,
1097+ PROT_READ | PROT_WRITE,
1098+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
1099+ if (mis->postcopy_tmp_page == MAP_FAILED) {
1100+ err = errno;
1101+ mis->postcopy_tmp_page = NULL;
1102+ error_report("%s: Failed to map postcopy_tmp_page %s",
1103+ __func__, strerror(err));
1104+ return -err;
1105+ }
1106+
1107+ /*
1108+ * Map large zero page when kernel can't use UFFDIO_ZEROPAGE for hugepages
1109+ */
1110+ mis->postcopy_tmp_zero_page = mmap(NULL, mis->largest_page_size,
1111+ PROT_READ | PROT_WRITE,
1112+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
1113+ if (mis->postcopy_tmp_zero_page == MAP_FAILED) {
1114+ err = errno;
1115+ mis->postcopy_tmp_zero_page = NULL;
1116+ error_report("%s: Failed to map large zero page %s",
1117+ __func__, strerror(err));
1118+ return -err;
1119+ }
1120+
1121+ memset(mis->postcopy_tmp_zero_page, '\0', mis->largest_page_size);
1122+
1123+ return 0;
1124+}
1125+
10851126 int postcopy_ram_incoming_setup(MigrationIncomingState *mis)
10861127 {
10871128 /* Open the fd for the kernel to give us userfaults */
@@ -1122,32 +1163,11 @@ int postcopy_ram_incoming_setup(MigrationIncomingState *mis)
11221163 return -1;
11231164 }
11241165
1125- mis->postcopy_tmp_page = mmap(NULL, mis->largest_page_size,
1126- PROT_READ | PROT_WRITE, MAP_PRIVATE |
1127- MAP_ANONYMOUS, -1, 0);
1128- if (mis->postcopy_tmp_page == MAP_FAILED) {
1129- mis->postcopy_tmp_page = NULL;
1130- error_report("%s: Failed to map postcopy_tmp_page %s",
1131- __func__, strerror(errno));
1166+ if (postcopy_temp_pages_setup(mis)) {
1167+ /* Error dumped in the sub-function */
11321168 return -1;
11331169 }
11341170
1135- /*
1136- * Map large zero page when kernel can't use UFFDIO_ZEROPAGE for hugepages
1137- */
1138- mis->postcopy_tmp_zero_page = mmap(NULL, mis->largest_page_size,
1139- PROT_READ | PROT_WRITE,
1140- MAP_PRIVATE | MAP_ANONYMOUS,
1141- -1, 0);
1142- if (mis->postcopy_tmp_zero_page == MAP_FAILED) {
1143- int e = errno;
1144- mis->postcopy_tmp_zero_page = NULL;
1145- error_report("%s: Failed to map large zero page %s",
1146- __func__, strerror(e));
1147- return -e;
1148- }
1149- memset(mis->postcopy_tmp_zero_page, '\0', mis->largest_page_size);
1150-
11511171 trace_postcopy_ram_enable_notify();
11521172
11531173 return 0;