Commit Graph

576 Commits

Author SHA1 Message Date
Aliaksey Kandratsenka
8b9728b023 add memalign benchmark to malloc_bench 2017-11-30 18:14:11 +00:00
Aliaksey Kandratsenka
79c91a9810 always define empty PERFTOOLS_NOTHROW
Because somehow clang still builds "this function will not throw" code
even with noexcept. Which breaks performance of
tc_malloc/tc_new_nothrow. The difference with throw() seems to be just
which function is called when unexpected exception happens.

So we work around this sillyness by simply dropping any exception
specification when compiling tcmalloc.
2017-11-29 21:44:52 +00:00
Aliaksey Kandratsenka
03da6afff5 unbreak throw declarations on operators new/delete
We now clearly separate PERFTOOLS_NOTHROW (used for tc_XXX functions)
and throw()/noexcept (used for operators we define).

The former is basically "nothrow() for our callers, nothing for
us". It is roughly equivalent of what glibc declares for malloc and
friends. If some exception-full C++ code calls such function it
doesn't have to bother setting up exception handling around such
call. Notably, it is still important for those functions to _not have
throw() declarations when we're building tcmalloc. Because C++ throw()
requires setting up handling of unexpected exceptions thrown from
under such functions which we don't want.

The later is necessary to have operators new/delete definitions have
"correct" exception specifications to calm down compiler
warnings. Particularly older clang versions warn if new/delete aren't
defined with correct exception specifications. Also this commit fixes
annoying gcc 7+ warning (and gnu++14 mode) that complains about
throw() being deprecated.
2017-11-29 21:44:49 +00:00
Aliaksey Kandratsenka
89fe59c831 Fix OOM handling in fast-path
Previous fast-path malloc implementation failed to arrange proper oom
handling for operator new. I.e. operator new is supposed to call new
handler and throw exception, which was not arranged in fast-path case.

Fixed code now passes pointer for oom function to
ThreadCache::FetchFromCentralCache which will call it in oom
condition. Test is added to verify correct behavior.

I've also updated some fast-path-related comments for more accuracy.
2017-11-29 21:44:49 +00:00
Aliaksey Kandratsenka
a29a0cf348 delete-trailing-whitespace on thread_cache.* 2017-11-29 20:50:55 +00:00
Aliaksey Kandratsenka
e6cd69bdec reintroduce aliasing for aligned delete
Without aliasing performance is likely to be at least partially
affected. There is still concern that aliasing between functions of
different signatures is not 100% safe. We now explicitly list of
architectures where aliasing is known to be safe.
2017-11-29 19:52:32 +00:00
Aliaksey Kandratsenka
fb30c3d435 fully disable aligned new on windows for now 2017-11-29 19:52:32 +00:00
Andrey Semashev
7efb3ecf37 Add support for C++17 operator new/delete for overaligned types.
- Add auto-detection of std::align_val_t presence to configure scripts. This
  indicates that the compiler supports C++17 operator new/delete overloads
  for overaligned types.

- Add auto-detection of -faligned-new compiler option that appeared in gcc 7.
  The option allows the compiler to generate calls to the new operators. It is
  needed for tests.

- Added overrides for the new operators. The overrides are enabled if the
  support for std::align_val_t has been detected. The implementation is mostly
  based on the infrastructure used by memalign, which had to be extended to
  support being used by C++ operators in addition to C functions. In particular,
  the debug version of the library has to distinguish memory allocated by
  memalign from that by operator new. The current implementation of sized
  overaligned delete operators do not make use of the supplied size argument
  except for the debug allocator because it is difficult to calculate the exact
  allocation size that was used to allocate memory with alignment. This can be
  done in the future.

- Removed forward declaration of std::nothrow_t. This was not portable as
  the standard library is not required to provide nothrow_t directly in
  namespace std (it could use e.g. an inline namespace within std). The <new>
  header needs to be included for std::align_val_t anyway.

- Fixed operator delete[] implementation in libc_override_redefine.h.

- Moved TC_ALIAS definition to the beginning of the file in tcmalloc.cc so that
  the macro is defined before its first use in nallocx.

- Added tests to verify the added operators.

[alkondratenko@gmail.com: fixed couple minor warnings, and some
whitespace change]
[alkondratenko@gmail.com: removed addition of TC_ALIAS in debug allocator]
Signed-off-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
2017-11-29 19:51:42 +00:00
Andrew Morrow
7a6e25f3b1 Add new statistics for the PageHeap
[alkondratenko@gmail.com: addressed init order mismatch warning]
Signed-off-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
2017-11-28 14:19:08 +00:00
Jianbo Yang
6e3a702fb9 Fix data race setting size_left_ in ThreadCache::SetMaxSize
This commit is to fix the data race in ThreadCache::SetMaxSize.
ThreadCache::size_left_ is removed and ThreadCache::size_ is
added. ThreadCache::size_left_ was introduced for optimization.
It is updated in several functions of ThreadCache, including the
ThreadCache::SetMaxSize. But thread A can update size_left_ of
thread B via SetMaxSize without protection or synchronization.

There should not be data race around ThreadCache::size_, for it
isn't accessed by multi threads.

The optimization of tail-call in tc_{malloc, new, free} is kept
and no other logics are affected.
2017-10-17 01:09:18 +08:00
cs-lee
235471f965 fix memory leak in Symbolize function
[alkondratenko@gmail.com: reworded commit message]
Signed-off-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
2017-09-23 15:12:03 -07:00
cs-lee
47efdd60f5 Added mising va_end() in TracePrintf function
Normally the va_end function does not do anything,
but it should be called because some platforms need it.

[alkondratenko@gmail.com: reworded commit message]
Signed-off-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
2017-09-23 15:11:24 -07:00
Vladimir
497b60ef0f Implemented GetProgramInvocationName on FreeBSD
Few lines of code was taken from
/usr/src/contrib/libexecinfo/backtrace.c

