From owner-freebsd-hackers Sun Dec 24 00:50:20 1995 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id AAA13864 for hackers-outgoing; Sun, 24 Dec 1995 00:50:20 -0800 (PST) Received: from pancake.remcomp.fr (root@pancake.remcomp.fr [194.51.30.1]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id AAA13809 for ; Sun, 24 Dec 1995 00:50:02 -0800 (PST) Received: from didier@aida (localhost [127.0.0.1]) by aida (8.6.12/8.6.9) with SMTP id QAA01458; Sat, 23 Dec 1995 16:51:31 +0100 Date: Sat, 23 Dec 1995 16:51:31 +0100 Message-ID: X-Mailer: XFMail 0.3-beta [p0] on FreeBSD Organization: My Own FreeBSD-2.1-STABLE Site Reply-To: didier@aida.org In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=us-ascii From: Didier Derny To: David Hovemeyer Subject: RE: mmap and memory utilization Cc: , David Hovemeyer Sender: owner-hackers@FreeBSD.ORG Precedence: bulk On 16-Dec-95 David Hovemeyer wrote: >>Howdy all, > >I am writing a program that needs to do a lot of character at >a time reading through regular files, both forwards and backwards. >I decided to use mmap(2) rather than read(2) to implement this. >My reasoning is that it is easier to do random access in memory >than in a file. Also, I imagine that calling read(2) for reading >single characters is inefficient in terms of system call overhead. >I could use iostreams (it's a C++ program) to get buffering of >reads, but iostreams are big and hairy, and still more awkward >to use than memory for what I want to do. > >What I am wondering is > > What is the impact of mmap'ing a large file and then > scanning linearly through it? > >Currently I am thinking of mmap'ing the entire file; if the file is >approximately as large as physical memory, will this cause excessive >paging? (I am assuming an infinite amount of virtual memory, >but a limited amount of physical memory.) Will the program degrade >the performance of other programs which are running? Would the mmap >be likely to fail? > >In most cases I expect the mmap'ed file to be small (< 16K), but >I want the program to be a "good citizen" under extreme conditions. >I'm pretty clueless about the details of virtual memory and how >it is implemented in FreeBSD. > >Hmm, I just noticed the madvise(2) man page: is this what I need >to use? Maybe I could say MADV_DONTNEED to pages scanned past, >and MADV_WILLNEED to pages about to be accessed? > >Any thoughts appreciated. > >Dave >-- >David Hovemeyer | aclawisaclawandnobodyhasseenatalking | http://infoco >daveho@infocom.com | clawunlessthatclawisthefamousMr.Klaw | m.com/~daveho > I usualy map 32 mb file almost everyday without any problem. I only have 16Mb of memory. I'm using strstr inside the mapped file to find substring. In fact I map 2 32 mb files at the same time -- 12/18/95 20:01:22 Didier Derny | My computer is Microsoft Free... didier@aida.org | Private FreeBSD 2.1-STABLE site.