On 1/11/12 9:10 PM, Balbir Singh wrote:
Define MAP_UNINITIALIZED - are you referring to not zeroing out pages
before handing them down? Is this safe even between threads.
If it doesn't work for an app, it shouldn't be asking for this behavior
via an mmap flag?
Only calloc() specifies that the returned memory will be zero'ed. There
is no such guarantee for malloc().
+#define VM_UNINITIALIZED VM_SAO /* Steal a powerpc bit for now, since we're out
+ bits for 32 bit archs */
Without proper checks if it can be re-used?
Yeah - this is a complete hack. I'm trying to convince people that this
is a viable idea, before asking for a vm_flags bit.
Microbenchmark data:
# time -p ./test2
real 7.60
user 0.78
sys 6.81
# time -p ./test2 xx
real 4.40
user 0.78
sys 3.62
# cat test2.c
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <stdint.h>
#define MMAP_SIZE (20 * 1024 * 1024)
#define PAGE_SIZE 4096
#define MAP_UNINITIALIZED 0x4000000
main(int argc, char *argv[])
{
void *addr, *naddr;
char *p, *end, val;
int flag = 0;
int i;
if (argc > 1) {
flag = MAP_UNINITIALIZED;
}
addr = mmap(NULL, MMAP_SIZE, PROT_READ|PROT_WRITE,
flag | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (addr == MAP_FAILED) {
perror("mmap");
exit(-1);
}
end = (char *) addr + MMAP_SIZE;
for (i = 0; i < 1000; i++) {
int ret;
ret = madvise(addr, MMAP_SIZE, MADV_DONTNEED);
if (ret == -1)
perror("madvise");
for (p = (char *) addr; p < end; p += PAGE_SIZE) {
*p = 0xAB;
}
}
}
-Arun
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>