Commit Graph

681 Commits

Author SHA1 Message Date
Steve Langasek
3134955875 Additional porting for riscv64.
Adds handling for the PC register, malloc_hook_mmap, and syscalls.

Successfully built in Ubuntu with these changes.
2020-12-19 18:16:39 -08:00
Steve Langasek
f0e289bdbb Enable build on riscv64.
Cacheline length may be implementation-specific, but this is known to be
correct on the U54.
2020-12-19 18:16:38 -08:00
Tim Gates
6c715b4fa1 docs: fix simple typo, defininitions -> definitions
There is a small typo in src/base/linux_syscall_support.h.

Should read `definitions` rather than `defininitions`.
2020-12-19 18:15:14 -08:00
Aliaksey Kandratsenka
02d5264018 Revert "drop page heap lock when returning memory back to kernel"
This reverts commit be3da70298.

There are reports of crashes and false-positive OOMs from this
patch. Crashes under aggressive decommit mode are understood, but I
have yet to get confirmations whether false-positive OOMs were seen
under aggressive decommit or not. Thus lets revert for now.

Updates issue #1227 and issue #1204.
2020-12-19 17:15:31 -08:00
Grant Henke
151cbf5146 Add OS X arm64 program counter
[alkondratenko@gmail.com: updated comment that it is tested]

Signed-off-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
2020-12-19 12:39:15 -08:00
Aliaksey Kandratsenka (aka Aliaksei Kandratsenka)
140e3481d0
Merge pull request #1231 from PatriosTheGreat/master
Fix implicit-int-float-conversion warning.
2020-11-17 14:30:59 -08:00
Levon Ter-Grigoryan
0fc5cabdfc Fix implicit-int-float-conversion warning. 2020-11-17 12:29:22 +01:00
Kerrick Staley
bda3c82e11 Increase kMaxStackDepth to 254
[alkondratenko@gmail.com: reduced value from 256 to 254]
2020-07-11 21:25:45 -07:00
Aliaksey Kandratsenka
1d9b8bb59d don't test sbrk hook if we're on linux and don't have __sbrk
"mmap" hooks code for linux only hooks sbrk when __sbrk is
defined. But musl doesn't offer this function (reasonably so), so
sbrk hooking doesn't work there. Not big loss, but lets make sure
tests don't fail.

Lets reference this to issue #1198
2020-07-11 20:51:50 -07:00
Aliaksey Kandratsenka
180bfa10d7 bumped version to 2.8 2020-07-06 02:51:43 -07:00
Ryan Macnak
c1bcc412ba Don't try to mark esp as clobbered in linux syscall support.
Compare 9e5b162873, issue #1076
2020-07-06 01:46:48 -07:00
Aliaksey Kandratsenka
50f89afaed liberate gperftools tests from relying on -fno-builtin-XXX flags
Clang mostly ignores those anyways, so our tests needed better way to
disable optimizations (clang is quite aggressive replacing new/delete
pair with stack allocation).
2020-07-06 00:58:56 -07:00
Aliaksey Kandratsenka
98ccd0f102 prevent inlining in heap-checker unittest
The test relies on stuff "mmaper" function not being inlined, but
compilers are getting smarter and latest clang actually does inline it
now. Adding volatile to pointer declaration fixes it.
2020-07-05 23:26:12 -07:00
Aliaksey Kandratsenka
e521472f1a fix linking of page_heap_test on windows
After change to release page heap lock around returning memory back to
kernel, page heap test got dependency on page heap lock. Which was not
available on windows since relevant symbols are not exported.

Proposed fix is to simply duplicate all needed .cc files in
page_heap_test project instead of linking to dll. This is not perfect
but gets job done, until we figure out better solution (GNU/Linux will
eventually get hidden visibility and will need it).

This fixes github issue 1189.
2020-07-05 23:17:36 -07:00
Aliaksey Kandratsenka
e5f77d6485 chmod -x Makefile.am gperftools.sln 2020-03-23 01:22:16 -07:00
Aliaksey Kandratsenka
6b92e00cec don't assume HAVE_MMAP on mingw builds
Fixes github issue #1108.
2020-03-23 01:15:40 -07:00
Kirill Müller
4cddede399 New ProfilerGetStackTrace() 2020-03-08 23:58:13 -07:00
Aliaksey Kandratsenka
db7aa547ab bumped version to 2.8rc 2020-03-08 21:06:08 -07:00
Aliaksey Kandratsenka
be3da70298 drop page heap lock when returning memory back to kernel
Fixes issue #754.
2020-03-08 19:32:02 -07:00
Aliaksey Kandratsenka
87acc2782f amputate span events history
Nobody used it in years. Abseil tcmalloc had it amputated years ago.
2020-03-08 18:22:17 -07:00
Ilya Leoshkevich
e40c7f231a Fix mmap syscall on s390
mmap arguments must be passed in an array on s390.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
2020-03-08 18:13:40 -07:00
Jon Kohler
b7607ee7d4 tcmalloc: ability to disable fallback allocator in memfs
Whenever tcmalloc memfs allocator runs out of huge memory, it falls back to the
default system allocator, which will start allocating from normal anonymous
memory pool (small pages).  For use cases that exclusively want hugepage backed
memory, such as using tcmalloc in combination with Intel SPDK, this is
problematic.

This change adds an environment variable "TCMALLOC_MEMFS_DISABLE_FALLBACK"
which when set to true will ensure that tcmalloc doesn't fallback to using the
system allocator when the system runs out of hugepages. This is false by
default, such that all other tcmalloc consumers will not see any changes.

For those curious, you can see part of our upstream SPDK work here: 
https://review.gerrithub.io/c/spdk/spdk/+/475943
2020-02-23 12:25:15 -08:00
Jon Kohler
1bfcb5bc3a tcmalloc: fragmentation overhead instrumentation
This patch adds visibility into the overhead due to fragmentation for each size
class in the tcmalloc central free list, which is helpful when debugging
fragmentation issues.
2020-02-23 12:17:22 -08:00
Todd Lipcon
36bf1309de Fix a clang-tidy readability warning for static member access
This fixes the following warning:

src/thread_cache.cc:281:10: warning: static member accessed through instance [readability-static-accessed-through-instance]
  return sampler_.GetSamplePeriod();
         ^~~~~~~~~~~~~~~~~~~~~~~~
         tcmalloc::Sampler::
2020-02-10 00:53:46 -08:00
prehistoricpenguin
2b2a962c2b Remove executable flag for c++ files 2020-02-09 23:46:29 -08:00
Henrik Edin
8f308afbfe Increase kClassSizesMax to 128 to allow for page size of 4K 2020-02-09 23:26:07 -08:00
Henrik Edin
d3fefdb694 Allow configuring page size to 4K, 8K, 16K, 32K, 64K, 128K and 256K 2020-02-09 23:26:06 -08:00
Laurent Stacul
cf2df3b000 Fix the removed std::allocator::pointer member type removed in C++20 2020-02-09 23:16:50 -08:00
shipujin
31024506c5 Add mips64* support 2020-02-09 22:59:33 -08:00
Holy Wu
fe62a0baab Update config.h in Windows 2019-04-21 23:14:40 -07:00
8272631b5a
Fix a long time typo
Thought this fix may not effect the behavior or performance, but it seems indeed a bug.
2019-04-17 10:55:06 +08:00
Aliaksey Kandratsenka
c1d546d7b2 never test and always default HAVE_MMAP to on
This should alleviate vboxfs problems from issue #1008.
2019-04-07 21:48:00 -07:00
pkubaj
fba6ce0e7a Fix build on FreeBSD
On FreeBSD the following syntax is used:
mr REGA,REGB
2019-04-07 14:25:40 -07:00
Jakub Wilk
98ac4ee9bc Fix typos 2019-04-07 13:32:47 -07:00
Aliaksey Kandratsenka
9e5b162873 don't try to mark rsp as clobbered in linux syscall support
rsp is not actually clobbered by that code and later gccs actually (correctly) bark
at it.

Fixed issue #1076.
2019-02-10 12:46:22 -08:00
Romain Geissler
1e36ed7055 Use initial exec TLS model for all thread local variables from thread_cache.cc
This avoids a deadlock when a library which is being dlopen'ed creates
as part of its static constructors a thread which quickly need to call
malloc. We are still in the dlopen call (so with some internal glibc
mutex taken) when the thread executes code and later needs to call
malloc which in term calls tls_get_addr_tail, which wait for the dlopen
mutex to be unlocked. If later the dlopen'ing thread also calls malloc
as part of its constructors, we are in a deadlock.

Fix is similar to
7852eeb75b

Stack of the dlopening thread:
    #0  0x00007fd5406ca93c in __lll_lock_wait () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libpthread.so.0
    #1  0x00007fd5406c45a5 in pthread_mutex_lock () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libpthread.so.0
    ... proprietary code in the stack
    #9  0x00007fd5074f0367 in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at src/ClientImpl.cpp:15
    #10 0x00007fd5074f06d7 in _GLOBAL__sub_I_ClientImpl.cpp(void) () at src/ClientImpl.cpp:85
    #11 0x00007fd50757aa46 in __do_global_ctors_aux ()
    #12 0x00007fd5073e985f in _init () from ...
    #13 0x00007fd53bf9dec8 in ?? () from ...
    #14 0x00007fd54d637a5d in call_init.part () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/ld-linux-x86-64.so.2
    #15 0x00007fd54d637bab in _dl_init () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/ld-linux-x86-64.so.2
    #16 0x00007fd54d63c160 in dl_open_worker () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/ld-linux-x86-64.so.2
    #17 0x00007fd54d637944 in _dl_catch_error () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/ld-linux-x86-64.so.2
    #18 0x00007fd54d63b7d9 in _dl_open () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/ld-linux-x86-64.so.2
    #19 0x00007fd54d61f2b9 in dlopen_doit () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libdl.so.2
    #20 0x00007fd54d637944 in _dl_catch_error () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/ld-linux-x86-64.so.2
    #21 0x00007fd54d61f889 in _dlerror_run () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libdl.so.2
    #22 0x00007fd54d61f351 in dlopen@@GLIBC_2.2.5 () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libdl.so.2

Stack of the newly created thread calling tls_get_addr_tail:
    #0  0x00007fd5406ca93c in __lll_lock_wait () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libpthread.so.0
    #1  0x00007fd5406c4622 in pthread_mutex_lock () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libpthread.so.0
    #2  0x00007fd54d63a2ed in tls_get_addr_tail () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/ld-linux-x86-64.so.2
    #3  0x00007fd53fee877d in tcmalloc::ThreadCache::CreateCacheIfNecessary () at src/thread_cache.cc:344
    #4  0x00007fd53fecb4ab in tcmalloc::ThreadCache::GetCache () at src/thread_cache.h:437
    #5  0x00007fd53fefeccb in (anonymous namespace)::do_malloc (size=56) at src/tcmalloc.cc:1354
    #6  tcmalloc::do_allocate_full<tcmalloc::cpp_throw_oom> (size=56) at src/tcmalloc.cc:1762
    #7  tcmalloc::allocate_full_cpp_throw_oom (size=56) at src/tcmalloc.cc:1776
    #8  0x00007fd53ff01b80 in tcmalloc::dispatch_allocate_full<tcmalloc::cpp_throw_oom> (size=56) at src/tcmalloc.cc:1785
    #9  malloc_fast_path<tcmalloc::cpp_throw_oom> (size=56) at src/tcmalloc.cc:1845
    #10 tc_new (size=56) at src/tcmalloc.cc:1980
    ... proprietary code in the stack
    #26 0x00007fd5406c1ef4 in start_thread () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libpthread.so.0
    #27 0x00007fd5403ba01d in clone () from /data3/mwrep/rgeissler/core.tls/opt/1A/toolchain/x86_64-2.6.32-v2/lib64/libc.so.6
2019-02-10 11:57:18 -08:00
pkubaj
8f9a873fce Fix accessing PC on FreeBSD/powerpc and powerpc64 2019-02-10 11:47:03 -08:00
Tulio Magno Quites Machado Filho
fc00474ddc Include asm/ptrace.h when accessing ucontext_t
In some architectures (e.g. powerpc, powerpc64 and powerpc64le), the
macro that specifies the position of the program counter is defined in
header asm/ptrace.h.

When glibc bug 21457 got fixed in version 2.27, header sys/ucontext.h
stopped including signal.h, which indirectly removed asm/ptrace.h too.

Signed-off-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
2019-02-10 11:16:56 -08:00
Laurent Stacul
5574c87e39 Compile time aggressive decommit option
[alkondratenko@gmail.com: performed s/agressive/aggressive/g]
Signed-off-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
2019-02-10 11:14:23 -08:00
Fabrice Fontaine
e9ab4c5304 undef mmap64 function
mmap64 can already been defined and as a result the following error is
raised:

