aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAliaksey Kandratsenka <alkondratenko@gmail.com>2016-02-21 19:26:37 -0800
committerAliaksey Kandratsenka <alkondratenko@gmail.com>2016-02-21 19:26:37 -0800
commit7dd4af65365d74a5d8d30d5811c26117a9192238 (patch)
treec54ea9917d734788158a3a0a9168af9f7488c953
parent4f3410e759ec42cb307429222d690a81e3cd37b0 (diff)
downloadgperftools-7dd4af65365d74a5d8d30d5811c26117a9192238.tar.gz
don't round up sizes for large allocation when sampling
This closes #723. Since rounding up prior to sampling is introducing possibility of arithmetic overflow, we're just not doing it. It introduces some error (up to 4k), but since we're dealing with at least 256k allocations, we're fine.
-rw-r--r--src/tcmalloc.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/tcmalloc.cc b/src/tcmalloc.cc
index 2f74fa5..578ea5c 100644
--- a/src/tcmalloc.cc
+++ b/src/tcmalloc.cc
@@ -1154,8 +1154,13 @@ inline void* do_malloc_pages(ThreadCache* heap, size_t size) {
bool report_large;
Length num_pages = tcmalloc::pages(size);
- size = num_pages << kPageShift;
+ // NOTE: we're passing original size here as opposed to rounded-up
+ // size as we do in do_malloc_small. The difference is small here
+ // (at most 4k out of at least 256k). And not rounding up saves us
+ // from possibility of overflow, which rounding up could produce.
+ //
+ // See https://github.com/gperftools/gperftools/issues/723
if (heap->SampleAllocation(size)) {
result = DoSampledAllocation(size);