auto res = allocs.insert(std::make_pair(loc, shared_data_t()));
auto data = res.first;
if (res.second) {
- // The insertion did not take place.
+ // The new element was inserted.
// Generate a shared memory name from the address of the shared_data:
char shmname[32]; // cannot be longer than PSHMNAMLEN = 31 on Mac OS X (shm_open raises ENAMETOOLONG otherwise)
snprintf(shmname, 31, "/shmalloc%p", &*data);
void* smpi_shared_malloc_partial(size_t size, size_t* shared_block_offsets, int nb_shared_blocks)
{
- char *huge_page_mount_point = xbt_cfg_get_string("smpi/shared-malloc-hugepage");
- bool use_huge_page = huge_page_mount_point[0] != '\0';
+ std::string huge_page_mount_point = xbt_cfg_get_string("smpi/shared-malloc-hugepage");
+ bool use_huge_page = not huge_page_mount_point.empty();
#ifndef MAP_HUGETLB /* If the system header don't define that mmap flag */
xbt_assert(not use_huge_page,
"Huge pages are not available on your system, you cannot use the smpi/shared-malloc-hugepage option.");
* We cannot use a same file for the two type of calls, since the first one needs to be
* opened in a hugetlbfs mount point whereas the second needs to be a "classical" file. */
if(use_huge_page && smpi_shared_malloc_bogusfile_huge_page == -1) {
- char* huge_page_filename = bprintf("%s/simgrid-shmalloc-XXXXXX", huge_page_mount_point);
- smpi_shared_malloc_bogusfile_huge_page = mkstemp(huge_page_filename);
- XBT_DEBUG("bogusfile_huge_page: %s\n", huge_page_filename);
- unlink(huge_page_filename);
- xbt_free(huge_page_filename);
+ std::string huge_page_filename = huge_page_mount_point + "/simgrid-shmalloc-XXXXXX";
+ smpi_shared_malloc_bogusfile_huge_page = mkstemp((char*)huge_page_filename.c_str());
+ XBT_DEBUG("bogusfile_huge_page: %s\n", huge_page_filename.c_str());
+ unlink(huge_page_filename.c_str());
}
if(smpi_shared_malloc_bogusfile == -1) {
char name[] = "/tmp/simgrid-shmalloc-XXXXXX";
"stop_offset (%zu) should be lower than its successor start offset (%zu)", stop_offset, shared_block_offsets[2*i_block+2]);
size_t start_block_offset = ALIGN_UP(start_offset, smpi_shared_malloc_blocksize);
size_t stop_block_offset = ALIGN_DOWN(stop_offset, smpi_shared_malloc_blocksize);
- for (unsigned block_id=0, i = start_block_offset / smpi_shared_malloc_blocksize; i < stop_block_offset / smpi_shared_malloc_blocksize; block_id++, i++) {
- XBT_DEBUG("\t\tglobal shared allocation, mmap block offset %u", block_id);
- void* pos = (void*)((unsigned long)mem + i * smpi_shared_malloc_blocksize);
+ for (size_t offset = start_block_offset; offset < stop_block_offset; offset += smpi_shared_malloc_blocksize) {
+ XBT_DEBUG("\t\tglobal shared allocation, mmap block offset %zx", offset);
+ void* pos = (void*)((unsigned long)mem + offset);
void* res = mmap(pos, smpi_shared_malloc_blocksize, PROT_READ | PROT_WRITE, mmap_flag,
huge_fd, 0);
xbt_assert(res == pos, "Could not map folded virtual memory (%s). Do you perhaps need to increase the "