How to set `opt.narenas` for jemalloc in code?

63 views Asked by At

Except of the ways of ln -s 'narenas:xxx' /etc/malloc.conf and export MALLOC_CONF=narenas:xxx, I want to set narenas in my code. I use mallcnt like this:

unsigned new_arena_num = 64;
size_t sz = sizeof(new_arena_num);
int res = mallctl("arenas.narenas", NULL, NULL, &new_arena_num, sz);

However, res != 0 and failed. What's wrong ?

1

There are 1 answers

0
Bouncner On BEST ANSWER

narenas cannot be written.

The jemalloc documentation (http://jemalloc.net/jemalloc.3.html) states the option as follows: opt.narenas (unsigned) r-

The read write flags (in this case r-) indicate that this value can only be read, not written. background_threads on the other hand has rw flags.