X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0e8887add35541e0413f219dd6174b33b7237578..bf165065929ff669867aa4820dd92e1cd6b16f26:/src/smpi/smpi_shared.cpp diff --git a/src/smpi/smpi_shared.cpp b/src/smpi/smpi_shared.cpp index f15a847b28..f8033fdfe3 100644 --- a/src/smpi/smpi_shared.cpp +++ b/src/smpi/smpi_shared.cpp @@ -33,7 +33,7 @@ * \ | | * ---- */ -#include +#include #include "private.h" #include "private.hpp" @@ -117,7 +117,7 @@ typedef struct { shared_data_key_type* data; } shared_metadata_t; -std::unordered_map allocs_metadata; +std::map allocs_metadata; xbt_dict_t calls = nullptr; /* Allocated on first use */ #ifndef WIN32 static int smpi_shared_malloc_bogusfile = -1; @@ -212,6 +212,8 @@ void *smpi_shared_malloc(size_t size, const char *file, int line) if (smpi_shared_malloc_bogusfile == -1) { /* Create a fd to a new file on disk, make it smpi_shared_malloc_blocksize big, and unlink it. * It still exists in memory but not in the file system (thus it cannot be leaked). */ + smpi_shared_malloc_blocksize = static_cast(xbt_cfg_get_double("smpi/shared-malloc-blocksize")); + XBT_DEBUG("global shared allocation. Blocksize %lu", smpi_shared_malloc_blocksize); char* name = xbt_strdup("/tmp/simgrid-shmalloc-XXXXXX"); smpi_shared_malloc_bogusfile = mkstemp(name); unlink(name); @@ -230,7 +232,8 @@ void *smpi_shared_malloc(size_t size, const char *file, int line) void* res = mmap(pos, smpi_shared_malloc_blocksize, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED | MAP_POPULATE, smpi_shared_malloc_bogusfile, 0); xbt_assert(res == pos, "Could not map folded virtual memory (%s). Do you perhaps need to increase the " - "STARPU_MALLOC_SIMULATION_FOLD environment variable or the sysctl vm.max_map_count?", + "size of the mapped file using --cfg=smpi/shared-malloc-blocksize=newvalue (default 1048576) ?" + "You can also try using the sysctl vm.max_map_count", strerror(errno)); } if (size % smpi_shared_malloc_blocksize) { @@ -238,7 +241,8 @@ void *smpi_shared_malloc(size_t size, const char *file, int line) void* res = mmap(pos, size % smpi_shared_malloc_blocksize, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED | MAP_POPULATE, smpi_shared_malloc_bogusfile, 0); xbt_assert(res == pos, "Could not map folded virtual memory (%s). Do you perhaps need to increase the " - "STARPU_MALLOC_SIMULATION_FOLD environment variable or the sysctl vm.max_map_count?", + "size of the mapped file using --cfg=smpi/shared-malloc-blocksize=newvalue (default 1048576) ?" + "You can also try using the sysctl vm.max_map_count", strerror(errno)); } @@ -258,15 +262,19 @@ void *smpi_shared_malloc(size_t size, const char *file, int line) return mem; } -int smpi_is_shared(void*ptr){ +int smpi_is_shared(void* ptr){ + if (allocs_metadata.empty()) + return 0; if ( smpi_cfg_shared_malloc == shmalloc_local || smpi_cfg_shared_malloc == shmalloc_global) { - if (allocs_metadata.count(ptr) != 0) - return 1; - for(auto it : allocs_metadata){ - if (ptr >= it.first && ptr < (char*)it.first + it.second.size) - return 1; - } + auto low = allocs_metadata.lower_bound(ptr); + if (low->first==ptr) + return 1; + if (low == allocs_metadata.begin()) return 0; + low --; + if (ptr < (char*)low->first + low->second.size) + return 1; + return 0; } else { return 0; }