Re: mmap with MAP_PRIVATE is useless

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: mmap with MAP_PRIVATE is useless

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:48:14

Paolo Bonzini [off-list ref] writes:
This means that MAP_PRIVATE is utterly useless.
I do not think we ever used MAP_PRIVATE in order to protect outselves from
uncontrolled changes made by the outside world in the first place.  Back
when most of these mmap calls were written by Linus and myself, we weren't
interested in using MAP_PRIVATE, or any other trick for that matter, to
deal with the case where the user tells git to go index a file, and then
mucks with the file before git finishes and gives back control.

We do use mmap in read-write mode when reading from the index file, and we
use MAP_PRIVATE to protect the outside world from our writing into the
mapped memory.  As far as I know that is the only mmap for which
MAP_PRIVATE matters in the core git codebase.

Our calls to mmap() almost all have MAP_PRIVATE, even for read-only mmap,
but that is more or less from inertia, aka "an existing call to mmap is
with these options, I'll add another call imitating that".

Re: mmap with MAP_PRIVATE is useless

From: Paolo Bonzini <hidden>
Date: 2016-06-15 22:48:14

On 02/14/2010 02:53 AM, Junio C Hamano wrote:
Back when most of these mmap calls were written by Linus and myself,
we weren't interested in using MAP_PRIVATE, or any other trick for
that matter, to deal with the case where the user tells git to go
index a file, and then mucks with the file before git finishes and
gives back control.
Eh, this one in particular (in index_fd) is quite ancient...

commit e83c5163316f89bfbde7d9ab23ca2e25604af290
Author: Linus Torvalds [off-list ref]
Date:   Thu Apr 7 15:13:13 2005 -0700

     Initial revision of "git", the information manager from hell

:-)

There were three mmap calls -- in read_sha1_file, read_cache and 
index_fd -- and all three were of the same mmap (NULL, st.st_size, 
PROT_READ, MAP_PRIVATE, fd, 0) shape.

Paolo
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help