cosmopolitan/libc/log
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
..
addr2linepath.c Improve crash backtrace reliability 2024-05-07 18:10:28 -07:00
appendresourcereport.c Run clang-format (#1197) 2024-06-01 16:30:43 -04:00
appendresourcereport.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
attachdebugger.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
backtrace.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
backtrace2.c Improve backtraces 2024-05-30 15:23:11 -07:00
backtrace3.c Document __demangle() and fix a const func ptr bug 2024-06-02 04:15:48 -07:00
bsd.h Reduce header complexity 2023-11-28 14:39:42 -08:00
BUILD.mk Implement proper time zone support 2024-05-04 23:06:37 -07:00
check.h Reduce header complexity 2023-11-28 14:39:42 -08:00
checkaligned.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
checkfail.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
checkfail_ndebug.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
color.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
commandvenv.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
countbranch.h Run clang-format (#1197) 2024-06-01 16:30:43 -04:00
countbranch_data.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
countbranch_report.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
countexpr.h Reduce header complexity 2023-11-28 14:39:42 -08:00
countexpr_data.S Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
countexpr_report.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
cxaprintexits.c Rename _bsr/_bsf to bsr/bsf 2024-03-04 17:33:26 -08:00
die.c Make improvements 2024-02-12 10:23:00 -08:00
err.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
flogf.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
gdb.h Run clang-format (#1197) 2024-06-01 16:30:43 -04:00
gdbexec.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
gdbpath.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
gdbsync.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
getcallername.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
getcallername.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
internal.h Favor siginfo_t over struct siginfo 2024-05-28 02:34:17 -07:00
leaks.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
libfatal.internal.h Run clang-format (#1197) 2024-06-01 16:30:43 -04:00
log.h Run clang-format (#1197) 2024-06-01 16:30:43 -04:00
log_exit.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
log_get_errno.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
log_retrace.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
log_set_errno.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
log_untrace.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
logerrno.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
logfile.c Fix regression in logger functions 2024-02-22 14:08:20 -08:00
loglevel.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
meminfo.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
memsummary.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
minicrash.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
oncrash_amd64.c Favor siginfo_t over struct siginfo 2024-05-28 02:34:17 -07:00
oncrash_arm64.c Favor siginfo_t over struct siginfo 2024-05-28 02:34:17 -07:00
printwindowsmemory.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
rop.internal.h Introduce #include <cosmo.h> to toolchain users 2023-06-09 18:03:05 -07:00
showcrashreports.c Make crash reports reliable in multithreaded case 2024-05-24 11:44:44 -07:00
showcrashreportsearly.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
startfatal.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
traceme.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
traceme.h Reduce header complexity 2023-11-28 14:39:42 -08:00
vflogf.c Implement proper time zone support 2024-05-04 23:06:37 -07:00
watch-hook.S Fix more vi modelines (#1006) 2023-12-13 02:28:11 -05:00
watch.c Run clang-format (#1197) 2024-06-01 16:30:43 -04:00