Commit Graph

1096 Commits

Author SHA1 Message Date
Aliaksey Kandratsenka
159c9e5c53 clean up and gtest-ify large_heap_fragmentation_unittest 2024-03-20 16:04:28 -04:00
Aliaksey Kandratsenka
27a57a1b30 MmapSysAllocator: try to extend previous mapping
This improves fragmentation in some use-cases when mmap sys allocator
is used. In specific terms, it unbreaks
tcmalloc_large_heap_fragmentation_unittest on OSX. They have sbrk that
seemingly always fails (fair game). And this test aggressive
fragmentation use-case pretty much requires tcmalloc to allocate
memory "linearly". Which sbrk does.

Previously, our mmap sys allocator didn't pass any start address hint,
so it caused the test to fail. Now we remember end of previous mmap
allocation into hint_ member variable and try to pass it as address
hint to next mmap.

Note, it doesn't help TCMALLOC_SKIP_SBRK=t to pass this test on Linux,
as Linux tends to pick initial mmap chunk "backwards" and too close to
library allocations. So it leaves not enough address space to extend
into. We may address this use-case some other time.
2024-03-20 16:04:05 -04:00
Aliaksey Kandratsenka
641cef6b4c unbreak early use of MallocExtension and simpify it some
On OSX and Windows we could end up with "default" and no-op
MallocExtension to be used if MallocExtension::instance() is used
before tcmalloc is fully initialized. It was nearly intended after my
recent change. But thinking about this more, even in use-cases where
we don't replace systems malloc APIs, we want MallocExtension to
reflect tcmalloc's state. So we now truly force tcmalloc
initialization on first MallocExtension::instance() use and
MallocExtension is now abstract class.
2024-03-20 16:03:11 -04:00
Aliaksey Kandratsenka
02adc8ceab also disable _TIME_BITS in mmap_hook.cc
Otherwise when _TIME_BITS are set, glibc complains that it seems
_TIME_BITS=64 without seeing _FILE_OFFSET_BITS=64. Thankfully, none of
the code in mmap_hook.cc depends on time_t.
2024-03-07 13:23:30 -05:00
Aliaksey Kandratsenka
198b3dd2d0 disable _FILE_OFFSET_BITS in mmap_hook.cc
Debian is doing massive rebuild of everything with 64-bit off_t (and
time_t), but on those systems where it matters, glibc still has mmap
with 32-bit off_t argument and mmap64 with 64-bit off_t. Since we're
aiming to match glibc's ABI, we need to see system's native off_t
width.
2024-03-01 16:28:04 -05:00
Aliaksey Kandratsenka
37b59a206e gtestify current_allocated_bytes_test 2024-02-27 17:04:53 -05:00
Aliaksey Kandratsenka
f9e6c517b8 gtestify markidle_unittest 2024-02-27 17:04:39 -05:00
Aliaksey Kandratsenka
3b12487a83 gtestify memalign_unittest 2024-02-27 17:00:42 -05:00
Aliaksey Kandratsenka
9cb7f7040e gtestify frag_unittest 2024-02-27 17:00:35 -05:00
Aliaksey Kandratsenka
80a02ea645 update {tcmalloc_unit,debugallocation_}test to use TestingPortal
So that they're not reaching into guts of
libtcmalloc{,_debug}{,_minimal} anymore.
2024-02-27 17:00:35 -05:00
Aliaksey Kandratsenka
ddc162f1d1 implement TestingPortal
Some our tests are intended to test behavior of external APIs (like
operator new etc), but they do need occasional ability to peek into
the guts of tcmalloc. We want to make our .so libraries to be built
with -fvisibility=hidden, so we'll loose this ability.

In order to have this limited ability for tests to get into the guts
of tcmalloc, we introduce TestingPortal exactly for that. It uses
carefuly designed and thouroughly undocumented GetNumericProperty
extension to grab pointer to TestingPortal. Then through calling
member functions of this instance, we're able to do the right thing.
2024-02-27 17:00:35 -05:00
Aliaksey Kandratsenka
66bdf24061 initialize correct MallocExtension instance early
Previous implementation only had tcmalloc.cc's TCMallocGuard to
register correct MallocExtension instance. Which is occasionally too
late.

This original design (as well as it's ancestor in abseil tcmalloc)
allows malloc_extension.cc to be built and linked separately from
tcmalloc. So that software that uses extended features can be linked
with non-tcmalloc malloc (or, for example, asan).

In our case, we don't offer such flexibility. But we choose to keep
ability to (re)enable it.

New implementation makes sure to register malloc extension on first
call to memory allocation. Which typically happens super-early.

In case malloc/operator new aren't called early enough, we make sure
that first call to MallocExtension::instance invokes malloc as part of
creating it's 'empty' malloc extension, and thus provoking
tcmalloc (or any other malloc that chose to implement our malloc
extension interface) to register it's proper MallocExtension instance.
2024-02-27 17:00:35 -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
5fabaea30d link page_heap_test with entirety of tcmalloc_minimal
This makes page_heap_test a bit more uniform with rest of things and
prevents any future missing symbols issues.
2024-02-27 17:00:35 -05:00
Aliaksey Kandratsenka
5f9eb91129 cleanup and untangle sampling-test from tcmalloc guts 2024-02-27 17:00:35 -05:00
Aliaksey Kandratsenka
9381dd0b19 tcmalloc_unittest: wrap calloc reference with noopt
It is not clear why we didn't hit this before, but in some cases we
see calloc being optimized away (just like we had with
new/malloc). And noopt is how we deal with it.
2024-02-27 16:50:07 -05:00
Aliaksey Kandratsenka
de3066fb1f unbreak unnecessary slowness of addressmap_unittest 2024-02-27 16:50:07 -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
9bebef9ff3 bump WIN32_WINNT request to windows 8
We already require it for spinlock futex-like waiting stuff, so lets
make it more official to enable newer APIs in other places too.
2024-02-27 16:50:07 -05:00
Aliaksey Kandratsenka
7d664c702a reimplement windows GetenvBeforeMain to avoid memory allocation
Previous implementation used GetEnvironmentVariableA which appears to
be calling into Heap{Alloc,Free}, so in some cases may recurse into
tcmalloc. So we use 'wide' character version and perform trivial
conversion to/from 7-bit ASCII.
2024-02-27 16:50:07 -05:00
Aliaksey Kandratsenka
f2f301df7a gitignore build/
This is a common directory used by out-of-tree cmake builds.
2024-02-27 16:50:07 -05:00
Aliaksey Kandratsenka
b81d639793 ignore googletest .dirstamp 2024-02-22 17:54:01 -05:00
Aliaksey Kandratsenka
896804dcb2 delete accidentally added .dirstamp file 2024-02-22 17:39:00 -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
61b1e05848 unbreak make dist
In 57d6ecc4ae I removed obsolete
src/windows/TODO but failed to remove it from Makefile.am

I also previously failed to arrange distribution of vendored
googletest. And we also failed to distribute headers in src/tests/

This is all fixed now.
2024-02-21 13:44:17 -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
ad6e29e7c9 move gtest-like asserts into legacy_assertions.h 2024-02-20 14:24:12 -05:00
Aliaksey Kandratsenka
8318e08962 fix missing AM_CXXFLAGS introduced in recent automake refactoring 2024-02-20 12:06:30 -05:00
oPiZiL
b02d36d2eb fix compile error with gcc 7.5
In file included from /home/louwei/arcs/gperftools/src/span.cc:41:0:
/home/louwei/arcs/gperftools/src/static_vars.h:125:37: error: ‘byte’ in namespace ‘std’ does not name a type
     alignas(alignof(PageHeap)) std::byte memory[sizeof(PageHeap)];
                                     ^~~~
/home/louwei/arcs/gperftools/src/static_vars.h: In static member function ‘static tcmalloc::PageHeap* tcmalloc::Static::pageheap()’:
/home/louwei/arcs/gperftools/src/static_vars.h:76:80: error: ‘struct tcmalloc::Static::<unnamed>’ has no member named ‘memory’
   static PageHeap* pageheap() { return reinterpret_cast<PageHeap *>(&pageheap_.memory); }
                                                                                ^~~~~~
2024-02-19 11:21:08 -05:00
Aliaksey Kandratsenka
3d155f6624 apply tcmalloc::FunctionRef in AddressMap 2024-02-17 20:10:21 -05:00
Aliaksey Kandratsenka
8c1a7ef17f implement tcmalloc::FunctionRef 2024-02-17 20:10:21 -05:00
Aliaksey Kandratsenka
5f92c0616a implement tcmalloc::Cleanup
This is similar, but slightly less featureful than
absl::{Make,}Cleanup.
2024-02-17 20:10:21 -05:00
Aliaksey Kandratsenka
dec85dcc03 avoid undefined behavior when parsing proc maps
Clang's undefined behavior sanitized correctly pointed out that
memmove requires non-nil args, so lets initialize sbuf to something.
2024-02-17 18:32:03 -05:00
Aliaksey Kandratsenka
9b5838f084 modernize overalignment testing bits 2024-02-17 18:32:03 -05:00
Aliaksey Kandratsenka
3a2a7e05f6 add missing internal_logging.cc to packed_cache_test
It wasn't caught before because when optimization is enabled ASSERT-s
inside packed-cache-inl get optimized away (because checks are
tautological).
2024-02-17 18:03:41 -05:00
Aliaksey Kandratsenka
57d6ecc4ae drop obsolete src/windows/TODO 2024-02-08 09:41:38 -05:00
Aliaksey Kandratsenka
8a147b4833 untangle a number of unittests from libtcmalloc_minimal.so 2024-02-07 23:54:03 -05:00
Aliaksey Kandratsenka
cad457ad23 actualize .gitignore 2024-02-07 20:30:53 -05:00
Aliaksey Kandratsenka
b0e2928343 mingw: don't add patch_functions.cc in libcommon.la 2024-02-07 20:30:53 -05:00
Aliaksey Kandratsenka
e544d402f7 amputate unused log_message_write 2024-02-07 19:40:08 -05:00
Aliaksey Kandratsenka
b6798a5130 amputate unused kCrashWithStats 2024-02-07 19:40:08 -05:00
Aliaksey Kandratsenka
45a4ad8b70 mmap_hook_test: don't printf early
The test includes override of
MallocHook_InitAtFirstAllocation_HeapLeakChecker which runs early
enough to trigger FreeBSD bug of not having nearly anything working
early.
2024-02-07 19:37:04 -05:00