Re: mremap() use is racy

From: Linus Torvalds
Date: Tue Aug 23 2005 - 16:28:34 EST




On Tue, 23 Aug 2005, Ulrich Drepper wrote:
>
> Using mmap with a too-large size for the underlying file and then hoping
> that future file growth is magically handled when those pages are
> accessed is not valid.

Actually, it should be pretty much as valid as using mremap - ie it works
on Linux.

Especially if you use MAP_SHARED, you don't even need to mprotect
anything: you'll get a nice SIGBUS if you ever try to access past the last
page that maps the file.

I think that works correctly for any half-way modern kernel - anything
that has mremap() should do the right thing (I think older kernels would
map zero pages past the end of the file mapping, and then if you touched
the page first, you'd lose the coherency).

Linus
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/