Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Jul 1999 22:17:23 -0700 (PDT)
From:      Matthew Dillon <dillon@apollo.backplane.com>
To:        "Kelly Yancey" <kbyanc@alcnet.com>
Cc:        <freebsd-hackers@FreeBSD.ORG>
Subject:   Re: mmap question
Message-ID:  <199907060517.WAA79921@apollo.backplane.com>
References:   <000101bec73c$e20e3660$291c453f@kbyanc.alcnet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
:  Which is fine and dandy, I'll just stat() the file to get the filesize and
:mmap() it. But what happens in someone comes along and replaces the file
:with
:a larger file? I understand that my view of the file will change to the new
:file, but only the length that I mmap()ed originally. Do I have to
:periodically stat() the file to determine if I need to re-mmap() it should
:the file size change? And if so, doesn't that partly diminish the usefulness
:of mmap()? I mean, sure you can edit the file as a file and they are
:reflected in the in-memory image, but how many edits don't change the file
:size?

    You can mmap() an area that is larger then the file.  For example, you
    could mmap a 100 bytes file into a 32MB area.  If the file then
    grows, you can access the new data up to the amount of space you
    reserved.  However, accessing pages beyond the file EOF via the mmap() 
    will result in a segfault.  This is also true if a file is truncated 
    out from under you - previously valid data pages will disappear.

    If you mmap() the exact size of a file and the file grows, you have to
    mmap() the new area of the file or unmap the old area and remap the 
    entire file to gain access to the additional data.  You can mmap() areas 
    of a file in a piecemeal fashion though this should not be taken to 
    extremes since it will slow down page-fault handling.

    Most programs using mmap() use it on files which are not expected to 
    change out from under the program's control.  Thus most programs using
    mmap() simply map the file's full size and do not try to do anything
    fancy.

:  Kelly
: ~kbyanc@posi.net~

					-Matt
					Matthew Dillon 
					<dillon@backplane.com>


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199907060517.WAA79921>