[Bf-blender-cvs] [120e9924c17] master: Cleanup: remove legacy mmap memory allocation for 32 bit

Brecht Van Lommel noreply at git.blender.org
Wed May 20 01:07:28 CEST 2020


Commit: 120e9924c177c7a8fde06b9c5eca98e4e2a19180
Author: Brecht Van Lommel
Date:   Wed May 20 00:24:26 2020 +0200
Branches: master
https://developer.blender.org/rB120e9924c177c7a8fde06b9c5eca98e4e2a19180

Cleanup: remove legacy mmap memory allocation for 32 bit

This helped to go beyond the 4GB limit, but is no longer relevant for 64 bit.

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

M	intern/guardedalloc/MEM_guardedalloc.h
M	intern/guardedalloc/intern/mallocn.c
M	intern/guardedalloc/intern/mallocn_guarded_impl.c
M	intern/guardedalloc/intern/mallocn_intern.h
M	intern/guardedalloc/intern/mallocn_lockfree_impl.c
M	source/blender/blenkernel/intern/tracking_util.c
M	source/blender/compositor/operations/COM_VectorBlurOperation.cpp
M	source/blender/editors/render/render_internal.c
M	source/blender/editors/sculpt_paint/sculpt_undo.c
M	source/blender/editors/space_image/image_undo.c
M	source/blender/editors/space_info/info_stats.c
M	source/blender/freestyle/intern/application/Controller.cpp
M	source/blender/imbuf/intern/allocimbuf.c
M	source/blender/imbuf/intern/cache.c
M	source/blender/imbuf/intern/divers.c
M	source/blender/imbuf/intern/openexr/openexr_api.cpp
M	source/blender/render/intern/source/pipeline.c
M	source/blender/render/intern/source/render_result.c

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

diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h
index d5b109ee59f..f4fcebf6811 100644
--- a/intern/guardedalloc/MEM_guardedalloc.h
+++ b/intern/guardedalloc/MEM_guardedalloc.h
@@ -145,14 +145,6 @@ extern void *(*MEM_mallocN_aligned)(size_t len,
                                     const char *str) /* ATTR_MALLOC */ ATTR_WARN_UNUSED_RESULT
     ATTR_ALLOC_SIZE(1) ATTR_NONNULL(3);
 
-/**
- * Same as callocN, clears memory and uses mmap (disk cached) if supported.
- * Can be free'd with MEM_freeN as usual.
- * */
-extern void *(*MEM_mapallocN)(size_t len,
-                              const char *str) /* ATTR_MALLOC */ ATTR_WARN_UNUSED_RESULT
-    ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2);
-
 /** Print a list of the names and sizes of all allocated memory
  * blocks. as a python dict for easy investigation */
 extern void (*MEM_printmemlist_pydict)(void);
@@ -183,13 +175,8 @@ extern void (*MEM_set_lock_callback)(void (*lock)(void), void (*unlock)(void));
 /** Attempt to enforce OSX (or other OS's) to have malloc and stack nonzero */
 extern void (*MEM_set_memory_debug)(void);
 
-/**
- * Memory usage stats
- * - MEM_get_memory_in_use is all memory
- * - MEM_get_mapped_memory_in_use is a subset of all memory */
+/** Memory usage stats. */
 extern size_t (*MEM_get_memory_in_use)(void);
-/** Get mapped memory usage. */
-extern size_t (*MEM_get_mapped_memory_in_use)(void);
 /** Get amount of memory blocks in use. */
 extern unsigned int (*MEM_get_memory_blocks_in_use)(void);
 
diff --git a/intern/guardedalloc/intern/mallocn.c b/intern/guardedalloc/intern/mallocn.c
index d24437c85f2..82a8aa3eb21 100644
--- a/intern/guardedalloc/intern/mallocn.c
+++ b/intern/guardedalloc/intern/mallocn.c
@@ -48,7 +48,6 @@ void *(*MEM_malloc_arrayN)(size_t len, size_t size, const char *str) = MEM_lockf
 void *(*MEM_mallocN_aligned)(size_t len,
                              size_t alignment,
                              const char *str) = MEM_lockfree_mallocN_aligned;
-void *(*MEM_mapallocN)(size_t len, const char *str) = MEM_lockfree_mapallocN;
 void (*MEM_printmemlist_pydict)(void) = MEM_lockfree_printmemlist_pydict;
 void (*MEM_printmemlist)(void) = MEM_lockfree_printmemlist;
 void (*MEM_callbackmemlist)(void (*func)(void *)) = MEM_lockfree_callbackmemlist;
@@ -59,7 +58,6 @@ void (*MEM_set_lock_callback)(void (*lock)(void),
                               void (*unlock)(void)) = MEM_lockfree_set_lock_callback;
 void (*MEM_set_memory_debug)(void) = MEM_lockfree_set_memory_debug;
 size_t (*MEM_get_memory_in_use)(void) = MEM_lockfree_get_memory_in_use;
-size_t (*MEM_get_mapped_memory_in_use)(void) = MEM_lockfree_get_mapped_memory_in_use;
 unsigned int (*MEM_get_memory_blocks_in_use)(void) = MEM_lockfree_get_memory_blocks_in_use;
 void (*MEM_reset_peak_memory)(void) = MEM_lockfree_reset_peak_memory;
 size_t (*MEM_get_peak_memory)(void) = MEM_lockfree_get_peak_memory;
@@ -111,7 +109,6 @@ void MEM_use_guarded_allocator(void)
   MEM_mallocN = MEM_guarded_mallocN;
   MEM_malloc_arrayN = MEM_guarded_malloc_arrayN;
   MEM_mallocN_aligned = MEM_guarded_mallocN_aligned;
-  MEM_mapallocN = MEM_guarded_mapallocN;
   MEM_printmemlist_pydict = MEM_guarded_printmemlist_pydict;
   MEM_printmemlist = MEM_guarded_printmemlist;
   MEM_callbackmemlist = MEM_guarded_callbackmemlist;
@@ -121,7 +118,6 @@ void MEM_use_guarded_allocator(void)
   MEM_set_lock_callback = MEM_guarded_set_lock_callback;
   MEM_set_memory_debug = MEM_guarded_set_memory_debug;
   MEM_get_memory_in_use = MEM_guarded_get_memory_in_use;
-  MEM_get_mapped_memory_in_use = MEM_guarded_get_mapped_memory_in_use;
   MEM_get_memory_blocks_in_use = MEM_guarded_get_memory_blocks_in_use;
   MEM_reset_peak_memory = MEM_guarded_reset_peak_memory;
   MEM_get_peak_memory = MEM_guarded_get_peak_memory;
diff --git a/intern/guardedalloc/intern/mallocn_guarded_impl.c b/intern/guardedalloc/intern/mallocn_guarded_impl.c
index f601609c6e0..8aa9fc767dd 100644
--- a/intern/guardedalloc/intern/mallocn_guarded_impl.c
+++ b/intern/guardedalloc/intern/mallocn_guarded_impl.c
@@ -104,7 +104,7 @@ typedef struct MemHead {
   const char *name;
   const char *nextname;
   int tag2;
-  short mmap;      /* if true, memory was mmapped */
+  short pad1;
   short alignment; /* if non-zero aligned alloc was used
                     * and alignment is stored here.
                     */
@@ -187,7 +187,7 @@ static const char *check_memlist(MemHead *memh);
 /* --------------------------------------------------------------------- */
 
 static unsigned int totblock = 0;
-static size_t mem_in_use = 0, mmap_in_use = 0, peak_mem = 0;
+static size_t mem_in_use = 0, peak_mem = 0;
 
 static volatile struct localListBase _membase;
 static volatile struct localListBase *membase = &_membase;
@@ -320,10 +320,8 @@ void *MEM_guarded_dupallocN(const void *vmemh)
     memh--;
 
 #ifndef DEBUG_MEMDUPLINAME
-    if (UNLIKELY(memh->mmap))
-      newp = MEM_guarded_mapallocN(memh->len, "dupli_mapalloc");
-    else if (LIKELY(memh->alignment == 0))
-      newp = MEM_guarded_mapallocN(memh->len, "dupli_mapalloc");
+    if (LIKELY(memh->alignment == 0))
+      newp = MEM_guarded_mallocN(memh->len, "dupli_alloc");
     else
       newp = MEM_guarded_mallocN_aligned(memh->len, (size_t)memh->alignment, "dupli_alloc");
 
@@ -334,11 +332,7 @@ void *MEM_guarded_dupallocN(const void *vmemh)
       MemHead *nmemh;
       char *name = malloc(strlen(memh->name) + 24);
 
-      if (UNLIKELY(memh->mmap)) {
-        sprintf(name, "%s %s", "dupli_mapalloc", memh->name);
-        newp = MEM_guarded_mapallocN(memh->len, name);
-      }
-      else if (LIKELY(memh->alignment == 0)) {
+      if (LIKELY(memh->alignment == 0)) {
         sprintf(name, "%s %s", "dupli_alloc", memh->name);
         newp = MEM_guarded_mallocN(memh->len, name);
       }
@@ -478,7 +472,7 @@ static void make_memhead_header(MemHead *memh, size_t len, const char *str)
   memh->name = str;
   memh->nextname = NULL;
   memh->len = len;
-  memh->mmap = 0;
+  memh->pad1 = 0;
   memh->alignment = 0;
   memh->tag2 = MEMTAG2;
 
@@ -646,58 +640,6 @@ void *MEM_guarded_calloc_arrayN(size_t len, size_t size, const char *str)
   return MEM_guarded_callocN(total_size, str);
 }
 
-/* note; mmap returns zero'd memory */
-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_guarded_callocN(len, str);
-
-  len = SIZET_ALIGN_4(len);
-
-#if defined(WIN32)
-  /* our windows mmap implementation is not thread safe */
-  mem_lock_thread();
-#endif
-  memh = mmap(NULL,
-              len + sizeof(MemHead) + sizeof(MemTail),
-              PROT_READ | PROT_WRITE,
-              MAP_SHARED | MAP_ANON,
-              -1,
-              0);
-#if defined(WIN32)
-  mem_unlock_thread();
-#endif
-
-  if (memh != (MemHead *)-1) {
-    make_memhead_header(memh, len, str);
-    memh->mmap = 1;
-    atomic_add_and_fetch_z(&mmap_in_use, len);
-    mem_lock_thread();
-    peak_mem = mmap_in_use > peak_mem ? mmap_in_use : peak_mem;
-    mem_unlock_thread();
-#ifdef DEBUG_MEMCOUNTER
-    if (_mallocn_count == DEBUG_MEMCOUNTER_ERROR_VAL)
-      memcount_raise(__func__);
-    memh->_count = _mallocn_count++;
-#endif
-    return (++memh);
-  }
-  else {
-    print_error(
-        "Mapalloc returns null, fallback to regular malloc: "
-        "len=" SIZET_FORMAT " in %s, total %u\n",
-        SIZET_ARG(len),
-        str,
-        (unsigned int)mmap_in_use);
-    return MEM_guarded_callocN(len, str);
-  }
-}
-
 /* Memory statistics print */
 typedef struct MemPrintBlock {
   const char *name;
@@ -765,7 +707,7 @@ void MEM_guarded_printmemlist_stats(void)
     pb++;
 
 #ifdef USE_MALLOC_USABLE_SIZE
-    if (!membl->mmap && membl->alignment == 0) {
+    if (membl->alignment == 0) {
       mem_in_use_slop += (sizeof(MemHead) + sizeof(MemTail) + malloc_usable_size((void *)membl)) -
                          membl->len;
     }
@@ -1098,27 +1040,13 @@ static void rem_memblock(MemHead *memh)
     free((char *)memh->name);
 #endif
 
-  if (memh->mmap) {
-    atomic_sub_and_fetch_z(&mmap_in_use, memh->len);
-#if defined(WIN32)
-    /* our windows mmap implementation is not thread safe */
-    mem_lock_thread();
-#endif
-    if (munmap(memh, memh->len + sizeof(MemHead) + sizeof(MemTail)))
-      printf("Couldn't unmap memory %s\n", memh->name);
-#if defined(WIN32)
-    mem_unlock_thread();
-#endif
+  if (UNLIKELY(malloc_debug_memset && memh->len))
+    memset(memh + 1, 255, memh->len);
+  if (LIKELY(memh->alignment == 0)) {
+    free(memh);
   }
   else {
-    if (UNLIKELY(malloc_debug_memset && memh->len))
-      memset(memh + 1, 255, memh->len);
-    if (LIKELY(memh->alignment == 0)) {
-      free(memh);
-    }
-    else {
-      aligned_free(MEMHEAD_REAL_PTR(memh));
-    }
+    aligned_free(MEMHEAD_REAL_PTR(memh));
   }
 }
 
@@ -1270,17 +1198,6 @@ size_t MEM_guarded_get_memory_in_use(void)
   return _mem_in_use;
 }
 
-size_t MEM_guarded_get_mapped_memory_in_use(void)
-{
-  size_t _mmap_in_use;
-
-  mem_lock_thread();
-  _mmap_in_use = mmap_in_use;
-  mem_unlock_thread();
-
-  return _mmap_in_use;
-}
-
 unsigned int MEM_guarded_get_memory_blocks_in_use(void)
 {
   unsigned int _totblock;
diff --git a/intern/guardedalloc/intern/mallocn_intern.h b/intern/guardedalloc/intern/mallocn_intern.h
index 876607fdb77..6e8c580e0ad 100644
--- a/intern/guardedalloc/intern/mallocn_intern.h
+++ b/intern/guardedalloc/intern/mallocn_intern.h
@@ -24,13 +24,6 @@
 #ifndef __MALLOCN_INTERN_H__
 #define __MALLOCN_INTERN_H__
 
-/* mmap exception */
-#if defined(WIN32)
-#  include "mmap_win.h"
-#else
-#  include <sys/mman.h>
-#endif
-
 #ifdef __GNUC__
 #  define UNUSED(x) UNUSED_##x __attribute__((__unused__))
 #else
@@ -140,9 +133,6 @@ void *MEM_lockfree_mallocN_aligned(size_t len,
                                    size_t alignment,
                                    const char *UNUSED(str)) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
     ATTR_ALLOC_SIZE(1) ATTR_NONNULL(3);
-void *MEM_lockfree_mapa

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list