Skip to content
Draft
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions tcmalloc/central_freelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,12 @@ inline Span* CentralFreeList<Forwarder>::ReleaseToSpans(
nonempty_.Add(span, cur_index);
span->set_nonempty_index(cur_index);
} else if (cur_index != prev_index) {
#ifdef TCMALLOC_INTERNAL_LEGACY_LOCKING
nonempty_.Remove(span, prev_index);
nonempty_.Add(span, cur_index);
#else
nonempty_.Move(span, prev_index, cur_index);
#endif
span->set_nonempty_index(cur_index);
}
return nullptr;
Expand Down Expand Up @@ -774,8 +778,12 @@ inline int CentralFreeList<Forwarder>::RemoveRange(absl::Span<void*> batch) {
const uint8_t cur_index =
IndexFor(span->is_long_lived_span(), cur_allocated, cur_bitwidth);
if (cur_index != prev_index) {
#ifdef TCMALLOC_INTERNAL_LEGACY_LOCKING
nonempty_.Remove(span, prev_index);
nonempty_.Add(span, cur_index);
#else
nonempty_.Move(span, prev_index, cur_index);
#endif
span->set_nonempty_index(cur_index);
}
}
Expand Down
20 changes: 20 additions & 0 deletions tcmalloc/hinted_tracker_lists.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ class HintedTrackerLists {
}
--size_;
}

// Moves pointer <pt> from list `from` to list `to`.
// REQUIRES: from < N && to < N && pt != nullptr
void Move(TrackerType* absl_nonnull pt TCMALLOC_CAPTURED_BY_THIS,
const size_t from, const size_t to) {
TC_ASSERT_LT(from, N);
TC_ASSERT_LT(to, N);
// This check is not strictly required, but we should avoid the linked list
// manipulations if we can.
TC_ASSERT_NE(from, to);
TC_ASSERT_NE(pt, nullptr);

if (lists_[from].remove(pt)) {
TC_ASSERT(nonempty_.GetBit(from));
nonempty_.ClearBit(from);
}
lists_[to].prepend(pt);
nonempty_.SetBit(to);
}

const TrackerList& operator[](const size_t n) const {
TC_ASSERT_LT(n, N);
return lists_[n];
Expand Down
Loading