From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Tue, 16 Mar 2004 01:28:56 +0000 Subject: Re: [PATCH] cleanup udevstart Message-Id: <20040316012856.GA6187@vrfy.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="azLHFNyN32YCQGCU" List-Id: References: <20040302215536.GA12039@vrfy.org> In-Reply-To: <20040302215536.GA12039@vrfy.org> To: linux-hotplug@vger.kernel.org --azLHFNyN32YCQGCU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --azLHFNyN32YCQGCU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="80-mmap.patch" ===== 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 #include #include +#include #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; } --azLHFNyN32YCQGCU-- ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel