修訂 | 476ebf77fe8909ded10046edf26685bc28438162 (tree) |
---|---|
時間 | 2022-01-28 23:38:23 |
作者 | Peter Xu <peterx@redh...> |
Commiter | Juan Quintela |
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>
@@ -523,6 +523,19 @@ int postcopy_ram_incoming_init(MigrationIncomingState *mis) | ||
523 | 523 | return 0; |
524 | 524 | } |
525 | 525 | |
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 | + | |
526 | 539 | /* |
527 | 540 | * At the end of a migration where postcopy_ram_incoming_init was called. |
528 | 541 | */ |
@@ -564,14 +577,8 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis) | ||
564 | 577 | } |
565 | 578 | } |
566 | 579 | |
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 | + | |
575 | 582 | trace_postcopy_ram_incoming_cleanup_blocktime( |
576 | 583 | get_postcopy_total_blocktime()); |
577 | 584 |
@@ -1082,6 +1089,40 @@ retry: | ||
1082 | 1089 | return NULL; |
1083 | 1090 | } |
1084 | 1091 | |
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 | + | |
1085 | 1126 | int postcopy_ram_incoming_setup(MigrationIncomingState *mis) |
1086 | 1127 | { |
1087 | 1128 | /* Open the fd for the kernel to give us userfaults */ |
@@ -1122,32 +1163,11 @@ int postcopy_ram_incoming_setup(MigrationIncomingState *mis) | ||
1122 | 1163 | return -1; |
1123 | 1164 | } |
1124 | 1165 | |
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 */ | |
1132 | 1168 | return -1; |
1133 | 1169 | } |
1134 | 1170 | |
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 | - | |
1151 | 1171 | trace_postcopy_ram_enable_notify(); |
1152 | 1172 | |
1153 | 1173 | return 0; |