Commit cb1fa5f8 authored by Sangmin Seo's avatar Sangmin Seo
Browse files

Add environment variables to control memory tracing overhead.



When the memory overhead for memory usage tracing is bigger than
the threshold value, a warning message is generated to indicate the
amount of the memory used in the tracing. Environment variables
to control the threshold value were added.

See #2068.
Signed-off-by: Pavan Balaji's avatarPavan Balaji <balaji@anl.gov>
parent 274a5a70
......@@ -24,7 +24,6 @@ void *MPL_trcalloc(size_t, size_t, int, const char[]);
void *MPL_trrealloc(void *, size_t, int, const char[]);
void *MPL_trstrdup(const char *, int, const char[]);
void MPL_TrSetMaxMem(size_t);
void MPL_TrSetMaxAlloc(size_t);
/* Make sure that FILE is defined */
#include <stdio.h>
......
......@@ -127,8 +127,8 @@ static int TRSetBytes = 0;
/* Used to keep track of allocations */
static volatile size_t TRMaxMem = 0;
static volatile int TRMaxMemId = 0;
static volatile size_t TRNumAlloc = 0;
static volatile size_t TRMaxAlloc = (size_t)2E6;
static volatile size_t TRCurOverhead = 0;
static volatile size_t TRMaxOverhead = 314572800;
/* Used to limit allocation */
static volatile size_t TRMaxMemAllow = 0;
......@@ -180,6 +180,11 @@ void MPL_trinit(int rank)
TRDefaultByte = 0;
TRFreedByte = 0;
}
s = getenv("MPICH_TRMEM_MAX_OVERHEAD");
if (s && *s) {
long l = atol(s);
TRMaxOverhead = (size_t)l;
}
s = getenv("MPL_TRMEM_INIT");
if (s && *s && (strcmp(s, "YES") == 0 || strcmp(s, "yes") == 0)) {
TRSetBytes = 1;
......@@ -198,6 +203,11 @@ void MPL_trinit(int rank)
int l = atoi(s);
TRlevel = l;
}
s = getenv("MPL_TRMEM_MAX_OVERHEAD");
if (s && *s) {
long l = atol(s);
TRMaxOverhead = (size_t)l;
}
}
......@@ -288,14 +298,13 @@ void *MPL_trmalloc(size_t a, int lineno, const char fname[])
world_rank, (long)a, (long)nsize, new, fname, lineno);
}
/* Warn the user about tracing overhead if the total number of memory
* allocation is larger than the threshold, TRMaxAlloc. */
TRNumAlloc++;
if (TRNumAlloc >= TRMaxAlloc) {
/* Warn the user about tracing overhead if the total memory overhead for
* tracing is larger than the threshold, TRMaxOverhead. */
TRCurOverhead += sizeof(TrSPACE);
if ((TRCurOverhead > TRMaxOverhead) && TRMaxOverhead) {
MPL_error_printf("[%d] %.1lf MB was used for memory usage tracing!\n",
world_rank,
(double)(sizeof(TrSPACE) * TRNumAlloc) / 1024 / 1024);
MPL_TrSetMaxAlloc((size_t)(TRMaxAlloc + 1E6));
world_rank, (double)TRCurOverhead / 1024 / 1024);
TRMaxOverhead = TRMaxOverhead * 2;
}
/* Without these macros valgrind actually catches far fewer errors when
......@@ -439,7 +448,7 @@ void MPL_trfree(void *a_ptr, int line, const char file[])
file, line);
}
TRNumAlloc--;
TRCurOverhead -= sizeof(TrSPACE);
/*
* Now, scrub the data (except possibly the first few ints) to
......@@ -1040,11 +1049,6 @@ void MPL_TrSetMaxMem(size_t size)
TRMaxMemAllow = size;
}
void MPL_TrSetMaxAlloc(size_t size)
{
TRMaxAlloc = size;
}
static void addrToHex(void *addr, char string[MAX_ADDRESS_CHARS])
{
int i;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment