From owner-freebsd-hackers Sat Dec 16 10:20:06 1995 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id KAA22239 for hackers-outgoing; Sat, 16 Dec 1995 10:20:06 -0800 (PST) Received: from infocom.com (tye.infocom.com [199.120.185.1]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id KAA22202 for ; Sat, 16 Dec 1995 10:20:02 -0800 (PST) Received: (from daveho@localhost) by infocom.com (8.6.12/8.6.12) id NAA13722; Sat, 16 Dec 1995 13:16:40 -0500 Date: Sat, 16 Dec 1995 13:16:39 -0500 (EST) From: David Hovemeyer To: hackers@freebsd.org cc: David Hovemeyer Subject: mmap and memory utilization Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-hackers@freebsd.org Precedence: bulk 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