Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
From: "Bill Todd" <billtodd@metrocast.net>
Subject: Re: mmap for fast file access?
Date: Fri, 19 Oct 2001 00:59:31 GMT	[thread overview]
Message-ID: <TVKz7.1027497$ai2.77403589@bin2.nnrp.aus1.giganews.com> (raw)
In-Reply-To: rzwvghd2r8h.fsf@wallaby.sanger.ac.uk

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|||
>    `-' `-'   `-' `-'   `-' `-'
>  -------------------------------------------------------------
>




      parent reply	other threads:[~2001-10-19  0:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]
read-only archive

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