Skip to content

Commit b43b61d

Browse files
author
Fabiano Rosas
committed
migration: Add direct-io parameter
Add the direct-io migration parameter that tells the migration code to use O_DIRECT when opening the migration stream file whenever possible. This is currently only used with the mapped-ram migration that has a clear window guaranteed to perform aligned writes. Acked-by: Markus Armbruster <[email protected]> Reviewed-by: Peter Xu <[email protected]> Signed-off-by: Fabiano Rosas <[email protected]>
1 parent 46cec74 commit b43b61d

File tree

6 files changed

+76
-3
lines changed

6 files changed

+76
-3
lines changed

include/qemu/osdep.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,8 @@ int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive);
612612
bool qemu_has_ofd_lock(void);
613613
#endif
614614

615+
bool qemu_has_direct_io(void);
616+
615617
#if defined(__HAIKU__) && defined(__i386__)
616618
#define FMT_pid "%ld"
617619
#elif defined(WIN64)

migration/migration-hmp-cmds.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,13 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
351351
monitor_printf(mon, "%s: %s\n",
352352
MigrationParameter_str(MIGRATION_PARAMETER_MODE),
353353
qapi_enum_lookup(&MigMode_lookup, params->mode));
354+
355+
if (params->has_direct_io) {
356+
monitor_printf(mon, "%s: %s\n",
357+
MigrationParameter_str(
358+
MIGRATION_PARAMETER_DIRECT_IO),
359+
params->direct_io ? "on" : "off");
360+
}
354361
}
355362

356363
qapi_free_MigrationParameters(params);
@@ -624,6 +631,10 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
624631
p->has_mode = true;
625632
visit_type_MigMode(v, param, &p->mode, &err);
626633
break;
634+
case MIGRATION_PARAMETER_DIRECT_IO:
635+
p->has_direct_io = true;
636+
visit_type_bool(v, param, &p->direct_io, &err);
637+
break;
627638
default:
628639
assert(0);
629640
}

migration/options.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,25 @@ bool migrate_cpu_throttle_tailslow(void)
702702
return s->parameters.cpu_throttle_tailslow;
703703
}
704704

705+
bool migrate_direct_io(void)
706+
{
707+
MigrationState *s = migrate_get_current();
708+
709+
/*
710+
* O_DIRECT is only supported with mapped-ram and multifd.
711+
*
712+
* mapped-ram is needed because filesystems impose restrictions on
713+
* O_DIRECT IO alignment (see MAPPED_RAM_FILE_OFFSET_ALIGNMENT).
714+
*
715+
* multifd is needed to keep the unaligned portion of the stream
716+
* isolated to the main migration thread while multifd channels
717+
* process the aligned data with O_DIRECT enabled.
718+
*/
719+
return s->parameters.direct_io &&
720+
s->capabilities[MIGRATION_CAPABILITY_MAPPED_RAM] &&
721+
s->capabilities[MIGRATION_CAPABILITY_MULTIFD];
722+
}
723+
705724
uint64_t migrate_downtime_limit(void)
706725
{
707726
MigrationState *s = migrate_get_current();
@@ -905,6 +924,8 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
905924
params->mode = s->parameters.mode;
906925
params->has_zero_page_detection = true;
907926
params->zero_page_detection = s->parameters.zero_page_detection;
927+
params->has_direct_io = true;
928+
params->direct_io = s->parameters.direct_io;
908929

909930
return params;
910931
}
@@ -937,6 +958,7 @@ void migrate_params_init(MigrationParameters *params)
937958
params->has_vcpu_dirty_limit = true;
938959
params->has_mode = true;
939960
params->has_zero_page_detection = true;
961+
params->has_direct_io = true;
940962
}
941963

