This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
Re: Increase st_blksize to 64k
On Wed, 3 Jan 2007, Eric Blake wrote:
> coreutils has the following, in src/system.h, used by cp, install, mv, du,
> ls, stat...
[snip]
> For example, in cp, the following usage appears:
[snip]
> It sounds like we want to ensure that cygwin chooses ST_BLKSIZE at 64k
> (optimal I/O size) but ST_NBLOCKS/ST_NBLOCKSIZE at the disk granularity (512).
I got lost in all the code details you presented above, but I confess to
not trying very hard. I don't think changing the block size to 512 bytes
is really necessary, though.
These are the examples that I had in mind:
newlib stdio http://cygwin.com/cgi-bin/cvsweb.cgi/src/newlib/libc/stdio/makebuf.c?rev=1.6&content-type=text/x-cvsweb-markup&cvsroot=src :
#ifdef HAVE_BLKSIZE
size = st.st_blksize <= 0 ? BUFSIZ : st.st_blksize;
#else
size = BUFSIZ;
#endif
[skip]
#ifdef HAVE_BLKSIZE
fp->_blksize = st.st_blksize;
#else
fp->_blksize = 1024;
#endif
which is used to size and fill the stdio buffer.
and coreutils cp
http://cvs.savannah.gnu.org/viewcvs/coreutils/src/copy.c?rev=1.223&root=coreutils&view=auto :
/* Choose a suitable buffer size; it may be adjusted later. */
size_t buf_alignment = lcm (getpagesize (), sizeof (word));
size_t buf_alignment_slop = sizeof (word) + buf_alignment - 1;
size_t buf_size = ST_BLKSIZE (sb);
[skip]
/* If not making a sparse file, try to use a more-efficient
buffer size. */
if (! make_holes)
{
/* These days there's no point ever messing with buffers smaller
than 8 KiB. It would be nice to configure SMALL_BUF_SIZE
dynamically for this host and pair of files, but there
doesn't
seem to be a good way to get readahead info portably. */
enum { SMALL_BUF_SIZE = 8 * 1024 };
/* Compute the least common multiple of the input and output
buffer sizes, adjusting for outlandish values. */
size_t blcm_max = MIN (SIZE_MAX, SSIZE_MAX) -
buf_alignment_slop;
size_t blcm = buffer_lcm (ST_BLKSIZE (src_open_sb), buf_size,
blcm_max);
/* Do not use a block size that is too small. */
buf_size = MAX (SMALL_BUF_SIZE, blcm);
/* Do not bother with a buffer larger than the input file, plus
one
byte to make sure the file has not grown while reading it.
*/
if (S_ISREG (src_open_sb.st_mode) && src_open_sb.st_size <
buf_size)
buf_size = src_open_sb.st_size + 1;
/* However, stick with a block size that is a positive multiple
of
blcm, overriding the above adjustments. Watch out for
overflow. */
buf_size += blcm - 1;
buf_size -= buf_size % blcm;
if (buf_size == 0 || blcm_max < buf_size)
buf_size = blcm;
}
--
Brian Ford
Lead Realtime Software Engineer
VITAL - Visual Simulation Systems
FlightSafety International
the best safety device in any aircraft is a well-trained crew...