From owner-freebsd-current@FreeBSD.ORG Mon Aug 20 13:58:41 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CD10F106564A; Mon, 20 Aug 2012 13:58:41 +0000 (UTC) (envelope-from mj@feral.com) Received: from ns1.feral.com (ns1.feral.com [192.67.166.1]) by mx1.freebsd.org (Postfix) with ESMTP id 7FFA88FC19; Mon, 20 Aug 2012 13:58:41 +0000 (UTC) Received: from [192.168.135.103] (c-24-5-173-152.hsd1.ca.comcast.net [24.5.173.152]) (authenticated bits=0) by ns1.feral.com (8.14.4/8.14.4) with ESMTP id q7KDwX6q078221 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Mon, 20 Aug 2012 06:58:34 -0700 (PDT) (envelope-from mj@feral.com) Message-ID: <50324284.2080305@feral.com> Date: Mon, 20 Aug 2012 06:58:28 -0700 From: Matthew Jacob Organization: Feral Software User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: John Baldwin References: <6800.1345323911@critter.freebsd.dk> <201208200824.38500.jhb@freebsd.org> In-Reply-To: <201208200824.38500.jhb@freebsd.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (ns1.feral.com [192.67.166.1]); Mon, 20 Aug 2012 06:58:35 -0700 (PDT) Cc: Poul-Henning Kamp , freebsd-current@freebsd.org, Matt Jacob Subject: Re: BUFSIZ = 1024, still ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: mj@feral.com 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 13:58:41 -0000 On 8/20/2012 5:24 AM, John Baldwin wrote: > 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. > Perfect. Data.