Skip to content

Commit

Permalink
Remove the unified alloc feature from the HugePageFiller
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 662669066
Change-Id: I6aa7b178b717f8eec658fb27ad57ca0e96fb41f4
  • Loading branch information
nilayvaish authored and copybara-github committed Aug 13, 2024
1 parent ff292bc commit a40d2c7
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 144 deletions.
7 changes: 0 additions & 7 deletions tcmalloc/global_stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,6 @@ void DumpStats(Printer* out, int level) {
Parameters::huge_region_demand_based_release() ? 1 : 0);
out->printf("PARAMETER tcmalloc_release_pages_from_huge_region %d\n",
Parameters::release_pages_from_huge_region() ? 1 : 0);
out->printf(
"PARAMETER tcmalloc_separate_allocs_for_few_and_many_objects_spans "
"%d\n",
Parameters::separate_allocs_for_few_and_many_objects_spans());
out->printf("PARAMETER tcmalloc_use_wider_slabs %d\n",
tc_globals.cpu_cache().UseWiderSlabs() ? 1 : 0);
out->printf("PARAMETER tcmalloc_configure_size_class_max_capacity %d\n",
Expand Down Expand Up @@ -756,9 +752,6 @@ void DumpStatsInPbtxt(Printer* out, int level) {
Parameters::profile_sampling_interval());
region.PrintRaw("percpu_vcpu_type",
PerCpuTypeString(subtle::percpu::GetRseqVcpuMode()));
region.PrintBool(
"separate_allocs_for_few_and_many_objects_spans",
Parameters::separate_allocs_for_few_and_many_objects_spans());
region.PrintBool("tcmalloc_use_wider_slabs",
tc_globals.cpu_cache().UseWiderSlabs());
region.PrintBool("tcmalloc_configure_size_class_max_capacity",
Expand Down
7 changes: 1 addition & 6 deletions tcmalloc/huge_page_aware_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ class StaticForwarder {
struct HugePageAwareAllocatorOptions {
MemoryTag tag;
HugeRegionUsageOption use_huge_region_more_often = huge_region_option();
HugePageFillerAllocsOption allocs_for_sparse_and_dense_spans =
Parameters::separate_allocs_for_few_and_many_objects_spans()
? HugePageFillerAllocsOption::kSeparateAllocs
: HugePageFillerAllocsOption::kUnifiedAllocs;
absl::Duration huge_cache_time = Parameters::huge_cache_release_time();
};

Expand Down Expand Up @@ -400,8 +396,7 @@ inline HugePageAwareAllocator<Forwarder>::HugePageAwareAllocator(
: PageAllocatorInterface("HugePageAware", options.tag),
unback_(*this),
unback_without_lock_(*this),
filler_(options.allocs_for_sparse_and_dense_spans, unback_,
unback_without_lock_),
filler_(unback_, unback_without_lock_),
regions_(options.use_huge_region_more_often),
vm_allocator_(*this),
metadata_allocator_(*this),
Expand Down
9 changes: 1 addition & 8 deletions tcmalloc/huge_page_aware_allocator_fuzz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ void FuzzHPAA(const std::string& s) {
// [1] - HugeRegionsMode.
// [2] - HugeCache release time
// [3:4] - Reserved.
// [5] - Determine if we use separate filler allocs based on number of
// objects per span.
// [5] - (available)
// [6:12] - Reserved.
//
// TODO(b/271282540): Convert these to strongly typed fuzztest parameters.
Expand Down Expand Up @@ -115,11 +114,6 @@ void FuzzHPAA(const std::string& s) {
? HugeRegionUsageOption::kDefault
: HugeRegionUsageOption::kUseForAllLargeAllocs;

const HugePageFillerAllocsOption allocs_option =
static_cast<uint8_t>(data[5]) >= 128
? HugePageFillerAllocsOption::kUnifiedAllocs
: HugePageFillerAllocsOption::kSeparateAllocs;

const int32_t huge_cache_release_s = std::max<int32_t>(data[2], 1);

// data[6:12] - Reserve additional bytes for any features we might want to add
Expand All @@ -134,7 +128,6 @@ void FuzzHPAA(const std::string& s) {
HugePageAwareAllocatorOptions options;
options.tag = tag;
options.use_huge_region_more_often = huge_region_option;
options.allocs_for_sparse_and_dense_spans = allocs_option;
options.huge_cache_time = absl::Seconds(huge_cache_release_s);
HugePageAwareAllocator<FakeStaticForwarderWithUnback>* allocator;
allocator =
Expand Down
30 changes: 8 additions & 22 deletions tcmalloc/huge_page_filler.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,11 @@ template <class TrackerType>
class HugePageFiller {
public:
explicit HugePageFiller(
HugePageFillerAllocsOption allocs_option,
MemoryModifyFunction& unback ABSL_ATTRIBUTE_LIFETIME_BOUND,
MemoryModifyFunction& unback_without_lock ABSL_ATTRIBUTE_LIFETIME_BOUND);
HugePageFiller(Clock clock, HugePageFillerAllocsOption allocs_options,
MemoryModifyFunction& unback ABSL_ATTRIBUTE_LIFETIME_BOUND,
MemoryModifyFunction& unback_without_lock
ABSL_ATTRIBUTE_LIFETIME_BOUND);
HugePageFiller(
Clock clock, MemoryModifyFunction& unback ABSL_ATTRIBUTE_LIFETIME_BOUND,
MemoryModifyFunction& unback_without_lock ABSL_ATTRIBUTE_LIFETIME_BOUND);

typedef TrackerType Tracker;

Expand Down Expand Up @@ -446,8 +444,6 @@ class HugePageFiller {
// n_used_partial_released_ is the number of pages which have been allocated
// from the hugepages in the set regular_alloc_partial_released.
Length n_used_partial_released_[AccessDensityPrediction::kPredictionCounts];
const HugePageFillerAllocsOption allocs_for_sparse_and_dense_spans_ =
HugePageFillerAllocsOption::kUnifiedAllocs;

// RemoveFromFillerList pt from the appropriate PageTrackerList.
void RemoveFromFillerList(TrackerType* pt);
Expand Down Expand Up @@ -639,19 +635,17 @@ inline Length PageTracker::free_pages() const {

template <class TrackerType>
inline HugePageFiller<TrackerType>::HugePageFiller(
HugePageFillerAllocsOption allocs_option, MemoryModifyFunction& unback,
MemoryModifyFunction& unback_without_lock)
MemoryModifyFunction& unback, MemoryModifyFunction& unback_without_lock)
: HugePageFiller(Clock{.now = absl::base_internal::CycleClock::Now,
.freq = absl::base_internal::CycleClock::Frequency},
allocs_option, unback, unback_without_lock) {}
unback, unback_without_lock) {}

// For testing with mock clock
template <class TrackerType>
inline HugePageFiller<TrackerType>::HugePageFiller(
Clock clock, HugePageFillerAllocsOption allocs_option,
MemoryModifyFunction& unback, MemoryModifyFunction& unback_without_lock)
: allocs_for_sparse_and_dense_spans_(allocs_option),
size_(NHugePages(0)),
Clock clock, MemoryModifyFunction& unback,
MemoryModifyFunction& unback_without_lock)
: size_(NHugePages(0)),
fillerstats_tracker_(clock, absl::Minutes(10), absl::Minutes(5)),
clock_(clock),
unback_(unback),
Expand Down Expand Up @@ -731,8 +725,6 @@ HugePageFiller<TrackerType>::TryGet(Length n, SpanAllocInfo span_alloc_info) {

bool was_released = false;
const AccessDensityPrediction type =
ABSL_PREDICT_TRUE(allocs_for_sparse_and_dense_spans_ ==
HugePageFillerAllocsOption::kSeparateAllocs) &&
IsDenseSpan(span_alloc_info.density)
? AccessDensityPrediction::kDense
: AccessDensityPrediction::kSparse;
Expand Down Expand Up @@ -858,8 +850,6 @@ inline void HugePageFiller<TrackerType>::Contribute(
TC_ASSERT_EQ(pt->released_pages(), Length(0));

const AccessDensityPrediction type =
ABSL_PREDICT_TRUE(allocs_for_sparse_and_dense_spans_ ==
HugePageFillerAllocsOption::kSeparateAllocs) &&
IsDenseSpan(span_alloc_info.density)
? AccessDensityPrediction::kDense
: AccessDensityPrediction::kSparse;
Expand Down Expand Up @@ -1924,8 +1914,6 @@ inline void HugePageFiller<TrackerType>::RemoveFromFillerList(TrackerType* pt) {
size_t chunk = IndexFor(pt);
size_t i = ListFor(longest, chunk);
const AccessDensityPrediction type =
ABSL_PREDICT_TRUE(allocs_for_sparse_and_dense_spans_ ==
HugePageFillerAllocsOption::kSeparateAllocs) &&
pt->HasDenseSpans()
? AccessDensityPrediction::kDense
: AccessDensityPrediction::kSparse;
Expand Down Expand Up @@ -1957,8 +1945,6 @@ inline void HugePageFiller<TrackerType>::AddToFillerList(TrackerType* pt) {

size_t i = ListFor(longest, chunk);
const AccessDensityPrediction type =
ABSL_PREDICT_TRUE(allocs_for_sparse_and_dense_spans_ ==
HugePageFillerAllocsOption::kSeparateAllocs) &&
pt->HasDenseSpans()
? AccessDensityPrediction::kDense
: AccessDensityPrediction::kSparse;
Expand Down
8 changes: 1 addition & 7 deletions tcmalloc/huge_page_filler_fuzz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void FuzzFiller(const std::string& s) {
// HugePageFiller.
//
// [0] - (available)
// [1] - We choose the separate_allocs_for_few_and_many_objects_spans
// [1] - (available)
// [2] - (available)
//
// Afterwards, we read 5 bytes at a time until the buffer is exhausted.
Expand All @@ -116,16 +116,10 @@ void FuzzFiller(const std::string& s) {
// For example, this input can provide a Length to
// allocate, or the index of the previous allocation to
// deallocate.

const HugePageFillerAllocsOption allocs_for_few_and_many_objects_spans =
static_cast<uint8_t>(data[1]) >= 128
? HugePageFillerAllocsOption::kSeparateAllocs
: HugePageFillerAllocsOption::kUnifiedAllocs;
data += kInitBytes;
size -= kInitBytes;

HugePageFiller<PageTracker> filler(Clock{.now = mock_clock, .freq = freq},
allocs_for_few_and_many_objects_spans,
unback, unback);

struct Alloc {
Expand Down
Loading

0 comments on commit a40d2c7

Please sign in to comment.