2003-03-31 14:29:51

by Kenny Simpson

[permalink] [raw]
Subject: mmap-related questions

Greetings! I hate to ask this type of questions here,
but having searched the list and googling, I have
found no good answers, so here goes..

If I use mmap to give me a sliding window view onto a
file (mmap/munmap/mmap or mremap), how can I sync all
unmapped memory associated with the file?

I read from Stevens that "the call to munmap does not
cause the contents of the mapped region to be written
to the disk file.", but I don't want to pay the
penalty of doing many msync()'s each time I move my
window.
I tested that fsync() does not seem to sync pages that
were mapped with mmap. Is there some way to sync all
data associated with the file? Is there a way which
is also portable to Solaris 2.6?

Thanks,
-Kenny

BTW: I'm using 2.4.7 (RH enterprise)


__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com


2003-03-31 17:44:27

by Benjamin LaHaise

[permalink] [raw]
Subject: Re: mmap-related questions

On Mon, Mar 31, 2003 at 06:41:10AM -0800, Kenny Simpson wrote:
> I tested that fsync() does not seem to sync pages that
> were mapped with mmap. Is there some way to sync all
> data associated with the file? Is there a way which
> is also portable to Solaris 2.6?

No. You must use msync(). Note that fsync() after munmap() will flush the
pages to disk under Linux.

> BTW: I'm using 2.4.7 (RH enterprise)

2.4.7 is way out of date and should be updated for the numerous bugfixes and
security errata.

-ben

2003-04-01 03:14:26

by Kenny Simpson

[permalink] [raw]
Subject: Re: mmap-related questions

--- Benjamin LaHaise <[email protected]> wrote:
> No. You must use msync().

> Note that fsync() after
> munmap() will flush the
> pages to disk under Linux.
Sweet! Paydirt! Is this documented/guaranteed to
continue to work for a while?
Is this true for all non-mmap()ed dirty buffers for a
given file?

Just to restate what you said:
- if part of a file is mmap()ed, msync() MUST be used
to sync it.
- any non-mmap()ed portions are synched with fsync().

I'm assuming this is a per-process thing. i.e. The
above is true regardless of what other processes are
doing (e.g. even if another process has the same file
mmap()'d, I don't care).

> 2.4.7 is way out of date and should be updated for
> the numerous bugfixes and
> security errata.
I know. Unfortunately not my call. Desperately
trying to beat people with clue sticks....

Thanks!,
-Kenny

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
http://platinum.yahoo.com