From owner-freebsd-current@FreeBSD.ORG Mon Aug 20 12:31:40 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id D37B6106567D; Mon, 20 Aug 2012 12:31:40 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id A8DF38FC1B; Mon, 20 Aug 2012 12:31:40 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 08A66B91C; Mon, 20 Aug 2012 08:31:40 -0400 (EDT) From: John Baldwin To: freebsd-current@freebsd.org Date: Mon, 20 Aug 2012 08:24:38 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p17; KDE/4.5.5; amd64; ; ) References: <6800.1345323911@critter.freebsd.dk> In-Reply-To: <6800.1345323911@critter.freebsd.dk> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201208200824.38500.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Mon, 20 Aug 2012 08:31:40 -0400 (EDT) Cc: Poul-Henning Kamp , Matt Jacob Subject: Re: BUFSIZ = 1024, still ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Aug 2012 12:31:40 -0000 On Saturday, August 18, 2012 5:05:11 pm Poul-Henning Kamp wrote: > In message <5030033B.4060705@feral.com>, Matthew Jacob writes: > >On 8/18/2012 1:32 PM, Poul-Henning Kamp wrote: > >> Shouldn't we at least increase it to pagesize ? > >> > >What data suggests to you it would be better at pagesize? > > The number of system calls to fwrite() a big file ? Have you looked at an actual ktrace? :) stdio doesn't use BUFSIZ for regular files: head/lib/libc/stdio/makebuf.c: /* * Internal routine to determine `proper' buffering for a file. */ int __swhatbuf(fp, bufsize, couldbetty) FILE *fp; size_t *bufsize; int *couldbetty; { struct stat st; if (fp->_file < 0 || _fstat(fp->_file, &st) < 0) { ... *bufsize = BUFSIZ; return (__SNPT); } ... if (st.st_blksize <= 0) { *bufsize = BUFSIZ; return (__SNPT); } *bufsize = st.st_blksize; ... } For a regular file stdio will use the filesystem's block size, not BUFSIZ. Test program: #include #include int main(int ac, char **av) { char junk; FILE *fp; int i; fp = fopen("/tmp/junk", "w"); if (fp == NULL) err(1, "fopen"); for (i = 0; i < 1024 * 1024; i++) if (fwrite(&junk, sizeof(junk), 1, fp) != 1) errx(1, "fwrite failed"); return (0); } ktrace excerpt: 42599 a.out CALL write(0x3,0x800a04000,0x4000) 42599 a.out RET write 16384/0x4000 42599 a.out CALL write(0x3,0x800a04000,0x4000) 42599 a.out RET write 16384/0x4000 42599 a.out CALL write(0x3,0x800a04000,0x4000) 42599 a.out RET write 16384/0x4000 42599 a.out CALL write(0x3,0x800a04000,0x4000) 42599 a.out RET write 16384/0x4000 42599 a.out CALL write(0x3,0x800a04000,0x4000) 42599 a.out RET write 16384/0x4000 42599 a.out CALL write(0x3,0x800a04000,0x4000) 42599 a.out RET write 16384/0x4000 This hint also works for pipes (they set st_blksize to PAGE_SIZE). Given that, I think BUFSIZ should just be left alone. -- John Baldwin