Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,9 @@ Status TransferEngineImpl::freeLocalMemory(void* addr) {
++it) {
if (it->addr == addr) {
auto status = it->transport->freeLocalMemory(addr, it->size);
if (!status.ok()) return status;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Advise to prints warning.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a warning before returning the transport error. It includes the address, allocation size, and original status while preserving the ownership entry for a later retry. Fixed in ce87244.

allocated_memory_.erase(it);
return status;
return Status::OK();
}
}
return Status::InvalidArgument("Address region not registered" LOC_MARK);
Expand Down
12 changes: 12 additions & 0 deletions mooncake-transfer-engine/tent/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,18 @@ target_include_directories(tent_runtime_queue_dispatch_test
add_test(NAME tent_runtime_queue_dispatch_test
COMMAND tent_runtime_queue_dispatch_test)

add_executable(tent_local_memory_lifecycle_test
local_memory_lifecycle_test.cpp)
target_link_libraries(tent_local_memory_lifecycle_test
PRIVATE gtest gtest_main tent_link_group)
if(TARGET asio_shared)
target_link_libraries(tent_local_memory_lifecycle_test PRIVATE asio_shared)
endif()
target_include_directories(tent_local_memory_lifecycle_test
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
add_test(NAME tent_local_memory_lifecycle_test
COMMAND tent_local_memory_lifecycle_test)

# Causal chain stage decomposition: validates that dispatch_time and post_time
# timestamps are populated on both queue and direct-commit paths.
add_executable(causal_chain_test causal_chain_test.cpp)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright 2026 KVCache.AI
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gtest/gtest.h>

#include <cstdlib>
#include <memory>
#include <string>

#include "tent/common/config.h"
#include "tent/runtime/transfer_engine_impl.h"
#include "tent/runtime/transport.h"

namespace mooncake {
namespace tent {
namespace {

class FailOnceFreeTransport : public Transport {
public:
Status allocateLocalMemory(void** addr, size_t size,
MemoryOptions&) override {
*addr = std::malloc(size);
return *addr ? Status::OK()
: Status::InternalError("malloc failed" LOC_MARK);
}

Status freeLocalMemory(void* addr, size_t) override {
++free_calls;
if (free_calls == 1) {
return Status::InternalError("injected free failure" LOC_MARK);
}
std::free(addr);
return Status::OK();
}

const char* getName() const override { return "fail-once-free"; }

int free_calls{0};
};

std::shared_ptr<Config> makeConfig() {
auto config = std::make_shared<Config>();
config->set("metadata_type", "p2p");
config->set("metadata_servers", "");
config->set("rpc_server_hostname", "127.0.0.1");
config->set("rpc_server_port", "0");
config->set("log_level", "warning");

for (const char* transport : {"tcp", "shm", "rdma", "io_uring", "nvlink",
"mnnvl", "gds", "ascend_direct"}) {
config->set(std::string("transports/") + transport + "/enable", false);
}
return config;
}

TEST(LocalMemoryLifecycle, RetainsOwnershipWhenTransportFreeFails) {
TransferEngineImpl engine(makeConfig());
ASSERT_TRUE(engine.available());

auto transport = std::make_shared<FailOnceFreeTransport>();
engine.swapTransportForTest(RDMA, transport);

MemoryOptions options;
options.type = RDMA;
options.location = "cpu:0";
void* addr = nullptr;
ASSERT_TRUE(engine.allocateLocalMemory(&addr, 4096, options).ok());

auto first = engine.freeLocalMemory(addr);
EXPECT_FALSE(first.ok());
EXPECT_EQ(transport->free_calls, 1);

auto second = engine.freeLocalMemory(addr);
EXPECT_TRUE(second.ok()) << second.ToString();
EXPECT_EQ(transport->free_calls, 2);

auto third = engine.freeLocalMemory(addr);
EXPECT_TRUE(third.IsInvalidArgument());
EXPECT_EQ(transport->free_calls, 2);
}

} // namespace
} // namespace tent
} // namespace mooncake
Loading