cosmopolitan/libc/isystem
Justine Tunney 3609f65de3
Make malloc() go 200x faster
If pthread_create() is linked into the binary, then the cosmo runtime
will create an independent dlmalloc arena for each core. Whenever the
malloc() function is used it will index `g_heaps[sched_getcpu() / 2]`
to find the arena with the greatest hyperthread / numa locality. This
may be configured via an environment variable. For example if you say
`export COSMOPOLITAN_HEAP_COUNT=1` then you can restore the old ways.
Your process may be configured to have anywhere between 1 - 128 heaps

We need this revision because it makes multithreaded C++ applications
faster. For example, an HTTP server I'm working on that makes extreme
use of the STL went from 16k to 2000k requests per second, after this
change was made. To understand why, try out the malloc_test benchmark
which calls malloc() + realloc() in a loop across many threads, which
sees a a 250x improvement in process clock time and 200x on wall time

The tradeoff is this adds ~25ns of latency to individual malloc calls
compared to MODE=tiny, once the cosmo runtime has transitioned into a
fully multi-threaded state. If you don't need malloc() to be scalable
then cosmo provides many options for you. For starters the heap count
variable above can be set to put the process back in single heap mode
plus you can go even faster still, if you include tinymalloc.inc like
many of the programs in tool/build/.. are already doing since that'll
shave tens of kb off your binary footprint too. Theres also MODE=tiny
which is configured to use just 1 plain old dlmalloc arena by default

