Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] kexec: use mmap instead of read for slurp_file()
@ 2015-08-18 16:17 Michael Holzheu
  2015-08-28 14:26 ` PING: " Michael Holzheu
  2015-09-02  1:07 ` Simon Horman
  0 siblings, 2 replies; 9+ messages in thread
From: Michael Holzheu @ 2015-08-18 16:17 UTC (permalink / raw)
  To: Simon Horman; +Cc: stefan.roscher, kexec

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.

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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-10-15 12:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox