Ulrich Hobelmann <u.hobelmann@web.de> wrote:
+---------------
| Rob Warnock wrote:
| > Ulrich Hobelmann <u.hobelmann@web.de> wrote:
| > +---------------
| > | mmap()ed files are also cached, no?
| > +---------------
| >
| > Not always. See the O_SYNC to "open()" on some OSes, e.g., Linux:
...
| But this only guarantees that any writes you did so far are made
| persistent. It says nothing about the pages still being in cache
| memory after you munmap() the region.
+---------------
Oh, sorry, you're correct. When opened O_SYNC and mmap'd MAP_SHARED,
the pages -- written or not -- *will* be cached [if there's sufficient
free memory]. One main case when this is not true is when a file has
been mmap'd MAP_PRIVATE. Then I think the modified pages would get tossed
immediately when the munmap() occurs, since the modified pages are no
longer accessible. [Unmodified pages would still be cached, of course.]
-Rob
p.s. Another exception: If you open("/dev/mem", O_RDWR | O_SYNC)
and then mmap() it MAP_SHARED, you'll actually get uncached loads
and stores to the underlying bus space. [I use this a lot for
hardware debugging!]
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607