[Bf-blender-cvs] [282ad43] master: Memory allocation: do not use mmap for memory allocation on 64 bit.

Brecht Van Lommel noreply at git.blender.org
Thu Jan 23 01:15:46 CET 2014


Commit: 282ad434a8bca760372f98ceec8a15725bf30bd1
Author: Brecht Van Lommel
Date:   Thu Jan 23 01:08:37 2014 +0100
https://developer.blender.org/rB282ad434a8bca760372f98ceec8a15725bf30bd1

Memory allocation: do not use mmap for memory allocation on 64 bit.

On Windows we can only do mmap memory allocation up to 4 GB, which causes a
crash when doing very large renders on 64 bit systems with a lot of memory.

As far as I can tell the reason to use mmap is to get around address space
limitation on some 32 bit operating systems, and I can't see a reason to use
it on 64 bit. For the original explanation see here:
http://orange.blender.org/blog/stupid-memory-problems

Fixes T37841.

===================================================================

M	intern/guardedalloc/intern/mallocn_guarded_impl.c
M	intern/guardedalloc/intern/mallocn_lockfree_impl.c
M	intern/guardedalloc/intern/mmap_win.c

===================================================================

diff --git a/intern/guardedalloc/intern/mallocn_guarded_impl.c b/intern/guardedalloc/intern/mallocn_guarded_impl.c
index 92392ce..9aa140d 100644
--- a/intern/guardedalloc/intern/mallocn_guarded_impl.c
+++ b/intern/guardedalloc/intern/mallocn_guarded_impl.c
@@ -541,6 +541,12 @@ void *MEM_guarded_mapallocN(size_t len, const char *str)
 {
 	MemHead *memh;
 
+	/* on 64 bit, simply use calloc instead, as mmap does not support
+	 * allocating > 4 GB on Windows. the only reason mapalloc exists
+	 * is to get around address space limitations in 32 bit OSes. */
+	if(sizeof(void*) >= 8)
+		return MEM_lockfree_callocN(len, str);
+
 	len = SIZET_ALIGN_4(len);
 
 #if defined(WIN32)
diff --git a/intern/guardedalloc/intern/mallocn_lockfree_impl.c b/intern/guardedalloc/intern/mallocn_lockfree_impl.c
index 44f51a3..2c7c087 100644
--- a/intern/guardedalloc/intern/mallocn_lockfree_impl.c
+++ b/intern/guardedalloc/intern/mallocn_lockfree_impl.c
@@ -265,6 +265,12 @@ void *MEM_lockfree_mapallocN(size_t len, const char *str)
 {
 	MemHead *memh;
 
+	/* on 64 bit, simply use calloc instead, as mmap does not support
+	 * allocating > 4 GB on Windows. the only reason mapalloc exists
+	 * is to get around address space limitations in 32 bit OSes. */
+	if(sizeof(void*) >= 8)
+		return MEM_lockfree_callocN(len, str);
+
 	len = SIZET_ALIGN_4(len);
 
 #if defined(WIN32)
diff --git a/intern/guardedalloc/intern/mmap_win.c b/intern/guardedalloc/intern/mmap_win.c
index 3096c58..4f65c0a 100644
--- a/intern/guardedalloc/intern/mmap_win.c
+++ b/intern/guardedalloc/intern/mmap_win.c
@@ -129,6 +129,7 @@ void *mmap(void *UNUSED(start), size_t len, int prot, int flags, int fd, off_t o
 		}
 	}
 
+	/* note len is passed to a 32 bit DWORD, so can't be > 4 GB */
 	maphandle = CreateFileMapping(fhandle, NULL, prot_flags, 0, len, NULL);
 	if (maphandle == 0) {
 		errno = EBADF;




More information about the Bf-blender-cvs mailing list