diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-10-10 15:58:01 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-10-10 15:58:01 +0400 |
commit | 4bd40372769e9ebf078dadb0442366176e8990e6 (patch) | |
tree | f2b9aef273590b809a658df2072987261e96633c /source | |
parent | 77a0b90cdf5d42b774f75b392aa0e3aeb7ed3452 (diff) |
Lock-free memory allocator
Release builds will now use lock-free allocator by
default without any internal locks happening.
MemHead is also reduces to as minimum as it's possible.
It still need to be size_t stored in a MemHead in order
to make us keep track on memory we're requesting from
the system, not memory which system is allocating. This
is probably also faster than using a malloc's usable
size function.
Lock-free guarded allocator will say you whether all
the blocks were freed, but wouldn't give you a list
of unfreed blocks list. To have such a list use a
--debug or --debug-memory command line arguments.
Debug builds does have the same behavior as release
builds. This is so tools like valgrind are not
screwed up by guarded allocator as they're currently
are.
--
svn merge -r59941:59942 -r60072:60073 -r60093:60094 \
-r60095:60096 ^/branches/soc-2013-depsgraph_mt
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/makesdna/intern/CMakeLists.txt | 7 | ||||
-rw-r--r-- | source/blender/makesdna/intern/SConscript | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/CMakeLists.txt | 7 | ||||
-rw-r--r-- | source/blender/makesrna/intern/SConscript | 2 | ||||
-rw-r--r-- | source/creator/creator.c | 43 |
5 files changed, 43 insertions, 18 deletions
diff --git a/source/blender/makesdna/intern/CMakeLists.txt b/source/blender/makesdna/intern/CMakeLists.txt index cae607949a9..317141b14e3 100644 --- a/source/blender/makesdna/intern/CMakeLists.txt +++ b/source/blender/makesdna/intern/CMakeLists.txt @@ -40,6 +40,8 @@ blender_include_dirs( set(SRC makesdna.c ../../../../intern/guardedalloc/intern/mallocn.c + ../../../../intern/guardedalloc/intern/mallocn_guarded_impl.c + ../../../../intern/guardedalloc/intern/mallocn_lockfree_impl.c ) if(WIN32 AND NOT UNIX) @@ -50,11 +52,6 @@ endif() # SRC_DNA_INC is defined in the parent dir -# for mallocn.c -if (WITH_GUARDEDALLOC) - add_definitions(-DWITH_GUARDEDALLOC) -endif() - add_executable(makesdna ${SRC} ${SRC_DNA_INC}) # Output dna.c diff --git a/source/blender/makesdna/intern/SConscript b/source/blender/makesdna/intern/SConscript index 7c3af30ee83..35b4ff262ed 100644 --- a/source/blender/makesdna/intern/SConscript +++ b/source/blender/makesdna/intern/SConscript @@ -36,8 +36,6 @@ cflags = '' defines = [] root_build_dir=normpath(env['BF_BUILDDIR']) -defines.append('WITH_GUARDEDALLOC') - source_files = ['makesdna.c'] header_files = env.Glob('../*.h') diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index 9554941ec1f..3d710917e3d 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -137,6 +137,8 @@ set(SRC ${DEFSRC} ${APISRC} ../../../../intern/guardedalloc/intern/mallocn.c + ../../../../intern/guardedalloc/intern/mallocn_guarded_impl.c + ../../../../intern/guardedalloc/intern/mallocn_lockfree_impl.c ../../../../intern/guardedalloc/intern/mmap_win.c ) @@ -253,11 +255,6 @@ if(WITH_BULLET) add_definitions(-DWITH_BULLET) endif() -# for mallocn.c -if (WITH_GUARDEDALLOC) - add_definitions(-DWITH_GUARDEDALLOC) -endif() - # Build makesrna executable blender_include_dirs( . diff --git a/source/blender/makesrna/intern/SConscript b/source/blender/makesrna/intern/SConscript index 10b6a8c8d10..e1fad55f485 100644 --- a/source/blender/makesrna/intern/SConscript +++ b/source/blender/makesrna/intern/SConscript @@ -150,8 +150,6 @@ if env['WITH_BF_INTERNATIONAL']: if not env['BF_DEBUG']: defs.append('NDEBUG') -defs.append('WITH_GUARDEDALLOC') - makesrna_tool.Append(CPPDEFINES=defs) makesrna_tool.Append (CPPPATH = Split(incs)) diff --git a/source/creator/creator.c b/source/creator/creator.c index a3bce79b6e7..1596fe5359c 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -300,6 +300,7 @@ static int print_help(int UNUSED(argc), const char **UNUSED(argv), void *data) #ifdef WITH_LIBMV BLI_argsPrintArgDoc(ba, "--debug-libmv"); #endif + BLI_argsPrintArgDoc(ba, "--debug-memory"); BLI_argsPrintArgDoc(ba, "--debug-jobs"); BLI_argsPrintArgDoc(ba, "--debug-python"); @@ -439,6 +440,12 @@ static int debug_mode_libmv(int UNUSED(argc), const char **UNUSED(argv), void *U } #endif +static int debug_mode_memory(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data)) +{ + MEM_set_memory_debug(); + return 0; +} + static int set_debug_value(int argc, const char **argv, void *UNUSED(data)) { if (argc > 1) { @@ -1384,6 +1391,7 @@ static void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle) #ifdef WITH_LIBMV BLI_argsAdd(ba, 1, NULL, "--debug-libmv", "\n\tEnable debug messages from libmv library", debug_mode_libmv, NULL); #endif + BLI_argsAdd(ba, 1, NULL, "--debug-memory", "\n\tEnable fully guarded memory allocation and debugging", debug_mode_memory, NULL); BLI_argsAdd(ba, 1, NULL, "--debug-value", "<value>\n\tSet debug value of <value> on startup\n", set_debug_value, NULL); BLI_argsAdd(ba, 1, NULL, "--debug-jobs", "\n\tEnable time profiling for background jobs.", debug_mode_generic, (void *)G_DEBUG_JOBS); @@ -1454,23 +1462,50 @@ int main(int argc, const char **UNUSED(argv_c)) /* Do not mess with const */ int main(int argc, const char **argv) #endif { - bContext *C = CTX_create(); + bContext *C; SYS_SystemHandle syshandle; #ifndef WITH_PYTHON_MODULE bArgs *ba; #endif -#ifdef WIN32 +#ifdef WIN32 /* Win32 Unicode Args */ + /* NOTE: cannot use guardedalloc malloc here, as it's not yet initialised + * (it depends on the args passed in, which is what we're getting here!) + */ wchar_t **argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc); + char **argv = malloc(argc * sizeof(char *)); int argci = 0; - char **argv = MEM_mallocN(argc * sizeof(char *), "argv array"); + for (argci = 0; argci < argc; argci++) { argv[argci] = alloc_utf_8_from_16(argv_16[argci], 0); } + LocalFree(argv_16); #endif + /* NOTE: Special exception for guarded allocator type switch: + * we need to perform switch from lock-free to fully + * guarded allocator before any allocation happened. + */ + { + int i; + for (i = 0; i < argc; i++) { + if (STREQ(argv[i], "--debug") || STREQ(argv[i], "-d") || + STREQ(argv[i], "--debug-memory")) + { + printf("Switching to fully guarded memory allocator.\n"); + MEM_use_guarded_allocator(); + break; + } + else if (STREQ(argv[i], "--")) { + break; + } + } + } + + C = CTX_create(); + #ifdef WITH_PYTHON_MODULE #ifdef __APPLE__ environ = *_NSGetEnviron(); @@ -1641,7 +1676,7 @@ int main(int argc, const char **argv) while (argci) { free(argv[--argci]); } - MEM_freeN(argv); + free(argv); argv = NULL; #endif |