Sunday, February 15, 2009

Unbuffered I/O and effect of buffer size

Most UNIX I/O can be accomplished by 5 system calls - open, lseek, read, write and close. They are unbuffered I/O calls. Programmer needs to allocate a buffer and pass it as one of the arguments to these I/O functions. If the buffer size picked is small, more I/O read/wrtie calls will have be made to transfer the same amount of data in and out of the program. A small buffer size results in higer CPU utilization (System and User) as well as longer total run time. Using larger buffer size will decrease CPU time. This is an example of trading CPU with memory usage. The CPU improvement will taper off at a certain buffer size beyond which further CPU utilization decrease will not be significant when the number of I/O call has already become quite small.

UNIX standard I/O packages provides a buffered I/O call interface for program. When using these calls, programmer no longer needs to concern with buffer size as it will be taken care by the standard I/O calls.

No comments: