Unless I'm misunderstanding something, anonymously mmapped memory is
always zeroed by the kernel and this memset call is therefore redundant.
Best,
Michael
Index: rrl.c
Unless I'm misunderstanding something, anonymously mmapped memory is
always zeroed by the kernel and this memset call is therefore redundant.
Best,
Michael
Index: rrl.c
a message of 24 lines which said:
Unless I'm misunderstanding something, anonymously mmapped memory is
always zeroed by the kernel
This is written in Linux mmap man page:
its contents are initialized to zero
But not in FreeBSD mmap man page:
MAP_ANON Map anonymous memory not associated with any specific
file. The file descriptor used for creating MAP_ANON
must be -1. The offset argument must be 0.
So, portability seems to require mmset.
Stephane Bortzmeyer wrote:
a message of 24 lines which said:
> Unless I'm misunderstanding something, anonymously mmapped memory is
> always zeroed by the kernelThis is written in Linux mmap man page:
> its contents are initialized to zero
But not in FreeBSD mmap man page:
> MAP_ANON Map anonymous memory not associated with any specific
> file. The file descriptor used for creating MAP_ANON
> must be -1. The offset argument must be 0.So, portability seems to require mmset.
I know that OpenBSD zeroes anonymously mmapped pages. This assumption is
used throughout the codebase, but it isn't mentioned in the man page
(see below).
I just looked at FreeBSD code. It seems that it also zeroes and that
core code depends on that. For example, see pages_map() called through
chunk_alloc_mmap_slow() in jemalloc. Interestingly, I also found some
apparently needless memset() calls elsewhere.
It seems that software that uses anonymous mmapping often depends on it
being zeroed, so there isn't much of a choice. For example, both
jemalloc and Firefox contain the idiom of using VirtualAlloc (which
zeroes) on Windows and anonymous mmapping on Unix.
Regardless, remember that this memory is coming from the kernel. If it
weren't zeroed, it would be likely to contain sensitive memory from the
kernel or other processes. I've been told that that's why it doesn't
appear in the OpenBSD man page: it's considered implied.
New upcoming POSIX will standardize mmap(MAP_ANON),
which says that zero-filling is mandatory:
http://austingroupbugs.net/view.php?id=850
I agree to do memset(0) until new standard prevails, too.
It doesn't. If anything, it is a bug in the FreeBSD man page.
Joerg