From: Avi Kivity <avi@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Avoid loading ram pages that are all zeroes
Date: Sun, 14 Dec 2008 19:14:33 +0200 [thread overview]
Message-ID: <1229274873-15218-1-git-send-email-avi@redhat.com> (raw)
Restoring or migrating zero pages causes unnecessary allocation of memory.
We can avoid this by dropping the loaded page instead of memset()ing it.
Signed-off-by: Avi Kivity <avi@redhat.com>
diff --git a/vl.c b/vl.c
index 7b58605..42e97c9 100644
--- a/vl.c
+++ b/vl.c
@@ -3019,6 +3019,19 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
/***********************************************************/
/* ram save/restore */
+static void drop_page(uint8_t *page)
+{
+ if (TARGET_PAGE_SIZE < getpagesize())
+ return;
+#ifdef CONFIG_KVM
+ if (kvm_enabled() && !kvm_has_sync_mmu())
+ return;
+#endif
+#ifdef MADV_DONTNEED
+ madvise(page, TARGET_PAGE_SIZE, MADV_DONTNEED);
+#endif
+}
+
static int ram_get_page(QEMUFile *f, uint8_t *buf, int len)
{
int v;
@@ -3032,6 +3045,8 @@ static int ram_get_page(QEMUFile *f, uint8_t *buf, int len)
case 1:
v = qemu_get_byte(f);
memset(buf, v, len);
+ if (v == 0)
+ drop_page(buf);
break;
default:
return -EINVAL;
@@ -3289,6 +3304,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
if (flags & RAM_SAVE_FLAG_COMPRESS) {
uint8_t ch = qemu_get_byte(f);
memset(phys_ram_base + addr, ch, TARGET_PAGE_SIZE);
+ if (ch == 0)
+ drop_page(phys_ram_base + addr);
} else if (flags & RAM_SAVE_FLAG_PAGE)
qemu_get_buffer(f, phys_ram_base + addr, TARGET_PAGE_SIZE);
} while (!(flags & RAM_SAVE_FLAG_EOS));
reply other threads:[~2008-12-14 17:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1229274873-15218-1-git-send-email-avi@redhat.com \
--to=avi@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).