942964
/*
@@ -1110,6 +1132,11 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)
11101132
return false;
11111133
}
11121134

1135+
if (params->has_direct_io && params->direct_io && !qemu_has_direct_io()) {
1136+
error_setg(errp, "No build-time support for direct-io");
1137+
return false;
1138+
}
1139+
11131140
return true;
11141141
}
11151142

@@ -1216,6 +1243,10 @@ static void migrate_params_test_apply(MigrateSetParameters *params,
12161243
if (params->has_zero_page_detection) {
12171244
dest->zero_page_detection = params->zero_page_detection;
12181245
}
1246+
1247+
if (params->has_direct_io) {
1248+
dest->direct_io = params->direct_io;
1249+
}
12191250
}
12201251

12211252
static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
@@ -1341,6 +1372,10 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
13411372
if (params->has_zero_page_detection) {
13421373
s->parameters.zero_page_detection = params->zero_page_detection;
13431374
}
1375+
1376+
if (params->has_direct_io) {
1377+
s->parameters.direct_io = params->direct_io;
1378+
}
13441379
}
13451380

13461381
void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)

migration/options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ uint32_t migrate_checkpoint_delay(void);
6969
uint8_t migrate_cpu_throttle_increment(void);
7070
uint8_t migrate_cpu_throttle_initial(void);
7171
bool migrate_cpu_throttle_tailslow(void);
72+
bool migrate_direct_io(void);
7273
uint64_t migrate_downtime_limit(void);
7374
uint8_t migrate_max_cpu_throttle(void);
7475
uint64_t migrate_max_bandwidth(void);

qapi/migration.json

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,10 @@
821821
# See description in @ZeroPageDetection. Default is 'multifd'.
822822
# (since 9.0)
823823
#
824+
# @direct-io: Open migration files with O_DIRECT when possible. This
825+
# only has effect if the @mapped-ram capability is enabled.
826+
# (Since 9.1)
827+
#
824828
# Features:
825829
#
826830
# @unstable: Members @x-checkpoint-delay and
@@ -845,7 +849,8 @@
845849
{ 'name': 'x-vcpu-dirty-limit-period', 'features': ['unstable'] },
846850
'vcpu-dirty-limit',
847851
'mode',
848-
'zero-page-detection'] }
852+
'zero-page-detection',
853+
'direct-io'] }
849854

850855
##
851856
# @MigrateSetParameters:
@@ -991,6 +996,10 @@
991996
# See description in @ZeroPageDetection. Default is 'multifd'.
992997
# (since 9.0)
993998
#
999+
# @direct-io: Open migration files with O_DIRECT when possible. This
1000+
# only has effect if the @mapped-ram capability is enabled.
1001+
# (Since 9.1)
1002+
#
9941003
# Features:
9951004
#
9961005
# @unstable: Members @x-checkpoint-delay and
@@ -1030,7 +1039,8 @@
10301039
'features': [ 'unstable' ] },
10311040
'*vcpu-dirty-limit': 'uint64',
10321041
'*mode': 'MigMode',
1033-
'*zero-page-detection': 'ZeroPageDetection'} }
1042+
'*zero-page-detection': 'ZeroPageDetection',
1043+
'*direct-io': 'bool' } }
10341044

10351045
##
10361046
# @migrate-set-parameters:
@@ -1190,6 +1200,10 @@
11901200
# See description in @ZeroPageDetection. Default is 'multifd'.
11911201
# (since 9.0)
11921202
#
1203+
# @direct-io: Open migration files with O_DIRECT when possible. This
1204+
# only has effect if the @mapped-ram capability is enabled.
1205+
# (Since 9.1)
1206+
#
11931207
# Features:
11941208
#
11951209
# @unstable: Members @x-checkpoint-delay and
@@ -1226,7 +1240,8 @@
12261240
'features': [ 'unstable' ] },
12271241
'*vcpu-dirty-limit': 'uint64',
12281242
'*mode': 'MigMode',
1229-
'*zero-page-detection': 'ZeroPageDetection'} }
1243+
'*zero-page-detection': 'ZeroPageDetection',
1244+
'*direct-io': 'bool' } }
12301245

12311246
##
12321247
# @query-migrate-parameters:

util/osdep.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,15 @@ int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive)
282282
}
283283
#endif
284284

285+
bool qemu_has_direct_io(void)
286+
{
287+
#ifdef O_DIRECT
288+
return true;
289+
#else
290+
return false;
291+
#endif
292+
}
293+
285294
static int qemu_open_cloexec(const char *name, int flags, mode_t mode)
286295
{
287296
int ret;

0 commit comments

Comments
 (0)