Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion tcmalloc/central_freelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,12 @@ inline Span* CentralFreeList<Forwarder>::ReleaseToSpans(

const uint8_t prev_index = span->nonempty_index();
const uint16_t prev_allocated = span->Allocated();
#ifndef TCMALLOC_INTERNAL_LEGACY_LOCKING
const uint8_t prev_bitwidth =
absl::bit_width(static_cast<unsigned>(prev_allocated));
#else
const uint8_t prev_bitwidth = absl::bit_width(prev_allocated);
#endif
if (ABSL_PREDICT_FALSE(
!span->FreelistPushBatch(batch, object_size, size_reciprocal))) {
// Update the histogram as the span is full and will be removed from the
Expand All @@ -483,7 +488,12 @@ inline Span* CentralFreeList<Forwarder>::ReleaseToSpans(
// utilization to the histogram after we release objects to the span.
uint16_t cur_allocated = prev_allocated - batch.size();
TC_ASSERT_EQ(cur_allocated, span->Allocated());
#ifndef TCMALLOC_INTERNAL_LEGACY_LOCKING
const uint8_t cur_bitwidth =
absl::bit_width(static_cast<unsigned>(cur_allocated));
#else
const uint8_t cur_bitwidth = absl::bit_width(cur_allocated);
#endif
if (cur_bitwidth != prev_bitwidth) {
RecordSpanUtil(prev_bitwidth, /*increase=*/false);
RecordSpanUtil(cur_bitwidth, /*increase=*/true);
Expand Down Expand Up @@ -714,8 +724,11 @@ inline int CentralFreeList<Forwarder>::RemoveRange(absl::Span<void*> batch) {
const uint16_t prev_allocated = span->Allocated();
#ifndef TCMALLOC_INTERNAL_LEGACY_LOCKING
ASSUME(prev_allocated > 0);
#endif
const uint8_t prev_bitwidth =
absl::bit_width(static_cast<unsigned>(prev_allocated));
#else
const uint8_t prev_bitwidth = absl::bit_width(prev_allocated);
#endif
TC_ASSERT_EQ(prev_index, span->nonempty_index());
#ifdef TCMALLOC_INTERNAL_LEGACY_LOCKING
// Clobber prev_index to trigger reload, restoring previous behavior.
Expand All @@ -737,7 +750,12 @@ inline int CentralFreeList<Forwarder>::RemoveRange(absl::Span<void*> batch) {
// add it again once we pop the objects.
const uint16_t cur_allocated = prev_allocated + here;
TC_ASSERT_EQ(cur_allocated, span->Allocated());
#ifndef TCMALLOC_INTERNAL_LEGACY_LOCKING
const uint8_t cur_bitwidth =
absl::bit_width(static_cast<unsigned>(cur_allocated));
#else
const uint8_t cur_bitwidth = absl::bit_width(cur_allocated);
#endif
if (cur_bitwidth != prev_bitwidth) {
RecordSpanUtil(prev_bitwidth, /*increase=*/false);
RecordSpanUtil(cur_bitwidth, /*increase=*/true);
Expand Down
Loading