In file included from src/malloc_hook.cc:686:0:
src/malloc_hook_mmap_linux.h: In function ‘void* mmap(void*, size_t, int, int, int, off_t)’:
src/malloc_hook_mmap_linux.h:173:18: error: redefinition of ‘void* mmap(void*, size_t, int, int, int, off_t)’
 extern "C" void* mmap(void *start, size_t length, int prot, int flags,
                  ^~~~
In file included from src/malloc_hook.cc:41:0:
src/malloc_hook_mmap_linux.h:159:18: note: ‘void* mmap(void*, size_t, int, int, int, off_t)’ previously defined here
 extern "C" void* mmap64(void *start, size_t length, int prot, int flags,
                  ^
Makefile:4874: recipe for target 'src/libtcmalloc_minimal_internal_la-malloc_hook.lo' failed

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2018-10-07 11:22:59 -07:00
Aliaksey Kandratsenka
5eec9d0ae3 Drop not very portable and not very useful unwind benchmark. 2018-10-07 08:17:04 -07:00
Fabrice Fontaine
1561f0946f check for __sbrk
__sbrk is not defined in musl so add a check for it in configure.ac and
replace the check on ifndef __UCLIBC__ by a check on ifdef HAVE__SBRK
in src/malloc_hook_mmap_linux.h

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2018-10-06 16:58:55 -07:00
Gabriel Marin
1de76671d4 Fix mmap region iteration while no regions are recorded.
If no mmap regions are recorded, iteration failed since the RegionSet
(std::set) object is not initialized.

Original CL https://codereview.chromium.org/14769008

Reviewed-on: https://chromium-review.googlesource.com/c/1130807
2018-10-06 11:39:39 -07:00
Fabrice Fontaine
acdcacc28f Use off64_t instead of __off64_t
__off64_t is a kernel internal symbol, which happens to be user-visible
with glibc, but not necessarily with other C libraries such as musl.

Switching from __off64_t to off64_t allows the code to build properly
with musl.

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2018-10-06 11:28:27 -07:00
Gabriel Marin
0177a2420a Return early in WriteProfile to reduce indentation
Small code refactoring to reduce indentation. This change was originally
part of https://codereview.chromium.org/9963095.

Reviewed-on: https://chromium-review.googlesource.com/c/1130804
2018-10-06 11:24:01 -07:00
Gabriel Marin
b85652bf26 Add generic.total_physical_bytes property to MallocExtension
Original CL:

- https://codereview.chromium.org/1410353005

  Add generic.total_physical_bytes property to MallocExtension

  The actual physical memory usage of tcmalloc cannot be obtained by
  GetNumericProperty. This accounts for the current_allocated_bytes,
  fragmentation and malloc metadata, and excludes the unmapped memory
  regions. This helps the user to understand how much memory is actually
  being used for the allocations that were made.

Reviewed-on: https://chromium-review.googlesource.com/1130803
2018-10-06 11:07:59 -07:00
Gabriel Marin
90df23c81f Make some tcmalloc constants truly const
Reviewed-on: https://chromium-review.googlesource.com/c/1130809
2018-10-05 17:17:55 -07:00
Aliaksey Kandratsenka
49dbe4362b Add comment about gperftools 2.8 not deduplicating heapz samples. 2018-09-03 16:44:52 -07:00
Aliaksey Kandratsenka
63a12a5ed3 Drop de-duplication of heap sample (aka heapz) entries.
pprof can aggregate them, and it can do it way better than we can. With
proper unsampling etc.
2018-08-27 20:10:09 -07:00
Aliaksey Kandratsenka
954f9dc0e3 Add flag to disable installing unmaintained & deprecated pprof.
Everyone should be using golang pprof from github.com/google/pprof, but
distros still ship our perl version and not everyone is aware of
better pprof yet.

This is another step in completely dropping perl pprof. We still
default to installing it, but hopefully we'll be able to convince
distros to disable this soon.

We still install pprof under pprof-symbolize name because
stack traces symbolization depends on it, and because golang pprof
won't support this feature.

This is related to issue #1038.
2018-08-26 11:37:59 -07:00