From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,e55b9780504fa95e X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2001-10-18 17:59:48 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sunqbc.risq.qc.ca!nf3.bellglobal.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!nntp3.aus1.giganews.com!bin2.nnrp.aus1.giganews.com.POSTED!not-for-mail From: "Bill Todd" Newsgroups: comp.unix.tru64 References: Subject: Re: mmap for fast file access? Organization: (note new email address) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Message-ID: NNTP-Posting-Date: Thu, 18 Oct 2001 19:59:31 CDT X-Trace: sv3-a9fG1oLxDDM8SRiKMphtZ22tcnJLWEvFVdaYOThBAhYrQKCLD5tKvpcjIgLD0HFw6f8iRLhzpgtT1r+!7hsJOgt+RCnhYBOj+DEpxz9BJ/fU0xDXVDpptQSYRdeMV2kt+f5K0FqzMymZJ/Ol2vCZsXHupCZw!Bi2ggcxIaV4HgGjHmIUFU/jKLQ== X-Complaints-To: abuse@GigaNews.Com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-Info: Please be sure to forward a copy of ALL headers X-Abuse-Info: Otherwise we will be unable to process your complaint properly Date: Fri, 19 Oct 2001 00:59:31 GMT Xref: archiver1.google.com comp.unix.tru64:5424 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 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||| > `-' `-' `-' `-' `-' `-' > ------------------------------------------------------------- >