Increase st_blksize to 64k

Brian Ford
Wed Jan 3 15:44:00 GMT 2007

On Wed, 3 Jan 2007, Eric Blake wrote:

> coreutils has the following, in src/system.h, used by cp, install, mv, du,
> ls, stat...
> For example, in cp, the following usage appears:
> 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 :

      size = st.st_blksize <= 0 ? BUFSIZ : st.st_blksize;
      size = BUFSIZ;
          fp->_blksize = st.st_blksize;
          fp->_blksize = 1024;

which is used to size and fill the stdio buffer.

and coreutils cp :

      /* 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);
      /* 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
	     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) -
	  size_t blcm = buffer_lcm (ST_BLKSIZE (src_open_sb), buf_size,

	  /* 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
	     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 = src_open_sb.st_size + 1;

	  /* However, stick with a block size that is a positive multiple
	     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...

More information about the Cygwin-patches mailing list