For different reasons, cp(1) and cat(1) were both using 64 kB buffers to copy data. Cat was trying to find out what the block size on the file system is (which, for various reasons, ends up almost always being 64 kB) and used 1 kB for non-files, and cp just gave up and used MAXBSIZE (maximum file system block size), which is predefined to be 64 kB. This is less useful today when drives and memory caches are big, and especially with file systems like ZFS where "block size" isn't even the same file system concept as in UFS.
This is not nearly as bad as it might seem because file system caching and prereading make the data available before it's needed so the effects of small reads are very minimal. A related problem here is that the kernel MAXPHYS value (maximum IO block size) is defined to be 128 kB, which puts the upper cap on IO transfers to and from disk drives. This is also not very noticable, for similar reasons, in regular usage but might be in highly loaded servers with large RAID arrays. Unfortunately this particular setting is entrenched in the kernel and disk controller drivers so it will require much restructuring. Every now and then there are signals that someone is working on increasing MAXPHYS so it might happen soon.
Returning to cp and cat, the buffer for both is now set to 128 kB (MAXPHYS) if the machine has 128 MB or less physical memory, or 1 MB (8*MAXPHYS) if there's more memory available. The most visible improvement is that the number of context switches is reduced now:
before:
> /usr/bin/time -hlp cat file1 > file2
...
163 voluntary context switches
11194 involuntary context switches
after:
> /usr/bin/time -hlp ./cat file1 > file2
417 voluntary context switches
272 involuntary context switches
There are no noticable improvements in performance, but this larger buffer size will maybe pay out better in the future, on RAM drives, or on really, really overloaded systems :)
(p.s. cp copies files smaller than 8 MB by mmap+write... this remains untouched).
Nice Thanks !
This keeps the System from aging. And its better to not rely on some magic optimizations instead of doing it right, - right ?