Commit Graph

873 Commits

Author SHA1 Message Date
Aliaksey Kandratsenka
83fccceffa bump README freshness a bit 2023-08-14 22:05:47 -04:00
Ken Raffenetti
c41eb9e8b5 Add MPICH HPC environment detection
Default MPICH builds use the Hydra process manager (mpiexec) which sets
PMI_RANK in the application environment. Update GetUniquePathFromEnv()
test accordingly.

Signed-off-by: Ken Raffenetti <raffenet@mcs.anl.gov>
2023-08-11 15:21:15 -04:00
Aliaksey Kandratsenka
1d2654f3a0 heap-checker: unbreak PTRACE_GETREGS detection on older Linux-es
This unbreaks RHEL6.
2023-08-10 14:30:27 -04:00
Aliaksey Kandratsenka
dbd1071680 link libprofiler with pthread
This unbreaks building on older Linux distros. We missed this at
46d3315ad7901099bd414740dbfbe6d27f33da9a when dropped maybe_thread
stuff, since libprofiler indeed uses pthread, and because on newer
libc-s pthread stuff is now part of regular libc.so.

I am also dropping bogus LIBPROFILER stuff referring to some rpath
badness. Unsure what it was, maybe way back we did libstacktrace as a
proper libtool library, so maybe something was needed. But it is just
a convenience archive this days, so we don't really need to add it
everywhere libprofiler.la is linked.
2023-08-09 23:57:06 -04:00
Aliaksey Kandratsenka
729383b486 make sure that ListerThread runs on properly aligned stack
Without this fix we're failing unit tests on ubuntu 18.04 and centos 7
and 6. It looks like clone() in old glibc-s doesn't align stack, so
lets handle it ourselves. How we didn't hit this much earlier (before
massive thread listing refactoring), I am not sure. Most likely pure
luck(?)
2023-08-09 23:42:56 -04:00
Aliaksey Kandratsenka
51c5e2bec7 massage latest GetUniquePathFromEnv changes
This fixes a number of minor bits (like build details) as well as
making overall code style similar to what we're doing elsewhere.
2023-08-09 16:29:13 -04:00
Artem Polyakov
86450ad99f Add unit test for GetUniquePathFromEnv()
Signed-off-by: Artem Polyakov <artpol84@gmail.com>
2023-08-08 16:44:18 -07:00
Artem Y. Polyakov
881b754da0 Advanced UniquePathFromEnv generation
* Add support for known HPC environments (TODO: needs to be extended
with more nevironments)
* Added the "CPUPROFILE_USE_PID" environment variable to force appending
PID for the non-covered environments
* Preserve the old way of handling the Child-Parent case

Signed-off-by: Artem Polyakov <artpol84@gmail.com>
2023-08-08 16:44:18 -07:00
Aliaksey Kandratsenka
57512e9c3d unbreak -Wthread-safety
It actually found real (but arguably minor) issue with memory region
map locking.

As part of that we're replacing PageHeap::DeleteAndUnlock that had
somewhat ambitious 'move' of SpinLockHolder, with more straightforward
PageHeap::PrepareAndDelete. Doesn't look like we can support move
thingy with thread annotations.
2023-08-06 19:32:32 -04:00
Aliaksey Kandratsenka
862039c185 don't -momit-leaf-frame-pointer when asked for full frame pointers 2023-08-06 14:44:05 -04:00
Aliaksey Kandratsenka
dc25c1fd4c bump version to 2.11rc 2023-07-31 20:11:55 -04:00
Aliaksey Kandratsenka
909fa3e649 unbreak MallocExtension::GetAllocatedSize() for debug allocator
Some years back we fixed memalign vs realloc bug, but we preserved
'wrong' malloc_size/GetAllocatedSize implementation for debug
allocator.

This commit refactors old code making sure we always use right
data_size and it fixes GetAllocatedSize. We update our unittest
accordingly.

Closes #738
2023-07-31 16:28:48 -04:00
Aliaksey Kandratsenka
a51e08b06a drop obsolete TODO file 2023-07-31 15:40:13 -04:00
Aliaksey Kandratsenka
a1c7ce7793 refresh README-s 2023-07-31 15:16:14 -04:00
Aliaksey Kandratsenka
bef6592746 refresh INSTALL 2023-07-31 15:10:56 -04:00
Aliaksey Kandratsenka
e3de2e3242 remove obsolete references to code.google.com
I.e. somehow we managed to still point to (very) old gperftools
hosting location, so lets fix it at last.
2023-07-31 14:28:58 -04:00
Aliaksey Kandratsenka
1ff09a680e drop obsolete deb/rpm packaging stuff 2023-07-31 14:28:40 -04:00
Aliaksey Kandratsenka
8b3f0d6145 undo MarkThreadTemporarilyIdle and make it same as MarkThreadIdle
As noted on github issue #880 'temporarily' thing saves us not just on
freeing thread cache, but also returning thread's share of thread
cache (max_size_) into common pool. And the later has caused trouble
to mongo folk who originally proposed 'temporarily' thing. They claim
they don't use it anymore.

And thus with no users and no clear benefit, it makes no sense for us
to keep this API. For API and ABI compat sake we keep it, but it is
now identical to regular MarkThreadIdle.

Fixes issue #880
2023-07-31 14:11:51 -04:00
Aliaksey Kandratsenka
c3059a56be dont workaround unknown problem in thread_dealloc_unittest
We had some sleep added at the end up thread dealloc unittest claiming
some race trouble with glibc. Which is likely years or even decades
irrelevant.
2023-07-31 12:37:15 -04:00
Aliaksey Kandratsenka
9b91ce917a [win32:patching] define single empty __expand replacement
This unbreaks some cases where patching complains about too short
functions to patch.

What happens is we first locate one of CRT-s (like ucrt or msvcrt) and
patch __expand there, redirecting to our implementation. Then "static"
__expand replacement is patched, but it is usually imported from that
same C runtime DLL. And through several jmp redirections we end up at
our own __expand from libc<1>. Patching that (and other cases) is
wrong, but I am unsure how to fix it properly. So we do most simple
workaround. I found that when it not fails is either in debug builds
where empty expand is not too short or when MSVC deduplicates multiple
identical __expand implementations into single function, or when
64-bit patching has to do extra trampoline thingy. And then our
patching code checks if we're trying to replace some function with
itself. So we "just" take advantage of that and get immediate issue
fixed, while punting on more general "duplicate" patching for later.

Update github issue #667
2023-07-27 19:38:52 -04:00
Aliaksey Kandratsenka
b6cdd8f510 [mingw] dont add libstacktrace to libtcmalloc_minimal
There was this piece of makefile with indention to add stack tracing
functionality (for stuff like growthz, GetCallerStackTrace and
probably heap sampling) to work even in minimal configuration on
mingw.

What is odd is we fail to actually define libstacktrace.la target on
mingw, since libstacktrace.la requires WITH_STACK_TRACE automake
conditional which we don't enable on this platform. And yet somehow it
doesn't fail. It produces empty libstacktrace.la, so build kinda
works. Except at least on my machine it produces racy makefiles. So
lets not pretend and stop breaking our parallel builds.
2023-07-27 19:27:42 -04:00
Aliaksey Kandratsenka
a5cfd38884 [win32] amend and unbreak previous NOMINMAX fix 2023-07-27 19:27:20 -04:00
Aliaksey Kandratsenka
d2c89ba534 don't return raw span when sampling and stacktrace oomed
This is nearly impossible in practice, but still. Somehow we missed
this logic that DoSampledAllocation always returns actual object, but
in that condition where stacktrace_allocator failed to get us
StackTrace object we ended up returning span instead of it's object.
2023-07-24 21:01:35 -04:00
Aliaksey Kandratsenka
59464404d1 capture growthz backtraces outside of pageheap_lock
Actual growthz list is now lockless since we never delete anything
from it. And we now pass special 'locking context' object down page
heap allocation path, both as a documentation that it is under lock
and for tracking whether we needed to grow heap and by how much. Then
whenever lock is released in RAII fashion, we're able to trigger
growthz recording outside of lock.

Closes #1159
2023-07-24 21:01:35 -04:00
Aliaksey Kandratsenka
0d42a48699 move page heap locking under PageHeap
While there is still plenty of code that takes pageheap_lock outside
of page_heap module for all kinds of reasons, at least
bread-and-butter logic of allocating/deallocating larger chunks of
memory is now handling page heap locking inside PageHeap itself. This
gives us flexibility.

Update issue #1159
2023-07-24 21:01:35 -04:00
Aliaksey Kandratsenka
a3e1080c2e handle large alloc reporting locklessly
Which simplifies codes a bit.

Update issue #1159
2023-07-24 21:01:35 -04:00
Aliaksey Kandratsenka
f1eb3c82c6 correctly release memory when system's pagesize is >kPageSize
I.e. this covers case of arms that by default compile tcmalloc for 8k
logical pages (assuming 4k system pages), but can actually run on
systems with 64k pages.

Closes #1135
2023-07-24 21:01:35 -04:00
Aliaksey Kandratsenka
d521e3b30e move page heap allocations with alignment into page heap 2023-07-24 21:01:35 -04:00
Aliaksey Kandratsenka
ad0ca2b83b unbreak large heap fragmentation unittest
Smart compilers again (and lack of -fno-builtin-malloc which we
dropped because of clang).
2023-07-24 20:24:52 -04:00
Aliaksey Kandratsenka
bd3bf9abd7 define NOMINMAX on windows
Otherwise we cannot use some std bits, like numeric_limits.
2023-07-24 20:24:28 -04:00
Aliaksey Kandratsenka
814f340eed add --enable-libgcc-unwinder-by-default for configure
We want distros to ship gperftools with this options, now that they
have _Unwind_Backtrace that is powered by dl_find_object.
2023-07-22 20:45:52 -04:00
Aliaksey Kandratsenka
f06ccc6f79 dont test HAVE_{STDINT,INTTYPES}_H
Those are fairly standard by now. We already require C++11 or later
compiler.
2023-07-22 14:32:40 -04:00
Aliaksey Kandratsenka
86867674f0 don't do syscall on osx
Their compiler barks and we only need this syscall business on FreeBSD.
2023-07-22 14:32:40 -04:00
Aliaksey Kandratsenka
bdae3615ca osx's dyld_present is always true
As reported to us by their compiler's warning.
2023-07-22 14:32:34 -04:00
Aliaksey Kandratsenka
91b8024aa1 drop unused ThreadCache::DropCacheWhichMustBePresent 2023-07-22 14:00:32 -04:00
Aliaksey Kandratsenka
42dde1b883 heap-checker_unittest: run thread-unsafe libc calls less unsafely
Comment there says race is fine, bit it isn't. Crashes under
musl. Lets not crash.
2023-07-22 00:08:38 -04:00
Aliaksey Kandratsenka
8be84e4a5c drop old mmap hooks and introduce internal & simpler mmap_hook.h
Previous implementation wasn't entirely safe w.r.t. 32-bit off_t
systems. Specifically around mmap replacement hook. Also, API was a
lot more general and broad than we actually need.

Sadly, old mmap hooks API was shipped with our public headers. But
thankfully it appears to be unused externally (checked via github
search). So we keep this old API and ABI for the sake of formal API
and ABI compatibility. But this old API is now empty and always
fails (some OS/hardware combinations didn't have functional
implementations of those hooks anyways).

New API is 64-bit clean and only provides us with what we need. Namely
being able to react to virtual address space mapping changes for
logging, heap profiling and heap leak checker. I.e. no pre hooks or
mmap-replacement hooks. We also explicitly not ship this API
externally to give us freedom to change it.

New code is also hopefully tidier and slightly more portable. At least
there are fewer arch-specific ifdef-s.

Another somewhat notable change is, since mmap hook isn't needed in
"minimal" configuration, we now don't override system's
mmap/munmap/etc functions in this configuration. No big deal, but it
reduces risk of damage if we somehow mess those up. I.e. musl's mmap
does few things that our mmap replacement doesn't, such as very fancy
vm_lock thingy. Which doesn't look critical, but is good thing for us
not to interfere with when not necessary.

Fixes issue #1406 and issue #1407. Lets also mention issue #1010 which
is somewhat relevant.
2023-07-21 16:13:19 -04:00
Aliaksey Kandratsenka
6b691cc019 drop patching virtual alloc fns on windows
It wasn't implemented exactly right and, most importantly, there is
nothing on windows that uses those (now dead) mmap hooks.
2023-07-21 14:32:48 -04:00
Aliaksey Kandratsenka
fecaf37ae4 drop DevMemSysAllocator
It was never useful for anything.
2023-07-21 14:32:37 -04:00
Aliaksey Kandratsenka
e53ec241b6 unbreak __sbrk detection on cmake 2023-07-21 14:32:37 -04:00
Aliaksey Kandratsenka
d4f3362035 add missing .gitignore for safe_strerror_test.exe 2023-07-21 14:32:37 -04:00
Aliaksey Kandratsenka
e0f4c0e6fb manually inline MapObjectToSpan into ReleaseToSpans
It was originally separated into own function due to some (now
obsolete) compiler optimization bug. We stopped worked around that bug
few commits ago. But as github user plopresti rightfully pointed
out (much, much thanks!), we lost `static' on that function. But since
it is trivial function and used exactly once, it is best to simply
inline it's 2 lines of code back instead of returning static.

Previous commit was: 68b442714a
2023-07-17 15:56:19 -04:00
Aliaksey Kandratsenka
46d3315ad7 amputate maybe_threads
This facility allowed us to build tcmalloc without linking in actual
-lpthread. Via weak symbols we checked at runtime if pthread functions
are available and if not, special single-threaded stubs were used
instead. Not always brining in pthread dependency helped performance
of some programs or libraries which depended at runtime on whether
threads are linked or not. Most notable of those are libstdc++ which
uses non-atomic refcounting on single threaded programs.

But such optional dependency on pthreads caused complications for
nearly no benefit. One trouble was reported in github issue #1110.

This days glibc/libstdc++ combo actually depends on
sys/single_threaded.h facility. So bringing pthread at runtime is
fine. Also modern glibc ships pthread symbols inside libc anyways and
libpthread is empty. I also found that for whatever reason on BSDs and
osx we already pulled in proper pthreads too.

So we loose nothing and we get issue #1110 fixed. And we simplify
everything.
2023-07-14 03:07:16 -04:00
Aliaksey Kandratsenka
3cd265b05a replace pthread_once usages with simple spinlock-backed flag
Our perftools_pthread_once implementation has some ifdefs and what
not. I.e. some OSes have complications around early usage and windows
is windows. But in fact we can implement trivial spinlock-supported
implementation and depend on nothing.

Update issue #1110
2023-07-14 03:07:16 -04:00
Aliaksey Kandratsenka
215b2d939a drop disabled windows-specific spinlock code 2023-07-14 02:31:17 -04:00
Aliaksey Kandratsenka
37fd4adab4 use regular off_t on 64-bit linuxes
off64_t is legacy of the past.

Update github issue #1407
2023-07-13 22:06:12 -04:00
Gabriel Marin
4a923a6b36 tcmalloc: enable large object pointer offset check
Original CL: https://chromiumcodereview.appspot.com/10391178

  1. Enable large object pointer offset check in release build.
  Following code will now cause a check error:
  char* p = reinterpret_cast<char*>(malloc(kMaxSize + 1));
  free(p + 1);

  2. Remove a duplicated error reporting function "DieFromBadFreePointer",
  can use "InvalidGetAllocatedSize".

Reviewed-on: https://chromium-review.googlesource.com/1184335
[alkondratenko@gmail.com] removed some unrelated formatting changes
Signed-off-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
2023-07-13 19:41:21 -04:00
Aliaksey Kandratsenka
4b3fc02082 fix clang barking at debugallocator's magic2_ field
It barks because we access the field in a special way through address
computation (see magic2_addr), so it is indeed not accessed
directly. To emphasize that it comes directly after size2_ we simply
converted size2 and magic2_ into explicit array size_and_magic2_.
2023-07-13 19:21:38 -04:00
Aliaksey Kandratsenka
c29e3059dd mark CheckCachedSizeClass as used
It is only used from inside ASSERT and clang doesn't like it being
declared but unused when NDEBUG is set.
2023-07-13 19:21:30 -04:00
Aliaksey Kandratsenka
f7c6835fac drop unused linuxthreads.cc:local_itoa function 2023-07-13 18:58:55 -04:00