Another tradeoff is we need more memory now (except in MODE=tiny), to
track the provenance of memory allocation. This is so allocations can
be freely shared across threads, and because OSes can reschedule code
to different CPUs at any time.
2024-06-05 02:02:14 -07:00
..
__algorithm Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__atomic Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__bit Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__charconv Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__chrono Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__compare Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__concepts Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__condition_variable Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__coroutine Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__debug_utils Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__exception Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__expected Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__filesystem Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__format Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__functional Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__fwd Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__ios Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__iterator Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__locale_dir/locale_base_api Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__mdspan Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__memory Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__memory_resource Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__mutex Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__numeric Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__pstl/internal Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__random Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__ranges Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__stop_token Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__string Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__support Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__system_error Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__thread Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__tuple Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__type_traits Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__utility Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__variant Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
arpa Add libresolv from Musl Libc 2023-12-08 20:04:10 -08:00
experimental Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
ext Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
linux Reduce header complexity 2023-11-28 14:39:42 -08:00
net Get us closer to building busybox 2023-06-18 04:13:45 -07:00
netinet libc headers: make <complex.h> work, add struct ipv6_mreq (#1100) 2024-02-05 17:22:56 -05:00
sys Run clang-format (#1197) 2024-06-01 16:30:43 -04:00
__assert Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__availability Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__bit_reference Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__config Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__config_site Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__debug Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__hash_table Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__locale Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__mbstate_t.h Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__node_handle Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__pstl_algorithm Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__pstl_config_site Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__pstl_memory Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__pstl_numeric Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__split_buffer Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__std_mbstate_t.h Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__threading_support Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__tree Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__undef_macros Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
__verbose_abort Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
alloca.h Remove some dead code 2023-07-03 02:48:29 -07:00
ammintrin.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00
ar.h Remove some dead code 2023-07-03 02:48:29 -07:00
arm_acle.h Fix some more issues 2023-09-21 11:41:42 -07:00
arm_bf16.h Fix some more issues 2023-09-21 11:41:42 -07:00
arm_fp16.h Fix some more issues 2023-09-21 11:41:42 -07:00
arm_neon.h Fix some more issues 2023-09-21 11:41:42 -07:00
assert.h Further improve fatcosmocc 2023-08-13 01:51:39 -07:00
barrier Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
byteswap.h Clean up more code 2023-06-18 01:00:05 -07:00
clzerointrin.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00
complex.h Clean up more code 2023-06-18 01:00:05 -07:00
concepts Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
coroutine Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
cosmo.h Make malloc() go 200x faster 2024-06-05 02:02:14 -07:00
cpio.h Clean up more code 2023-06-18 01:00:05 -07:00
cpuid.h Clean up more code 2023-06-18 01:00:05 -07:00
crypt.h Clean up more code 2023-06-18 01:00:05 -07:00
ctype.h Clean up more code 2023-06-18 01:00:05 -07:00
cuchar Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
cxxabi.h Run clang-format (#1197) 2024-06-01 16:30:43 -04:00
dirent.h Clean up more code 2023-06-18 01:00:05 -07:00
dlfcn.h Introduce dlopen() support 2023-11-03 06:37:18 -07:00
elf.h Clean up more code 2023-06-18 01:00:05 -07:00
emmintrin.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00
endian.h Clean up more code 2023-06-18 01:00:05 -07:00
err.h Clean up more code 2023-06-18 01:00:05 -07:00
errno.h Clean up more code 2023-06-18 01:00:05 -07:00
expected Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
fcntl.h Clean up more code 2023-06-18 01:00:05 -07:00
features.h Walk back most uses of __STRICT_ANSI__ 2024-02-27 04:09:49 -08:00
fenv.h Clean up more code 2023-06-18 01:00:05 -07:00
float.h Clean up more code 2023-06-18 01:00:05 -07:00
fnmatch.h Clean up more code 2023-06-18 01:00:05 -07:00
format Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
ftw.h Run clang-format (#1197) 2024-06-01 16:30:43 -04:00
getopt.h Fix getopt again 2023-08-15 20:06:19 -07:00
glob.h Clean up more code 2023-06-18 01:00:05 -07:00
grp.h Clean up more code 2023-06-18 01:00:05 -07:00
iconv.h Clean up more code 2023-06-18 01:00:05 -07:00
ifaddrs.h Introduce getifaddrs() 2023-11-02 08:33:03 -07:00
immintrin.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00
inttypes.h Clean up more code 2023-06-18 01:00:05 -07:00
iso646.h Clean up more code 2023-06-18 01:00:05 -07:00
langinfo.h Clean up more code 2023-06-18 01:00:05 -07:00
latch Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
libcxx.imp Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
libgen.h Implement more toolchain fixes 2023-06-18 05:39:31 -07:00
limits.h Clean up more code 2023-06-18 01:00:05 -07:00
link.h Add <link.h> for absl 2023-12-08 20:04:10 -08:00
locale.h Clean up more code 2023-06-18 01:00:05 -07:00
malloc.h Clean up more code 2023-06-18 01:00:05 -07:00
math.h Clean up more code 2023-06-18 01:00:05 -07:00
mdspan Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
memory.h Clean up more code 2023-06-18 01:00:05 -07:00
memory_resource Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
mm3dnow.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00
mm_malloc.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00
mmintrin.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00
mntent.h Make some foss compatibility improvements 2022-10-14 13:59:34 -07:00
module.modulemap Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
monetary.h Greatly expand system() shell code features 2022-10-11 21:30:31 -07:00
mwaitxintrin.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00
netdb.h libc headers: make <complex.h> work, add struct ipv6_mreq (#1100) 2024-02-05 17:22:56 -05:00
nl_types.h Fold LIBC_UNICODE into LIBC_STR 2022-08-13 08:42:32 -07:00
nmmintrin.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00
nsync.h Add *NSYNC to libc/isystem 2022-09-13 01:47:12 -07:00
nsync_atomic.h Add *NSYNC to libc/isystem 2022-09-13 01:47:12 -07:00
nsync_counter.h Add *NSYNC to libc/isystem 2022-09-13 01:47:12 -07:00
nsync_cv.h Add *NSYNC to libc/isystem 2022-09-13 01:47:12 -07:00
nsync_debug.h Add *NSYNC to libc/isystem 2022-09-13 01:47:12 -07:00
nsync_mu.h Add *NSYNC to libc/isystem 2022-09-13 01:47:12 -07:00
nsync_mu_wait.h Add *NSYNC to libc/isystem 2022-09-13 01:47:12 -07:00
nsync_note.h Add *NSYNC to libc/isystem 2022-09-13 01:47:12 -07:00
nsync_once.h Add *NSYNC to libc/isystem 2022-09-13 01:47:12 -07:00
nsync_time.h Add *NSYNC to libc/isystem 2022-09-13 01:47:12 -07:00
nsync_waiter.h Add *NSYNC to libc/isystem 2022-09-13 01:47:12 -07:00
numbers Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
omp-tools.h Fine tune OpenMP some more 2024-01-30 06:30:24 -08:00
omp.h Fine tune OpenMP some more 2024-01-30 06:30:24 -08:00
ompx.h Fine tune OpenMP some more 2024-01-30 06:30:24 -08:00
paths.h Initial import 2020-06-15 07:18:57 -07:00
pmmintrin.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00
poll.h Improve cosmo's conformance to libc-test 2022-10-10 17:52:41 -07:00
popcntintrin.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00
pthread.h Improve cosmo's conformance to libc-test 2022-10-10 17:52:41 -07:00
pty.h Introduce forkpty() 2023-11-28 19:59:57 -08:00
pwd.h Fix isystem headers including wrong files (#108) 2021-03-06 21:06:29 -08:00
ranges Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
regex.h Initial import 2020-06-15 07:18:57 -07:00
resolv.h Add libresolv from Musl Libc 2023-12-08 20:04:10 -08:00
sched.h Improve cosmo's conformance to libc-test 2022-10-10 17:52:41 -07:00
search.h Add tsearch from Musl Libc (#912) 2023-10-15 16:50:54 -07:00
semaphore Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
semaphore.h Add posix semaphores support 2022-10-14 09:21:02 -07:00
setjmp.h Clean up more code 2023-06-18 01:00:05 -07:00
sgxintrin.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00
shadow.h Import /etc/shadow support from Musl for Linux 2023-12-07 16:26:04 -08:00
signal.h Simplify cosmocc builds (#863) 2023-07-23 11:11:08 -07:00
smmintrin.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00
source_location Upgrade to 2022-era LLVM LIBCXX 2024-05-27 02:12:27 -07:00
spawn.h Make improvements 2023-09-18 21:04:47 -07:00
stdalign.h Clean up more code 2023-06-18 01:00:05 -07:00
stdarg.h Make the Windows Console work better 2023-09-07 18:27:22 -07:00
stdatomic.h Clean up more code 2023-06-18 01:00:05 -07:00
stdbool.h Make fatcosmocc good enough to build ncurses 6.4 2023-08-12 22:30:05 -07:00
stdc-predef.h Initial import 2020-06-15 07:18:57 -07:00
stdckdint.h Clean up more code 2023-06-18 01:00:05 -07:00
stddef.h Clean up more code 2023-06-18 01:00:05 -07:00
stdint.h Clean up more code 2023-06-18 01:00:05 -07:00
stdio.h Clean up some code 2023-11-16 17:31:07 -08:00
stdio_ext.h Clean up more code 2023-06-18 01:00:05 -07:00
stdlib.h Don't include <crypt.h> from <stdlib.h> (#1112) 2024-02-23 07:18:35 -08:00
stdnoreturn.h Clean up more code 2023-06-18 01:00:05 -07:00
string.h Clean up more code 2023-06-18 01:00:05 -07:00
strings.h Clean up more code 2023-06-18 01:00:05 -07:00
syscall.h Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
sysexits.h Clean up more code 2023-06-18 01:00:05 -07:00
syslog.h Clean up more code 2023-06-18 01:00:05 -07:00
termios.h Clean up more code 2023-06-18 01:00:05 -07:00
tgmath.h Run clang-format (#1197) 2024-06-01 16:30:43 -04:00
threads.h Add much of C11 threads.h API 2024-04-28 07:04:08 -07:00
time.h Implement proper time zone support 2024-05-04 23:06:37 -07:00
tinygetopt.h Introduce #include <tinygetopt.h> 2024-05-29 10:11:17 -07:00
tmmintrin.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00
uchar.h Add more missing C / C++ headers 2022-09-04 04:53:52 -07:00
ucontext.h Changes made for cosmocc builds (#908) 2023-10-09 14:39:02 -07:00
uio.h Improve isystem includes and magic numbers 2021-08-14 23:36:36 -07:00
unistd.h Implement proper time zone support 2024-05-04 23:06:37 -07:00
unwind.h Make improvements 2024-01-29 16:31:58 -08:00
utime.h Implement proper time zone support 2024-05-04 23:06:37 -07:00
utmp.h Clean up more code 2023-06-18 01:00:05 -07:00
utmpx.h Clean up more code 2023-06-18 01:00:05 -07:00
wait.h Clean up more code 2023-06-18 01:00:05 -07:00
wchar.h Implement proper time zone support 2024-05-04 23:06:37 -07:00
wctype.h Clean up more code 2023-06-18 01:00:05 -07:00
windowsesque.h Resurrect <windows.h> as <windowsesque.h> 2024-02-21 16:41:11 -08:00
winternl.h Drop support for Windows 8 2024-05-29 19:37:47 -07:00
wmmintrin.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00
x86intrin.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00
xmmintrin.h Add Intel intrinsics headers 2023-04-27 05:44:38 -07:00