From: Simon Horman <horms@verge.net.au>
To: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Cc: stefan.roscher@de.ibm.com, kexec@lists.infradead.org
Subject: Re: [RFC PATCH] kexec: use mmap instead of read for slurp_file()
Date: Wed, 2 Sep 2015 10:07:21 +0900 [thread overview]
Message-ID: <20150902010721.GE30886@verge.net.au> (raw)
In-Reply-To: <1439914643-26484-1-git-send-email-holzheu@linux.vnet.ibm.com>
Hi Michael,
sorry for the delay in responding to your patch.
On Tue, Aug 18, 2015 at 06:17:23PM +0200, Michael Holzheu wrote:
> The slurp_fd() function allocates memory and uses the read() system call.
> This results in double memory consumption for image and initrd:
>
> 1) Memory allocated in user space by the kexec tool
> 2) Memory allocated in kernel by the kexec() system call
>
> Therefore use mmap() for non-character devices to reduce the memory
> consumption of the kexec tool.
I'm not opposed to this change but I also don't see a strong motivation for
it. I would imagine that the memory saving is not that large. And that the
memory consumption disappears when the presumably short-lived kexec process
exits.
>
> Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
> ---
> kexec/kexec.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/kexec/kexec.c b/kexec/kexec.c
> index 8ce6885..fecf061 100644
> --- a/kexec/kexec.c
> +++ b/kexec/kexec.c
> @@ -26,6 +26,7 @@
> #include <stdlib.h>
> #include <errno.h>
> #include <limits.h>
> +#include <sys/mman.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <sys/reboot.h>
> @@ -552,11 +553,12 @@ char *slurp_file(const char *filename, off_t *r_size)
> if (err < 0)
> die("Can not seek to the begin of file %s: %s\n",
> filename, strerror(errno));
> + buf = slurp_fd(fd, filename, size, &nread);
> } else {
> - size = stats.st_size;
> + size = nread = stats.st_size;
> + buf = mmap(NULL, size,
> + PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
> }
> -
> - buf = slurp_fd(fd, filename, size, &nread);
> if (!buf)
> die("Cannot read %s", filename);
>
> --
> 2.3.0
>
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
next prev parent reply other threads:[~2015-09-02 1:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-18 16:17 [RFC PATCH] kexec: use mmap instead of read for slurp_file() Michael Holzheu
2015-08-28 14:26 ` PING: " Michael Holzheu
2015-09-02 1:07 ` Simon Horman [this message]
2015-09-02 8:48 ` Michael Holzheu
2015-09-04 9:45 ` Simon Horman
2015-09-04 12:11 ` [PATCH] " Michael Holzheu
2015-09-07 6:44 ` Simon Horman
2015-10-15 0:05 ` Geoff Levand
2015-10-15 12:31 ` Michael Holzheu
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=20150902010721.GE30886@verge.net.au \
--to=horms@verge.net.au \
--cc=holzheu@linux.vnet.ibm.com \
--cc=kexec@lists.infradead.org \
--cc=stefan.roscher@de.ibm.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