Re: mmap/write vs read/write supprise

Systemkennung Linux (
Thu, 10 Jul 1997 21:20:06 +0200 (MET DST)

> Hello all,
> I read with interest yesterdays discussions of web server performance,
> and I learned a lot. I decided to write a program last night that tested
> the speed of doing I/O using the mmap/write vs the more traditional
> read/write method. I will post the results and the source code later,
> after I have enhanced/debugged it a little more, but my inital results
> are a little supprising, so I thought I would share them with you.
> At least with my test program, it seems like using the mmap/write
> method shows the best performance gain when the file is small (ie 400 bytes).
> As the file size grows, the performance gain decreases, and when the
> file size get close to 1M, it becomes faster to use read/write rather
> than mmap. This is with a 2.0.28 kernel on a Cyrix 6x68 P166+. I don't
> have a stable 2.1.X kenel to test right now ;-)
> Now these results are exactly the opposite of what I would expect.
> I will post the source tomorrow, but I wanted to get this out now so that
> people could tell me that I must be doing something wrong if this is
> supposed to be impossible.

Alot of CPU performance is sometimes wasted in stdio libraries. On
such systems the win of using mmap is high because it cuts down the entire
library overhead. Old AT&T figures that said mmap is up to seven times
faster than stdio libraries. Things look a bit different if you directly
compare mmap(2) vs. read(2)/write(2) and friends.

Another advantage of the mmap interface is that it is a very simple and
natural way to do things.