Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
* mmap for fast file access?
@ 2001-10-18 10:10 Tony Cox
  2001-10-18 20:19 ` Rob Nichols
  2001-10-19  0:59 ` Bill Todd
  0 siblings, 2 replies; 3+ messages in thread
From: Tony Cox @ 2001-10-18 10:10 UTC (permalink / raw)



Hi,

I have an application that involves parsing a large number of text
files (say 1000 of say 60-100Mb each) and I want to do this as quickly
as possible. At the moment I just read the files line by line into a buffer
(using the C++ getline function). I'd like to speed this up by reading
in the files using memory mapping instead, and the Compaq realtime
programmers guide is pretty clear on how to do this using mmap, but:

1. How much speedup am I likely to get by using memory mapping?

2. When reading a file sequentially, is it faster to mmap it into 
memory page by page as needed, or mmap it all at once (presumably the latter, 
if you  have enough memory)?

3. Would it be faster to use a shared memory approach instead, e.g. shmat?

The machine I'm likely to run this on uses Tru64 UNIX 5.1.

Thanks in advance,

Tony Cox

-- 
 -------------------------------------------------------------
  Dr. Anthony J. Cox              -.   .-. .-.   .-. .-.   .-
  Informatics Division,           ||\ /|||X|||\ /|||X|||\ /||   
  The Sanger Centre,              |||X|||/ \|||X|||/ \|||X|||
  Hinxton, Cambridge CB10 1SD, UK `-' `-'   `-' `-'   `-' `-'
   -.   .-. .-.   .-. .-.   .-
   ||\ /|||X|||\ /|||X|||\ /||    ac2 at sanger dot ac dot uk
   |||X|||/ \|||X|||/ \|||X|||    
   `-' `-'   `-' `-'   `-' `-'
 ------------------------------------------------------------- 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: mmap for fast file access?
  2001-10-18 10:10 mmap for fast file access? Tony Cox
@ 2001-10-18 20:19 ` Rob Nichols
  2001-10-19  0:59 ` Bill Todd
  1 sibling, 0 replies; 3+ messages in thread
From: Rob Nichols @ 2001-10-18 20:19 UTC (permalink / raw)



I've spent a little time before trying to make reads of large files as
fast as possible.  I'm sorry that I don't recall exactly what the
hardware was, I think the os was 4.0D, and the c++ compiler was around
6.1.  The short of it was that std::iostream's were fairly slow.
Using std::getline into a std::string was very slow for large lines
(big lines, like 100k).  I didn't see much difference between kernel
read() and mmap(), but both were *much* faster than std::iostream.

I was a little disapointed that iostream was this slow.  I expect a
10% penelty for using iostream, but it was worse than that.  While
read()/mmap() was much faster, it still seemed a little slow to me.
Seems like something like 6meg/second, but I realize that this number
doesn't help at all without knowning what the hardware was.  I was
also a little surprised that read() and mmap() had very similar
performance.  I guess it shouldn't be too much of a surprise with a
very fast (and wide) memory bus.  (I tried mmap() all at once, or in
pieces, using various madvise() calls, and all had the same
performance.)  

Again, this has been about a year ago, so could be old hardware, old
os, and my failing memory.  I to would be very interested to hear from
others who found a faster way to read large files.

Later,
Rob


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: mmap for fast file access?
  2001-10-18 10:10 mmap for fast file access? Tony Cox
  2001-10-18 20:19 ` Rob Nichols
@ 2001-10-19  0:59 ` Bill Todd
  1 sibling, 0 replies; 3+ messages in thread
From: Bill Todd @ 2001-10-19  0:59 UTC (permalink / raw)


As an old but unrepentent RSX and VMS user, I have to observe that the
absolute fastest way to stream large files into memory is to do so
explicitly, using asynchronous multi-buffering that bypasses any system
caching (and the overhead of per-line system calls).  Not only does this
eliminate the overhead of copying data from system cache to application
memory (assuming the system doesn't do something suave in the way of simply
remapping it for at least read-only access), but it avoids depending upon
whatever system algorithms may be doing in the way of intelligent pre-fetch
(and those algorithms are almost sure to be some kind of compromise rather
than speed-optimal).

Depending upon how a given system handles mapped files compared with
explicitly-read files, mmapping may or may not be as fast:  when one issues
an explicit read the system at least knows how much data is needed, whereas
using mmap it just knows you need the next page (and may or may not retain
access-history information to give it a clue about how much more than a
single page to ask for from disk in case you'll soon want to touch more).
In either case, you're still at the mercy of whatever the system designer
thought was best (if s/he thought at all) rather than in direct control of
your destiny.

- bill

Tony Cox <nospam@nospam.com> wrote in message
news:rzwvghd2r8h.fsf@wallaby.sanger.ac.uk...
>
> Hi,
>
> I have an application that involves parsing a large number of text
> files (say 1000 of say 60-100Mb each) and I want to do this as quickly
> as possible. At the moment I just read the files line by line into a
buffer
> (using the C++ getline function). I'd like to speed this up by reading
> in the files using memory mapping instead, and the Compaq realtime
> programmers guide is pretty clear on how to do this using mmap, but:
>
> 1. How much speedup am I likely to get by using memory mapping?
>
> 2. When reading a file sequentially, is it faster to mmap it into
> memory page by page as needed, or mmap it all at once (presumably the
latter,
> if you  have enough memory)?
>
> 3. Would it be faster to use a shared memory approach instead, e.g. shmat?
>
> The machine I'm likely to run this on uses Tru64 UNIX 5.1.
>
> Thanks in advance,
>
> Tony Cox
>
> --
>  -------------------------------------------------------------
>   Dr. Anthony J. Cox              -.   .-. .-.   .-. .-.   .-
>   Informatics Division,           ||\ /|||X|||\ /|||X|||\ /||
>   The Sanger Centre,              |||X|||/ \|||X|||/ \|||X|||
>   Hinxton, Cambridge CB10 1SD, UK `-' `-'   `-' `-'   `-' `-'
>    -.   .-. .-.   .-. .-.   .-
>    ||\ /|||X|||\ /|||X|||\ /||    ac2 at sanger dot ac dot uk
>    |||X|||/ \|||X|||/ \|||X|||
>    `-' `-'   `-' `-'   `-' `-'
>  -------------------------------------------------------------
>




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-10-19  0:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-10-18 10:10 mmap for fast file access? Tony Cox
2001-10-18 20:19 ` Rob Nichols
2001-10-19  0:59 ` Bill Todd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox