[nylug-talk] questions about /dev/null
Alex Pilosov
alex at pilosoft.com
Mon Nov 5 14:43:48 EST 2007
On Mon, 5 Nov 2007, Peter C. Norton wrote:
> Run again, this time with ">", which still gives the process a file
> descriptor that leads to /dev/null:
<snip>
> So that's the slowdown for a simple, simple, simple program like "cat"
> to read buffere stdin and to throw it out. A >50% slowdown. The kernel
> or the C library simply has to stat() the file being written to, and see
> if it matches the st_rdev of /dev/null on the current system (yes, it's
> not codified anywhere that these device numbers must be uniform across
> platforms or releases).
No, you are so very wrong.
The difference is because of unix pipe()s having 4kb buffer. In other
words, when dd is reading 1Mbyte blocks, you have 0 context switches. In
case of dd | cat, you have two context switches every 4kb. Context
switches are not cheap.
-alex
More information about the nylug-talk
mailing list