mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shaohua Li <shaohua.li@intel.com>
To: lkml <linux-kernel@vger.kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Ingo Molnar <mingo@elte.hu>,
	Arjan van de Ven <arjan@infradead.org>
Subject: [patch]fastboot: remove duplicate unpack_to_rootfs()
Date: Wed, 13 Aug 2008 14:07:49 +0800	[thread overview]
Message-ID: <1218607669.3463.9.camel@sli10-desk.sh.intel.com> (raw)

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);



             reply	other threads:[~2008-08-13  5:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-13  6:07 Shaohua Li [this message]
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

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=1218607669.3463.9.camel@sli10-desk.sh.intel.com \
    --to=shaohua.li@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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

all inboxes | Powered by JetHome®