Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ckmalloc
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaytonKnittel committed Nov 2, 2024
2 parents 3dc1b4d + 90c8012 commit 6b85202
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 30 deletions.
6 changes: 6 additions & 0 deletions folly.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ cc_library(
name = "folly",
srcs = [
"folly/Demangle.cpp",
"folly/ExceptionString.cpp",
"folly/Executor.cpp",
"folly/Random.cpp",
"folly/ScopeGuard.cpp",
"folly/SharedMutex.cpp",
"folly/SingletonThreadLocal.cpp",
"folly/concurrency/CacheLocality.cpp",
"folly/container/detail/F14Table.cpp",
"folly/detail/Futex.cpp",
"folly/detail/StaticSingletonManager.cpp",
"folly/detail/ThreadLocalDetail.cpp",
Expand All @@ -19,7 +22,10 @@ cc_library(
"folly/memory/ReentrantAllocator.cpp",
"folly/memory/SanitizeLeak.cpp",
"folly/memory/detail/MallocImpl.cpp",
"folly/portability/SysMembarrier.cpp",
"folly/synchronization/AsymmetricThreadFence.cpp",
"folly/synchronization/Hazptr.cpp",
"folly/synchronization/HazptrDomain.cpp",
"folly/synchronization/ParkingLot.cpp",
"folly/synchronization/SanitizeThread.cpp",
"folly/system/AtFork.cpp",
Expand Down
13 changes: 8 additions & 5 deletions src/correctness_checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ absl::Status CorrectnessChecker::Check(
CorrectnessChecker::CorrectnessChecker(TracefileReader& reader,
HeapFactory& heap_factory, bool verbose)
: MallocRunner(reader, heap_factory, verbose),
heap_factory_(&heap_factory),
allocated_blocks_(reader.SuggestedAtomicMapSize()) {}
heap_factory_(&heap_factory) {}

absl::Status CorrectnessChecker::PostAlloc(void* ptr, size_t size,
std::optional<size_t> alignment,
Expand Down Expand Up @@ -124,9 +123,13 @@ absl::Status CorrectnessChecker::PostRealloc(void* new_ptr, void* old_ptr,
kFailedTestPrefix, old_ptr, size));
}
} else {
// This write cannot be a race since operations on allocations are
// synchronized.
block_it->second.size = size;
auto result = allocated_blocks_.assign(new_ptr, size);
if (!result.has_value()) {
return absl::InternalError(
absl::StrFormat("Reassigning size of realloc-ed memory %p from %zu "
"to %zu failed, not found in map.",
new_ptr, orig_size, size));
}
}

RETURN_IF_ERROR(
Expand Down
4 changes: 2 additions & 2 deletions src/correctness_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <optional>

#include "absl/status/status.h"
#include "folly/AtomicHashMap.h"
#include "folly/concurrency/ConcurrentHashMap.h"

#include "src/heap_factory.h"
#include "src/malloc_runner.h"
Expand All @@ -28,7 +28,7 @@ class CorrectnessChecker : private MallocRunner {
uint64_t magic_bytes;
};

using BlockMap = folly::AtomicHashMap<void*, AllocatedBlock>;
using BlockMap = folly::ConcurrentHashMap<void*, AllocatedBlock>;

CorrectnessChecker(TracefileReader& reader, HeapFactory& heap_factory,
bool verbose);
Expand Down
6 changes: 1 addition & 5 deletions src/tracefile_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include "absl/status/status.h"
#include "absl/synchronization/mutex.h"
#include "folly/AtomicHashMap.h"
#include "util/absl_util.h"

#include "proto/tracefile.pb.h"
Expand Down Expand Up @@ -192,10 +191,7 @@ absl::Status TracefileExecutor::ProcessTracefileMultithreaded(
std::atomic<bool> done = false;

std::atomic<size_t> idx = 0;
HashIdMap id_map_container{
.id_map = folly::AtomicHashMap<uint64_t, void*>(
reader_.SuggestedAtomicMapSize()),
};
HashIdMap id_map_container;

absl::Mutex queue_mutex;
std::deque<uint64_t> queued_idxs;
Expand Down
6 changes: 3 additions & 3 deletions src/tracefile_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/synchronization/mutex.h"
#include "folly/AtomicHashMap.h"
#include "folly/concurrency/ConcurrentHashMap.h"

#include "src/heap_factory.h"
#include "src/tracefile_reader.h"
Expand Down Expand Up @@ -53,13 +53,13 @@ class TracefileExecutor {

private:
struct HashIdMap {
folly::AtomicHashMap<uint64_t, void*> id_map;
folly::ConcurrentHashMap<uint64_t, void*> id_map;

bool SetId(uint64_t id, void* ptr) {
auto [it, inserted] = id_map.insert({ id, ptr });
return inserted;
}
std::optional<void*> GetId(uint64_t id) {
std::optional<void*> GetId(uint64_t id) const {
auto it = id_map.find(id);
return it != id_map.end() ? std::optional(it->second) : std::nullopt;
}
Expand Down
6 changes: 0 additions & 6 deletions src/tracefile_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ size_t TracefileReader::size() const {
return tracefile_.lines_size();
}

size_t TracefileReader::SuggestedAtomicMapSize() const {
// Use load factor of ~50%, assuming about 50% of operations are allocs and
// 50% are frees.
return size();
}

TracefileReader::const_iterator TracefileReader::begin() const {
return tracefile_.lines().cbegin();
}
Expand Down
4 changes: 0 additions & 4 deletions src/tracefile_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class TracefileReader {

size_t size() const;

// A suggested size to use for atomic maps that will contain all allocated
// pointers from this trace.
size_t SuggestedAtomicMapSize() const;

const_iterator begin() const;
const_iterator end() const;

Expand Down
11 changes: 8 additions & 3 deletions src/utiltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ absl::StatusOr<double> Utiltest::MeasureUtilization(
}

Utiltest::Utiltest(TracefileReader& reader, HeapFactory& heap_factory)
: MallocRunner(reader, heap_factory),
size_map_(reader.SuggestedAtomicMapSize()) {}
: MallocRunner(reader, heap_factory) {}

absl::Status Utiltest::PostAlloc(void* ptr, size_t size,
std::optional<size_t> alignment,
Expand Down Expand Up @@ -90,7 +89,13 @@ absl::Status Utiltest::PostRealloc(void* new_ptr, void* old_ptr, size_t size) {
RecomputeMax(total_allocated_bytes);

if (new_ptr == old_ptr) {
it->second = size;
auto result = size_map_.assign(new_ptr, size);
if (!result.has_value()) {
return absl::InternalError(
absl::StrFormat("Reassigning size of realloc-ed memory %p from %zu "
"to %zu failed, not found in map.",
new_ptr, old_size, size));
}
return absl::OkStatus();
}

Expand Down
4 changes: 2 additions & 2 deletions src/utiltest.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "absl/status/statusor.h"
#include "folly/AtomicHashMap.h"
#include "folly/concurrency/ConcurrentHashMap.h"

#include "src/heap_factory.h"
#include "src/malloc_runner.h"
Expand Down Expand Up @@ -33,7 +33,7 @@ class Utiltest : private MallocRunner {

absl::StatusOr<double> ComputeUtilization() const;

folly::AtomicHashMap<void*, size_t> size_map_;
folly::ConcurrentHashMap<void*, size_t> size_map_;

std::atomic<size_t> total_allocated_bytes_ = 0;
std::atomic<size_t> max_allocated_bytes_ = 0;
Expand Down

0 comments on commit 6b85202

Please sign in to comment.