Date: Mon, 17 Oct 2011 14:44:36 -0600 (MDT) From: Ian Lepore <freebsd@damnhippie.dyndns.org> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/161756: [patch] /bin/sh: read files in 1024-byte chunks rather than 1023 Message-ID: <201110172044.p9HKiaxe088680@revolution.hippie.lan> Resent-Message-ID: <201110172050.p9HKoAiI051688@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 161756
>Category: bin
>Synopsis: [patch] /bin/sh: read files in 1024-byte chunks rather than 1023
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Mon Oct 17 20:50:10 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator: Ian Lepore <freebsd@damnhippie.dyndns.org>
>Release: FreeBSD 8.2-STABLE arm
>Organization:
Symmetricom, Inc.
>Environment:
FreeBSD tflex 8.2-STABLE FreeBSD 8.2-STABLE #29: Tue Oct 11 13:32:35 UTC 2011 root@revolution.hippie.lan:/usr/obj/arm/usr/src/sys/TFLEX arm
>Description:
Script files are read by /bin/sh in 1023-byte gulps using unbuffered IO
(read(2) calls); not very efficient for direct reads from disk.
The current code uses BUFSIZ (from stdio.h, current value is 1024) to
allocate buffers, then reads BUFSIZ-1 bytes at a time. The attached
patch allocates buffers using BUFSIZ+1 and reads BUFSIZ bytes at a time.
The performance increase from reading 1024 bytes at a time isn't going to
knock your socks off, but on a slow embedded platform it can be noticible.
>How-To-Repeat:
N/A
>Fix:
This patch should apply cleanly to -current and -stable (with fuzz).
--- temp.diff begins here ---
--- bin/sh/input.c.orig 2011-10-11 10:56:15.000000000 -0600
+++ bin/sh/input.c 2011-10-17 14:24:49.000000000 -0600
@@ -97,7 +97,7 @@ int parsenleft; /* copy of parsefile->
MKINIT int parselleft; /* copy of parsefile->lleft */
char *parsenextc; /* copy of parsefile->nextc */
MKINIT struct parsefile basepf; /* top level input file */
-char basebuf[BUFSIZ]; /* buffer for top level input file */
+char basebuf[BUFSIZ+1]; /* buffer for top level input file */
static struct parsefile *parsefile = &basepf; /* current input file */
int init_editline = 0; /* editline library initialized? */
int whichprompt; /* 1 == PS1, 2 == PS2 */
@@ -188,8 +188,8 @@ retry:
nr = 0;
else {
nr = el_len;
- if (nr > BUFSIZ - 1)
- nr = BUFSIZ - 1;
+ if (nr > BUFSIZ)
+ nr = BUFSIZ;
memcpy(parsenextc, rl_cp, nr);
if (nr != el_len) {
el_len -= nr;
@@ -199,7 +199,7 @@ retry:
}
} else
#endif
- nr = read(parsefile->fd, parsenextc, BUFSIZ - 1);
+ nr = read(parsefile->fd, parsenextc, BUFSIZ);
if (nr <= 0) {
if (nr < 0) {
@@ -427,13 +427,13 @@ setinputfd(int fd, int push)
(void)fcntl(fd, F_SETFD, FD_CLOEXEC);
if (push) {
pushfile();
- parsefile->buf = ckmalloc(BUFSIZ);
+ parsefile->buf = ckmalloc(BUFSIZ+1);
}
if (parsefile->fd > 0)
close(parsefile->fd);
parsefile->fd = fd;
if (parsefile->buf == NULL)
- parsefile->buf = ckmalloc(BUFSIZ);
+ parsefile->buf = ckmalloc(BUFSIZ+1);
parselleft = parsenleft = 0;
plinno = 1;
}
--- temp.diff ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201110172044.p9HKiaxe088680>
