void chpl_mem_layerInit(void) { void* heap_base_; size_t heap_size_; chpl_comm_desired_shared_heap(&heap_base_, &heap_size_); if (heap_base_ != NULL && heap_size_ == 0) { chpl_internal_error("if heap address is specified, size must be also"); } // If we have a shared heap, initialize our shared heap. This will take care // of initializing jemalloc. If we're not using a shared heap, do a first // allocation to allow jemaloc to set up: // // jemalloc 4.0.4 man: "Once, when the first call is made to one of the // memory allocation routines, the allocator initializes its internals" if (heap_base_ != NULL) { heap_base = heap_base_; heap_size = heap_size_; cur_heap_offset = 0; if (pthread_mutex_init(&chunk_alloc_lock, NULL) != 0) { chpl_internal_error("cannot init chunk_alloc lock"); } initializeSharedHeap(); } else { void* p; if ((p = je_malloc(1)) == NULL) { chpl_internal_error("cannot init heap: je_malloc() failed"); } je_free(p); } }
void chpl_mem_layerInit(void) { void* start; size_t size; chpl_comm_desired_shared_heap(&start, &size); if (start || size) chpl_error("set CHPL_MEM to a more appropriate mem type", 0, 0); }
void chpl_mem_layerInit(void) { chpl_comm_desired_shared_heap(&saved_heap_start, &saved_heap_size); if (!saved_heap_start || !saved_heap_size) { chpl_dlmalloc_heap = create_mspace(0, 1); } else { chpl_dlmalloc_heap = create_mspace_with_base(saved_heap_start, saved_heap_size, 1); } }
void chpl_mem_layerInit(void) { void* heap_base; size_t heap_size; chpl_comm_desired_shared_heap(&heap_base, &heap_size); if (heap_base == NULL || heap_size == 0) chpl_dlmalloc_heap = create_mspace(0, 1); else chpl_dlmalloc_heap = create_mspace_with_base(heap_base, heap_size, 1); }
void chpl_mem_layerInit(void) { void* heap_base; size_t heap_size; chpl_comm_desired_shared_heap(&heap_base, &heap_size); if (heap_base != NULL && heap_size == 0) chpl_internal_error("if heap address is specified, size must be also"); // // Do a first allocation, to allow tcmalloc to set up its internal // management structures. // { void* p; if ((p = tc_malloc(1)) == NULL) chpl_internal_error("cannot init heap: tc_malloc() failed"); tc_free(p); } // // Initialize our tcmalloc system allocator. // tcmallocChapelInit_c(heap_base, heap_size); // // If the heap has to come from the memory supplied to us (say, in // order that the comm layer be able to depend on all allocations // having come from it), use up all the system memory tcmalloc had // acquired before we set up our own system allocator just now. // All allocations after this will come from the memory supplied // to us. // // Note that this can waste up to twice INITIAL_USE_UP_SIZE bytes // of the memory supplied to us, plus overhead. // if (heap_base != NULL) { #define INITIAL_USE_UP_SIZE ((size_t) 4 * 1024) size_t size; char* p; for (size = INITIAL_USE_UP_SIZE; size > 0; size /= 2) { do { p = tc_malloc(size); } while (p != NULL && (p < (char*) heap_base || p > (char*) heap_base + heap_size)); #undef INITIAL_USE_UP_SIZE } } }
void chpl_mem_layerInit(void) { void* start; size_t size; chpl_comm_desired_shared_heap(&start, &size); // // TODO (EJR 12/17/15): add support for shared heaps. I think we basically // need to create a custom chunk allocator. // // HPX-5 did this so I think we can too: // http://jemalloc-discuss.canonware.narkive.com/FzSQ4Qv4/need-help-in-porting-jemalloc // // http://www.canonware.com/pipermail/jemalloc-discuss/2015-October/001179.html // // TODO (EJR 12/17/15): when we support shared heaps, I need to remember to // update the third-party README // if (start || size) chpl_error("set CHPL_MEM to a more appropriate mem type", 0, 0); // // Do a first allocation, to allow jemalloc to set up: // // """ // Once, when the first call is made to one of the memory allocation // routines, the allocator initializes its internals based in part on various // options that can be specified at compile- or run-time. // """ // { void* p; if ((p = je_malloc(1)) == NULL) chpl_internal_error("cannot init heap: je_malloc() failed"); je_free(p); } }