From: Stefano Garzarella <sgarzare@redhat.com>
To: qemu-devel@nongnu.org
Cc: Eduardo Habkost <ehabkost@redhat.com>,
Sergio Lopez <slp@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Julio Montes <julio.montes@intel.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Richard Henderson <rth@twiddle.net>
Subject: [Qemu-devel] [PATCH 2/2] hw/i386/pc: Map into memory the initrd
Date: Tue, 23 Jul 2019 11:07:18 +0200 [thread overview]
Message-ID: <20190723090718.14590-3-sgarzare@redhat.com> (raw)
In-Reply-To: <20190723090718.14590-1-sgarzare@redhat.com>
In order to reduce the memory footprint we map into memory
the initrd using g_mapped_file_new() instead of reading it.
In this way we can share the initrd pages between multiple
instances of QEMU.
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
hw/i386/pc.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 549c437050..b139589777 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1241,17 +1241,20 @@ static void load_linux(PCMachineState *pcms,
/* load initrd */
if (initrd_filename) {
+ GMappedFile *gmf;
gsize initrd_size;
gchar *initrd_data;
GError *gerr = NULL;
- if (!g_file_get_contents(initrd_filename, &initrd_data,
- &initrd_size, &gerr)) {
+ gmf = g_mapped_file_new(initrd_filename, false, &gerr);
+ if (!gmf) {
fprintf(stderr, "qemu: error reading initrd %s: %s\n",
initrd_filename, gerr->message);
exit(1);
}
+ initrd_data = g_mapped_file_get_contents(gmf);
+ initrd_size = g_mapped_file_get_length(gmf);
initrd_max = pcms->below_4g_mem_size - pcmc->acpi_data_size - 1;
if (initrd_size >= initrd_max) {
fprintf(stderr, "qemu: initrd is too large, cannot support."
@@ -1378,6 +1381,7 @@ static void load_linux(PCMachineState *pcms,
/* load initrd */
if (initrd_filename) {
+ GMappedFile *gmf;
gsize initrd_size;
gchar *initrd_data;
GError *gerr = NULL;
@@ -1387,12 +1391,15 @@ static void load_linux(PCMachineState *pcms,
exit(1);
}
- if (!g_file_get_contents(initrd_filename, &initrd_data,
- &initrd_size, &gerr)) {
+ gmf = g_mapped_file_new(initrd_filename, false, &gerr);
+ if (!gmf) {
fprintf(stderr, "qemu: error reading initrd %s: %s\n",
initrd_filename, gerr->message);
exit(1);
}
+
+ initrd_data = g_mapped_file_get_contents(gmf);
+ initrd_size = g_mapped_file_get_length(gmf);
if (initrd_size >= initrd_max) {
fprintf(stderr, "qemu: initrd is too large, cannot support."
"(max: %"PRIu32", need %"PRId64")\n",
--
2.20.1
prev parent reply other threads:[~2019-07-23 9:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-23 9:07 [Qemu-devel] [PATCH 0/2] pc: mmap kernel (ELF image) and initrd Stefano Garzarella
2019-07-23 9:07 ` [Qemu-devel] [PATCH 1/2] elf-ops.h: Map into memory the ELF to load Stefano Garzarella
2019-07-23 9:32 ` Peter Maydell
2019-07-23 9:42 ` Stefano Garzarella
2019-07-23 9:49 ` Paolo Bonzini
2019-07-23 10:10 ` Stefano Garzarella
2019-07-23 9:50 ` Peter Maydell
2019-07-23 10:12 ` Stefano Garzarella
2019-07-23 9:07 ` Stefano Garzarella [this message]
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=20190723090718.14590-3-sgarzare@redhat.com \
--to=sgarzare@redhat.com \
--cc=ehabkost@redhat.com \
--cc=julio.montes@intel.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--cc=slp@redhat.com \
/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).