Re: mremap() use is racy

2005-08-24 Thread Hugh Dickins
On Tue, 23 Aug 2005, Linus Torvalds wrote: > On Tue, 23 Aug 2005, Ulrich Drepper wrote: > > Linus Torvalds wrote: > > > > > > 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

Re: mremap() use is racy

2005-08-24 Thread Hugh Dickins
On Tue, 23 Aug 2005, Linus Torvalds wrote: On Tue, 23 Aug 2005, Ulrich Drepper wrote: Linus Torvalds wrote: 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.

Re: mremap() use is racy

2005-08-23 Thread Linus Torvalds
On Tue, 23 Aug 2005, Ulrich Drepper wrote: > > Linus Torvalds wrote: > > > > 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. > > If you guarantee this (and test for

Re: mremap() use is racy

2005-08-23 Thread Hugh Dickins
On Tue, 23 Aug 2005, Ulrich Drepper wrote: > Linus Torvalds wrote: > > 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

Re: mremap() use is racy

2005-08-23 Thread Ulrich Drepper
Linus Torvalds wrote: > 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. If you

Re: mremap() use is racy

2005-08-23 Thread Linus Torvalds
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

Re: mremap() use is racy

2005-08-23 Thread Ulrich Drepper
Hugh Dickins wrote: > If the app can plan ahead as you're proposing, why doesn't it just > mmap the maximum it might need, mprotect PROT_NONE the end it doesn't > need yet, then progressively re-mprotect parts to make them accessible > as needed? Because the underlying file isn't larger than the

Re: mremap() use is racy

2005-08-23 Thread Hugh Dickins
On Tue, 23 Aug 2005, Ulrich Drepper wrote: > > One possible solution would be to add a flag to mremap() which allows > mremap() to steal memory. In general that would be too dangerous but we > could limit it to private, anonymous mappings which have no access > permissions (i.e., PROT_NONE with

mremap() use is racy

2005-08-23 Thread Ulrich Drepper
Not the mremap() implementation itself, so don't worry. If mremap() is to be used without the MREMAP_MAYMOVE flag the call will only succeed of the address space after the block which is to be remapped is empty. This is rarely the case since there are many users of mmap and memory is allocated

mremap() use is racy

2005-08-23 Thread Ulrich Drepper
Not the mremap() implementation itself, so don't worry. If mremap() is to be used without the MREMAP_MAYMOVE flag the call will only succeed of the address space after the block which is to be remapped is empty. This is rarely the case since there are many users of mmap and memory is allocated

Re: mremap() use is racy

2005-08-23 Thread Hugh Dickins
On Tue, 23 Aug 2005, Ulrich Drepper wrote: One possible solution would be to add a flag to mremap() which allows mremap() to steal memory. In general that would be too dangerous but we could limit it to private, anonymous mappings which have no access permissions (i.e., PROT_NONE with

Re: mremap() use is racy

2005-08-23 Thread Ulrich Drepper
Hugh Dickins wrote: If the app can plan ahead as you're proposing, why doesn't it just mmap the maximum it might need, mprotect PROT_NONE the end it doesn't need yet, then progressively re-mprotect parts to make them accessible as needed? Because the underlying file isn't larger than the

Re: mremap() use is racy

2005-08-23 Thread Linus Torvalds
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.

Re: mremap() use is racy

2005-08-23 Thread Ulrich Drepper
Linus Torvalds wrote: 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. If you

Re: mremap() use is racy

2005-08-23 Thread Hugh Dickins
On Tue, 23 Aug 2005, Ulrich Drepper wrote: Linus Torvalds wrote: 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

Re: mremap() use is racy

2005-08-23 Thread Linus Torvalds
On Tue, 23 Aug 2005, Ulrich Drepper wrote: Linus Torvalds wrote: 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. If you guarantee this (and test for this) it's