Skip to content
Open
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
62 changes: 57 additions & 5 deletions mooncake-transfer-engine/tent/include/tent/transport/ub/buffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,48 @@ struct UbBufferSegmentMetadata {
SegmentDescriptor descriptor;
};

struct UbBufferChunkMetadata {
uint64_t offset{0};
uint64_t length{0};
std::vector<UbBufferSegmentMetadata> segments;
};

struct HugePageMapping {
uint64_t base{0};
uint64_t end{0};
uint64_t page_size{0};
};

struct PlannedChunk {
uint64_t base{0};
uint64_t length{0};
};

Status planBufferChunks(uint64_t base, uint64_t length,
uint64_t max_segment_size,
const std::vector<HugePageMapping>& huge_mappings,
std::vector<PlannedChunk>& chunks);

struct UbBufferMetadata {
static constexpr uint32_t kSchemaVersion = 1;
static constexpr uint32_t kChunkedSchemaVersion = 2;

uint32_t schema_version{kSchemaVersion};
uint64_t generation{0};
uint64_t base{0};
uint64_t length{0};
std::string location;
Permission permission{kLocalReadWrite};
std::vector<UbBufferSegmentMetadata> segments;
// Both wire versions normalize to a contiguous, ordered chunk list.
std::vector<UbBufferChunkMetadata> chunks;

const UbBufferChunkMetadata* findChunk(uint64_t address, size_t size) const;
};

Status encodeBufferMetadata(const UbBufferMetadata& metadata,
std::string& encoded);
Status decodeBufferMetadata(std::string_view encoded,
UbBufferMetadata& metadata);
Status decodeBufferMetadata(const BufferDesc& desc, UbBufferMetadata& metadata);

struct LocalSegmentRef {
UbContextPtr context;
Expand All @@ -69,8 +95,11 @@ struct ImportedSegmentRef {
// work releases its last reference.
class UbBufferManager final {
public:
static constexpr uint64_t kDefaultMaxSegmentSize = 0x10000000000ULL;

UbBufferManager(std::shared_ptr<UrmaAdapter> adapter,
std::vector<UbContextPtr> contexts);
std::vector<UbContextPtr> contexts,
uint64_t max_segment_size = kDefaultMaxSegmentSize);
~UbBufferManager();

UbBufferManager(const UbBufferManager&) = delete;
Expand All @@ -82,6 +111,12 @@ class UbBufferManager final {
Status removeBuffer(BufferDesc& desc);
Status clear();

bool shouldWarmup(size_t length) const {
return length <= max_segment_size_;
}
Status localChunkEnds(uint64_t address, size_t length,
std::vector<uint64_t>& ends) const;

Status findLocal(uint64_t address, size_t length,
Topology::NicID local_topology_id,
LocalSegmentRef& result) const;
Expand All @@ -93,6 +128,13 @@ class UbBufferManager final {
uint64_t address, size_t length,
ImportedSegmentRef& result);

Status importRemote(SegmentID remote_segment_id,
Topology::NicID local_topology_id,
Topology::NicID remote_topology_id,
const UbBufferMetadata& metadata,
Request::OpCode opcode, uint64_t address, size_t length,
ImportedSegmentRef& result);

[[nodiscard]] size_t localBufferCount() const;
[[nodiscard]] size_t importedSegmentCount() const;

Expand All @@ -107,18 +149,26 @@ class UbBufferManager final {
[[nodiscard]] bool contains(uint64_t address, size_t size) const;
};

struct LocalChunk {
AddressRange range;
std::unordered_map<Topology::NicID, LocalSegmentPtr> segments;
};

struct LocalRecord {
MemoryOptions options;
uint64_t generation{0};
std::unordered_map<Topology::NicID, LocalSegmentPtr> segments;
bool retiring{false};
std::vector<LocalChunk> chunks;
};

const LocalRecord* findLocalRecord(uint64_t address, size_t length) const;

struct ImportKey {
Topology::NicID local_topology_id{-1};
SegmentID remote_segment_id{LOCAL_SEGMENT_ID};
Topology::NicID remote_topology_id{-1};
uint64_t buffer_base{0};
uint64_t generation{0};
uint64_t chunk_offset{0};

bool operator==(const ImportKey&) const = default;
};
Expand All @@ -128,6 +178,7 @@ class UbBufferManager final {
};

Status addBufferInternal(BufferDesc& desc, const MemoryOptions& options);
Status unregisterSegment(LocalSegmentPtr& segment);
Status unregisterRecord(LocalRecord& record);
void retainPendingRecord(LocalRecord& record);
static uint32_t segmentAccess(Permission permission);
Expand All @@ -136,6 +187,7 @@ class UbBufferManager final {

std::shared_ptr<UrmaAdapter> adapter_;
std::vector<UbContextPtr> contexts_;
const uint64_t max_segment_size_;
std::unordered_map<Topology::NicID, UbContextPtr> context_by_topology_id_;

mutable std::shared_mutex local_mutex_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ class UbWorkers final {
std::vector<LocalDeviceCandidate> orderedLocalDevices(
const PendingSlice& pending) const;
static std::vector<Topology::NicID> orderedRemoteDevices(
const SegmentDesc& segment, const BufferDesc& buffer);
const SegmentDesc& segment, const BufferDesc& buffer,
const UbBufferChunkMetadata& chunk);

std::shared_ptr<UrmaAdapter> adapter_;
std::vector<UbContextPtr> contexts_;
Expand Down
Loading
Loading