[alkondratenko@gmail.com: updated commit message
Signed-off-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
2017-09-23 15:01:07 -07:00
Aliaksey Kandratsenka
ac072a3fc7 Revert "Ignore current_instance heap allocation when leak sanitizer is enabled"
This reverts commit 70a35422b5.
2017-09-23 14:55:33 -07:00
Aliaksey Kandratsenka
fb5987d579 Revert "Ensure that lsan flags are appended on all necessary targets"
This reverts commit a3bf61ca81.
2017-09-23 14:55:20 -07:00
Aliaksey Kandratsenka
5815f02105 Use safe getenv for setting up backtrace capturing method
This code runs very early, so using special "early" version of getenv
is reasonable. It should fix issue #912.
2017-09-23 11:35:58 -07:00
Dorin Lazăr
aab4277311 Fixed LTO warning about the mismatch between return values for ProfilingIsEnabledForAllThreads() 2017-09-23 11:19:34 -07:00
Aliaksey Kandratsenka
d406f22853 implement support for C11 aligned_alloc
Just like glibc does, we simply alias it to memalign.
2017-09-16 20:38:44 -07:00
Piotr Sikora
92a27e41a1 Fix build on macOS.
Fixes #910.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-08-21 15:06:23 -07:00
Khem Raj
e033431e5a include fcntl.h for loff_t definition
Fixes
linux_syscall_support.h:2641:26: error: 'loff_t' has not been declared

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2017-07-16 19:33:25 -07:00
Khem Raj
e41bc41404 Use ucontext_t instead of struct ucontext
Newer glibc has dropped the ucontext tag from exposing

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2017-07-16 15:57:34 -07:00
Aliaksey Kandratsenka
bf840dec04 bumped version to 2.6.1 2017-07-09 14:55:33 -07:00
Romain Geissler
2d220c7e26 Replace "throw()" by "PERFTOOLS_NOTHROW"
Automatically done with:
sed -e 's/\<throw[[:space:]]*([[:space:]]*)/PERFTOOLS_NOTHROW/g' -i
$(git grep -l 'throw[[:space:]]*([[:space:]]*)')

[alkondratenko@gmail.com: updated to define empty PERFTOOLS_NOTHROW
only on pre-c++11 standards]
2017-07-09 14:10:06 -07:00
Romain Geissler
c4de73c0e6 Add PERFTOOLS_THROW where necessary (as detected by GCC). 2017-07-08 16:22:27 -07:00
Romain Geissler
e5fbd0e24e Rename PERFTOOLS_THROW into PERFTOOLS_NOTHROW.
Automatically done with:
sed -e 's/\<PERFTOOLS_THROW\>/PERFTOOLS_NOTHROW/g' -i $(git grep -l PERFTOOLS_THROW)
2017-07-08 16:22:27 -07:00
Aliaksey Kandratsenka
eeb7b84c20 Register tcmalloc atfork handler as early as possible
This is what other mallocs do (glibc malloc and jemalloc). The idea is
malloc is usually initialized very eary. So if we register atfork
handler at that time, we're likely to be first. And that makes our
atfork handler a bit safer, since there is much less chance of some
other library installing their "take all locks" handler first and
having fork take malloc lock before library's lock and deadlocking.

This should address issue #904.
2017-07-08 16:08:29 -07:00
Aliaksey Kandratsenka
208c26caef Add initial syscall support for mips64 32-bit ABI
This applies patch by Adhemerval Zanella from
https://github.com/gperftools/gperftools/issues/845.

Only malloc (i.e. tcmalloc_minimal) was tested to work so far.
2017-07-08 13:34:41 -07:00
Francis Ricci
a3bf61ca81 Ensure that lsan flags are appended on all necessary targets 2017-07-08 13:33:30 -07:00
Aliaksey Kandratsenka
97646a1932 Add missing NEWS entry for recent 2.6 release
Somehow I managed to miss this last commit in 2.6 release. So lets add
it now even if it is too late.
2017-07-04 21:02:34 -07:00
Aliaksey Kandratsenka
4be05e43a1 bumped version up to 2.6 2017-07-04 20:35:25 -07:00
Francis Ricci
70a35422b5 Ignore current_instance heap allocation when leak sanitizer is enabled
Without this patch, any user program that enables LeakSanitizer will
see a leak from tcmalloc. Add a weak hook to __lsan_ignore_object,
so that if LeakSanitizer is enabled, the allocation can be ignored.
2017-07-04 20:24:47 -07:00
Aliaksey Kandratsenka
6eca6c64fa Revert "issue-654: [pprof] handle split text segments"
This reverts commit 8c3dc52fcf.

People have reported issues with this so lets stay safe and use older
even if less powerful code.
2017-07-01 18:48:58 -07:00
KernelMaker
a495969cb6 update the prev_class_size in each loop, or the min_object_size of tcmalloc.thread will always be 1 when calling GetFreeListSizes 2017-05-29 15:05:55 -07:00
Kim Gräsman
163224d8af Document HEAPPROFILESIGNAL environment variable 2017-05-29 15:04:00 -07:00
Aliaksey Kandratsenka
5ac82ec5b9 added stacktrace capturing benchmark 2017-05-29 14:57:13 -07:00
Aliaksey Kandratsenka
c571ae2fc9 2.6rc4 2017-05-22 19:04:20 -07:00
Aliaksey Kandratsenka
f2bae51e7e Revert "Revert "disable dynamic sized delete support by default""
This reverts commit b82d89cb7c.

Dynamic sized delete support relies on ifunc handler being able to
look up environment variable. The issue is, when stuff is linked with
-z now linker flags, all relocations are performed early. And sadly
ifunc relocations are not treated specially. So when ifunc handler
runs, it cannot rely on any dynamic relocations at all, otherwise
crash is real possibility. So we cannot afford doing it until (and if)
ifunc is fixed.

This was brought to my attention by Fedora people at
https://bugzilla.redhat.com/show_bug.cgi?id=1452813
2017-05-22 18:58:15 -07:00
Aliaksey Kandratsenka
6426c0cc80 2.6rc3 2017-05-22 03:08:30 -07:00
Aliaksey Kandratsenka
0c0e2fe43b enable 48-bit page map on msvc as well 2017-05-22 03:08:30 -07:00
Aliaksey Kandratsenka
83d6818295 speed up 3-level page map access
There is no need to have pointer indirection for root node. This also
helps the case of early free of garbage pointer because we didn't
check root_ pointer for NULL.
2017-05-22 03:08:15 -07:00
Aliaksey Kandratsenka
f7ff175b92 add configure-time warning on unsupported backtrace capturing
Both libgcc and libc's backtrace() are not really options for stack
trace capturing from inside profiling signal handler. So lets warn
people.
2017-05-22 01:55:50 -07:00
Aliaksey Kandratsenka
cef582350c align fast-path functions only if compiler supports that
Apparently gcc only supports __attribute__((aligned(N))) on functions
only since version 4.3. So lets test it in configure script and only
use when possible. We now use CACHELINE_ALIGNED_FN macro for aligning
functions.
2017-05-22 01:55:50 -07:00
Aliaksey Kandratsenka
bddf862b18 actually support very early freeing of NULL
This was caught by unit tests on centos 5. Apparently some early
thingy is trying to do vprintf which calls free(0). Which used to
crash since before size class cache is initialized it'll report
hit (with size class 0) for NULL pointer, so we'd miss the case of
checking NULL pointer free and crash.

The fix is to check for IsInited in the case when thread cache is
null, and if so then we escalte to free_null_or_invalid.
2017-05-22 01:54:56 -07:00
Aliaksey Kandratsenka
07a124d8c1 don't use arg-ful constructor attribute for early nallocx test
101 is not very early anyways and arg-ful constructor attribute is
only supported since gcc 4.3 (and e.g. rhel 5's compiler fails to
compile it). So there seems to be very little value trying to ask for
priority of 101.
2017-05-21 22:49:54 -07:00
Aliaksey Kandratsenka
5346b8a4de don't depend on SIZE_MAX definition in sampler.cc
It was reported that SIZE_MAX isn't getting defined in C++ mode when
C++ standard is less than c++11. Because we still want to support
non-c++11 systems (for now), lets make it simple and not depend on
SIZE_MAX (original google-internal code used
std::numeric_limits<ssize_t>::max, but that failed to compile on
msvc).

Fixes issue #887 and issue #889.
2017-05-21 22:49:20 -07:00
Aliaksey Kandratsenka
50125d8f70 2.6rc2 2017-05-15 00:02:43 -07:00
Aliaksey Kandratsenka
a5e8e42a47 don't link-in libunwind if libunwind.h is missing
I got report that some build environments for
https://github.com/lyft/envoy are having link-time issue due to
linking libunwind. It was happening despite libunwind.h being present,
which is clear bug as without header we won't really use libunwind.
2017-05-14 23:45:08 -07:00
Rajalakshmi Srinivasaraghavan
e92acdf98d Fix compilation error for powerpc32
Fix the following compilation error for powerpc32 platform when using
latest glibc.
error: ‘siginfo_t’ was not declared in this scope
2017-05-14 23:08:13 -07:00
Aliaksey Kandratsenka
b48403a4b0 2.6rc 2017-05-14 22:00:28 -07:00
Aliaksey Kandratsenka
53f15325d9 fix compilation of tcmalloc_unittest.cc on older llvm-gcc 2017-05-14 20:35:22 -07:00