Skip to content

Commit

Permalink
Merge pull request #4506 from sysown/v2.x-jemalloc_defaults
Browse files Browse the repository at this point in the history
Change default jemalloc conf enabling 'prof_accum' by default
  • Loading branch information
renecannao authored Apr 21, 2024
2 parents ea477ab + 9894621 commit fc065c1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,18 @@ ifeq ($(TEST_WITHASAN),1)
WASAN += -DTEST_WITHASAN
endif

NOJEMALLOC := $(shell echo $(NOJEMALLOC))
ifeq ($(NOJEMALLOC),1)
NOJEM=-DNOJEM
else
NOJEM=
endif

MYCXXFLAGS := $(STDCPP)
ifeq ($(CXX),clang++)
MYCXXFLAGS += -fuse-ld=lld
endif
MYCXXFLAGS += $(IDIRS) $(OPTZ) $(DEBUG) $(PSQLCH) -DGITVERSION=\"$(GIT_VERSION)\" $(WGCOV) $(WASAN)
MYCXXFLAGS += $(IDIRS) $(OPTZ) $(DEBUG) $(PSQLCH) -DGITVERSION=\"$(GIT_VERSION)\" $(NOJEM) $(WGCOV) $(WASAN)


STATICMYLIBS := -Wl,-Bstatic -lconfig -lproxysql -ldaemon -lconfig++ -lre2 -lpcrecpp -lpcre -lmariadbclient -lhttpserver -lmicrohttpd -linjection -lcurl -lssl -lcrypto -lev
Expand Down
58 changes: 56 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ static volatile int load_;
//#else
//const char *malloc_conf = "xmalloc:true,lg_tcache_max:16,purge:decay";
#ifndef __FreeBSD__
const char *malloc_conf = "xmalloc:true,lg_tcache_max:16,prof:true,prof_leak:true,lg_prof_sample:20,lg_prof_interval:30,prof_active:false";
const char *malloc_conf = "xmalloc:true,lg_tcache_max:16,prof:true,prof_accum:true,prof_leak:true,lg_prof_sample:20,lg_prof_interval:30,prof_active:false";
#endif
//#endif /* DEBUG */
//const char *malloc_conf = "prof_leak:true,lg_prof_sample:0,prof_final:true,xmalloc:true,lg_tcache_max:16";
Expand Down Expand Up @@ -1859,7 +1859,7 @@ void handleProcessRestart() {
// Calculate wait time using exponential backoff
int waitTime = 1 << restartAttempts;
parent_open_error_log();
proxy_info("ProxySQL exited after only %d seconds , below the %d seconds threshold. Restarting attempt %d\n", elapsed_seconds, EXECUTION_THRESHOLD, restartAttempts);
proxy_info("ProxySQL exited after only %ld seconds , below the %d seconds threshold. Restarting attempt %d\n", elapsed_seconds, EXECUTION_THRESHOLD, restartAttempts);
proxy_info("Angel process is waiting %d seconds before starting a new ProxySQL process\n", waitTime);
parent_close_error_log();

Expand Down Expand Up @@ -1902,7 +1902,61 @@ void handleProcessRestart() {
} while (pid > 0);
}

#ifndef NOJEM
int print_jemalloc_conf() {
int rc = 0;

bool xmalloc = 0;
bool prof_accum = 0;
bool prof_leak = 0;

size_t lg_cache_max = 0;
size_t lg_prof_sample = 0;
size_t lg_prof_interval = 0;

size_t bool_sz = sizeof(bool);
size_t size_sz = sizeof(size_t);
size_t ssize_sz = sizeof(ssize_t);

rc = mallctl("config.xmalloc", &xmalloc, &bool_sz, NULL, 0);
if (rc) { proxy_error("Failed to fetch 'config.xmalloc' with error %d", rc); return rc; }

rc = mallctl("opt.lg_tcache_max", &lg_cache_max, &size_sz, NULL, 0);
if (rc) { proxy_error("Failed to fetch 'opt.lg_tcache_max' with error %d", rc); return rc; }

rc = mallctl("opt.prof_accum", &prof_accum, &bool_sz, NULL, 0);
if (rc) { proxy_error("Failed to fetch 'opt.prof_accum' with error %d", rc); return rc; }

rc = mallctl("opt.prof_leak", &prof_leak, &bool_sz, NULL, 0);
if (rc) { proxy_error("Failed to fetch 'opt.prof_leak' with error %d", rc); return rc; }

rc = mallctl("opt.lg_prof_sample", &lg_prof_sample, &size_sz, NULL, 0);
if (rc) { proxy_error("Failed to fetch 'opt.lg_prof_sample' with error %d", rc); return rc; }

rc = mallctl("opt.lg_prof_interval", &lg_prof_interval, &ssize_sz, NULL, 0);
if (rc) { proxy_error("Failed to fetch 'opt.lg_prof_interval' with error %d", rc); return rc; }

proxy_info(
"Using jemalloc with MALLOC_CONF:"
" config.xmalloc:%d, lg_tcache_max:%lu, opt.prof_accum:%d, opt.prof_leak:%d,"
" opt.lg_prof_sample:%lu, opt.lg_prof_interval:%lu, rc:%d\n",
xmalloc, lg_cache_max, prof_accum, prof_leak, lg_prof_sample, lg_prof_interval, rc
);

return 0;
}
#else
int print_jemalloc_conf() {
return 0;
}
#endif

int main(int argc, const char * argv[]) {
// Output current jemalloc conf; no action taken when disabled
{
int rc = print_jemalloc_conf();
if (rc) { exit(EXIT_FAILURE); }
}

{
MYSQL *my = mysql_init(NULL);
Expand Down

0 comments on commit fc065c1

Please sign in to comment.