+
+ } else if (smpi_cfg_shared_malloc == shmalloc_global) {
+ /* First reserve memory area */
+ mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+
+ xbt_assert(mem != MAP_FAILED, "Failed to allocate %luMiB of memory. Run \"sysctl vm.overcommit_memory=1\" as root "
+ "to allow big allocations.\n",
+ (unsigned long)(size >> 20));
+
+ /* Create bogus file if not done already */
+ 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). */
+ char* name = xbt_strdup("/tmp/simgrid-shmalloc-XXXXXX");
+ smpi_shared_malloc_bogusfile = mkstemp(name);
+ unlink(name);
+ free(name);
+ char* dumb = (char*)calloc(1, smpi_shared_malloc_blocksize);
+ ssize_t err = write(smpi_shared_malloc_bogusfile, dumb, smpi_shared_malloc_blocksize);
+ if(err<0)
+ xbt_die("Could not write bogus file for shared malloc");
+ free(dumb);
+ }
+
+ /* Map the bogus file in place of the anonymous memory */
+ unsigned int i;
+ for (i = 0; i < size / smpi_shared_malloc_blocksize; i++) {
+ void* pos = (void*)((unsigned long)mem + i * smpi_shared_malloc_blocksize);
+ 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?",
+ strerror(errno));
+ }
+ if (size % smpi_shared_malloc_blocksize) {
+ void* pos = (void*)((unsigned long)mem + i * smpi_shared_malloc_blocksize);
+ 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?",
+ strerror(errno));
+ }
+