mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 08:13:54 -06:00
Postcopy: Mark nohugepage before discard
Prior to servicing userfault requests we must ensure we've not got huge pages in the area that might include non-transferred memory, since a hugepage could incorrectly mark the whole huge page as present. We mark the area as non-huge page (nhp) just before we perform discards; the discard code now tells us to discard any areas that haven't been sent (as well as any that are redirtied); any already formed transparent-huge-pages get fragmented by this discard process if they cotnain any discards. Transparent huge pages that have been entirely transferred and don't contain any discards are not broken by this mechanism; they stay as huge pages. By starting postcopy after a full precopy pass, many of the pages then stay as huge pages; this is important for maintaining performance after the end of the migration. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Juan Quintela <quintela@redhat.com>
This commit is contained in:
parent
27c6825bd3
commit
f952710757
4 changed files with 59 additions and 4 deletions
|
@ -226,12 +226,10 @@ static int cleanup_range(const char *block_name, void *host_addr,
|
|||
* We turned off hugepage for the precopy stage with postcopy enabled
|
||||
* we can turn it back on now.
|
||||
*/
|
||||
#ifdef MADV_HUGEPAGE
|
||||
if (madvise(host_addr, length, MADV_HUGEPAGE)) {
|
||||
if (qemu_madvise(host_addr, length, QEMU_MADV_HUGEPAGE)) {
|
||||
error_report("%s HUGEPAGE: %s", __func__, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* We can also turn off userfault now since we should have all the
|
||||
|
@ -307,6 +305,43 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState *mis)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Disable huge pages on an area
|
||||
*/
|
||||
static int nhp_range(const char *block_name, void *host_addr,
|
||||
ram_addr_t offset, ram_addr_t length, void *opaque)
|
||||
{
|
||||
trace_postcopy_nhp_range(block_name, host_addr, offset, length);
|
||||
|
||||
/*
|
||||
* Before we do discards we need to ensure those discards really
|
||||
* do delete areas of the page, even if THP thinks a hugepage would
|
||||
* be a good idea, so force hugepages off.
|
||||
*/
|
||||
if (qemu_madvise(host_addr, length, QEMU_MADV_NOHUGEPAGE)) {
|
||||
error_report("%s: NOHUGEPAGE: %s", __func__, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Userfault requires us to mark RAM as NOHUGEPAGE prior to discard
|
||||
* however leaving it until after precopy means that most of the precopy
|
||||
* data is still THPd
|
||||
*/
|
||||
int postcopy_ram_prepare_discard(MigrationIncomingState *mis)
|
||||
{
|
||||
if (qemu_ram_foreach_block(nhp_range, mis)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
postcopy_state_set(POSTCOPY_INCOMING_DISCARD);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Mark the given area of RAM as requiring notification to unwritten areas
|
||||
* Used as a callback on qemu_ram_foreach_block.
|
||||
|
@ -583,6 +618,12 @@ int postcopy_ram_discard_range(MigrationIncomingState *mis, uint8_t *start,
|
|||
return -1;
|
||||
}
|
||||
|
||||
int postcopy_ram_prepare_discard(MigrationIncomingState *mis)
|
||||
{
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int postcopy_ram_enable_notify(MigrationIncomingState *mis)
|
||||
{
|
||||
assert(0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue