From owner-freebsd-hackers@FreeBSD.ORG Mon Sep 8 16:25:40 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 54D9A16A4BF for ; Mon, 8 Sep 2003 16:25:40 -0700 (PDT) Received: from priv-edtnes51.telusplanet.net (defout.telus.net [199.185.220.240]) by mx1.FreeBSD.org (Postfix) with ESMTP id 209D843FE5 for ; Mon, 8 Sep 2003 16:25:39 -0700 (PDT) (envelope-from sh@bel.bc.ca) Received: from antalus ([154.5.106.237]) by priv-edtnes51.telusplanet.net (InterMail vM.5.01.05.17 201-253-122-126-117-20021021) with SMTP id <20030908223400.BMAW22247.priv-edtnes51.telusplanet.net@antalus> for ; Mon, 8 Sep 2003 16:34:00 -0600 Message-ID: <001c01c37659$4d38f090$0300000a@antalus> From: "Sean Hamilton" To: Date: Mon, 8 Sep 2003 15:32:16 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Subject: mmap(2) questions, reads not caching X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Sep 2003 23:25:40 -0000 I have some code resembling: FILE * f = fopen (filename, "rb"); mmap (NULL, st.st_size, PROT_READ, MAP_PRIVATE, fileno (f), 0); I've found that reads are not brought into disk cache. Successive reads on the same file once again read from disk. If I cat the file to /dev/null, then the mmap(2) does indeed read the data from cache. What's going on here? Also, the man page states that the mapped region may be longer than the specified size. Does this have any implications for the size which is passed to munmap(2)? If I pass the same size to munmap(2), then will there still be leftover, or will the entire region be unmapped? And, should I be passing MAP_PRIVATE or MAP_SHARED to read-only mmaps? Does it make any difference at all? Running 5.1-RELEASE.