about summary refs log tree commit homepage
DateCommit message (Collapse)
2022-12-11set un.sun_len on *BSD systems
Maybe this fixes some t/mwrap-httpd.t reliability problems I've noticed on FreeBSD...
2022-12-10httpd: put location names into a contiguous buffer
This drastically reduces the number of malloc+free calls in the /$PID/each/$MIN endpoint for large processes by writing out all the names into one contiguous buffer and having pointers point inside of it from the h1_src_loc array. IOW, this means we have parallel arrays working together, instead of one array and thousands of discreet strings. This makes /each/2000 in my application roughly 7x faster than before and 10x faster than the equivalent Devel::Mwrap::PSGI Perl code. I wasn't exactly happy with the performance of the C version before this change, but now it's pretty good :>
2022-12-10httpd: fix leak in backtrace_symbols(3) usage
Again...
2022-12-10t/httpd-unit: extra test for fencepost errors
I'm terrible at this stuff :<
2022-12-10t/mwrap-httpd: better errors for local socket failures
The syswrite() needs to be replaced by send(.*MSG_NOSIGNAL), but I'm ignoring SIGPIPE anyways in case connect() somehow triggers it. In any case, I'm noticing the local socket created in Perl (not curl) sometimes fails the first send/write and/or fails the second send/write syscall. Maybe this can help diagnose things...
2022-12-10rproxy: fix for `plackup --path=/$PREFIX/' mounts
Plack::App::URLMap (used by plackup --path=) adjusts SCRIPT_NAME and PATH_INFO, but not REQUEST_URI. We need to adjust REQUEST_URI since we don't want the URI-unescaped PATH_INFO.
2022-12-10httpd: fix leaks when using persistent connections
Persistent connections is probably not going to be a real use case, but I may end up supporting them anyways.
2022-12-10C-only HTTP Unix socket server + PSGI TCP reverse proxy
The C-only HTTP server (mwrap_httpd) should be able to run in non-Perl programs and anything which LD_PRELOADs Mwrap.so. This HTTP server emulates the existing Devel::Mwrap::PSGI app, but without any Perl or PSGI runtime dependencies. It only binds to a per-process UNIX stream socket at $socket_dir/$PID.sock where $socket_dir is set by the `socket_dir:' directive in the MWRAP environment variable. URLs for mwrap_httpd are similar to Devel::Mwrap::PSGI ones, but prefixed with the $PID to simplify use with the reverse proxy. Thus, "/each/2000" endpoint becomes "/$PID/each/2000" The PSGI reverse proxy (Devel::Mwrap::Rproxy + mwrap-rproxy) is a tiny PSGI application designed to expose the mwrap_httpd UNIX sockets to web browsers such as `w3m'. The overall configuration allows mwrap-proxy to provide access to every mwrapped process via the `/$PID/' prefixed endpoints. browser <-> mwrap-rproxy <----> mwrapped #1 (on /$socket_dir/$PID_1.sock) \---> mwrapped #2 (on /$socket_dir/$PID_2.sock) \---> mwrapped #3 (on /$socket_dir/$PID_3.sock) ... The process running mwrap-rproxy and Devel::Mwrap::Rproxy does not require Mwrap.so to be loaded in them, so they can use any malloc implementation if tracing rproxy isn't necessary.
2022-12-10tests: hoist out test_common.perl
This will make it easier to split out tests to separate files in the future.
2022-12-10move mwrap_reset to core
It'll be used for the C HTTP server.
2022-12-09pool filenames into separate table
This will save memory with large projects where files have many allocation sites. More importantly, the internal change will make supporting deeper C backtraces (via backtrace(3)) possible in the future.
2022-12-09freebsd: fix infinite recursion during startup
pthread_mutex_lock needs malloc under FreeBSD :<
2022-12-09provide mwrap_assert due to Perl header conflicts
Relying on assert() is difficult since we may be linked into non-Perl processes via LD_PRELOAD, and Perl headers will have assert() working on Perl-only symbols which cause runtime failures during symbol resolution. Instead of tracking down every potentially assert()-ed symbol and marking it as weak, it's easier to name our own assert as `mwrap_assert' and use that everywhere during development.
2022-12-02mwrap_core: do not manually resize lfht
URCU actually uses a workqueue that pre-spawns a thread at creation time, so we're safe as long as we call cds_lfht_new while signals are blocked.
2022-12-02increase DEFAULT_GRANULARITY to 64M
Since Linux maps are file-backed, it won't provide an increase in physical memory. Using larger chunks reduces syscalls and avoids hitting the Linux system-wide /proc/sys/vm/max_map_count limit. It's probably safe for all x86-64 systems these days, and 32-bit is prone to overflow and not a target of this project (though this project aims to make other projects suitable for underpowered 32-bit systems).
2022-12-02use file-backed mmap on Linux
Due to the high memory usage of mwrap, it may be useful to force allocations onto file-backed maps. This means more physical memory for the rest of the system. As opposed to adding swap indiscriminately, this provides the ability to give the equivalent of swap space only to the processes using mwrap. O_TMPFILE in Linux makes supporting this a breeze, since we can't expect to use tmpfile(3) before malloc is initialized.
2022-12-02initialize src_loc.freed_bytes to zero
While this is copied from the pre-zeroed TSD, it won't always be the case since the TSD area will be used more extensively.
2022-12-02build: optionally support XXH3 from xxHash
This seems to provide a 2% speedup or so in my test case compared to jhash, but we are only picking 32 of the 64 output bits from XXH3_64bits. Using the 32-bit XXH32 variant did not show any measurable improvement over jhash.
2022-12-02malloc_trim: clean up idle arenas immediately
There's no need to worry about race conditions if operating on idle arenas, so clean them up immediately rather than cleaning them up after a pthread_create (which may never come). We'll also inform active threads about the trim earlier so they have more cycles to react to the lazy trim request.
2022-12-02dump_to_file: check for backtrace_symbols errors
We can also limit the scope of its return value since the pointers inside the return value do not get freed.
2022-12-02totals_add_rcu: improve readability
We no longer need to unlock in this function if it fails, and asserting rcu_read_ongoing() is a good idea to ensure cds_lfht_lookup() is used properly.
2022-11-19eliminate alloca(3) use
alloca(3) is difficult for the compiler and static checkers to deal with, and we already reserve TSD space for storing path names.
2022-11-16location_name: handle malloc failure on backtrace_symbols(3)
backtrace_symbols(3) may fail due to malloc failures, so we must account for it and return `undef' in that case.
2022-11-16mwrap_get: golf out redundant assignment across branches
Terminal space is precious with my font sizes.
2022-11-16fix under-allocated kbuf size
kbuf is always `struct src_loc', not `struct alloc_hdr'. Fortunately, nobody really needs PATH_MAX size for pathnames, so this wasn't a problem in practice.
2022-11-16wrap jhash calls to hash_loc
This will make it easier to keep a consistent hash seed and/or switch to different hashes in the future.
2022-11-16mwrap_core: document the reason for padding the mutex
While 64 has an obvious meaning to me, I reject Moore's law and have no idea what cache line sizes modern CPUs use.
2022-11-16avoid leaking array returned by backtrace_symbols()
Oops :x Fortunately, most allocations are tracked to a Perl location and the non-Perl code path is infrequently hit.
2022-11-16split out mwrap_core.h and use provide our own malloc
This simplifies portability and can eventually give us more portability involving malloc use. We can also track allocations earlier since we no longer need to rely on dlsym. This malloc implementation (based on dlmalloc) also provides us with wait-free free(3) calls thanks to wfcqueue, so it makes call_rcu usage far cheaper.
2022-11-16mwrap-perl: use grep and fix regexp
There's no need to pay O(n) cost to create a short-lived hash table and the original regexp was obviously wrong :x
2022-11-16document of kbuf allocation size
This may be increased in the future if we add C addr2line support.
2022-11-16block signals when spawning URCU-related threads
rculfhash, call_rcu, and urcu-bp will spawn background threads. Ensure we spawn all of these threads while signals are blocked since the underlying codebase may block signals and rely on signalfd.
2022-11-16Devel::Mwrap::reset is a no-op if `totals' not initialized
Don't segfault in case we fail to create rculfhash.
2022-11-16test cfree and aligned_alloc aliases
These aliases aren't necessary for modern glibc, at least, but they also don't hurt. This quiets an old warning about cfree.
2022-09-20do not access aTHR when in a non-Perl process
This is needed to avoid segfaults in non-Perl processes such as `cmake'. Fixes: 3197316f33fdc5d4 "create the `totals' rculfhash as early as possible"
2022-09-15create the `totals' rculfhash as early as possible
This allows us to start tracking allocations before Perl calls our BOOT code, which can be far later if it has to boot other modules first. As an LD_PRELOAD, the constructor can fire before Perl's main().
2022-09-15Makefile.PL: check for execinfo on FreeBSD
This is required for it to work reliably in FreeBSD if we hit a code path which calls backtrace_symbols before BOOT:. This will allow the next commit to setup `totals' rculfhash earlier in the constructor, rather than BOOT, allowing allocations to be tracked as early as possible.
2022-09-04workaround breakage from urcu v0.11.4
urcu v0.11.4+ introduced commit 7ca7fe9c03 (Make temporary variable in _rcu_dereference non-const, 2021-07-29) which conflicts with our use of _LGPL_SOURCE. In retrospect, CMM_LOAD_SHARED and CMM_STORE_SHARED seem sufficient for our use of the `totals' cds_lfht pointer since the constructur should always fire before any threads are running. This is fixed in urcu v0.12.4 and v0.13.2 (released 2022-08-18) but I suspect older versions will live on in enterprise/LTS distros for a long while. Link: https://lore.kernel.org/lttng-dev/20220809181927.GA3718@dcvr/
2022-09-04use macro to quiet uninitialized and unused variable warnings
This allows us to avoid some #ifdefs inside function bodies. This cleanup comes from the Ruby version.
2022-09-04cleanup some FreeBSD-related workarounds
This is to keep up with the Ruby version.
2022-09-04favor _Thread_local under C11
__thread is a gcc-ism which clang supports, but _Thread_local is part of C11 and more likely to be supported by future compilers.
2022-09-03paranoid safety fix to clamp pathnames to PATH_MAX
While I doubt Ruby (nor Perl) would store pathnames longer than PATH_MAX by default, it's possible `eval' users to specify whatever path (and line number) they wish to use. Likely was the case with `# line $FILE' directives in Perl5 which prompted this clamping.
2022-09-03Ractor compatibility
We can no longer depend on having GVL/GIL when we have a Ruby execution context, so so make `kbuf' thread-specific to avoid data corruption. This was ported from the Perl5 version, since Perl5 has had MVM/Ractor-like abilities with native threads for decades, despite the Perl5 ecosystem largely avoids and discourages threads.
2022-09-03mwrap 2.3.0 v2.3.0
This release now supports --enable-shared builds of Ruby which is the common setting for GNU/Linux distros. FreeBSD 12.3 support remains broken, but the code is somewhat revised so it can be more easily fixed and maintained in the future. `mwrap --help' and and `mwrap --version' are now supported, and an RDoc error which only happens during `gem install' is fixed. * support --enabled-shared builds of Ruby * extconf.rb: avoid RDoc errors during gem install * add --version and --help args * cleanup some FreeBSD-related workarounds
2022-09-03cleanup some FreeBSD-related workarounds
While FreeBSD 12.3 + Ruby 3.0.4p208 remains broken with mwrap (likely due to threading bugs in Ruby) at least get the code more consistently closer to a working state. Thus we'll remember to account for PTHREAD_MUTEX_INITIALIZER requiring malloc for HeapPageBody tracking, as we do with other mutexes. For reference, the Perl5 port of mwrap seems to have no problems on FreeBSD 12.3, so it seems down to misbehavior w.r.t. pthreads usage within Ruby itself. Perl5 on FreeBSD is configured with threads support, but Perl5 doesn't spawn background threads by default like Ruby can.
2022-09-03add --version and --help args
These may make things easier for new users, and we'll also with help text if given no args. We'll programmatically generate version based on `git describe', but fallback to a hardcoded version if outside of git. We'll also start appending `-dirty' to the version string to match git.git conventions.
2022-09-03extconf.rb: avoid RDoc errors during gem install
RDoc doesn't seem to like <<'' (blank line) as a heredoc terminator. That said, RDoc scanning extconf.rb during "gem install" is unexpected and make no sense to me. Normal `rdoc' invocations seem to ignore extconf.rb.
2022-08-23support --enabled-shared builds of Ruby
Most GNU/Linux distros build Ruby with --enable-shared, so it makes sense to support it properly even if it's not the default favored by ruby-core. __attribute__((weak)) on a local function is not weak enough for the shared library, so we add the extra check for the function's existence to have_ec_p(), instead. Tested with ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux-gnu] on Debian 11 (bullseye) as well as default builds w/o --enable-shared. Note: FreeBSD 12.3 appears broken with mwrap and I no longer have older FreeBSD systems handy.
2022-08-22mwrap 2.2.0 v2.2.0
This release adds Ruby 2.7, 3.0, and 3.1 support. This also fixes breakage in urcu v0.11.4, v0.12.3, and v0.13.1. While urcu v0.12.4 and v0.13.2 were released 2022-08-18, old versions will continue to be in distros for a while (and urcu v0.11.x won't be updated). There are also several updates ported from the Perl version. 7 changes since v2.1.0 in 2018: memalign: perform rcu_read_unlock on ENOMEM workaround breakage from urcu v0.11.4 constify arg for totals_add_rcu support Ruby 3.0.x disable HeapPageBody count test for Ruby 3.1 quiet uninitialized and unused variable warnings various doc updates
2022-08-22various doc updates
Copyright years are unnecessary churn and probably aren't necessary: https://www.linuxfoundation.org/blog/copyright-notices-in-open-source-software-projects/ add POP3 and IMAP archive info, and drop the outdated link to the live demo since I no longer have the resources to run it. Finally, add rdoc (olddoc) + rsync support