Commit Graph

130 Commits

Author SHA1 Message Date
Aliaksei Kandratsenka
d5055ef3a2 new symbolize api and implementation
This is part of effort to get rid of perl pprof dependency. We're
replacing forking to pprof --symbols with carefully crafted
libbacktrace integration which has enough support for symbolizing
backtraces.
2024-10-03 21:18:04 -04:00
Aliaksei Kandratsenka
d0d4363a34 structure low_level_alloc as own convenience archive 2024-10-03 17:06:22 -04:00
Aliaksei Kandratsenka
3c261d9090 stop linking malloc_hooks to low_level_alloc 2024-10-03 16:56:53 -04:00
Aliaksei Kandratsenka
6fee38e5e7 build symbolizer stuff only for debug allocator
Since it is now the only place that uses it
2024-10-02 16:46:44 -04:00
Aliaksei Kandratsenka
9d58d03fa4 set default cmake build type to RelWithDebInfo
Which is the only sensible default. Should have been upstream default,
really.
2024-10-02 16:42:32 -04:00
Aliaksei Kandratsenka
608e6d0625 unbreak cmake testing of heap-profiler 2024-09-27 17:34:36 -04:00
Aliaksei Kandratsenka
6a7419e39f drop mmap_hook 2024-09-25 18:34:10 -04:00
Aliaksei Kandratsenka
00d235325f drop memory region map 2024-09-25 18:34:10 -04:00
Aliaksei Kandratsenka
187b31e952 amputate heap checker 2024-09-25 18:34:09 -04:00
Aliaksei Kandratsenka
e1014dead2 bump version to 2.16 2024-09-25 18:25:20 -04:00
Aliaksei Kandratsenka
c2dc36d00d improve quality of sampling_test
Part of this change is better diagnostic for when/if it fails. And
most important part is compensating for the delay between sampling
parameter is set for the test and when it is actually taken into
account by thread cache Sampler logic.

As a result about 1% of flaking probability has been fixed as we're
getting mean estimate for the allocated size actually same (or about
same) as allocated size.

Update github ticket #1557.
2024-09-18 12:59:04 -04:00
Aliaksey Kandratsenka
6b8962d797 bump version to 2.16rc 2024-09-16 20:28:05 -04:00
Aliaksey Kandratsenka
ea81e46ff1 improve benchmarks facility
We now support a set of command line flags similar to "abseil"
benchmark thingy. I.e. to let people specify a subset of benchmarks or
run them longer/shorter as needed.

This commit also includes small, portable and very simple regexp
facility. It isn't good enough for some production use, but it is
plenty good for some testing uses or benchmark selection.
2024-09-13 18:01:25 -04:00
Ishant Goyal
addf751420 Added support to configure lower bound on per-thread cache size
[alkondratenko@gmail.com: removed spurious new line at thread_cache.h]
Signed-off-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
2024-06-04 12:11:01 -04:00
Aliaksey Kandratsenka
c61f35f04c simplify tcmalloc/sbrk/sbrk-hooks integration
Instead of relying on __sbrk (on subset of Linux systems) or invoking
sbrk syscall directly (on subset of FreeBSD systems), we have malloc
invoke special tcmalloc_hooked_sbrk function. Which handles hooking
and then invokes regular system's sbrk. Yes, we loose theoretical
ability to hook into non-tcmalloc uses of sbrk, but we gain portable
simplicity.
2024-05-29 18:30:09 -04:00
Aliaksey Kandratsenka
29f394339b refactor and simplify capturing backtraces from mmap hooks
The case of mmap and sbrk hooks is simple enough that we can do
simpler "skip right number of frames" approach. Instead of relying on
less portable and brittle attribute section trick.
2024-05-29 18:30:09 -04:00
Aliaksey Kandratsenka
29b6eff4c7 replace heap-checker "bcad" stuff
The comments in this file stated that it has to be linked in specific
order to get initialized early enough. But our initialization is
de-facto via initial malloc hook. And to deal with latest-possible
destruction, we use more convenient destructor function
attribute, and make things simpler.
2024-05-29 18:30:09 -04:00
Aliaksey Kandratsenka
d9a99c290a expand emergency malloc integration to !kHaveGoodTLS systems
References github issue #1503.

This significantly reworks both early thread cache access and related
emergency malloc mode checking integration. As a result, we're able to
to rely on emergency malloc even on systems without "good"
TLS (e.g. QNX which does emutls).

One big change here is we're undoing early change to have single
"global" thread cache early during process lifetime. It was nice and
somewhat simpler approach. But because of inherent locking during
early process lifetime, we couldn't be sure of certain lock ordering
aspects w.r.t. backtracing/exception-stack-unwinding. So I choose to
keep it safe. So the new idea is we use SlowTLS facility to find
threads' caches when normal tls isn't ready yet. It avoids holding
locks around potentially recursion-ful things (like
ThreadCache::ModuleInit or growing heap). But we then have to be
careful to "re-attach" those early thread cache instances to regular
TLS. There will nearly always be just one of such thread caches. For
initial thread. But we cannot entirely rule out more general case
where someone creates threads before process initializers ran and
main() is reached. Another notable thing is free-ing memory in this
early mode will always using slow-path deletion directly into central
free list.

SlowTLS facility is "simply" a generalization of previous
CreateBadTLSCache code. I.e. we have a small fixed-size cache that
holds "exceptional" instances of thread-identitity to
thread-cache+emergency-mode-flag mappings.

We also take advantage of tcmalloc::kInvalidTLSKey we introduced
earlier and remove potentially raceful memory ordering between reading
tls_ready_ and tls_key_.

For emergency malloc detection we previously used thread_local
flag. Which we cannot use on !kHaveGoodTLS systems. So we instead
_remove_ thread's cache from it's normal tls storage and place it
"into" SlowTLS instead for the duration of WithStacktraceScope
call (which is how emergency mode is enabled now).
2024-05-23 13:31:42 -04:00
Aliaksey Kandratsenka
38d741710b drop unused pwd.h/grp.h checks 2024-03-24 16:59:58 -04:00
Aliaksey Kandratsenka
e867bb7818 amputate unused Elf32_Versym check 2024-03-24 16:59:57 -04:00
Aliaksey Kandratsenka
fc496c87c4 liberate our tests from makefile setting TCMALLOC_SAMPLE_PARAMETER 2024-03-20 16:06:59 -04:00
Aliaksey Kandratsenka
8cb41da4f9 gtestify debugallocation_test
As part of that we eliminate use of shell script and rely on gtest's
death testing facility instead (which this test was originally using).
2024-03-20 16:06:48 -04:00
Aliaksey Kandratsenka
14598dd4ac gtestify and refactor tcmalloc_unittest
While it still needs more work to be up to highest standards of
cleanness and clarity, we made it better.

One big part of this change is we're now liberated from
tcmalloc_unittest.sh. We now arrange testing of various environment
variable tweaks in C++ by self-execing with updated environment at the
end of tests.
2024-03-20 16:05:14 -04:00
Aliaksey Kandratsenka
93380fc754 drop dependency on sys/resource.h
Biggest part of it is removal of SetTestResourceLimit. The reasoning
behind it is, we don't do it on windows. Tests pass just fine. So,
there is no reason to bother.
2024-03-20 16:05:06 -04:00
Aliaksey Kandratsenka
a4fe2d7cd0 liberate sampling test from use of shell script
As part of that we do somewhat tighter job with temp files.
2024-03-20 16:04:52 -04:00
Aliaksey Kandratsenka
6b53b1a4c1 gtestify and cleanup system-alloc_unittest 2024-03-20 16:04:45 -04:00
Aliaksey Kandratsenka
f7c8b45dcd gtestify realloc_unittest 2024-03-20 16:04:41 -04:00
Aliaksey Kandratsenka
0dddc476b3 gtestify malloc_extension_c_test 2024-03-20 16:04:39 -04:00
Aliaksey Kandratsenka
3cda0c4185 gtestify malloc_extension_test 2024-03-20 16:04:37 -04:00
Aliaksey Kandratsenka
159c9e5c53 clean up and gtest-ify large_heap_fragmentation_unittest 2024-03-20 16:04:28 -04:00
Aliaksey Kandratsenka
3b12487a83 gtestify memalign_unittest 2024-02-27 17:00:42 -05:00
Aliaksey Kandratsenka
9dfab2cdce cmake: refactor CMakeLists.txt
It is still somewhat broken and somewhat of a mess, but it is much
lesser mess now.

As part of this change I also amputated a number of unnecessary or too
complicated bits. Like attempt to build both static and shared
versions of tcmalloc libraries at the same time. We stick to cmake's
"common" (seemingly) behavior of defaulting to something (in our case
shared library) and letting users override BUILD_SHARED_LIBS.

All the "install" bits are amputated as well, they're not ready.
2024-02-27 17:00:35 -05:00
Aliaksey Kandratsenka
2940450c7a gtestify profiledata_unittest 2024-02-27 16:50:07 -05:00
Aliaksey Kandratsenka
bbae941492 gtestify profile-handler_unittest 2024-02-27 16:50:07 -05:00
Aliaksey Kandratsenka
a4d9540d8b unbreak cmake for packed-cache_test 2024-02-27 16:50:07 -05:00
Aliaksey Kandratsenka
f8da159013 add function_ref_test 2024-02-21 21:57:37 -05:00
Aliaksey Kandratsenka
bfbfa333eb add cleanup_test
This also let us spot and fix missing include in the header.
2024-02-21 21:37:47 -05:00
Aliaksey Kandratsenka
0906dacc48 gtestify more tests
Those are malloc_hook_test, mmap_hook_test, page_heap_test,
sampler_test, stack_trace_table_test.
2024-02-20 14:34:28 -05:00
Aliaksey Kandratsenka
bfa30bf7df gtestify 3 simpler tests
Those are packed-cache_test, pagemap_unittest, safe_strerror_test
2024-02-20 14:34:23 -05:00
Aliaksey Kandratsenka
ff2dce5e67 gtestify addressmap_unittest 2024-02-20 14:34:23 -05:00
Aliaksey Kandratsenka
c1799405ae gtestify check_address_test 2024-02-20 14:34:23 -05:00
Aliaksey Kandratsenka
a46a391b14 gtestify low_level_alloc_unittest 2024-02-20 14:34:20 -05:00
Aliaksey Kandratsenka
6c24a59682 introduce vendor copy of googletest 2024-02-20 14:30:24 -05:00
Aliaksey Kandratsenka
c52c321bdd replace raw printer with usage of generic writer facility 2024-02-07 15:46:54 -05:00
Aliaksey Kandratsenka
771a01ed28 rework and simplify emergency malloc integration
We now wrap StackTraceScope thingy in tcmalloc-specific parts, instead
of automagically inside every stacktrace.cc function. TCMalloc bits
all need to grab stacktraces via newly introduced
tcmalloc::GrabBacktrace (which handles emergency malloc wrapping).

New approach eliminates the need for doing fake stacktrace scope. CPU
profiler, being distinct .so library couldn't take advantage of
emergency malloc anyways.

This simplifies the build further and eliminates another potential
point of runtime divergence when stacktrace is linked to both
libprofiler and libtcmalloc.
2024-02-05 14:27:02 -05:00
Aliaksey Kandratsenka
1331c0e0d1 drop long deprecated google/ headers 2024-02-04 21:54:46 -05:00
Aliaksey Kandratsenka
2e5ecb4de6 amputate src/base/simple_mutex.h
Use standard mutex instead
2024-02-04 16:38:21 -05:00
Aliaksey Kandratsenka
6691226953 split and rewrite TLS access for thread caches
Logic was removed from thread_cache.{h,cc} into
thread_cache_ptr.{h,cc}.

Separation will help possible future evolution, and we already changed
the logic quite a bit:

* early access (when TLS isn't initialized yet) now uses global
ThreadCache instance. We therefore have ThreadCachePtr instances
managing required locking. This eliminates unnecessary complication of
PTHREADS_CRASHES_IF_RUN_TOO_EARLY logic, and any other danger of
touching TLS too early. BTW previous implementation actually leaked
initial early-initialized ThreadCache instance(!)

* old configure-time HAVE_TLS logic is amputated. Config-time part of
it made little sense as C++ 17 guarantees availability of
thread_local, but we have manually curated deny-list of "bad" OSes,
that we tested (via compile checks!) at configure time. Now this
is all compile time. There is now compile-time kHaveGoodTLS variable
and we're using it mostly via if constexpr.

* kHaveGoodTLS case of creating thread cache is simplified and made
more straightforward (no need to have in_setspecific logic).

* !kHaveGoodTLS case if fixed and improved too. We avoid
std:🧵:get_id, as it deadlocks on mingw. We use errno address as
a portable and (usually) async-signal safe 'my thread' identifier. We
also eliminate linear searching of thread's cache and replace it with
straightforward hash table lookup.
2024-02-03 15:57:14 -05:00
Aliaksey Kandratsenka
51d3340b39 avoid -Wunused-results warnings from read/write
glibc with _FORTIFY_SOURCE sets those up to give warnings on unused
results. We used to disable this warning globally, but lets do better.
2024-01-30 17:08:29 -05:00
Aliaksey Kandratsenka
82a36a6fcd bump required c++ standard to c++-17 2024-01-30 15:54:24 -05:00