57 #include <sys/types.h> 78 #define DEFAULT_MEMSIZE (4 * 1024 * 1024) 79 #define MIN_LOW_MEMSIZE (80 * 1024) 80 #define DEFAULT_PAGESIZE 4096 103 return (size + 7) & ~7L;
116 static int init_done = 0;
124 if ((ans = sysconf(_SC_PAGESIZE)) > 0) {
130 if (str !=
NULL && sscanf(str,
"%ld", &ans) == 1) {
135 if (str !=
NULL && sscanf(str,
"%ld", &ans) == 1) {
143 TMSG(MALLOC,
"%s: pagesize = %ld, memsize = %ld, " 144 "low memsize = %ld, extra mmap = %d",
163 prot = PROT_READ | PROT_WRITE;
166 #if defined(MAP_ANON) 167 flags = MAP_PRIVATE | MAP_ANON;
168 #elif defined(MAP_ANONYMOUS) 169 flags = MAP_PRIVATE | MAP_ANONYMOUS;
172 fd = open(
"/dev/zero", O_RDWR);
174 str = strerror(errno);
175 EMSG(
"%s: open /dev/null failed: %s", __func__, str);
180 addr = mmap(
NULL, size, prot, flags, fd, 0);
181 if (addr == MAP_FAILED) {
182 str = strerror(errno);
183 EMSG(
"%s: mmap failed: %s", __func__, str);
190 TMSG(MALLOC,
"%s: size = %ld, fd = %d, addr = %p",
191 __func__, size, fd, addr);
243 EMSG(
"%s: out of memory, shutting down sampling", __func__);
295 EMSG(
"%s: out of memory, shutting down sampling", __func__);
302 TMSG(MALLOC,
"%s: size = %ld, addr = %p", __func__, size, addr);
315 EMSG(
"%s: out of memory, shutting down sampling", __func__);
324 TMSG(MALLOC,
"%s: size = %ld, failure: no memstore",
332 if (addr <= mi->mi_low) {
333 TMSG(MALLOC,
"%s: size = %ld, failure: out of memory",
342 TMSG(MALLOC,
"%s: size = %ld, addr = %p", __func__, size, addr);
366 TMSG(MALLOC,
"%s: size = %ld, failure: temporary out of memory",
375 TMSG(MALLOC,
"%s: low on memory, setting epoch flush flag", __func__);
381 TMSG(MALLOC,
"%s: size = %ld, addr = %p", __func__, size, addr);
389 double meg = 1024.0 * 1024.0;
391 AMSG(
"MEMORY: segment size: %.1f meg, num segments: %ld, " 392 "total allocation: %.1f meg, reclaims: %ld",
395 AMSG(
"MEMORY: total freeable: %.1f meg, total non-freeable: %.1f meg, " 396 "malloc failures: %ld",
static void hpcrun_mem_init(void)
const char * HPCRUN_MEMSIZE
static long total_non_freeable
static int allow_extra_mmap
static long total_allocation
static long total_freeable
void hpcrun_memory_reinit(void)
static int out_of_mem_mesg
static size_t round_up(size_t size)
static void * hpcrun_mmap_anon(size_t size)
void hpcrun_make_memstore(hpcrun_meminfo_t *mi, int is_child)
static size_t hpcrun_align_pagesize(size_t size)
static void hpcrun_disable_sampling(void)
const char * HPCRUN_LOW_MEMSIZE
void * hpcrun_malloc_freeable(size_t size)
void hpcrun_reclaim_freeable_mem(void)
void * hpcrun_malloc(size_t size)
static size_t low_memsize
void hpcrun_memory_summary(void)