Skip to contentSkip to conversation

migration: drop MADVISE_DONT_NEED for incoming zero pages

PATCH RESEND In review Peter Lieven 4 participants 7 messages Oct 24, 2013 – Nov 18, 2013

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 migration: drop MADVISE_DONT_NEED for incoming zero pages

The madvise for zeroed out pages was introduced when every transferred zero page was memset to zero and thus allocated. Since commit 211ea740 we check for zeroness of a target page before we memset it to zero. Additionally we memmap target memory so it is essentially zero initialized (except for e.g. option roms and bios which are loaded into target memory although they shouldn't).

It was reported recently that this madvise causes a performance degradation in some situations. As the madvise should only be called rarely and if it's called it is likely on a busy page (it was non-zero and changed to zero during migration) drop it completely.

---
 arch_init.c |    8 --------
 1 file changed, 8 deletions(-)
arch_init.c +0 -8
index 7545d96..e0acbc5 100644
@@ -850,14 +850,6 @@ void ram_handle_compressed(void *host, uint8_t ch, uint64_t size)
 {
     if (ch != 0 || !is_zero_range(host, size)) {
         memset(host, ch, size);
-#ifndef _WIN32
-        if (ch == 0 && (!kvm_enabled() || kvm_has_sync_mmu())) {
-            size = size & ~(getpagesize() - 1);
-            if (size > 0) {
-                qemu_madvise(host, size, QEMU_MADV_DONTNEED);
-            }
-        }
-#endif
     }
 }
 
Signature · 1 line
1.7.9.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Peter Lieven

The madvise for zeroed out pages was introduced when every transferred zero page was memset to zero and thus allocated. Since commit 211ea740 we check for zeroness of a target page before we memset it to zero. Additionally we memmap target memory so it is essentially zero initialized (except for e.g. option roms and bios which are loaded into target memory although they shouldn't).

It was reported recently that this madvise causes a performance degradation in some situations. As the madvise should only be called rarely and if it's called it is likely on a busy page (it was non-zero and changed to zero during migration) drop it completely.

I take it. I am on KVM Forum/LinuxCon this week. Will send when back at home.

Thanks.

Quoted 26 lines
---
 arch_init.c |    8 --------
 1 file changed, 8 deletions(-)
arch_init.c +0 -8
index 7545d96..e0acbc5 100644
@@ -850,14 +850,6 @@ void ram_handle_compressed(void *host, uint8_t ch, uint64_t size)
 {
     if (ch != 0 || !is_zero_range(host, size)) {
         memset(host, ch, size);
-#ifndef _WIN32
-        if (ch == 0 && (!kvm_enabled() || kvm_has_sync_mmu())) {
-            size = size & ~(getpagesize() - 1);
-            if (size > 0) {
-                qemu_madvise(host, size, QEMU_MADV_DONTNEED);
-            }
-        }
-#endif
     }
 }
#2 lore raw
Quoted 8 lines · Juan Quintela
Quoted 7 lines · Peter Lieven

The madvise for zeroed out pages was introduced when every transferred zero page was memset to zero and thus allocated. Since commit 211ea740 we check for zeroness of a target page before we memset it to zero. Additionally we memmap target memory so it is essentially zero initialized (except for e.g. option roms and bios which are loaded into target memory although they shouldn't).

Quoted 8 lines
Quoted 4 lines

It was reported recently that this madvise causes a performance degradation in some situations. As the madvise should only be called rarely and if it's called it is likely on a busy page (it was non-zero and changed to zero during migration) drop it completely.

I take it. I am on KVM Forum/LinuxCon this week. Will send when back at home.

Ping

Peter

#3 lore raw
In reply to Peter Lieven

Il 24/10/2013 08:21, Peter Lieven ha scritto:

Quoted 8 lines

Additionally we memmap target memory so it is essentially zero initialized (except for e.g. option roms and bios which are loaded into target memory although they shouldn't).

It was reported recently that this madvise causes a performance degradation in some situations. As the madvise should only be called rarely and if it's called it is likely on a busy page (it was non-zero and changed to zero during migration) drop it completely.

Tagging this patch for 1.7.

Paolo

#4 lore raw
Quoted 10 lines · Paolo Bonzini

Il 24/10/2013 08:21, Peter Lieven ha scritto:

Quoted 8 lines

Additionally we memmap target memory so it is essentially zero initialized (except for e.g. option roms and bios which are loaded into target memory although they shouldn't).

It was reported recently that this madvise causes a performance degradation in some situations. As the madvise should only be called rarely and if it's called it is likely on a busy page (it was non-zero and changed to zero during migration) drop it completely.

Tagging this patch for 1.7.

has this been merged?

Peter

#5 lore raw

Il 18/11/2013 13:48, Peter Lieven ha scritto:

Quoted 13 lines · Paolo Bonzini
Quoted 12 lines

Il 24/10/2013 08:21, Peter Lieven ha scritto:

Quoted 11 lines

Additionally we memmap target memory so it is essentially zero initialized (except for e.g. option roms and bios which are loaded into target memory although they shouldn't).

It was reported recently that this madvise causes a performance degradation
in some situations. As the madvise should only be called rarely and if it's called
it is likely on a busy page (it was non-zero and changed to zero during migration)
drop it completely.

Quoted 2 lines
Quoted 1 line

Tagging this patch for 1.7.

has this been merged?

No. Juan, can you prepare a quick pull request?

Paolo

#6 lore raw
In reply to Peter Lieven

The comments of ram_handle_compressed needs to be changed accordingly,

"Do not memset pages to zero if they already read as zero to avoid allocating zero pages and consuming memory unnecessarily."

Thanks,
Zhang Haoyu

Quoted 45 lines

The madvise for zeroed out pages was introduced when every transferred zero page was memset to zero and thus allocated. Since commit 211ea740 we check for zeroness of a target page before we memset it to zero. Additionally we memmap target memory so it is essentially zero initialized (except for e.g. option roms and bios which are loaded into target memory although they shouldn't).

It was reported recently that this madvise causes a performance degradation
in some situations. As the madvise should only be called rarely and if it's called
it is likely on a busy page (it was non-zero and changed to zero during migration)
drop it completely.

---
 arch_init.c |    8 --------
 1 file changed, 8 deletions(-)
arch_init.c +0 -9
index 7545d96..e0acbc5 100644
@@ -850,14 +850,6 @@ void ram_handle_compressed(void *host, uint8_t ch,
 uint64_t size)
 {
     if (ch != 0 || !is_zero_range(host, size)) {
         memset(host, ch, size);
-#ifndef _WIN32
-        if (ch == 0 && (!kvm_enabled() || kvm_has_sync_mmu())) {
-            size = size & ~(getpagesize() - 1);
-            if (size > 0) {
-                qemu_madvise(host, size, QEMU_MADV_DONTNEED);
-            }
-        }
-#endif
     }
 }
 
--

1.7.9.5