Last active
September 20, 2020 12:26
-
-
Save azat/9770f751c3e7d2da5422cc1ca26339c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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
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
)