From owner-freebsd-bugs@FreeBSD.ORG Mon Oct 17 20:50:10 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A32C91065670 for ; Mon, 17 Oct 2011 20:50:10 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 782998FC13 for ; Mon, 17 Oct 2011 20:50:10 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p9HKoAtk051689 for ; Mon, 17 Oct 2011 20:50:10 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p9HKoAiI051688; Mon, 17 Oct 2011 20:50:10 GMT (envelope-from gnats) Resent-Date: Mon, 17 Oct 2011 20:50:10 GMT Resent-Message-Id: <201110172050.p9HKoAiI051688@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Ian Lepore Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 47BC21065675 for ; Mon, 17 Oct 2011 20:44:39 +0000 (UTC) (envelope-from ilepore@damnhippie.dyndns.org) Received: from qmta09.emeryville.ca.mail.comcast.net (qmta09.emeryville.ca.mail.comcast.net [76.96.30.96]) by mx1.freebsd.org (Postfix) with ESMTP id 2CF928FC23 for ; Mon, 17 Oct 2011 20:44:38 +0000 (UTC) Received: from omta15.emeryville.ca.mail.comcast.net ([76.96.30.71]) by qmta09.emeryville.ca.mail.comcast.net with comcast id lwhR1h0071Y3wxoA9wkXPz; Mon, 17 Oct 2011 20:44:31 +0000 Received: from damnhippie.dyndns.org ([24.8.232.202]) by omta15.emeryville.ca.mail.comcast.net with comcast id lwsR1h01X4NgCEG8bwsR2r; Mon, 17 Oct 2011 20:52:26 +0000 Received: from revolution.hippie.lan (revolution.hippie.lan [172.22.42.240]) by damnhippie.dyndns.org (8.14.3/8.14.3) with ESMTP id p9HKiauX023552 for ; Mon, 17 Oct 2011 14:44:36 -0600 (MDT) (envelope-from ilepore@damnhippie.dyndns.org) Received: (from ilepore@localhost) by revolution.hippie.lan (8.14.5/8.14.4/Submit) id p9HKiaxe088680; Mon, 17 Oct 2011 14:44:36 -0600 (MDT) (envelope-from ilepore) Message-Id: <201110172044.p9HKiaxe088680@revolution.hippie.lan> Date: Mon, 17 Oct 2011 14:44:36 -0600 (MDT) From: Ian Lepore To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/161756: [patch] /bin/sh: read files in 1024-byte chunks rather than 1023 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Ian Lepore List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Oct 2011 20:50:10 -0000 >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 >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: