/** | |
* Reproducer for percpu_arena jemalloc issue [1]. | |
* Requires debug jemalloc (w/o NDEBUG to include assert()s) | |
* | |
* [1]: https://github.com/jemalloc/jemalloc/pull/1676 | |
* | |
* $ gcc -g3 -o /tmp/sched /tmp/sched.c | |
* $ MALLOC_CONF=percpu_arena:percpu LD_PRELOAD=jemalloc/build/lib/libjemalloc.so taskset --cpu-list 3 /tmp/sched | |
* <jemalloc>: ../src/jemalloc.c:321: Failed assertion: "ind <= narenas_total_get()" | |
* Aborted (core dumped) | |
*/ | |
#define _GNU_SOURCE | |
#include <sched.h> | |
#include <assert.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
int main() | |
{ | |
cpu_set_t set; | |
int err; | |
err = sched_getaffinity(0, sizeof(set), &set); | |
assert(!err); | |
printf("sched_getcpu() = %i\n", sched_getcpu()); | |
printf("sched_getaffinity() = %i\n", CPU_COUNT(&set)); | |
printf("_SC_NPROCESSORS_ONLN = %i\n", sysconf(_SC_NPROCESSORS_ONLN)); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
No
sched_setaffinity()
, since you can have different number of CPUs, if it will not hit theassert()
then change the cpu intaskset
(or you have non-debug jemalloc, i.e. w/NDEBUG
)