Re: BSD gettext - Mailing list pgsql-hackers

From ncm@zembu.com (Nathan Myers)
Subject Re: BSD gettext
Date
Msg-id 20010524141034.Q18121@store.zembu.com
Whole thread Raw
In response to Re: BSD gettext  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-hackers
On Thu, May 24, 2001 at 10:30:01AM -0400, Bruce Momjian wrote:
> > The HPUX man page for mmap documents its failure return value as "-1",
> > so I hacked around this with
> > 
> > #ifndef MAP_FAILED
> > #define MAP_FAILED ((void *) (-1))
> > #endif
> > 
> > whereupon it built and passed the simple self-test you suggested.
> > However, I think it's pretty foolish to depend on mmap for such
> > little reason as this code does.  I suggest ripping out the mmap
> > usage and just reading the file with good old read(2).
> 
> Agreed.  Let read() use mmap() internally if it wants to.

The reason mmap() is faster than read() is that it can avoid copying 
data to the place you specify.  read() can "use mmap() internally" only 
in cases rare enough to hardly be worth checking for.  

Stdio is often able to use mmap() internally for parsing, and in 
glibc-2.x (and, I think, on recent Solarix and BSDs) it does.  Usually, 
therefore, it would be better to use stdio functions (except fread()!) 
in place of read(), where possible, to allow this optimization.

Using mmap() in place of disk read() almost always results in enough
performance improvement to make doing so worth a lot of disruption.
Today mmap() is used heavily enough, in important programs, that 
worries about unreliability are no better founded than worries about
read().

Nathan Myers
ncm@zembu.com


pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: BSD gettext
Next
From: Hiroshi Inoue
Date:
Subject: Re: Plans for solving the VACUUM problem