From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: [PATCH] cleanup udevstart
Date: Tue, 16 Mar 2004 01:28:56 +0000 [thread overview]
Message-ID: <20040316012856.GA6187@vrfy.org> (raw)
In-Reply-To: <20040302215536.GA12039@vrfy.org>
[-- Attachment #1: Type: text/plain, Size: 604 bytes --]
On Mon, Mar 15, 2004 at 10:22:02PM +0100, Olaf Hering wrote:
> On Tue, Mar 02, Greg KH wrote:
>
> > # /usr/bin/time /sbin/udevstart
> > Command exited with non-zero status 22
> > 0.19user 0.67system 0:01.04elapsed 83%CPU (0avgtext+0avgdata 0maxresident)k
> > 0inputs+0outputs (2major+6065minor)pagefaults 0swaps
> >
> > 1 second to populate a full /dev while the system is under a very heavy
> > load is pretty good I think :)
>
>
> Yeah, I was using the klibc version, that makes it slower due to the
> clever fgets implementation.
Hey, better try to fix it :)
You may try this one.
thanks,
Kay
[-- Attachment #2: 80-mmap.patch --]
[-- Type: text/plain, Size: 2189 bytes --]
===== namedev_parse.c 1.32 vs edited =====
--- 1.32/namedev_parse.c Fri Mar 12 17:43:30 2004
+++ edited/namedev_parse.c Tue Mar 16 02:16:35 2004
@@ -36,6 +36,7 @@
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
+#include <sys/mman.h>
#include "udev.h"
#include "logging.h"
@@ -145,6 +146,47 @@
return NULL;
}
+static int file_map(const char *filename, char **buf, size_t *bufsize)
+{
+ struct stat stats;
+ int fd;
+
+ fd = open(filename, O_RDONLY);
+ if (fd < 0) {
+ dbg("can't open '%s'", filename);
+ return -1;
+ }
+
+ if (fstat(fd, &stats) < 0) {
+ dbg("error stating '%s'", filename);
+ return -1;
+ }
+
+ *buf = mmap(NULL, stats.st_size, PROT_READ, MAP_SHARED, fd, 0);
+ if (*buf == MAP_FAILED) {
+ dbg("error mapping file '%s'", filename);
+ return -1;
+ }
+ *bufsize = stats.st_size;
+
+ return 0;
+}
+
+static void file_unmap(char *buf, size_t bufsize)
+{
+ munmap(buf, bufsize);
+}
+
+
+static size_t buf_get_line(char *buf, size_t buflen, size_t cur)
+{
+ size_t count = 0;
+
+ for (count = cur; count < buflen && buf[count] != '\n'; count++);
+
+ return count - cur;
+}
+
static int namedev_parse_rules(char *filename)
{
char line[255];
@@ -153,27 +195,38 @@
char *temp2;
char *temp3;
char *attr;
- FILE *fd;
+ char *buf;
+ size_t bufsize;
+ size_t cur;
+ size_t count;
int program_given = 0;
int retval = 0;
struct config_device dev;
- fd = fopen(filename, "r");
- if (fd != NULL) {
+ if (file_map(filename, &buf, &bufsize) == 0) {
dbg("reading '%s' as rules file", filename);
} else {
dbg("can't open '%s' as a rules file", filename);
return -ENODEV;
}
+ dbg("bufsize %i", bufsize);
+
/* loop through the whole file */
+ cur = 0;
lineno = 0;
while (1) {
- /* get a line */
- temp = fgets(line, sizeof(line), fd);
- if (temp == NULL)
- goto exit;
+ count = buf_get_line(buf, bufsize, cur);
+
+ strncpy(line, buf + cur, count);
+ line[count] = '\0';
+ temp = line;
lineno++;
+
+ cur += count+1;
+ if (cur > bufsize)
+ break;
+
dbg_parse("read '%s'", temp);
/* eat the whitespace */
@@ -312,7 +365,7 @@
}
}
exit:
- fclose(fd);
+ file_unmap(buf, bufsize);
return retval;
}
next prev parent reply other threads:[~2004-03-16 1:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-02 21:55 [PATCH] cleanup udevstart Kay Sievers
2004-03-02 22:16 ` Greg KH
2004-03-02 23:09 ` Olaf Hering
2004-03-02 23:20 ` Greg KH
2004-03-02 23:23 ` Olaf Hering
2004-03-02 23:32 ` Greg KH
2004-03-15 21:22 ` Olaf Hering
2004-03-16 1:28 ` Kay Sievers [this message]
2004-03-16 2:49 ` Kay Sievers
2004-03-16 17:01 ` Patrick Mansfield
2004-03-16 21:57 ` Kay Sievers
2004-03-16 22:24 ` Patrick Mansfield
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=20040316012856.GA6187@vrfy.org \
--to=kay.sievers@vrfy.org \
--cc=linux-hotplug@vger.kernel.org \
/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).