mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [patch]fastboot: remove duplicate unpack_to_rootfs()
@ 2008-08-13  6:07 Shaohua Li
  2008-08-13  7:45 ` Ingo Molnar
  0 siblings, 1 reply; 10+ messages in thread
From: Shaohua Li @ 2008-08-13  6:07 UTC (permalink / raw)
  To: lkml; +Cc: Andrew Morton, Ingo Molnar, Arjan van de Ven

we check if initrd is initramfs first and then do real unpack. The check
isn't required, we can directly do unpack. If initrd isn't initramfs, we
can remove garbage. In my laptop, this saves 0.1s boot time. This
penalizes non-initramfs case, but now initramfs is mostly widely used.

Signed-off-by: Shaohua Li <shaohua.li@intel.com>

diff --git a/init/initramfs.c b/init/initramfs.c
index 644fc01..e51c92b 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -5,6 +5,7 @@
 #include <linux/fcntl.h>
 #include <linux/delay.h>
 #include <linux/string.h>
+#include <linux/dirent.h>
 #include <linux/syscalls.h>
 
 static __initdata char *message;
@@ -520,6 +521,37 @@ skip:
 	initrd_end = 0;
 }
 
+static void __init clean_rootfs(void)
+{
+	int fd = sys_open("/", O_RDONLY, 0);
+	void *buf = malloc(1024);
+	struct linux_dirent64 *dirp = buf;
+	int count;
+
+	memset(buf, 0, PAGE_SIZE);
+	count = sys_getdents64(fd, dirp, PAGE_SIZE);
+	while (count > 0) {
+		while (count > 0) {
+			struct stat st;
+
+			sys_newlstat(dirp->d_name, &st);
+			if (S_ISDIR(st.st_mode))
+				sys_rmdir(dirp->d_name);
+			else
+				sys_unlink(dirp->d_name);
+
+			count -= dirp->d_reclen;
+			dirp = (void *)dirp + dirp->d_reclen;
+		}
+		dirp = buf;
+		memset(buf, 0, 1024);
+		count = sys_getdents64(fd, dirp, PAGE_SIZE);
+	}
+
+	sys_close(fd);
+	free(buf);
+}
+
 static int __init populate_rootfs(void)
 {
 	char *err = unpack_to_rootfs(__initramfs_start,
@@ -531,13 +563,15 @@ static int __init populate_rootfs(void)
 		int fd;
 		printk(KERN_INFO "checking if image is initramfs...");
 		err = unpack_to_rootfs((char *)initrd_start,
-			initrd_end - initrd_start, 1);
+			initrd_end - initrd_start, 0);
 		if (!err) {
 			printk(" it is\n");
-			unpack_to_rootfs((char *)initrd_start,
-				initrd_end - initrd_start, 0);
 			free_initrd();
 			return 0;
+		} else {
+			clean_rootfs();
+			unpack_to_rootfs(__initramfs_start,
+				 __initramfs_end - __initramfs_start, 0);
 		}
 		printk("it isn't (%s); looks like an initrd\n", err);
 		fd = sys_open("/initrd.image", O_WRONLY|O_CREAT, 0700);



^ permalink raw reply	[flat|nested] 10+ messages in thread
* [2.6.30] What's in the async boot tree
@ 2009-03-15 18:23 Arjan van de Ven
  2009-03-15 18:25 ` [PATCH] fastboot: remove duplicate unpack_to_rootfs() Arjan van de Ven
  0 siblings, 1 reply; 10+ messages in thread
From: Arjan van de Ven @ 2009-03-15 18:23 UTC (permalink / raw)
  To: linux-kernel

The following changes since commit 326d8519fc97be186c55ac605c3a7c957c758ae1:
  Linus Torvalds (1):
        Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/arjan/linux-2.6-async-for-30.git master

Arjan van de Ven (2):
      async: remove the temporary (2.6.29) "async is off by default" code
      ide/net: flip the order of SATA and network init

Li, Shaohua (1):
      fastboot: remove duplicate unpack_to_rootfs()

 drivers/Makefile |    5 ++-
 init/initramfs.c |   71 ++++++++++++++++++++++++++++++++++++++++++-----------
 kernel/async.c   |   10 +-------
 3 files changed, 60 insertions(+), 26 deletions(-)


I will reply to this email with the three patches


-- 
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org

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

end of thread, other threads:[~2009-03-15 18:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-13  6:07 [patch]fastboot: remove duplicate unpack_to_rootfs() Shaohua Li
2008-08-13  7:45 ` Ingo Molnar
2008-08-13  7:52   ` Ingo Molnar
2008-08-13  8:06     ` Andrew Morton
2008-08-13  9:14       ` Ingo Molnar
2008-08-13  8:11     ` Frans Meulenbroeks
2008-08-13  9:15       ` Ingo Molnar
2008-08-13  8:00   ` Li, Shaohua
2008-08-13  9:26   ` Li, Shaohua
2009-03-15 18:23 [2.6.30] What's in the async boot tree Arjan van de Ven
2009-03-15 18:25 ` [PATCH] fastboot: remove duplicate unpack_to_rootfs() Arjan van de Ven

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

Powered by JetHome