From be9506572a2a0ab4d943389356513b987ba200ef Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Mon, 13 Oct 2025 17:20:40 +0800 Subject: [PATCH 01/59] naive interface definition of dramstore --- .../cc/domain/space/dram_space_layout.h | 50 +++++++++++ .../cc/domain/space/dram_space_manager.h | 47 +++++++++++ .../cc/domain/tsf_task/dram_tsf_task.h | 61 ++++++++++++++ .../domain/tsf_task/dram_tsf_task_manager.h | 60 +++++++++++++ .../cc/domain/tsf_task/dram_tsf_task_queue.h | 62 ++++++++++++++ .../cc/domain/tsf_task/dram_tsf_task_set.h | 35 ++++++++ .../cc/domain/tsf_task/dram_tsf_task_waiter.h | 84 +++++++++++++++++++ 7 files changed, 399 insertions(+) create mode 100644 ucm/store/dramstore/cc/domain/space/dram_space_layout.h create mode 100644 ucm/store/dramstore/cc/domain/space/dram_space_manager.h create mode 100644 ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task.h create mode 100644 ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.h create mode 100644 ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h create mode 100644 ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_set.h create mode 100644 ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_waiter.h diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h new file mode 100644 index 00000000..907ae6dc --- /dev/null +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h @@ -0,0 +1,50 @@ +/** + * MIT License + * + * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * */ +#ifndef UNIFIEDCACHE_DRAM_SPACE_LAYOUT_H +#define UNIFIEDCACHE_DRAM_SPACE_LAYOUT_H + +#include +#include +#include "status/status.h" + +namespace UC { + +class DramSpaceLayout { +public: + Status Setup(uint32_t maxSize); // TODO:这里面要先进行内存空间的初始化,通过调malloc这类函数,参数先只有1个,即总空间大小 + +private: + +private: + void* _dataStorePool; // KVCache存放的内存空间,在Setup函数中进行初始化 + std::map _dataStoreMap; // 键是 block_id+offset 的拼接,值是对应的KVCache的存放起始位置,初始化为空 + std::set _storedBlocks; // 被存了的 blocks 的所有 blockId,初始化为空 + size_t _curOffset; // 当前的内存池中可用的Offset(相较于内存池中初始地址的偏移) + size_t blockSize_; + // 目前为了简单,如果全写满了的话,就从头再来吧,把最头上(即_dataStorePool的起始位置)的数据替换掉 +}; + +} // namespace UC + +#endif \ No newline at end of file diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_manager.h b/ucm/store/dramstore/cc/domain/space/dram_space_manager.h new file mode 100644 index 00000000..4508d282 --- /dev/null +++ b/ucm/store/dramstore/cc/domain/space/dram_space_manager.h @@ -0,0 +1,47 @@ +/** + * MIT License + * + * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * */ +#ifndef UNIFIEDCACHE_DRAM_SPACE_MANAGER_H +#define UNIFIEDCACHE_DRAM_SPACE_MANAGER_H + +#include "dram_space_layout.h" +#include "status/status.h" + +namespace UC { + +class DramSpaceManager { +public: + Status Setup(const size_t blockSize); + Status NewBlock(const std::string& blockId) const; // 也许不需要实现它。无论如何先放这里 + Status CommitBlock(const std::string& blockId, bool success = true) const; // 等一个block完全存完或者被完全删除后,调用这个方法,并更新layout_中的_storedBlocks集合 + bool LookupBlock(const std::string& blockId) const; + const DramSpaceLayout* GetSpaceLayout() const; + +private: + DramSpaceLayout layout_; + size_t blockSize_; +}; + +} // namespace UC + +#endif \ No newline at end of file diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task.h b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task.h new file mode 100644 index 00000000..cbf136fd --- /dev/null +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task.h @@ -0,0 +1,61 @@ +/** + * MIT License + * + * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * */ +#ifndef UNIFIEDCACHE_DRAM_TSF_TASK_H +#define UNIFIEDCACHE_DRAM_TSF_TASK_H + +#include "ucmstore.h" +#include "dram_tsf_task_waiter.h" + +namespace UC { + +class DramTsfTask { +public: + using Type = CCStore::Task::Type; + // using Location = CCStore::Task::Location; // 这个不再需要了,因为只有D2H和H2D两种传输 + +public: + DramTsfTask(const Type type, const std::string& blockId, + const size_t offset, const uintptr_t address, const size_t length) + : type{type}, blockId{blockId}, offset{offset}, address{address}, + length{length}, owner{0}, waiter{nullptr} + { + } + DramTsfTask() : DramTsfTask{Type::DUMP, {}, 0, 0, 0} {} + +public: + Type type; + // Location location; // 不需要了 + std::string blockId; // 对于一个task来说,这个bloockID和下一行的offset还是需要的,因为它们本质上是上层传来的。(参考dramstore.py.cc) + size_t offset; + uintptr_t address; // 在显卡上的地址 + size_t length; // 数据传输的长度 + + size_t owner; // 大的Task的TaskId + std::shared_ptr waiter; + // std::shared_ptr hub; // 在nfsstore中,这个的意思是中转站(对于nfsstore来说,host的目的就是数据中转),因此在dram_connector中不再需要 +}; + +} // namespace UC + +#endif diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.h b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.h new file mode 100644 index 00000000..d4e7dd34 --- /dev/null +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.h @@ -0,0 +1,60 @@ +/** + * MIT License + * + * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * */ +#ifndef UNIFIEDCACHE_DRAM_TSF_TASK_MANAGER_H +#define UNIFIEDCACHE_DRAM_TSF_TASK_MANAGER_H + +#include +#include +#include +#include "dram_tsf_task_queue.h" + +namespace UC { + +class DramTsfTaskManager { +public: + Status Setup(const int32_t deviceId, const size_t streamNumber, + // const size_t bufferSize, const size_t bufferNumber, // 这两个可能不需要,对于dram来说,因为这个buffer是用来数据中转的? + const size_t timeoutMs, const DramSpaceLayout* layout); + Status Submit(std::list& tasks, const size_t size, const size_t number, + const std::string& brief, size_t& taskId); + Status Wait(const size_t taskId); + Status Check(const size_t taskId, bool& finish); + +private: + void Dispatch(std::list& tasks, std::vector>& targets, + const size_t taskId, std::shared_ptr waiter) const; + +private: + std::mutex _mutex; + DramTsfTaskSet _failureSet; + std::unordered_map> _waiters; + std::vector> _queues; + size_t _qIdx{0}; + size_t _taskIdSeed{0}; + size_t _timeoutMs{0}; +}; + +} // namespace UC + +#endif diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h new file mode 100644 index 00000000..e143db74 --- /dev/null +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h @@ -0,0 +1,62 @@ +/** + * MIT License + * + * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * */ +#ifndef UNIFIEDCACHE_DRAM_TSF_TAKS_QUEUE_H +#define UNIFIEDCACHE_DRAM_TSF_TAKS_QUEUE_H + +#include "idevice.h" +#include "space/dram_space_layout.h" +#include "thread/thread_pool.h" +#include "dram_tsf_task.h" +#include "dram_tsf_task_set.h" + +namespace UC { + +class DramTsfTaskQueue { +public: + Status Setup(const int32_t deviceId, + // const size_t bufferSize, const size_t bufferNumber, + DramTsfTaskSet* failureSet, const DramSpaceLayout* layout); // TODO:需要传入哪些参数,到时候再看。目前看需要deviceId,但是bufferSize和bufferNumber不需要 + void Push(std::list& tasks); + +private: + void StreamOper(DramTsfTask& task); + // void FileOper(DramTsfTask& task); // 与下面同步,不再需要了 + void H2D(DramTsfTask& task); // 这个函数和D2H函数里,需要用到this->_layout里的接口来得到数据在host内存中的位置,再调用this->_device来执行显卡与host中的内存拷贝的操作 + void D2H(DramTsfTask& task); // 完成后,要更新_layout中的_dataStoreMap字典 + // void H2S(DramTsfTask& task); + // void S2H(DramTsfTask& task); + void Done(const DramTsfTask& task, bool success); + +private: + ThreadPool _streamOper; + // ThreadPool _fileOper; // 在NFSStore中需要,但是在DRAM里不需要了,因为只涉及H与D之间的数据传输 + std::unique_ptr _device; + DramTsfTaskSet* _failureSet; + // TODO + DramSpaceLayout* _layout; // 这个大概也需要吧,因为NFSStore里是在H2S和S2H中需要用它,也就是真正和“存储”打交道时是需要它的。具体怎么定义后面再看 +}; + +} // namespace UC + +#endif diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_set.h b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_set.h new file mode 100644 index 00000000..655ee1d0 --- /dev/null +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_set.h @@ -0,0 +1,35 @@ +/** + * MIT License + * + * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * */ +#ifndef UNIFIEDCACHE_DRAM_TSF_TASK_SET_H +#define UNIFIEDCACHE_DRAM_TSF_TASK_SET_H + +#include "template/hashset.h" + +namespace UC { + +class DramTsfTaskSet : public HashSet {}; + +} // namespace UC + +#endif \ No newline at end of file diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_waiter.h b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_waiter.h new file mode 100644 index 00000000..c3624217 --- /dev/null +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_waiter.h @@ -0,0 +1,84 @@ +/** + * MIT License + * + * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * */ +#ifndef UNIFIEDCACHE_DRAM_TSF_TASK_WAITER_H +#define UNIFIEDCACHE_DRAM_TSF_TASK_WAITER_H + +#include "logger/logger.h" +#include "thread/latch.h" +#include "time/stopwatch.h" + +namespace UC { + +class DrAMTsfTaskWaiter : public Latch { +public: + DrAMTsfTaskWaiter(const size_t id, const size_t size, const size_t number, const std::string& brief) + : Latch{number}, id_{id}, size_{size}, number_{number}, brief_{brief} + { + } + void Done() + { + if (Latch::Done() == 0) { + auto elapsed = this->sw_.Elapsed().count(); + UC_DEBUG("Task({},{},{},{}) finished, elapsed={:.06f}s, bw={:.06f}GB/s.", this->id_, + this->brief_, this->number_, this->size_, elapsed, + this->size_ / elapsed / (1ULL << 30)); + this->Notify(); + } + } + using Latch::Wait; + bool Wait(const size_t timeoutMs) + { + if (timeoutMs == 0) { + this->Wait(); + return true; + } + auto finish = false; + { + std::unique_lock lk(this->mutex_); + if (this->counter_ == 0) { return true; } + auto elapsed = (size_t)this->sw_.ElapsedMs().count(); + if (elapsed < timeoutMs) { + finish = this->cv_.wait_for(lk, std::chrono::milliseconds(timeoutMs - elapsed), + [this] { return this->counter_ == 0; }); + } + } + if (!finish) { + UC_WARN("Task({},{},{},{}) timeout, elapsed={:.06f}s.", this->id_, this->brief_, + this->number_, this->size_, this->sw_.Elapsed().count()); + } + return finish; + } + bool Finish() { return this->counter_ == 0; } + +private: + size_t id_; + size_t size_; + size_t number_; + std::string brief_; + StopWatch sw_; +}; + +} // namespace UC + +#endif // UNIFIEDCACHE_DRAM_TSF_TASK_WAITER_H From c0f05aa0344e8a5c58e12d69ef39747d72a988ea Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Mon, 13 Oct 2025 17:56:24 +0800 Subject: [PATCH 02/59] fix --- ucm/store/dramstore/cc/domain/space/dram_space_layout.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h index 907ae6dc..6d69e244 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h @@ -40,7 +40,7 @@ class DramSpaceLayout { void* _dataStorePool; // KVCache存放的内存空间,在Setup函数中进行初始化 std::map _dataStoreMap; // 键是 block_id+offset 的拼接,值是对应的KVCache的存放起始位置,初始化为空 std::set _storedBlocks; // 被存了的 blocks 的所有 blockId,初始化为空 - size_t _curOffset; // 当前的内存池中可用的Offset(相较于内存池中初始地址的偏移) + size_t _curOffset; // 当前的内存池中下一个可用的Offset(相较于内存池中初始地址的偏移) size_t blockSize_; // 目前为了简单,如果全写满了的话,就从头再来吧,把最头上(即_dataStorePool的起始位置)的数据替换掉 }; From e40b5ea84c5a2ad5ae5dbab7f2aa4b72ca6a7454 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Mon, 13 Oct 2025 21:03:52 +0800 Subject: [PATCH 03/59] naive naive naive implementation --- .../cc/domain/space/dram_space_layout.cc | 92 ++++++++++++ .../cc/domain/space/dram_space_layout.h | 15 +- .../cc/domain/space/dram_space_manager.cc | 65 +++++++++ .../cc/domain/space/dram_space_manager.h | 2 +- .../cc/domain/tsf_task/dram_tsf_task.h | 2 +- .../domain/tsf_task/dram_tsf_task_manager.cc | 106 ++++++++++++++ .../cc/domain/tsf_task/dram_tsf_task_queue.cc | 133 ++++++++++++++++++ 7 files changed, 409 insertions(+), 6 deletions(-) create mode 100644 ucm/store/dramstore/cc/domain/space/dram_space_layout.cc create mode 100644 ucm/store/dramstore/cc/domain/space/dram_space_manager.cc create mode 100644 ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc create mode 100644 ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc new file mode 100644 index 00000000..e97cfecd --- /dev/null +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc @@ -0,0 +1,92 @@ +/** + * MIT License + * + * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * */ +#include "space_layout.h" +#include +#include +#include "file/file.h" +#include "logger/logger.h" + +namespace UC { + +constexpr size_t blockIdSize = 16; +constexpr size_t nU64PerBlock = blockIdSize / sizeof(uint64_t); +using BlockId = std::array; +static_assert(sizeof(BlockId) == blockIdSize); + +Status DramSpaceLayout::Setup(uint32_t maxSize, uint32_t blockSize, uint32_t minLength) +{ + if (maxSize <= 0) { + UC_ERROR("Invalid maxSize value."); + return Status::InvalidParam(); + } + _dataStorePool = nullptr; + _dataStorePool = new char[maxSize]; + if (!_dataStorePool) { + UC_ERROR("Allocate DRAM storage space failed"); + return Status::OutOfMemory(); + } + _dataStoreMap = {}; + _storedBlocks = {}; + blockSize_ = blockSize; + minLength_ = minLength; + capacity_ = maxSize; + return Status::OK(); +} + +char* DramSpaceLayout::AllocateDataAddr(std::string blockId, std::string offset) { + auto iter = _dataStoreMap.find(blockId + offset); + if (iter != _dataStoreMap.end()) { + // 已经存在,不需要重分配 + return _dataStoreMap[blockId + offset]; + } + _dataStoreMap[blockId + offset] = _dataStorePool + _curOffset; + _curOffset = (_curOffset + minLength) % capacity_; // 这个minLength的逻辑是否正确,还要再确认 + return _dataStoreMap[blockId + offset]; +} + +char* DramSpaceLayout::GetDataAddr(std::string blockId, std::string offset) { + auto iter = _dataStoreMap.find(blockId + offset); + if (iter == _dataStoreMap.end()) { + return nullptr; + } + return _dataStoreMap[blockId]; +} + +void DramSpaceLayout::DataStoreMapAppend(std::string key, char* address) { + _dataStoreMap[key] = address; +} + +void DramSpaceLayout::StoredBlocksAppend(std::string blockId) { + _storedBlocks.insert(blockId); +} + +void DramSpaceLayout::StoredBlocksErase(std::string blockId) { + _storedBlocks.erase(blockId); +} + +bool StoredBlocksExist(std::string blockId) { + return _storedBlocks.find(blockId) != _storedBlocks.end(); +} + +} // namespace UC diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h index 6d69e244..7c206187 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h @@ -32,16 +32,23 @@ namespace UC { class DramSpaceLayout { public: - Status Setup(uint32_t maxSize); // TODO:这里面要先进行内存空间的初始化,通过调malloc这类函数,参数先只有1个,即总空间大小 + Status Setup(uint32_t maxSize, uint32_t blockSize, uint32_t minLength); // TODO:这里面要先进行内存空间的初始化,通过调malloc这类函数 + char* GetDataAddr(std::string blockId, std::string offset); + void DataStoreMapAppend(std::string key, char* address); + void StoredBlocksAppend(std::string blockId); + void StoredBlocksErase(std::string blockId); + bool StoredBlocksExist(std::string blockId); private: private: - void* _dataStorePool; // KVCache存放的内存空间,在Setup函数中进行初始化 - std::map _dataStoreMap; // 键是 block_id+offset 的拼接,值是对应的KVCache的存放起始位置,初始化为空 + char* _dataStorePool; // KVCache存放的内存空间,在Setup函数中进行初始化 + std::map _dataStoreMap; // 键是 block_id+offset 的拼接,值是对应的KVCache的存放起始位置,初始化为空 std::set _storedBlocks; // 被存了的 blocks 的所有 blockId,初始化为空 - size_t _curOffset; // 当前的内存池中下一个可用的Offset(相较于内存池中初始地址的偏移) + size_t _curOffset{0}; // 当前的内存池中下一个可用的Offset(相较于内存池中初始地址的偏移) size_t blockSize_; + size_t capacity_; + size_t minLength_; // 目前为了简单,如果全写满了的话,就从头再来吧,把最头上(即_dataStorePool的起始位置)的数据替换掉 }; diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc b/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc new file mode 100644 index 00000000..b532bf15 --- /dev/null +++ b/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc @@ -0,0 +1,65 @@ +/** + * MIT License + * + * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * */ +#include "space_manager.h" +#include "file/file.h" +#include "logger/logger.h" + +namespace UC { + +Status DramSpaceManager::Setup(uint32_t maxSize, uint32_t blockSize, uint32_t minLength) +{ + if (blockSize == 0) { + UC_ERROR("Invalid block size({}).", blockSize); + return Status::InvalidParam(); + } + auto status = this->layout_.Setup(maxSize, blockSize, minLength); + if (status.Failure()) { return status; } + this->blockSize_ = blockSize; + return Status::OK(); +} + +Status DramSpaceManager::NewBlock(const std::string& blockId) const +{ + return Status::OK(); +} + +Status DramSpaceManager::CommitBlock(const std::string& blockId, bool success) const +{ + if (success) { + this->_layout->StoredBlocksAppend(blockId); + } + else { + this->_layout->StoredBlocksErase(blockId); + } + return Status::OK(); +} + +bool DramSpaceManager::LookupBlock(const std::string& blockId) const +{ + return this->_layout->StoredBlocksExist(blockId); +} + +const SpaceLayout* DramSpaceManager::GetSpaceLayout() const { return &this->layout_; } + +} // namespace UC diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_manager.h b/ucm/store/dramstore/cc/domain/space/dram_space_manager.h index 4508d282..18bd2bcd 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_manager.h +++ b/ucm/store/dramstore/cc/domain/space/dram_space_manager.h @@ -31,7 +31,7 @@ namespace UC { class DramSpaceManager { public: - Status Setup(const size_t blockSize); + Status Setup(uint32_t maxSize, uint32_t blockSize, uint32_t minLength); Status NewBlock(const std::string& blockId) const; // 也许不需要实现它。无论如何先放这里 Status CommitBlock(const std::string& blockId, bool success = true) const; // 等一个block完全存完或者被完全删除后,调用这个方法,并更新layout_中的_storedBlocks集合 bool LookupBlock(const std::string& blockId) const; diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task.h b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task.h index cbf136fd..0d33b0f3 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task.h +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task.h @@ -41,7 +41,7 @@ class DramTsfTask { length{length}, owner{0}, waiter{nullptr} { } - DramTsfTask() : DramTsfTask{Type::DUMP, {}, 0, 0, 0} {} + DramTsfTask() : DramTsfTask{Type::DUMP, {}, 0, 0, 0} {} // 无参构造函数 public: Type type; diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc new file mode 100644 index 00000000..4d428b01 --- /dev/null +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc @@ -0,0 +1,106 @@ +/** + * MIT License + * + * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * */ +#include "tsf_task_manager.h" + +namespace UC { + +Status DramTsfTaskManager::Setup(const int32_t deviceId, const size_t streamNumber, + const size_t timeoutMs, const SpaceLayout* layout) +{ + this->_queues.reserve(streamNumber); + for (size_t i = 0; i < streamNumber; ++i) { + auto& queue = this->_queues.emplace_back(std::make_unique()); + auto status = queue->Setup(deviceId, &this->_failureSet, layout); + if (status.Failure()) { return status; } + } + this->_timeoutMs = timeoutMs; + return Status::OK(); +} + +Status DramTsfTaskManager::Submit(std::list& tasks, const size_t size, const size_t number, + const std::string& brief, size_t& taskId) +{ + std::unique_lock lk(this->_mutex); + taskId = ++this->_taskIdSeed; + auto [iter, success] = this->_waiters.emplace( + taskId, std::make_shared(taskId, size, number, brief)); + if (!success) { return Status::OutOfMemory(); } + std::vector> lists; + this->Dispatch(tasks, lists, taskId, iter->second); + for (size_t i = 0; i < lists.size(); i++) { + if (lists[i].empty()) { continue; } + this->_queues[this->_qIdx]->Push(lists[i]); + this->_qIdx = (this->_qIdx + 1) % this->_queues.size(); + } + return Status::OK(); +} + +Status DramTsfTaskManager::Wait(const size_t taskId) +{ + std::shared_ptr waiter = nullptr; + { + std::unique_lock lk(this->_mutex); + auto iter = this->_waiters.find(taskId); + if (iter == this->_waiters.end()) { return Status::NotFound(); } + waiter = iter->second; + this->_waiters.erase(iter); + } + if (!waiter->Wait(this->_timeoutMs)) { + this->_failureSet.Insert(taskId); + waiter->Wait(); + } + bool failure = this->_failureSet.Contains(taskId); + this->_failureSet.Remove(taskId); + if (failure) { UC_ERROR("Transfer task({}) failed.", taskId); } + return failure ? Status::Error() : Status::OK(); +} + +Status DramTsfTaskManager::Check(const size_t taskId, bool& finish) +{ + std::lock_guard lk(this->_mutex); + auto iter = this->_waiters.find(taskId); + if (iter == this->_waiters.end()) { return Status::NotFound(); } + finish = iter->second->Finish(); + return Status::OK(); +} + +void DramTsfTaskManager::Dispatch(std::list& tasks, std::vector>& targets, + const size_t taskId, std::shared_ptr waiter) const +{ + auto qNumber = this->_queues.size(); + auto index = size_t(0); + targets.resize(qNumber); + auto it = tasks.begin(); + while (it != tasks.end()) { + auto next = std::next(it); + it->owner = taskId; + it->waiter = waiter; + auto& target = targets[index % qNumber]; + target.splice(target.end(), tasks, it); + index++; + it = next; + } +} + +} // namespace UC diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc new file mode 100644 index 00000000..f27c742a --- /dev/null +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc @@ -0,0 +1,133 @@ +/** + * MIT License + * + * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * */ + +#include "dram_tsf_task_queue.h" + +namespace UC { + +#define UC_TASK_ERROR(s, t) \ + do { \ + UC_ERROR("Failed({}) to run task({},{},{},{}).", (s), (t).owner, (t).blockId, (t).offset, \ + (t).length); \ + } while (0) + +Status DramTsfTaskQueue::Setup(const int32_t deviceId, DramTsfTaskSet* failureSet, const DramSpaceLayout* layout); +{ + this->_failureSet = failureSet; + this->_layout = layout; + if (deviceId >= 0) { + this->_device = DeviceFactory::Make(deviceId, 0, 0); // 这里不需要buffer,暂时都先传0吧 + if (!this->_device) { return Status::OutOfMemory(); } + } + if (!this->_streamOper.Setup([this](DramTsfTask& task) { this->StreamOper(task); })) { + return Status::Error(); + } + return Status::OK(); +} + +void DramTsfTaskQueue::Push(std::list& tasks) +{ + this->_streamOper.Push(tasks); +} + +void DramTsfTaskQueue::StreamOper(DramTsfTask& task) +{ + if (this->_failureSet->Contains(task.owner)) { + this->Done(task, false); + return; + } + if (task.type == DramTsfTask::Type::LOAD) { + this->H2D(task); + } else { + this->D2H(task); + } +} + +// 这个H2D和D2H函数是重点要重新实现的。这里70和71行是与nfsstore不同的。 +void DramTsfTaskQueue::H2D(DramTsfTask& task) +{ + auto host_src = this->_layout->GetDataAddr(task.blockId, task.offset); // 这里host_src是已知的 + if (!host_src) { + UC_TASK_ERROR(Status::Error(), task); + this->Done(task, false); + return; + } + auto status = this->_device->H2DAsync((std::byte*)task.address, host_src, task.length); + if (status.Failure()) { + UC_TASK_ERROR(status, task); + this->Done(task, false); + return; + } + status = this->_device->AppendCallback([this, task](bool success) mutable { + if (!success) { UC_TASK_ERROR(Status::Error(), task); } + this->Done(task, success); + // 这里是否需要return? + }); + if (status.Failure()) { + UC_TASK_ERROR(status, task); + this->Done(task, false); + return; + } +} + +// 这个函数也是重点要重新实现的。 +void DramTsfTaskQueue::D2H(DramTsfTask& task) +{ + // auto host_dst = this->layout->GetDataAddr(task.blockId, task.offset); // 这里host_dst是未知的,要新分配的!不能用GetDataAddr,而要用另一个接口才是 + auto host_dst = this->layout->AllocateDataAddr(task.blockId, task.offset); + if (!host_dst) { + UC_TASK_ERROR(Status::Error(), task); + this->Done(task, false); + return; + } + auto status = this->_device->D2HAsync(host_dst, (std::byte*)task.address, task.length); + if (status.Failure()) { + UC_TASK_ERROR(status, task); + this->Done(task, false); + return; + } + status = this->_device->AppendCallback([this, task](bool success) mutable { + if (!success) { + UC_TASK_ERROR(Status::Error(), task); + this->Done(task, false); + return; // 这里是否需要return? + } + // TODO: 更新_layout中的_dataStoreMap字典 + this->_layout->DataStoreMapAppend(task.blockId + task.offset, host_dst) + this->done(task, true); + }); + if (status.Failure()) { + UC_TASK_ERROR(status, task); + this->Done(task, false); + return; + } +} + +void TsfTaskQueue::Done(const DramTsfTask& task, bool success) +{ + if (!success) { this->_failureSet->Insert(task.owner); } + task.waiter->Done(); +} + +} // namespace UC From ba89e00f556ed1bb0ed29ff25f14f25067796355 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 10:09:44 +0800 Subject: [PATCH 04/59] fix --- ucm/store/dramstore/cc/domain/space/dram_space_layout.cc | 4 ++-- ucm/store/dramstore/cc/domain/space/dram_space_manager.cc | 2 +- .../dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc | 2 +- ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc index e97cfecd..830054ee 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * */ -#include "space_layout.h" +#include "dram_space_layout.h" #include #include #include "file/file.h" @@ -85,7 +85,7 @@ void DramSpaceLayout::StoredBlocksErase(std::string blockId) { _storedBlocks.erase(blockId); } -bool StoredBlocksExist(std::string blockId) { +bool DramSpaceLayout::StoredBlocksExist(std::string blockId) { return _storedBlocks.find(blockId) != _storedBlocks.end(); } diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc b/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc index b532bf15..fe5750b1 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc +++ b/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * */ -#include "space_manager.h" +#include "dram_space_manager.h" #include "file/file.h" #include "logger/logger.h" diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc index 4d428b01..875316ce 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * */ -#include "tsf_task_manager.h" +#include "dram_tsf_task_manager.h" namespace UC { diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc index f27c742a..dd4fa66a 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc @@ -124,7 +124,7 @@ void DramTsfTaskQueue::D2H(DramTsfTask& task) } } -void TsfTaskQueue::Done(const DramTsfTask& task, bool success) +void DramTsfTaskQueue::Done(const DramTsfTask& task, bool success) { if (!success) { this->_failureSet->Insert(task.owner); } task.waiter->Done(); From add41d4d60775cce78fa80e9b09352a948d3288a Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 10:35:56 +0800 Subject: [PATCH 05/59] fix --- ucm/store/dramstore/cc/domain/space/dram_space_layout.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc index 830054ee..7541fdca 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc @@ -41,7 +41,7 @@ Status DramSpaceLayout::Setup(uint32_t maxSize, uint32_t blockSize, uint32_t min return Status::InvalidParam(); } _dataStorePool = nullptr; - _dataStorePool = new char[maxSize]; + _dataStorePool = new char[maxSize]; // 这里内存分配的逻辑与方法是否正确?也要确认 if (!_dataStorePool) { UC_ERROR("Allocate DRAM storage space failed"); return Status::OutOfMemory(); From 119907416e91229cd3561a754c424591e0ca06dc Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 10:40:13 +0800 Subject: [PATCH 06/59] fix --- ucm/store/dramstore/cc/domain/space/dram_space_layout.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h index 7c206187..a9666ed8 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h @@ -27,12 +27,15 @@ #include #include #include "status/status.h" +#include +#include namespace UC { class DramSpaceLayout { public: Status Setup(uint32_t maxSize, uint32_t blockSize, uint32_t minLength); // TODO:这里面要先进行内存空间的初始化,通过调malloc这类函数 + char* AllocateDataAddr(std::string blockId, std::string offset); char* GetDataAddr(std::string blockId, std::string offset); void DataStoreMapAppend(std::string key, char* address); void StoredBlocksAppend(std::string blockId); From 880986cdaa0b64cf7b4d9ae39f145c65c61efc0e Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 10:41:54 +0800 Subject: [PATCH 07/59] fix --- ucm/store/dramstore/cc/domain/space/dram_space_layout.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc index 7541fdca..83f2e4a5 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc @@ -61,7 +61,7 @@ char* DramSpaceLayout::AllocateDataAddr(std::string blockId, std::string offset) return _dataStoreMap[blockId + offset]; } _dataStoreMap[blockId + offset] = _dataStorePool + _curOffset; - _curOffset = (_curOffset + minLength) % capacity_; // 这个minLength的逻辑是否正确,还要再确认 + _curOffset = (_curOffset + minLength_) % capacity_; // 这个minLength的逻辑是否正确,还要再确认 return _dataStoreMap[blockId + offset]; } From 1275c0f8c2071b3b947621c3b9112efbcddd567c Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 11:11:09 +0800 Subject: [PATCH 08/59] fix --- ucm/store/dramstore/cc/domain/space/dram_space_layout.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h index a9666ed8..10d3670c 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h @@ -27,7 +27,7 @@ #include #include #include "status/status.h" -#include +#include #include namespace UC { @@ -46,7 +46,7 @@ class DramSpaceLayout { private: char* _dataStorePool; // KVCache存放的内存空间,在Setup函数中进行初始化 - std::map _dataStoreMap; // 键是 block_id+offset 的拼接,值是对应的KVCache的存放起始位置,初始化为空 + std::unordered_map _dataStoreMap; // 键是 block_id+offset 的拼接,值是对应的KVCache的存放起始位置,初始化为空 std::set _storedBlocks; // 被存了的 blocks 的所有 blockId,初始化为空 size_t _curOffset{0}; // 当前的内存池中下一个可用的Offset(相较于内存池中初始地址的偏移) size_t blockSize_; From 9029a70aa44c46e77aeb9223027aac6c1b52ad8a Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 11:17:41 +0800 Subject: [PATCH 09/59] fix --- .../dramstore/cc/domain/space/dram_space_layout.cc | 10 +++++----- .../dramstore/cc/domain/space/dram_space_layout.h | 8 ++++---- .../dramstore/cc/domain/space/dram_space_manager.cc | 6 +++--- .../dramstore/cc/domain/space/dram_space_manager.h | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc index 83f2e4a5..b019d11c 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc @@ -34,7 +34,7 @@ constexpr size_t nU64PerBlock = blockIdSize / sizeof(uint64_t); using BlockId = std::array; static_assert(sizeof(BlockId) == blockIdSize); -Status DramSpaceLayout::Setup(uint32_t maxSize, uint32_t blockSize, uint32_t minLength) +Status DramSpaceLayout::Setup(uint32_t maxSize, uint32_t blockSize, uint32_t interval) { if (maxSize <= 0) { UC_ERROR("Invalid maxSize value."); @@ -48,9 +48,9 @@ Status DramSpaceLayout::Setup(uint32_t maxSize, uint32_t blockSize, uint32_t min } _dataStoreMap = {}; _storedBlocks = {}; - blockSize_ = blockSize; - minLength_ = minLength; - capacity_ = maxSize; + _blockSize = blockSize; + _interval = interval; + _capacity = maxSize; return Status::OK(); } @@ -61,7 +61,7 @@ char* DramSpaceLayout::AllocateDataAddr(std::string blockId, std::string offset) return _dataStoreMap[blockId + offset]; } _dataStoreMap[blockId + offset] = _dataStorePool + _curOffset; - _curOffset = (_curOffset + minLength_) % capacity_; // 这个minLength的逻辑是否正确,还要再确认 + _curOffset = (_curOffset + _interval) % _capacity; // 这个interval的逻辑是否正确,还要再确认 return _dataStoreMap[blockId + offset]; } diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h index 10d3670c..7529e2d3 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h @@ -34,7 +34,7 @@ namespace UC { class DramSpaceLayout { public: - Status Setup(uint32_t maxSize, uint32_t blockSize, uint32_t minLength); // TODO:这里面要先进行内存空间的初始化,通过调malloc这类函数 + Status Setup(uint32_t maxSize, uint32_t blockSize, uint32_t interval); // TODO:这里面要先进行内存空间的初始化,通过调malloc这类函数 char* AllocateDataAddr(std::string blockId, std::string offset); char* GetDataAddr(std::string blockId, std::string offset); void DataStoreMapAppend(std::string key, char* address); @@ -49,9 +49,9 @@ class DramSpaceLayout { std::unordered_map _dataStoreMap; // 键是 block_id+offset 的拼接,值是对应的KVCache的存放起始位置,初始化为空 std::set _storedBlocks; // 被存了的 blocks 的所有 blockId,初始化为空 size_t _curOffset{0}; // 当前的内存池中下一个可用的Offset(相较于内存池中初始地址的偏移) - size_t blockSize_; - size_t capacity_; - size_t minLength_; + size_t _blockSize; + size_t _capacity; + size_t _interval; // 目前为了简单,如果全写满了的话,就从头再来吧,把最头上(即_dataStorePool的起始位置)的数据替换掉 }; diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc b/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc index fe5750b1..d5e10cf1 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc +++ b/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc @@ -27,15 +27,15 @@ namespace UC { -Status DramSpaceManager::Setup(uint32_t maxSize, uint32_t blockSize, uint32_t minLength) +Status DramSpaceManager::Setup(uint32_t maxSize, uint32_t blockSize, uint32_t interval) { if (blockSize == 0) { UC_ERROR("Invalid block size({}).", blockSize); return Status::InvalidParam(); } - auto status = this->layout_.Setup(maxSize, blockSize, minLength); + auto status = this->layout_.Setup(maxSize, blockSize, interval); if (status.Failure()) { return status; } - this->blockSize_ = blockSize; + this->_blockSize = blockSize; return Status::OK(); } diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_manager.h b/ucm/store/dramstore/cc/domain/space/dram_space_manager.h index 18bd2bcd..b9da4ab5 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_manager.h +++ b/ucm/store/dramstore/cc/domain/space/dram_space_manager.h @@ -31,7 +31,7 @@ namespace UC { class DramSpaceManager { public: - Status Setup(uint32_t maxSize, uint32_t blockSize, uint32_t minLength); + Status Setup(uint32_t maxSize, uint32_t blockSize, uint32_t interval); Status NewBlock(const std::string& blockId) const; // 也许不需要实现它。无论如何先放这里 Status CommitBlock(const std::string& blockId, bool success = true) const; // 等一个block完全存完或者被完全删除后,调用这个方法,并更新layout_中的_storedBlocks集合 bool LookupBlock(const std::string& blockId) const; @@ -39,7 +39,7 @@ class DramSpaceManager { private: DramSpaceLayout layout_; - size_t blockSize_; + size_t _blockSize; }; } // namespace UC From b3bee5ff4146bd0623dc0750f7ce0a5aa8e873eb Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 11:52:55 +0800 Subject: [PATCH 10/59] fix --- ucm/store/dramstore/cc/domain/space/dram_space_layout.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc index b019d11c..5c38851a 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc @@ -58,6 +58,7 @@ char* DramSpaceLayout::AllocateDataAddr(std::string blockId, std::string offset) auto iter = _dataStoreMap.find(blockId + offset); if (iter != _dataStoreMap.end()) { // 已经存在,不需要重分配 + _dataStoreMap.erase(blockId + offset) return _dataStoreMap[blockId + offset]; } _dataStoreMap[blockId + offset] = _dataStorePool + _curOffset; From 6c79f65d43ac5b0c520ef05df86996f89c9c22d2 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 11:54:29 +0800 Subject: [PATCH 11/59] fix --- ucm/store/dramstore/cc/domain/space/dram_space_layout.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc index 5c38851a..6f933736 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc @@ -58,8 +58,9 @@ char* DramSpaceLayout::AllocateDataAddr(std::string blockId, std::string offset) auto iter = _dataStoreMap.find(blockId + offset); if (iter != _dataStoreMap.end()) { // 已经存在,不需要重分配 + char* addr = _dataStoreMap[blockId + offset]; _dataStoreMap.erase(blockId + offset) - return _dataStoreMap[blockId + offset]; + return addr; } _dataStoreMap[blockId + offset] = _dataStorePool + _curOffset; _curOffset = (_curOffset + _interval) % _capacity; // 这个interval的逻辑是否正确,还要再确认 From 60f72c7b27fe7079c0d017e1b12dd56e703fa336 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 12:14:00 +0800 Subject: [PATCH 12/59] fix --- .../cc/domain/space/dram_space_layout.h | 62 +++++++++++++------ 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h index 7529e2d3..98f833ca 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h @@ -21,40 +21,66 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * */ +#pragma once #ifndef UNIFIEDCACHE_DRAM_SPACE_LAYOUT_H #define UNIFIEDCACHE_DRAM_SPACE_LAYOUT_H #include #include -#include "status/status.h" #include #include +#include "status/status.h" namespace UC { class DramSpaceLayout { public: - Status Setup(uint32_t maxSize, uint32_t blockSize, uint32_t interval); // TODO:这里面要先进行内存空间的初始化,通过调malloc这类函数 - char* AllocateDataAddr(std::string blockId, std::string offset); - char* GetDataAddr(std::string blockId, std::string offset); - void DataStoreMapAppend(std::string key, char* address); - void StoredBlocksAppend(std::string blockId); - void StoredBlocksErase(std::string blockId); - bool StoredBlocksExist(std::string blockId); + // maxSize : 池字节数 + // blockSize : 一个 block 的字节数(仅用于计算 slotsPerBlock) + // interval : 一次存/取的数据量,也是槽位对齐大小 + Status Setup(uint32_t maxSize, uint32_t blockSize, uint32_t interval); -private: + // 返回可用于写入 _interval 字节的地址 + // 如果曾经写过同样 (blockId,offset) 直接返回原地址; + // 否则按 FIFO 复用或开辟新槽。 + char* AllocateDataAddr(const std::string& blockId, + const std::string& offset); + + // 纯查询,不会分配 + char* GetDataAddr(const std::string& blockId, + const std::string& offset); + + // 下面三个函数仅用于外部把 meta 信息同步进来 + void DataStoreMapAppend(const std::string& key, char* address); + void StoredBlocksAppend(const std::string& blockId); + void StoredBlocksErase (const std::string& blockId); + bool StoredBlocksExist (const std::string& blockId) const; private: - char* _dataStorePool; // KVCache存放的内存空间,在Setup函数中进行初始化 - std::unordered_map _dataStoreMap; // 键是 block_id+offset 的拼接,值是对应的KVCache的存放起始位置,初始化为空 - std::set _storedBlocks; // 被存了的 blocks 的所有 blockId,初始化为空 - size_t _curOffset{0}; // 当前的内存池中下一个可用的Offset(相较于内存池中初始地址的偏移) - size_t _blockSize; - size_t _capacity; - size_t _interval; - // 目前为了简单,如果全写满了的话,就从头再来吧,把最头上(即_dataStorePool的起始位置)的数据替换掉 + // 生成 _dataStoreMap 的 key + static std::string MakeKey(const std::string& blockId, + const std::string& offset) { + return blockId + "_" + offset; + } + + char* _dataStorePool = nullptr; // 裸池 + size_t _capacity = 0; // 池字节数 + size_t _interval = 0; // 槽字节数 + size_t _blockSize = 0; // block 字节数 + size_t _slotsPerBlock = 0; // blockSize / interval + size_t _totalSlots = 0; // 池槽位数 + + // FIFO 循环队列 + size_t _head = 0; // 下一个要被复用的槽号 + std::vector _fifoKey; // 槽号 -> 当前占用它的 key + + // 两个索引 + std::unordered_map _dataStoreMap; + std::set _storedBlocks; + + // 每个 block 已经写入了多少个 offset + std::unordered_map _blockWritten; }; } // namespace UC - #endif \ No newline at end of file From 1670d2f3d7c66100584f1a3a5823b07e86ae3cc1 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 12:14:45 +0800 Subject: [PATCH 13/59] fix --- .../cc/domain/space/dram_space_layout.cc | 110 +++++++++++------- 1 file changed, 65 insertions(+), 45 deletions(-) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc index 6f933736..41420db9 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc @@ -22,73 +22,93 @@ * SOFTWARE. * */ #include "dram_space_layout.h" -#include -#include -#include "file/file.h" #include "logger/logger.h" namespace UC { -constexpr size_t blockIdSize = 16; -constexpr size_t nU64PerBlock = blockIdSize / sizeof(uint64_t); -using BlockId = std::array; -static_assert(sizeof(BlockId) == blockIdSize); - -Status DramSpaceLayout::Setup(uint32_t maxSize, uint32_t blockSize, uint32_t interval) -{ - if (maxSize <= 0) { - UC_ERROR("Invalid maxSize value."); +Status DramSpaceLayout::Setup(uint32_t maxSize, + uint32_t blockSize, + uint32_t interval) { + if (maxSize == 0 || interval == 0 || blockSize == 0 || + blockSize % interval != 0) { + UC_ERROR("Setup: invalid param"); return Status::InvalidParam(); } - _dataStorePool = nullptr; - _dataStorePool = new char[maxSize]; // 这里内存分配的逻辑与方法是否正确?也要确认 - if (!_dataStorePool) { - UC_ERROR("Allocate DRAM storage space failed"); + + _capacity = maxSize; + _interval = interval; + _blockSize = blockSize; + _slotsPerBlock = blockSize / interval; + _totalSlots = maxSize / interval; + + try { + _dataStorePool = new char[_capacity]; + _fifoKey.resize(_totalSlots); + } catch (...) { + UC_ERROR("Allocate DRAM failed"); return Status::OutOfMemory(); } - _dataStoreMap = {}; - _storedBlocks = {}; - _blockSize = blockSize; - _interval = interval; - _capacity = maxSize; + + _head = 0; + _dataStoreMap.clear(); + _storedBlocks.clear(); + _blockWritten.clear(); return Status::OK(); } -char* DramSpaceLayout::AllocateDataAddr(std::string blockId, std::string offset) { - auto iter = _dataStoreMap.find(blockId + offset); - if (iter != _dataStoreMap.end()) { - // 已经存在,不需要重分配 - char* addr = _dataStoreMap[blockId + offset]; - _dataStoreMap.erase(blockId + offset) - return addr; +char* DramSpaceLayout::AllocateDataAddr(const std::string& blockId, + const std::string& offset) { + std::string key = MakeKey(blockId, offset); + + // 1. 曾经写过,直接返回 + auto it = _dataStoreMap.find(key); + if (it != _dataStoreMap.end()) return it->second; + + // 2. 没写过,需要挑一个物理槽位 + size_t slot = _head; + char* addr = _dataStorePool + slot * _interval; + + // 2.1 如果该槽位旧数据有效,先把它从映射里删掉 + if (!_fifoKey[slot].empty()) { + _dataStoreMap.erase(_fifoKey[slot]); } - _dataStoreMap[blockId + offset] = _dataStorePool + _curOffset; - _curOffset = (_curOffset + _interval) % _capacity; // 这个interval的逻辑是否正确,还要再确认 - return _dataStoreMap[blockId + offset]; -} -char* DramSpaceLayout::GetDataAddr(std::string blockId, std::string offset) { - auto iter = _dataStoreMap.find(blockId + offset); - if (iter == _dataStoreMap.end()) { - return nullptr; + // 2.2 占用槽位,记录映射 + _fifoKey[slot] = key; + _dataStoreMap[key] = addr; + + // 2.3 推进 FIFO 头 + _head = (_head + 1) % _totalSlots; + + // 3. 更新 block 计数 + size_t& cnt = _blockWritten[blockId]; + ++cnt; + if (cnt == _slotsPerBlock) { + _storedBlocks.insert(blockId); } - return _dataStoreMap[blockId]; + return addr; } -void DramSpaceLayout::DataStoreMapAppend(std::string key, char* address) { +char* DramSpaceLayout::GetDataAddr(const std::string& blockId, + const std::string& offset) { + std::string key = MakeKey(blockId, offset); + auto it = _dataStoreMap.find(key); + return (it == _dataStoreMap.end()) ? nullptr : it->second; +} + +void DramSpaceLayout::DataStoreMapAppend(const std::string& key, + char* address) { _dataStoreMap[key] = address; } -void DramSpaceLayout::StoredBlocksAppend(std::string blockId) { +void DramSpaceLayout::StoredBlocksAppend(const std::string& blockId) { _storedBlocks.insert(blockId); } - -void DramSpaceLayout::StoredBlocksErase(std::string blockId) { +void DramSpaceLayout::StoredBlocksErase(const std::string& blockId) { _storedBlocks.erase(blockId); } - -bool DramSpaceLayout::StoredBlocksExist(std::string blockId) { - return _storedBlocks.find(blockId) != _storedBlocks.end(); +bool DramSpaceLayout::StoredBlocksExist(const std::string& blockId) const { + return _storedBlocks.count(blockId) != 0; } -} // namespace UC +} // namespace UC \ No newline at end of file From 5fe616724b0c33c64196cd364846ac64b486f5d3 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 14:22:21 +0800 Subject: [PATCH 14/59] fix --- ucm/store/dramstore/cc/domain/space/dram_space_layout.cc | 9 --------- ucm/store/dramstore/cc/domain/space/dram_space_layout.h | 3 --- 2 files changed, 12 deletions(-) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc index 41420db9..cb2d9f03 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc @@ -52,7 +52,6 @@ Status DramSpaceLayout::Setup(uint32_t maxSize, _head = 0; _dataStoreMap.clear(); _storedBlocks.clear(); - _blockWritten.clear(); return Status::OK(); } @@ -79,14 +78,6 @@ char* DramSpaceLayout::AllocateDataAddr(const std::string& blockId, // 2.3 推进 FIFO 头 _head = (_head + 1) % _totalSlots; - - // 3. 更新 block 计数 - size_t& cnt = _blockWritten[blockId]; - ++cnt; - if (cnt == _slotsPerBlock) { - _storedBlocks.insert(blockId); - } - return addr; } char* DramSpaceLayout::GetDataAddr(const std::string& blockId, diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h index 98f833ca..46fd954e 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h @@ -77,9 +77,6 @@ class DramSpaceLayout { // 两个索引 std::unordered_map _dataStoreMap; std::set _storedBlocks; - - // 每个 block 已经写入了多少个 offset - std::unordered_map _blockWritten; }; } // namespace UC From 50612bec3a32b647bc40eba177802afdd78a09cf Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 14:26:28 +0800 Subject: [PATCH 15/59] fix --- ucm/store/dramstore/cc/domain/space/dram_space_layout.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc index cb2d9f03..e6565758 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc @@ -59,7 +59,7 @@ char* DramSpaceLayout::AllocateDataAddr(const std::string& blockId, const std::string& offset) { std::string key = MakeKey(blockId, offset); - // 1. 曾经写过,直接返回 + // 1. 曾经写过,直接返回(好像不应该出现) auto it = _dataStoreMap.find(key); if (it != _dataStoreMap.end()) return it->second; From 6dde7236ccd76c1a368fa2dd178744bb29366fa4 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 14:27:10 +0800 Subject: [PATCH 16/59] fix --- ucm/store/dramstore/cc/domain/space/dram_space_layout.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc index e6565758..49c981b0 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc @@ -78,6 +78,8 @@ char* DramSpaceLayout::AllocateDataAddr(const std::string& blockId, // 2.3 推进 FIFO 头 _head = (_head + 1) % _totalSlots; + + return addr; } char* DramSpaceLayout::GetDataAddr(const std::string& blockId, From 11726cdfdfb89ae1218761351b40b3ad1d988648 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 14:40:46 +0800 Subject: [PATCH 17/59] fix --- ucm/store/dramstore/cc/domain/space/dram_space_manager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc b/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc index d5e10cf1..7129242c 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc +++ b/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc @@ -60,6 +60,6 @@ bool DramSpaceManager::LookupBlock(const std::string& blockId) const return this->_layout->StoredBlocksExist(blockId); } -const SpaceLayout* DramSpaceManager::GetSpaceLayout() const { return &this->layout_; } +const DramSpaceLayout* DramSpaceManager::GetSpaceLayout() const { return &this->layout_; } } // namespace UC From 5306a45abc9bc87d50cba284b77804aece8d5a77 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 16:26:20 +0800 Subject: [PATCH 18/59] fix --- ucm/store/dramstore/cc/api/dramstore.cc | 80 +++++++++++++++++++++---- 1 file changed, 70 insertions(+), 10 deletions(-) diff --git a/ucm/store/dramstore/cc/api/dramstore.cc b/ucm/store/dramstore/cc/api/dramstore.cc index 56b4350f..57060a4b 100644 --- a/ucm/store/dramstore/cc/api/dramstore.cc +++ b/ucm/store/dramstore/cc/api/dramstore.cc @@ -24,27 +24,87 @@ #include "dramstore.h" #include "logger/logger.h" #include "status/status.h" +#include "space/dram_space_manager.h" +#include "tsf_task/dram_tsf_task_manager.h" +#include "tsf_task/dram_tsf_task.h" namespace UC { class DRAMStoreImpl : public DRAMStore { public: - int32_t Setup(const size_t ioSize, const size_t capacity, const int32_t deviceId) { return -1; } - int32_t Alloc(const std::string& block) override { return -1; } - bool Lookup(const std::string& block) override { return false; } - void Commit(const std::string& block, const bool success) override {} + int32_t Setup(const size_t ioSize, const size_t capacity, const int32_t deviceId) { + int32_t blockSize = 14400; // 这个参数是否需要,以及怎么传,还要讨论 + auto status = this->spaceMgr_.Setup(capacity, blockSize, ioSize); + if (status.Failure()) { + UC_ERROR("Failed({}) to setup DramSpaceManager.", status); + return status.Underlying(); + } + int32_t streamNumber = 60; // 这个参数是否需要,以及怎么传,还要讨论 + int32_t timeoutMs = 10000; // 这个参数是否需要,以及怎么传,还要讨论 + status = this->transMgr_.Setup(deviceId, streamNumber, timeoutMs, this->spaceMgr_.GetSpaceLayout()); + if (status.Failure()) { + UC_ERROR("Failed({}) to setup DramTransferTaskManager.", status); + return status.Underlying(); + } + return Status::OK().Underlying(); + } + + int32_t Alloc(const std::string& block) override { + return this->spaceMgr_.NewBlock(block).Underlying(); + } + + bool Lookup(const std::string& block) override { + return this->spaceMgr_.LookupBlock(block); + } + + void Commit(const std::string& block, const bool success) override { + this->spaceMgr_.CommitBlock(block, success); + } + std::list Alloc(const std::list& blocks) override { - return std::list(); + std::list results; + for (const auto &block : blocks) { + results.emplace_back(this->Alloc(block)); + } + return results; } + std::list Lookup(const std::list& blocks) override { - return std::list(); + std::list founds; + for (const auto &block : blocks) { + founds.emplace_back(this->Lookup(block)) + } + return founds; } - void Commit(const std::list& blocks, const bool success) override {} - size_t Submit(Task&& task) override { return 0; } - int32_t Wait(const size_t task) override { return -1; } - int32_t Check(const size_t task, bool& finish) override { return -1; } + + void Commit(const std::list& blocks, const bool success) override { + for (const auto &block : blocks) { + this->commit(block, success); + } + } + + size_t Submit(Task&& task) override { + std::list tasks; + for (auto& shard : task.shards) { + tasks.push_back({task.type, shard.block, shard.offset, shard.address, task.size}); + } + size_t taskId; + return this->transMgr_.Submit(tasks, task.number * task.size, task.number, task.bried, taskId).Success() ? taskId : CCStore::invalidTaskId; + } + + int32_t Wait(const size_t task) override { + return this->transMgr_.Wait(task).Underlying(); + } + + int32_t Check(const size_t task, bool& finish) override { + return this->transMgr_.Check(task, finish).Underlying(); + } + +private: + DramSpaceManager spaceMgr_; + DramTsfTaskManager transMgr_; }; int32_t DRAMStore::Setup(const Config& config) From 4d446ab318e7685dfaeff889552483b62a27cd53 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 16:32:40 +0800 Subject: [PATCH 19/59] fix --- ucm/store/dramstore/cc/api/dramstore.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ucm/store/dramstore/cc/api/dramstore.cc b/ucm/store/dramstore/cc/api/dramstore.cc index 57060a4b..e2bc77d4 100644 --- a/ucm/store/dramstore/cc/api/dramstore.cc +++ b/ucm/store/dramstore/cc/api/dramstore.cc @@ -32,16 +32,16 @@ namespace UC { class DRAMStoreImpl : public DRAMStore { public: - int32_t Setup(const size_t ioSize, const size_t capacity, const int32_t deviceId) { + int32_t Setup(const Config& config) { int32_t blockSize = 14400; // 这个参数是否需要,以及怎么传,还要讨论 - auto status = this->spaceMgr_.Setup(capacity, blockSize, ioSize); + auto status = this->spaceMgr_.Setup(config.capacity, blockSize, config.ioSize); if (status.Failure()) { UC_ERROR("Failed({}) to setup DramSpaceManager.", status); return status.Underlying(); } int32_t streamNumber = 60; // 这个参数是否需要,以及怎么传,还要讨论 int32_t timeoutMs = 10000; // 这个参数是否需要,以及怎么传,还要讨论 - status = this->transMgr_.Setup(deviceId, streamNumber, timeoutMs, this->spaceMgr_.GetSpaceLayout()); + status = this->transMgr_.Setup(config.deviceId, streamNumber, timeoutMs, this->spaceMgr_.GetSpaceLayout()); if (status.Failure()) { UC_ERROR("Failed({}) to setup DramTransferTaskManager.", status); return status.Underlying(); From 61cda77f82397274cda5a2df8e4bb0217c4fdc52 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 16:47:45 +0800 Subject: [PATCH 20/59] fix --- ucm/store/dramstore/cc/domain/space/dram_space_layout.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc index 49c981b0..6e5f3d7b 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc @@ -49,7 +49,6 @@ Status DramSpaceLayout::Setup(uint32_t maxSize, return Status::OutOfMemory(); } - _head = 0; _dataStoreMap.clear(); _storedBlocks.clear(); return Status::OK(); From 4c618e9732cc5d9b489ae1472d1dfade3e157982 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 16:53:59 +0800 Subject: [PATCH 21/59] fix --- ucm/store/dramstore/cc/domain/space/dram_space_layout.cc | 4 ++-- ucm/store/dramstore/cc/domain/space/dram_space_layout.h | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc index 6e5f3d7b..38de3fb5 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc @@ -55,7 +55,7 @@ Status DramSpaceLayout::Setup(uint32_t maxSize, } char* DramSpaceLayout::AllocateDataAddr(const std::string& blockId, - const std::string& offset) { + const size_t& offset) { std::string key = MakeKey(blockId, offset); // 1. 曾经写过,直接返回(好像不应该出现) @@ -82,7 +82,7 @@ char* DramSpaceLayout::AllocateDataAddr(const std::string& blockId, } char* DramSpaceLayout::GetDataAddr(const std::string& blockId, - const std::string& offset) { + const size_t& offset) { std::string key = MakeKey(blockId, offset); auto it = _dataStoreMap.find(key); return (it == _dataStoreMap.end()) ? nullptr : it->second; diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h index 46fd954e..c1ce86ad 100644 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h +++ b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h @@ -44,11 +44,11 @@ class DramSpaceLayout { // 如果曾经写过同样 (blockId,offset) 直接返回原地址; // 否则按 FIFO 复用或开辟新槽。 char* AllocateDataAddr(const std::string& blockId, - const std::string& offset); + const size_t& offset); // 纯查询,不会分配 char* GetDataAddr(const std::string& blockId, - const std::string& offset); + const size_t& offset); // 下面三个函数仅用于外部把 meta 信息同步进来 void DataStoreMapAppend(const std::string& key, char* address); @@ -59,8 +59,8 @@ class DramSpaceLayout { private: // 生成 _dataStoreMap 的 key static std::string MakeKey(const std::string& blockId, - const std::string& offset) { - return blockId + "_" + offset; + const size_t& offset) { + return blockId + "_" + std::to_string(offset); } char* _dataStorePool = nullptr; // 裸池 From 71072ffd7b1171ff56ac121e29498f50a1defb60 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 21:40:04 +0800 Subject: [PATCH 22/59] add memPool in infra/ and remove space/ dir in dramstore --- ucm/store/dramstore/cc/api/dramstore.cc | 21 ++-- ucm/store/dramstore/cc/api/dramstore.h | 5 +- .../cc/domain/space/dram_space_layout.cc | 106 ------------------ .../cc/domain/space/dram_space_layout.h | 83 -------------- .../cc/domain/space/dram_space_manager.cc | 65 ----------- .../cc/domain/space/dram_space_manager.h | 47 -------- .../domain/tsf_task/dram_tsf_task_manager.cc | 4 +- .../domain/tsf_task/dram_tsf_task_manager.h | 2 +- .../cc/domain/tsf_task/dram_tsf_task_queue.cc | 25 +++-- .../cc/domain/tsf_task/dram_tsf_task_queue.h | 16 +-- ucm/store/infra/memory/memory_pool.h | 104 +++++++++++++++++ 11 files changed, 141 insertions(+), 337 deletions(-) delete mode 100644 ucm/store/dramstore/cc/domain/space/dram_space_layout.cc delete mode 100644 ucm/store/dramstore/cc/domain/space/dram_space_layout.h delete mode 100644 ucm/store/dramstore/cc/domain/space/dram_space_manager.cc delete mode 100644 ucm/store/dramstore/cc/domain/space/dram_space_manager.h create mode 100644 ucm/store/infra/memory/memory_pool.h diff --git a/ucm/store/dramstore/cc/api/dramstore.cc b/ucm/store/dramstore/cc/api/dramstore.cc index e2bc77d4..08ae8429 100644 --- a/ucm/store/dramstore/cc/api/dramstore.cc +++ b/ucm/store/dramstore/cc/api/dramstore.cc @@ -27,21 +27,17 @@ #include "space/dram_space_manager.h" #include "tsf_task/dram_tsf_task_manager.h" #include "tsf_task/dram_tsf_task.h" +#include "infra/memory/memory_pool.h" namespace UC { class DRAMStoreImpl : public DRAMStore { public: - int32_t Setup(const Config& config) { - int32_t blockSize = 14400; // 这个参数是否需要,以及怎么传,还要讨论 - auto status = this->spaceMgr_.Setup(config.capacity, blockSize, config.ioSize); - if (status.Failure()) { - UC_ERROR("Failed({}) to setup DramSpaceManager.", status); - return status.Underlying(); - } + int32_t Setup(const Config& config) : this->memPool_(config.capacity, config.blockSize) { + // 初始化memPool的办法是否正确?如果失败的话怎么办? int32_t streamNumber = 60; // 这个参数是否需要,以及怎么传,还要讨论 int32_t timeoutMs = 10000; // 这个参数是否需要,以及怎么传,还要讨论 - status = this->transMgr_.Setup(config.deviceId, streamNumber, timeoutMs, this->spaceMgr_.GetSpaceLayout()); + auto status = this->transMgr_.Setup(config.deviceId, streamNumber, timeoutMs, &this->memPool_); if (status.Failure()) { UC_ERROR("Failed({}) to setup DramTransferTaskManager.", status); return status.Underlying(); @@ -50,15 +46,15 @@ class DRAMStoreImpl : public DRAMStore { } int32_t Alloc(const std::string& block) override { - return this->spaceMgr_.NewBlock(block).Underlying(); + return this->memPool_.NewBlock(block).Underlying(); } bool Lookup(const std::string& block) override { - return this->spaceMgr_.LookupBlock(block); + return this->memPool_.LookupBlock(block); } void Commit(const std::string& block, const bool success) override { - this->spaceMgr_.CommitBlock(block, success); + this->memPool_.CommitBlock(block, success); } std::list Alloc(const std::list& blocks) override @@ -103,7 +99,8 @@ class DRAMStoreImpl : public DRAMStore { } private: - DramSpaceManager spaceMgr_; + // DramSpaceManager spaceMgr_; + MemoryPool memPool_; DramTsfTaskManager transMgr_; }; diff --git a/ucm/store/dramstore/cc/api/dramstore.h b/ucm/store/dramstore/cc/api/dramstore.h index 1dc97573..080d92d3 100644 --- a/ucm/store/dramstore/cc/api/dramstore.h +++ b/ucm/store/dramstore/cc/api/dramstore.h @@ -33,9 +33,10 @@ class DRAMStore : public CCStore { struct Config { size_t ioSize; size_t capacity; + size_t blockSize; int32_t deviceId; - Config(const size_t ioSize, const size_t capacity) - : ioSize{ioSize}, capacity{capacity}, deviceId{-1} + Config(const size_t ioSize, const size_t capacity, const size_t blockSize) + : ioSize{ioSize}, capacity{capacity}, blockSize(blockSize), deviceId{-1} { } }; diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc b/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc deleted file mode 100644 index 38de3fb5..00000000 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.cc +++ /dev/null @@ -1,106 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * */ -#include "dram_space_layout.h" -#include "logger/logger.h" - -namespace UC { - -Status DramSpaceLayout::Setup(uint32_t maxSize, - uint32_t blockSize, - uint32_t interval) { - if (maxSize == 0 || interval == 0 || blockSize == 0 || - blockSize % interval != 0) { - UC_ERROR("Setup: invalid param"); - return Status::InvalidParam(); - } - - _capacity = maxSize; - _interval = interval; - _blockSize = blockSize; - _slotsPerBlock = blockSize / interval; - _totalSlots = maxSize / interval; - - try { - _dataStorePool = new char[_capacity]; - _fifoKey.resize(_totalSlots); - } catch (...) { - UC_ERROR("Allocate DRAM failed"); - return Status::OutOfMemory(); - } - - _dataStoreMap.clear(); - _storedBlocks.clear(); - return Status::OK(); -} - -char* DramSpaceLayout::AllocateDataAddr(const std::string& blockId, - const size_t& offset) { - std::string key = MakeKey(blockId, offset); - - // 1. 曾经写过,直接返回(好像不应该出现) - auto it = _dataStoreMap.find(key); - if (it != _dataStoreMap.end()) return it->second; - - // 2. 没写过,需要挑一个物理槽位 - size_t slot = _head; - char* addr = _dataStorePool + slot * _interval; - - // 2.1 如果该槽位旧数据有效,先把它从映射里删掉 - if (!_fifoKey[slot].empty()) { - _dataStoreMap.erase(_fifoKey[slot]); - } - - // 2.2 占用槽位,记录映射 - _fifoKey[slot] = key; - _dataStoreMap[key] = addr; - - // 2.3 推进 FIFO 头 - _head = (_head + 1) % _totalSlots; - - return addr; -} - -char* DramSpaceLayout::GetDataAddr(const std::string& blockId, - const size_t& offset) { - std::string key = MakeKey(blockId, offset); - auto it = _dataStoreMap.find(key); - return (it == _dataStoreMap.end()) ? nullptr : it->second; -} - -void DramSpaceLayout::DataStoreMapAppend(const std::string& key, - char* address) { - _dataStoreMap[key] = address; -} - -void DramSpaceLayout::StoredBlocksAppend(const std::string& blockId) { - _storedBlocks.insert(blockId); -} -void DramSpaceLayout::StoredBlocksErase(const std::string& blockId) { - _storedBlocks.erase(blockId); -} -bool DramSpaceLayout::StoredBlocksExist(const std::string& blockId) const { - return _storedBlocks.count(blockId) != 0; -} - -} // namespace UC \ No newline at end of file diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h b/ucm/store/dramstore/cc/domain/space/dram_space_layout.h deleted file mode 100644 index c1ce86ad..00000000 --- a/ucm/store/dramstore/cc/domain/space/dram_space_layout.h +++ /dev/null @@ -1,83 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * */ -#pragma once -#ifndef UNIFIEDCACHE_DRAM_SPACE_LAYOUT_H -#define UNIFIEDCACHE_DRAM_SPACE_LAYOUT_H - -#include -#include -#include -#include -#include "status/status.h" - -namespace UC { - -class DramSpaceLayout { -public: - // maxSize : 池字节数 - // blockSize : 一个 block 的字节数(仅用于计算 slotsPerBlock) - // interval : 一次存/取的数据量,也是槽位对齐大小 - Status Setup(uint32_t maxSize, uint32_t blockSize, uint32_t interval); - - // 返回可用于写入 _interval 字节的地址 - // 如果曾经写过同样 (blockId,offset) 直接返回原地址; - // 否则按 FIFO 复用或开辟新槽。 - char* AllocateDataAddr(const std::string& blockId, - const size_t& offset); - - // 纯查询,不会分配 - char* GetDataAddr(const std::string& blockId, - const size_t& offset); - - // 下面三个函数仅用于外部把 meta 信息同步进来 - void DataStoreMapAppend(const std::string& key, char* address); - void StoredBlocksAppend(const std::string& blockId); - void StoredBlocksErase (const std::string& blockId); - bool StoredBlocksExist (const std::string& blockId) const; - -private: - // 生成 _dataStoreMap 的 key - static std::string MakeKey(const std::string& blockId, - const size_t& offset) { - return blockId + "_" + std::to_string(offset); - } - - char* _dataStorePool = nullptr; // 裸池 - size_t _capacity = 0; // 池字节数 - size_t _interval = 0; // 槽字节数 - size_t _blockSize = 0; // block 字节数 - size_t _slotsPerBlock = 0; // blockSize / interval - size_t _totalSlots = 0; // 池槽位数 - - // FIFO 循环队列 - size_t _head = 0; // 下一个要被复用的槽号 - std::vector _fifoKey; // 槽号 -> 当前占用它的 key - - // 两个索引 - std::unordered_map _dataStoreMap; - std::set _storedBlocks; -}; - -} // namespace UC -#endif \ No newline at end of file diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc b/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc deleted file mode 100644 index 7129242c..00000000 --- a/ucm/store/dramstore/cc/domain/space/dram_space_manager.cc +++ /dev/null @@ -1,65 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * */ -#include "dram_space_manager.h" -#include "file/file.h" -#include "logger/logger.h" - -namespace UC { - -Status DramSpaceManager::Setup(uint32_t maxSize, uint32_t blockSize, uint32_t interval) -{ - if (blockSize == 0) { - UC_ERROR("Invalid block size({}).", blockSize); - return Status::InvalidParam(); - } - auto status = this->layout_.Setup(maxSize, blockSize, interval); - if (status.Failure()) { return status; } - this->_blockSize = blockSize; - return Status::OK(); -} - -Status DramSpaceManager::NewBlock(const std::string& blockId) const -{ - return Status::OK(); -} - -Status DramSpaceManager::CommitBlock(const std::string& blockId, bool success) const -{ - if (success) { - this->_layout->StoredBlocksAppend(blockId); - } - else { - this->_layout->StoredBlocksErase(blockId); - } - return Status::OK(); -} - -bool DramSpaceManager::LookupBlock(const std::string& blockId) const -{ - return this->_layout->StoredBlocksExist(blockId); -} - -const DramSpaceLayout* DramSpaceManager::GetSpaceLayout() const { return &this->layout_; } - -} // namespace UC diff --git a/ucm/store/dramstore/cc/domain/space/dram_space_manager.h b/ucm/store/dramstore/cc/domain/space/dram_space_manager.h deleted file mode 100644 index b9da4ab5..00000000 --- a/ucm/store/dramstore/cc/domain/space/dram_space_manager.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * */ -#ifndef UNIFIEDCACHE_DRAM_SPACE_MANAGER_H -#define UNIFIEDCACHE_DRAM_SPACE_MANAGER_H - -#include "dram_space_layout.h" -#include "status/status.h" - -namespace UC { - -class DramSpaceManager { -public: - Status Setup(uint32_t maxSize, uint32_t blockSize, uint32_t interval); - Status NewBlock(const std::string& blockId) const; // 也许不需要实现它。无论如何先放这里 - Status CommitBlock(const std::string& blockId, bool success = true) const; // 等一个block完全存完或者被完全删除后,调用这个方法,并更新layout_中的_storedBlocks集合 - bool LookupBlock(const std::string& blockId) const; - const DramSpaceLayout* GetSpaceLayout() const; - -private: - DramSpaceLayout layout_; - size_t _blockSize; -}; - -} // namespace UC - -#endif \ No newline at end of file diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc index 875316ce..191e6439 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc @@ -26,12 +26,12 @@ namespace UC { Status DramTsfTaskManager::Setup(const int32_t deviceId, const size_t streamNumber, - const size_t timeoutMs, const SpaceLayout* layout) + const size_t timeoutMs, const MemoryPool* memPool) { this->_queues.reserve(streamNumber); for (size_t i = 0; i < streamNumber; ++i) { auto& queue = this->_queues.emplace_back(std::make_unique()); - auto status = queue->Setup(deviceId, &this->_failureSet, layout); + auto status = queue->Setup(deviceId, &this->_failureSet, memPool); if (status.Failure()) { return status; } } this->_timeoutMs = timeoutMs; diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.h b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.h index d4e7dd34..bdc881f6 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.h +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.h @@ -35,7 +35,7 @@ class DramTsfTaskManager { public: Status Setup(const int32_t deviceId, const size_t streamNumber, // const size_t bufferSize, const size_t bufferNumber, // 这两个可能不需要,对于dram来说,因为这个buffer是用来数据中转的? - const size_t timeoutMs, const DramSpaceLayout* layout); + const size_t timeoutMs, const MemoryPool* memPool); Status Submit(std::list& tasks, const size_t size, const size_t number, const std::string& brief, size_t& taskId); Status Wait(const size_t taskId); diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc index dd4fa66a..ebaf0b75 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc @@ -32,10 +32,10 @@ namespace UC { (t).length); \ } while (0) -Status DramTsfTaskQueue::Setup(const int32_t deviceId, DramTsfTaskSet* failureSet, const DramSpaceLayout* layout); +Status DramTsfTaskQueue::Setup(const int32_t deviceId, DramTsfTaskSet* failureSet, const MemoryPool* memPool); { this->_failureSet = failureSet; - this->_layout = layout; + this->_memPool = memPool; if (deviceId >= 0) { this->_device = DeviceFactory::Make(deviceId, 0, 0); // 这里不需要buffer,暂时都先传0吧 if (!this->_device) { return Status::OutOfMemory(); } @@ -64,10 +64,12 @@ void DramTsfTaskQueue::StreamOper(DramTsfTask& task) } } -// 这个H2D和D2H函数是重点要重新实现的。这里70和71行是与nfsstore不同的。 +// 这个H2D和D2H函数是重点要重新实现的。 void DramTsfTaskQueue::H2D(DramTsfTask& task) { - auto host_src = this->_layout->GetDataAddr(task.blockId, task.offset); // 这里host_src是已知的 + // TODO 这里地址要重新写逻辑 + auto block_addr = this->memPool_->GetAddress(task.blockId); + auto host_src = block_addr + task.offset; if (!host_src) { UC_TASK_ERROR(Status::Error(), task); this->Done(task, false); @@ -94,8 +96,17 @@ void DramTsfTaskQueue::H2D(DramTsfTask& task) // 这个函数也是重点要重新实现的。 void DramTsfTaskQueue::D2H(DramTsfTask& task) { - // auto host_dst = this->layout->GetDataAddr(task.blockId, task.offset); // 这里host_dst是未知的,要新分配的!不能用GetDataAddr,而要用另一个接口才是 - auto host_dst = this->layout->AllocateDataAddr(task.blockId, task.offset); + // TODO 这里地址要重新写逻辑 + auto block_addr = this->memPool_->GetAddress(task.blockId); + if (!block_addr) { + block_addr = this->memPool_->NewBlock(); + if (!block_addr) { + UC_TASK_ERROR(Status::Error(), task); + this->Done(task, false); + return; + } + } + auto host_dst = block_addr + task.offset; if (!host_dst) { UC_TASK_ERROR(Status::Error(), task); this->Done(task, false); @@ -113,8 +124,6 @@ void DramTsfTaskQueue::D2H(DramTsfTask& task) this->Done(task, false); return; // 这里是否需要return? } - // TODO: 更新_layout中的_dataStoreMap字典 - this->_layout->DataStoreMapAppend(task.blockId + task.offset, host_dst) this->done(task, true); }); if (status.Failure()) { diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h index e143db74..5af98d13 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h @@ -25,36 +25,30 @@ #define UNIFIEDCACHE_DRAM_TSF_TAKS_QUEUE_H #include "idevice.h" -#include "space/dram_space_layout.h" #include "thread/thread_pool.h" #include "dram_tsf_task.h" #include "dram_tsf_task_set.h" +#include "infra/memory/memory_pool.h" namespace UC { class DramTsfTaskQueue { public: Status Setup(const int32_t deviceId, - // const size_t bufferSize, const size_t bufferNumber, - DramTsfTaskSet* failureSet, const DramSpaceLayout* layout); // TODO:需要传入哪些参数,到时候再看。目前看需要deviceId,但是bufferSize和bufferNumber不需要 + DramTsfTaskSet* failureSet, const MemoryPool* memPool); void Push(std::list& tasks); private: void StreamOper(DramTsfTask& task); - // void FileOper(DramTsfTask& task); // 与下面同步,不再需要了 - void H2D(DramTsfTask& task); // 这个函数和D2H函数里,需要用到this->_layout里的接口来得到数据在host内存中的位置,再调用this->_device来执行显卡与host中的内存拷贝的操作 - void D2H(DramTsfTask& task); // 完成后,要更新_layout中的_dataStoreMap字典 - // void H2S(DramTsfTask& task); - // void S2H(DramTsfTask& task); + void H2D(DramTsfTask& task); + void D2H(DramTsfTask& task); void Done(const DramTsfTask& task, bool success); private: ThreadPool _streamOper; - // ThreadPool _fileOper; // 在NFSStore中需要,但是在DRAM里不需要了,因为只涉及H与D之间的数据传输 std::unique_ptr _device; DramTsfTaskSet* _failureSet; - // TODO - DramSpaceLayout* _layout; // 这个大概也需要吧,因为NFSStore里是在H2S和S2H中需要用它,也就是真正和“存储”打交道时是需要它的。具体怎么定义后面再看 + MemoryPool* _memPool; }; } // namespace UC diff --git a/ucm/store/infra/memory/memory_pool.h b/ucm/store/infra/memory/memory_pool.h new file mode 100644 index 00000000..0c292ba8 --- /dev/null +++ b/ucm/store/infra/memory/memory_pool.h @@ -0,0 +1,104 @@ +/** + * MIT License + * + * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * */ +#ifndef UNIFIEDCACHE_MEMORY_POOL_H +#define UNIFIEDCACHE_MEMORY_POOL_H + +namespace UC { + +#pragma once +#include +#include +#include +#include "status/status.h" + +class MemoryPool { +public: + MemoryPool(uint32_t capacity, uint32_t blockSize) : capacity_(capacity), head_(0), blockSize_(blockSize) { + pool_ = new char[capacity]; + if (!pool_) { + throw std::bad_alloc(); + } + } + + ~MemoryPool() { + delete [] pool_; + } + + MemoryPool(const MemoryPool&) = delete; + MemoryPool& operator=(const MemoryPool&) = delete; + + void Reset() { + head_ = 0; + } + + uint32_t GetNextAvailableOffset() const { return head_; } + + Status NewBlock(std::string blockId) { + if (head_ >= capacity_) { + return Status::Error(); // 下一版本再实现GC逻辑,目前先忽略吧 + } + auto it = addressMap_.find(blockId); + if (it != addressMap_.end()) { + // duplicate key + return Status::OK(); + } + // addressMap_里目前还没有这个blockId,即将进行分配 + addressMap_[blockId] = pool_ + head_; + head_ = head_ + blockSize_; + return Status::OK(); + } + + bool LookupBlock(std::string blockId) { + return availableBlocks_.find(blockId) != availableBlocks_.end(); + } + + char* GetAddress(std::string blockId) { + if (addressMap_.find(blockId) == addressMap_.end()) { + return nullptr; + } + return addressMap_[blockId]; + } + + Status CommitBlock(std::string blockId, bool success) { + if (success) { + availableBlocks_.insert(blockId) + } + else { + availableBlocks_.erase(blockId); + } + return Status::OK(); + } + +private: + char* pool_ = nullptr; + uint32_t capacity_; + uint32_t head_; + uint32_t blockSize_; + std::unordered_map addressMap_; + std::set availableBlocks_; +}; + +} // namespace UC + +#endif From ae693924625fc9d234786e7de2afc417eacf3268 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Tue, 14 Oct 2025 21:45:41 +0800 Subject: [PATCH 23/59] fix --- ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc index ebaf0b75..1028a6f5 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc @@ -99,6 +99,7 @@ void DramTsfTaskQueue::D2H(DramTsfTask& task) // TODO 这里地址要重新写逻辑 auto block_addr = this->memPool_->GetAddress(task.blockId); if (!block_addr) { + // 如果还没有,那么临时分配 block_addr = this->memPool_->NewBlock(); if (!block_addr) { UC_TASK_ERROR(Status::Error(), task); From dbc7e261eaffa8eed64b912cabb827dfb568c758 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 10:05:56 +0800 Subject: [PATCH 24/59] fix --- ucm/store/dramstore/cc/api/dramstore.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ucm/store/dramstore/cc/api/dramstore.cc b/ucm/store/dramstore/cc/api/dramstore.cc index 08ae8429..fc54a336 100644 --- a/ucm/store/dramstore/cc/api/dramstore.cc +++ b/ucm/store/dramstore/cc/api/dramstore.cc @@ -50,7 +50,7 @@ class DRAMStoreImpl : public DRAMStore { } bool Lookup(const std::string& block) override { - return this->memPool_.LookupBlock(block); + return this->memPool_.LookupBlock(block).Underlying(); } void Commit(const std::string& block, const bool success) override { @@ -70,7 +70,7 @@ class DRAMStoreImpl : public DRAMStore { { std::list founds; for (const auto &block : blocks) { - founds.emplace_back(this->Lookup(block)) + founds.emplace_back(this->Lookup(block)); } return founds; } From 851e323c7f985eacc71b8c7bd43e2988df7ebfcf Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 10:08:57 +0800 Subject: [PATCH 25/59] fix --- ucm/store/dramstore/cc/api/dramstore.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/ucm/store/dramstore/cc/api/dramstore.cc b/ucm/store/dramstore/cc/api/dramstore.cc index fc54a336..d5caad18 100644 --- a/ucm/store/dramstore/cc/api/dramstore.cc +++ b/ucm/store/dramstore/cc/api/dramstore.cc @@ -24,7 +24,6 @@ #include "dramstore.h" #include "logger/logger.h" #include "status/status.h" -#include "space/dram_space_manager.h" #include "tsf_task/dram_tsf_task_manager.h" #include "tsf_task/dram_tsf_task.h" #include "infra/memory/memory_pool.h" From db39526e890b21b263f352ad5306e288d07bfb1b Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 10:14:45 +0800 Subject: [PATCH 26/59] fix --- ucm/store/dramstore/CMakeLists.txt | 5 ++++- .../dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ucm/store/dramstore/CMakeLists.txt b/ucm/store/dramstore/CMakeLists.txt index 53c9bce1..ea38a5c8 100644 --- a/ucm/store/dramstore/CMakeLists.txt +++ b/ucm/store/dramstore/CMakeLists.txt @@ -1,6 +1,9 @@ file(GLOB_RECURSE UCMSTORE_DRAM_CC_SOURCE_FILES "./cc/*.cc") add_library(dramstore STATIC ${UCMSTORE_DRAM_CC_SOURCE_FILES}) -target_include_directories(dramstore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/cc) +target_include_directories(dramstore PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/cc/api + ${CMAKE_CURRENT_SOURCE_DIR}/cc/domain +) target_link_libraries(dramstore PUBLIC storeinfra) file(GLOB_RECURSE UCMSTORE_DRAM_CPY_SOURCE_FILES "./cpy/*.cc") diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc index 1028a6f5..5bd51665 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc @@ -100,7 +100,8 @@ void DramTsfTaskQueue::D2H(DramTsfTask& task) auto block_addr = this->memPool_->GetAddress(task.blockId); if (!block_addr) { // 如果还没有,那么临时分配 - block_addr = this->memPool_->NewBlock(); + this->memPool_->NewBlock(task.blockId); + block_addr = this->memPool_->GetAddress(task.blockId); if (!block_addr) { UC_TASK_ERROR(Status::Error(), task); this->Done(task, false); From 67115665e1a89c5883676d18d99e46b6bf2a1e43 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 10:17:34 +0800 Subject: [PATCH 27/59] fix --- ucm/store/dramstore/cc/api/dramstore.cc | 2 +- ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ucm/store/dramstore/cc/api/dramstore.cc b/ucm/store/dramstore/cc/api/dramstore.cc index d5caad18..991a8661 100644 --- a/ucm/store/dramstore/cc/api/dramstore.cc +++ b/ucm/store/dramstore/cc/api/dramstore.cc @@ -26,7 +26,7 @@ #include "status/status.h" #include "tsf_task/dram_tsf_task_manager.h" #include "tsf_task/dram_tsf_task.h" -#include "infra/memory/memory_pool.h" +#include "memory/memory_pool.h" namespace UC { diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h index 5af98d13..920d0b65 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h @@ -28,7 +28,7 @@ #include "thread/thread_pool.h" #include "dram_tsf_task.h" #include "dram_tsf_task_set.h" -#include "infra/memory/memory_pool.h" +#include "memory/memory_pool.h" namespace UC { From 7441433708733f92e61742a33f9dc7bd808b5e49 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 10:19:28 +0800 Subject: [PATCH 28/59] fix --- ucm/store/dramstore/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ucm/store/dramstore/CMakeLists.txt b/ucm/store/dramstore/CMakeLists.txt index ea38a5c8..aceb3aa4 100644 --- a/ucm/store/dramstore/CMakeLists.txt +++ b/ucm/store/dramstore/CMakeLists.txt @@ -4,7 +4,7 @@ target_include_directories(dramstore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/cc/api ${CMAKE_CURRENT_SOURCE_DIR}/cc/domain ) -target_link_libraries(dramstore PUBLIC storeinfra) +target_link_libraries(dramstore PUBLIC storeinfra storedevice) file(GLOB_RECURSE UCMSTORE_DRAM_CPY_SOURCE_FILES "./cpy/*.cc") pybind11_add_module(ucmdramstore ${UCMSTORE_DRAM_CPY_SOURCE_FILES}) From 8261cf1608a7ef89aa35de451d83ee20e351f34b Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 10:23:08 +0800 Subject: [PATCH 29/59] fix --- ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_waiter.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_waiter.h b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_waiter.h index c3624217..61d920af 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_waiter.h +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_waiter.h @@ -30,9 +30,9 @@ namespace UC { -class DrAMTsfTaskWaiter : public Latch { +class DramTsfTaskWaiter : public Latch { public: - DrAMTsfTaskWaiter(const size_t id, const size_t size, const size_t number, const std::string& brief) + DramTsfTaskWaiter(const size_t id, const size_t size, const size_t number, const std::string& brief) : Latch{number}, id_{id}, size_{size}, number_{number}, brief_{brief} { } From bb2ee751b11767aff0a86cb41d7e826408bc1b74 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 10:36:59 +0800 Subject: [PATCH 30/59] fix --- ucm/store/dramstore/cc/api/dramstore.cc | 2 +- ucm/store/infra/CMakeLists.txt | 2 ++ ucm/store/infra/memory/memory_pool.h | 7 +++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ucm/store/dramstore/cc/api/dramstore.cc b/ucm/store/dramstore/cc/api/dramstore.cc index 991a8661..6875c0b8 100644 --- a/ucm/store/dramstore/cc/api/dramstore.cc +++ b/ucm/store/dramstore/cc/api/dramstore.cc @@ -86,7 +86,7 @@ class DRAMStoreImpl : public DRAMStore { tasks.push_back({task.type, shard.block, shard.offset, shard.address, task.size}); } size_t taskId; - return this->transMgr_.Submit(tasks, task.number * task.size, task.number, task.bried, taskId).Success() ? taskId : CCStore::invalidTaskId; + return this->transMgr_.Submit(tasks, task.number * task.size, task.number, task.brief, taskId).Success() ? taskId : CCStore::invalidTaskId; } int32_t Wait(const size_t task) override { diff --git a/ucm/store/infra/CMakeLists.txt b/ucm/store/infra/CMakeLists.txt index f3e0ce72..7cc1a68d 100644 --- a/ucm/store/infra/CMakeLists.txt +++ b/ucm/store/infra/CMakeLists.txt @@ -10,11 +10,13 @@ endif() file(GLOB_RECURSE UCMSTORE_COMMON_STATUS_SOURCE_FILES "status/*.cc") file(GLOB_RECURSE UCMSTORE_COMMON_TEMPLATE_SOURCE_FILES "template/*.cc") file(GLOB_RECURSE UCMSTORE_COMMON_THREAD_SOURCE_FILES "thread/*.cc") +file(GLOB_RECURSE UCMSTORE_COMMON_MEMORY_SOURCE_FILES "memory/*.cc") target_sources(storeinfra PRIVATE ${UCMSTORE_COMMON_FILE_SOURCE_FILES}) target_sources(storeinfra PRIVATE ${UCMSTORE_COMMON_LOGGER_SOURCE_FILES}) target_sources(storeinfra PRIVATE ${UCMSTORE_COMMON_STATUS_SOURCE_FILES}) target_sources(storeinfra PRIVATE ${UCMSTORE_COMMON_TEMPLATE_SOURCE_FILES}) target_sources(storeinfra PRIVATE ${UCMSTORE_COMMON_THREAD_SOURCE_FILES}) +target_sources(storeinfra PRIVATE ${UCMSTORE_COMMON_MEMORY_SOURCE_FILES}) target_link_libraries(storeinfra PUBLIC fmt) if(LOGGER_BACKEND STREQUAL "spdlog") target_link_libraries(storeinfra PUBLIC spdlog) diff --git a/ucm/store/infra/memory/memory_pool.h b/ucm/store/infra/memory/memory_pool.h index 0c292ba8..e87312ab 100644 --- a/ucm/store/infra/memory/memory_pool.h +++ b/ucm/store/infra/memory/memory_pool.h @@ -24,14 +24,13 @@ #ifndef UNIFIEDCACHE_MEMORY_POOL_H #define UNIFIEDCACHE_MEMORY_POOL_H -namespace UC { - -#pragma once #include #include -#include +#include #include "status/status.h" +namespace UC { + class MemoryPool { public: MemoryPool(uint32_t capacity, uint32_t blockSize) : capacity_(capacity), head_(0), blockSize_(blockSize) { From 3ca96519ec6fb5b71cd98e7fdb17f57bd5d4e21c Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 10:40:13 +0800 Subject: [PATCH 31/59] fix --- ucm/store/infra/memory/memory_pool.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ucm/store/infra/memory/memory_pool.h b/ucm/store/infra/memory/memory_pool.h index e87312ab..a7e036e4 100644 --- a/ucm/store/infra/memory/memory_pool.h +++ b/ucm/store/infra/memory/memory_pool.h @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include "status/status.h" namespace UC { From 22e10312242962030517d90f33e4b5d08fae523f Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 10:45:33 +0800 Subject: [PATCH 32/59] fix --- ucm/store/dramstore/cc/api/dramstore.cc | 6 +++--- ucm/store/infra/memory/memory_pool.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ucm/store/dramstore/cc/api/dramstore.cc b/ucm/store/dramstore/cc/api/dramstore.cc index 6875c0b8..83da7123 100644 --- a/ucm/store/dramstore/cc/api/dramstore.cc +++ b/ucm/store/dramstore/cc/api/dramstore.cc @@ -49,11 +49,11 @@ class DRAMStoreImpl : public DRAMStore { } bool Lookup(const std::string& block) override { - return this->memPool_.LookupBlock(block).Underlying(); + return this->memPool_.LookupBlock(block); } void Commit(const std::string& block, const bool success) override { - this->memPool_.CommitBlock(block, success); + this->memPool_.CommitBlock(block, success).Underlying(); } std::list Alloc(const std::list& blocks) override @@ -76,7 +76,7 @@ class DRAMStoreImpl : public DRAMStore { void Commit(const std::list& blocks, const bool success) override { for (const auto &block : blocks) { - this->commit(block, success); + this->Commit(block, success); } } diff --git a/ucm/store/infra/memory/memory_pool.h b/ucm/store/infra/memory/memory_pool.h index a7e036e4..d9c11f78 100644 --- a/ucm/store/infra/memory/memory_pool.h +++ b/ucm/store/infra/memory/memory_pool.h @@ -83,7 +83,7 @@ class MemoryPool { Status CommitBlock(std::string blockId, bool success) { if (success) { - availableBlocks_.insert(blockId) + availableBlocks_.insert(blockId); } else { availableBlocks_.erase(blockId); From 1347e466399368fd9f1c8ff5b153f4e78a78d005 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 10:51:41 +0800 Subject: [PATCH 33/59] fix --- ucm/store/dramstore/cc/api/dramstore.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ucm/store/dramstore/cc/api/dramstore.cc b/ucm/store/dramstore/cc/api/dramstore.cc index 83da7123..b2e08685 100644 --- a/ucm/store/dramstore/cc/api/dramstore.cc +++ b/ucm/store/dramstore/cc/api/dramstore.cc @@ -32,7 +32,8 @@ namespace UC { class DRAMStoreImpl : public DRAMStore { public: - int32_t Setup(const Config& config) : this->memPool_(config.capacity, config.blockSize) { + int32_t Setup(const Config& config) { + this->memPool_ = std::make_unique(config.capacity, config.blockSize); // 初始化memPool的办法是否正确?如果失败的话怎么办? int32_t streamNumber = 60; // 这个参数是否需要,以及怎么传,还要讨论 int32_t timeoutMs = 10000; // 这个参数是否需要,以及怎么传,还要讨论 @@ -45,15 +46,15 @@ class DRAMStoreImpl : public DRAMStore { } int32_t Alloc(const std::string& block) override { - return this->memPool_.NewBlock(block).Underlying(); + return this->memPool_->NewBlock(block).Underlying(); } bool Lookup(const std::string& block) override { - return this->memPool_.LookupBlock(block); + return this->memPool_->LookupBlock(block); } void Commit(const std::string& block, const bool success) override { - this->memPool_.CommitBlock(block, success).Underlying(); + this->memPool_->CommitBlock(block, success).Underlying(); } std::list Alloc(const std::list& blocks) override @@ -99,7 +100,7 @@ class DRAMStoreImpl : public DRAMStore { private: // DramSpaceManager spaceMgr_; - MemoryPool memPool_; + MemoryPool* memPool_; DramTsfTaskManager transMgr_; }; From 9fc2223ebe0e850512b4ebbcedd1ba66381d4508 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 10:55:24 +0800 Subject: [PATCH 34/59] fix --- ucm/store/dramstore/cc/api/dramstore.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ucm/store/dramstore/cc/api/dramstore.cc b/ucm/store/dramstore/cc/api/dramstore.cc index b2e08685..463548d1 100644 --- a/ucm/store/dramstore/cc/api/dramstore.cc +++ b/ucm/store/dramstore/cc/api/dramstore.cc @@ -37,7 +37,7 @@ class DRAMStoreImpl : public DRAMStore { // 初始化memPool的办法是否正确?如果失败的话怎么办? int32_t streamNumber = 60; // 这个参数是否需要,以及怎么传,还要讨论 int32_t timeoutMs = 10000; // 这个参数是否需要,以及怎么传,还要讨论 - auto status = this->transMgr_.Setup(config.deviceId, streamNumber, timeoutMs, &this->memPool_); + auto status = this->transMgr_.Setup(config.deviceId, streamNumber, timeoutMs, this->memPool_); if (status.Failure()) { UC_ERROR("Failed({}) to setup DramTransferTaskManager.", status); return status.Underlying(); @@ -100,7 +100,7 @@ class DRAMStoreImpl : public DRAMStore { private: // DramSpaceManager spaceMgr_; - MemoryPool* memPool_; + std::unique_ptr memPool_; DramTsfTaskManager transMgr_; }; From ce73e08ec5c8695fc4979b35639c9de21343ebf3 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 10:59:25 +0800 Subject: [PATCH 35/59] fix --- ucm/store/dramstore/cc/api/dramstore.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ucm/store/dramstore/cc/api/dramstore.cc b/ucm/store/dramstore/cc/api/dramstore.cc index 463548d1..c9d6f134 100644 --- a/ucm/store/dramstore/cc/api/dramstore.cc +++ b/ucm/store/dramstore/cc/api/dramstore.cc @@ -33,7 +33,7 @@ namespace UC { class DRAMStoreImpl : public DRAMStore { public: int32_t Setup(const Config& config) { - this->memPool_ = std::make_unique(config.capacity, config.blockSize); + this->memPool_ = std::make_unique(config.capacity, config.blockSize).release(); // 初始化memPool的办法是否正确?如果失败的话怎么办? int32_t streamNumber = 60; // 这个参数是否需要,以及怎么传,还要讨论 int32_t timeoutMs = 10000; // 这个参数是否需要,以及怎么传,还要讨论 @@ -100,7 +100,7 @@ class DRAMStoreImpl : public DRAMStore { private: // DramSpaceManager spaceMgr_; - std::unique_ptr memPool_; + MemoryPool* memPool_; DramTsfTaskManager transMgr_; }; From 1598d957e88ac81d246d7904601850a6338973ac Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 11:03:57 +0800 Subject: [PATCH 36/59] fix --- ucm/store/dramstore/cc/api/dramstore.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ucm/store/dramstore/cc/api/dramstore.cc b/ucm/store/dramstore/cc/api/dramstore.cc index c9d6f134..6df1bef5 100644 --- a/ucm/store/dramstore/cc/api/dramstore.cc +++ b/ucm/store/dramstore/cc/api/dramstore.cc @@ -112,7 +112,7 @@ int32_t DRAMStore::Setup(const Config& config) return Status::OutOfMemory().Underlying(); } this->impl_ = impl; - return impl->Setup(config.ioSize, config.capacity, config.deviceId); + return impl->Setup(config); } } // namespace UC From 488dca60a023efb61f4c9dc858c456821a955b26 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 11:07:53 +0800 Subject: [PATCH 37/59] fix --- .../cc/domain/tsf_task/dram_tsf_task_queue.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc index 5bd51665..b1a273fe 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc @@ -32,7 +32,7 @@ namespace UC { (t).length); \ } while (0) -Status DramTsfTaskQueue::Setup(const int32_t deviceId, DramTsfTaskSet* failureSet, const MemoryPool* memPool); +Status DramTsfTaskQueue::Setup(const int32_t deviceId, DramTsfTaskSet* failureSet, const MemoryPool* memPool) { this->_failureSet = failureSet; this->_memPool = memPool; @@ -68,7 +68,7 @@ void DramTsfTaskQueue::StreamOper(DramTsfTask& task) void DramTsfTaskQueue::H2D(DramTsfTask& task) { // TODO 这里地址要重新写逻辑 - auto block_addr = this->memPool_->GetAddress(task.blockId); + auto block_addr = this->_memPool->GetAddress(task.blockId); auto host_src = block_addr + task.offset; if (!host_src) { UC_TASK_ERROR(Status::Error(), task); @@ -97,11 +97,11 @@ void DramTsfTaskQueue::H2D(DramTsfTask& task) void DramTsfTaskQueue::D2H(DramTsfTask& task) { // TODO 这里地址要重新写逻辑 - auto block_addr = this->memPool_->GetAddress(task.blockId); + auto block_addr = this->_memPool->GetAddress(task.blockId); if (!block_addr) { // 如果还没有,那么临时分配 - this->memPool_->NewBlock(task.blockId); - block_addr = this->memPool_->GetAddress(task.blockId); + this->_memPool->NewBlock(task.blockId); + block_addr = this->_memPool->GetAddress(task.blockId); if (!block_addr) { UC_TASK_ERROR(Status::Error(), task); this->Done(task, false); From c73466afe0cf9867efb4cc35abd34575969b94c1 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 11:11:59 +0800 Subject: [PATCH 38/59] fix --- .../dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc index b1a273fe..74945aea 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc @@ -32,7 +32,7 @@ namespace UC { (t).length); \ } while (0) -Status DramTsfTaskQueue::Setup(const int32_t deviceId, DramTsfTaskSet* failureSet, const MemoryPool* memPool) +Status DramTsfTaskQueue::Setup(const int32_t deviceId, DramTsfTaskSet* failureSet, MemoryPool* memPool) { this->_failureSet = failureSet; this->_memPool = memPool; @@ -75,7 +75,7 @@ void DramTsfTaskQueue::H2D(DramTsfTask& task) this->Done(task, false); return; } - auto status = this->_device->H2DAsync((std::byte*)task.address, host_src, task.length); + auto status = this->_device->H2DAsync((std::byte*)task.address, (std::byte*)host_src, task.length); if (status.Failure()) { UC_TASK_ERROR(status, task); this->Done(task, false); @@ -114,7 +114,7 @@ void DramTsfTaskQueue::D2H(DramTsfTask& task) this->Done(task, false); return; } - auto status = this->_device->D2HAsync(host_dst, (std::byte*)task.address, task.length); + auto status = this->_device->D2HAsync((std::byte*)host_dst, (std::byte*)task.address, task.length); if (status.Failure()) { UC_TASK_ERROR(status, task); this->Done(task, false); From e349854b06563e5ad212633e83053f0b0144016b Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 11:15:00 +0800 Subject: [PATCH 39/59] fix --- ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc | 2 +- ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc index 74945aea..c44567fd 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc @@ -126,7 +126,7 @@ void DramTsfTaskQueue::D2H(DramTsfTask& task) this->Done(task, false); return; // 这里是否需要return? } - this->done(task, true); + this->Done(task, true); }); if (status.Failure()) { UC_TASK_ERROR(status, task); diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h index 920d0b65..ebcc84f8 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.h @@ -35,7 +35,7 @@ namespace UC { class DramTsfTaskQueue { public: Status Setup(const int32_t deviceId, - DramTsfTaskSet* failureSet, const MemoryPool* memPool); + DramTsfTaskSet* failureSet, MemoryPool* memPool); void Push(std::list& tasks); private: From 407dea75fb0d427c16f4b7cac7e48b3f95e15d74 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 11:18:31 +0800 Subject: [PATCH 40/59] fix --- ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc | 2 +- ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc index 191e6439..b3eb7c3f 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.cc @@ -26,7 +26,7 @@ namespace UC { Status DramTsfTaskManager::Setup(const int32_t deviceId, const size_t streamNumber, - const size_t timeoutMs, const MemoryPool* memPool) + const size_t timeoutMs, MemoryPool* memPool) { this->_queues.reserve(streamNumber); for (size_t i = 0; i < streamNumber; ++i) { diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.h b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.h index bdc881f6..d33348ac 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.h +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_manager.h @@ -35,7 +35,7 @@ class DramTsfTaskManager { public: Status Setup(const int32_t deviceId, const size_t streamNumber, // const size_t bufferSize, const size_t bufferNumber, // 这两个可能不需要,对于dram来说,因为这个buffer是用来数据中转的? - const size_t timeoutMs, const MemoryPool* memPool); + const size_t timeoutMs, MemoryPool* memPool); Status Submit(std::list& tasks, const size_t size, const size_t number, const std::string& brief, size_t& taskId); Status Wait(const size_t taskId); From 04aeb7220bc6505cb9ef401534006a615d6150ea Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 11:22:34 +0800 Subject: [PATCH 41/59] fix --- ucm/store/dramstore/cpy/dramstore.py.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ucm/store/dramstore/cpy/dramstore.py.cc b/ucm/store/dramstore/cpy/dramstore.py.cc index 635e9144..bc4634a7 100644 --- a/ucm/store/dramstore/cpy/dramstore.py.cc +++ b/ucm/store/dramstore/cpy/dramstore.py.cc @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * */ -#include "api/dramstore.h" +#include "dramstore.h" #include namespace py = pybind11; From cf90c05c049de853c1d3787f34d7020b811dc2c0 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 11:30:07 +0800 Subject: [PATCH 42/59] fix --- ucm/store/dramstore/cc/api/dramstore.cc | 4 +++- ucm/store/dramstore/cc/api/dramstore.h | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ucm/store/dramstore/cc/api/dramstore.cc b/ucm/store/dramstore/cc/api/dramstore.cc index 6df1bef5..b3fe2dbb 100644 --- a/ucm/store/dramstore/cc/api/dramstore.cc +++ b/ucm/store/dramstore/cc/api/dramstore.cc @@ -33,7 +33,9 @@ namespace UC { class DRAMStoreImpl : public DRAMStore { public: int32_t Setup(const Config& config) { - this->memPool_ = std::make_unique(config.capacity, config.blockSize).release(); + // config里之前没有blockSize,稳妥起见还是先打桩 + int32_t blockSize = 128; + this->memPool_ = std::make_unique(config.capacity, blockSize).release(); // 初始化memPool的办法是否正确?如果失败的话怎么办? int32_t streamNumber = 60; // 这个参数是否需要,以及怎么传,还要讨论 int32_t timeoutMs = 10000; // 这个参数是否需要,以及怎么传,还要讨论 diff --git a/ucm/store/dramstore/cc/api/dramstore.h b/ucm/store/dramstore/cc/api/dramstore.h index 080d92d3..1dc97573 100644 --- a/ucm/store/dramstore/cc/api/dramstore.h +++ b/ucm/store/dramstore/cc/api/dramstore.h @@ -33,10 +33,9 @@ class DRAMStore : public CCStore { struct Config { size_t ioSize; size_t capacity; - size_t blockSize; int32_t deviceId; - Config(const size_t ioSize, const size_t capacity, const size_t blockSize) - : ioSize{ioSize}, capacity{capacity}, blockSize(blockSize), deviceId{-1} + Config(const size_t ioSize, const size_t capacity) + : ioSize{ioSize}, capacity{capacity}, deviceId{-1} { } }; From 00c2bc2cef968389830b3459d05f1ee6d123cfae Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 15:35:21 +0800 Subject: [PATCH 43/59] add test for memory pool --- ucm/store/infra/memory/memory_pool.h | 2 +- ucm/store/test/case/infra/mem_pool_test.cc | 53 ++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 ucm/store/test/case/infra/mem_pool_test.cc diff --git a/ucm/store/infra/memory/memory_pool.h b/ucm/store/infra/memory/memory_pool.h index d9c11f78..f9137bee 100644 --- a/ucm/store/infra/memory/memory_pool.h +++ b/ucm/store/infra/memory/memory_pool.h @@ -62,7 +62,7 @@ class MemoryPool { auto it = addressMap_.find(blockId); if (it != addressMap_.end()) { // duplicate key - return Status::OK(); + return Status::DuplicateKey(); } // addressMap_里目前还没有这个blockId,即将进行分配 addressMap_[blockId] = pool_ + head_; diff --git a/ucm/store/test/case/infra/mem_pool_test.cc b/ucm/store/test/case/infra/mem_pool_test.cc new file mode 100644 index 00000000..4a7f5231 --- /dev/null +++ b/ucm/store/test/case/infra/mem_pool_test.cc @@ -0,0 +1,53 @@ +/** + * MIT License + * + * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * */ + +#include "infra/memory/memory_pool.h" +#include + +class UCMemoryPoolTest : public ::testing::Test {}; + +TEST_F(UCMemoryPoolTest, NewBlockAllocateAndCommit) +{ + UC::MemoryPool memPool(10, 2); // 初始化内存池 + const std::string block1 = "block1"; + ASSERT_FALSE(memPool.LookupBlock(block1)); + ASSERT_EQ(memPool.GetAddress(block1), nullptr); + ASSERT_EQ(memPool.NewBlock(block1), UC::Status::OK()); + ASSERT_FALSE(memPool.LookupBlock(block1)); + ASSERT_NE(memPool.GetAddress(block1), nullptr); + ASSERT_EQ(memPool.NewBlock(block1), UC::Status::DuplicateKey()); + ASSERT_EQ(memPool.CommitBlock(block1), UC::Status::OK()); + ASSERT_TRUE(memPool.LookupBlock(block1)); +} + +TEST_F(UCMemoryPoolTest, OutOfCapacity) +{ + UC::MemoryPool memPool(10, 5); // 初始化内存池 + const std::string block1 = "block1"; + const std::string block2 = "block2"; + const std::string block3 = "block3"; + ASSERT_EQ(memPool.NewBlock(block1), UC::Status::OK()); + ASSERT_EQ(memPool.NewBlock(block2), UC::Status::OK()); + ASSERT_EQ(memPool.NewBlock(block3), UC::Status::Error()); +} \ No newline at end of file From 5352792cbb18aec2c6428968558875fdfcbe66e3 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 15:38:03 +0800 Subject: [PATCH 44/59] fix --- ucm/store/test/case/infra/mem_pool_test.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ucm/store/test/case/infra/mem_pool_test.cc b/ucm/store/test/case/infra/mem_pool_test.cc index 4a7f5231..45a97831 100644 --- a/ucm/store/test/case/infra/mem_pool_test.cc +++ b/ucm/store/test/case/infra/mem_pool_test.cc @@ -48,6 +48,9 @@ TEST_F(UCMemoryPoolTest, OutOfCapacity) const std::string block2 = "block2"; const std::string block3 = "block3"; ASSERT_EQ(memPool.NewBlock(block1), UC::Status::OK()); + ASSERT_NE(memPool.GetAddress(block1), nullptr); ASSERT_EQ(memPool.NewBlock(block2), UC::Status::OK()); + ASSERT_NE(memPool.GetAddress(block2), nullptr); ASSERT_EQ(memPool.NewBlock(block3), UC::Status::Error()); + ASSERT_EQ(memPool.GetAddress(block3), nullptr); } \ No newline at end of file From 2069c76a3636e84d709a90478b74465c4ba4e96d Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 15:39:15 +0800 Subject: [PATCH 45/59] fix --- ucm/store/test/case/infra/mem_pool_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ucm/store/test/case/infra/mem_pool_test.cc b/ucm/store/test/case/infra/mem_pool_test.cc index 45a97831..ebcd95f7 100644 --- a/ucm/store/test/case/infra/mem_pool_test.cc +++ b/ucm/store/test/case/infra/mem_pool_test.cc @@ -37,7 +37,7 @@ TEST_F(UCMemoryPoolTest, NewBlockAllocateAndCommit) ASSERT_FALSE(memPool.LookupBlock(block1)); ASSERT_NE(memPool.GetAddress(block1), nullptr); ASSERT_EQ(memPool.NewBlock(block1), UC::Status::DuplicateKey()); - ASSERT_EQ(memPool.CommitBlock(block1), UC::Status::OK()); + ASSERT_EQ(memPool.CommitBlock(block1, true), UC::Status::OK()); ASSERT_TRUE(memPool.LookupBlock(block1)); } From ec55a36cbac49c72519be945f388bd067074a830 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Wed, 15 Oct 2025 17:06:37 +0800 Subject: [PATCH 46/59] fix --- .../dramstore/dram_tsf_task_waiter_test.cc | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 ucm/store/test/case/dramstore/dram_tsf_task_waiter_test.cc diff --git a/ucm/store/test/case/dramstore/dram_tsf_task_waiter_test.cc b/ucm/store/test/case/dramstore/dram_tsf_task_waiter_test.cc new file mode 100644 index 00000000..77df2355 --- /dev/null +++ b/ucm/store/test/case/dramstore/dram_tsf_task_waiter_test.cc @@ -0,0 +1,62 @@ +/** + * MIT License + * + * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * */ +#include +#include +#include +#include "tsf_task/dram_tsf_task_waiter.h" + +class UCDramTsfTaskWaiterTest : public ::testing::Test {}; + +TEST_F(UCDramTsfTaskWaiterTest, TaskTimeout) +{ + UC::DramTsfTaskWaiter waiter{1, 1024, 1, "xxx"}; + auto fut = std::async([&] { + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + waiter.Done(); + }); + ASSERT_FALSE(waiter.Wait(1)); + fut.get(); + ASSERT_TRUE(waiter.Finish()); +} + +TEST_F(UCDramTsfTaskWaiterTest, TaskSuccess) +{ + UC::DramTsfTaskWaiter waiter{1, 1024, 1, "xxx"}; + auto fut = std::async([&] { waiter.Done(); }); + ASSERT_TRUE(waiter.Wait(1000)); + ASSERT_TRUE(waiter.Finish()); + fut.get(); +} + +TEST_F(UCDramTsfTaskWaiterTest, TaskTimeoutButSuccess) +{ + UC::DramTsfTaskWaiter waiter{1, 1024, 1, "xxx"}; + auto fut = std::async([&] { + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + waiter.Done(); + }); + fut.get(); + ASSERT_TRUE(waiter.Finish()); + ASSERT_TRUE(waiter.Wait(1)); +} From 7e9dd61f76ce5f4eb2962baa1fa46d3c7d35de7d Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Thu, 16 Oct 2025 15:31:43 +0800 Subject: [PATCH 47/59] add LRU cache --- ucm/store/infra/memory/memory_pool.h | 123 ++++++++++++++------- ucm/store/test/case/infra/mem_pool_test.cc | 4 +- 2 files changed, 85 insertions(+), 42 deletions(-) diff --git a/ucm/store/infra/memory/memory_pool.h b/ucm/store/infra/memory/memory_pool.h index f9137bee..4c2751bf 100644 --- a/ucm/store/infra/memory/memory_pool.h +++ b/ucm/store/infra/memory/memory_pool.h @@ -27,79 +27,120 @@ #include #include #include -#include +#include #include +#include #include "status/status.h" namespace UC { class MemoryPool { public: - MemoryPool(uint32_t capacity, uint32_t blockSize) : capacity_(capacity), head_(0), blockSize_(blockSize) { - pool_ = new char[capacity]; - if (!pool_) { - throw std::bad_alloc(); + MemoryPool(uint32_t capacity, uint32_t blockSize) + : capacity_(capacity), + blockSize_(blockSize), + slotNum_(capacity / blockSize), + pool_(new char[capacity]) { + if (!pool_) throw std::bad_alloc(); + // 1. 预占满:dummy → 地址 同时写进 addressMap_ 和 LRU + for (uint32_t i = 0; i < slotNum_; ++i) { + std::string dummy = "__slot_" + std::to_string(i); + char* addr = pool_ + i * blockSize_; + // 填 LRU + lruList_.push_front(dummy); + lruIndex_[dummy] = lruList_.begin(); + // 填地址映射 + addressMap_[dummy] = addr; } } - ~MemoryPool() { - delete [] pool_; - } + ~MemoryPool() { delete[] pool_; } - MemoryPool(const MemoryPool&) = delete; + MemoryPool(const MemoryPool&) = delete; MemoryPool& operator=(const MemoryPool&) = delete; - void Reset() { - head_ = 0; - } - - uint32_t GetNextAvailableOffset() const { return head_; } - - Status NewBlock(std::string blockId) { - if (head_ >= capacity_) { - return Status::Error(); // 下一版本再实现GC逻辑,目前先忽略吧 - } - auto it = addressMap_.find(blockId); - if (it != addressMap_.end()) { - // duplicate key - return Status::DuplicateKey(); - } - // addressMap_里目前还没有这个blockId,即将进行分配 - addressMap_[blockId] = pool_ + head_; - head_ = head_ + blockSize_; + /* ---------------- 对外接口 ---------------- */ + Status NewBlock(const std::string& blockId) { + if (addressMap_.count(blockId)) return Status::DuplicateKey(); + if (lruList_.empty()) return Status::Error(); + char* addr = evictLRU(); + addressMap_[blockId] = addr; return Status::OK(); } - bool LookupBlock(std::string blockId) { - return availableBlocks_.find(blockId) != availableBlocks_.end(); + bool LookupBlock(const std::string& blockId) const { + return availableBlocks_.count(blockId); } - char* GetAddress(std::string blockId) { - if (addressMap_.find(blockId) == addressMap_.end()) { - return nullptr; - } - return addressMap_[blockId]; + char* GetAddress(const std::string& blockId) const { + auto it = addressMap_.find(blockId); + return it == addressMap_.end() ? nullptr : it->second; } - Status CommitBlock(std::string blockId, bool success) { + Status CommitBlock(const std::string& blockId, bool success) { if (success) { availableBlocks_.insert(blockId); - } - else { - availableBlocks_.erase(blockId); + touchUnsafe(blockId); + } else { + // availableBlocks_.erase(blockId); // 这句大概不需要? + auto it = addressMap_.find(blockId); + char* addr = it->second; + int32_t offset = static_cast(addr - pool_); + std::string dummy = "__slot_" + std::to_string(offset / blockSize_); + addressMap_.erase(blockId); + + auto lit = lruIndex_.find(blockId); + if (lit != lruIndex_.end()) { + lruList_.erase(lit->second); + lruIndex_.erase(lit); + } + lruList_.push_back(dummy); + lruIndex_[dummy] = std::prev(lruList_.end()); + addressMap_[dummy] = addr; } return Status::OK(); } private: + /* ---------------- 内部数据 ---------------- */ char* pool_ = nullptr; uint32_t capacity_; - uint32_t head_; uint32_t blockSize_; + uint32_t slotNum_; + std::unordered_map addressMap_; std::set availableBlocks_; + + using ListType = std::list; + ListType lruList_; + std::unordered_map lruIndex_; + + /* ---------------- 工具函数 ---------------- */ + // 把 blockId 移到 LRU 头 + void touchUnsafe(const std::string& blockId) { + auto it = lruIndex_.find(blockId); + if (it != lruIndex_.end()) { + lruList_.splice(lruList_.begin(), lruList_, it->second); + } else { + lruList_.push_front(blockId); + lruIndex_[blockId] = lruList_.begin(); + } + } + + // 踢最久未使用块 + char* evictLRU() { + const std::string& victim = lruList_.back(); + // 真数据块才清可用集合 + if (victim.rfind("__slot_", 0) != 0) { + availableBlocks_.erase(victim); + } + char* addr = addressMap_[victim]; + addressMap_.erase(victim); + lruIndex_.erase(victim); + lruList_.pop_back(); + return addr; + } }; } // namespace UC - -#endif +#endif \ No newline at end of file diff --git a/ucm/store/test/case/infra/mem_pool_test.cc b/ucm/store/test/case/infra/mem_pool_test.cc index ebcd95f7..cd21bc4d 100644 --- a/ucm/store/test/case/infra/mem_pool_test.cc +++ b/ucm/store/test/case/infra/mem_pool_test.cc @@ -52,5 +52,7 @@ TEST_F(UCMemoryPoolTest, OutOfCapacity) ASSERT_EQ(memPool.NewBlock(block2), UC::Status::OK()); ASSERT_NE(memPool.GetAddress(block2), nullptr); ASSERT_EQ(memPool.NewBlock(block3), UC::Status::Error()); - ASSERT_EQ(memPool.GetAddress(block3), nullptr); + ASSERT_NE(memPool.GetAddress(block3), nullptr); + ASSERT_EQ(memPool.GetAddress(block1), nullptr); + ASSERT_NE(memPool.GetAddress(block2), nullptr); } \ No newline at end of file From 114c3b2911c65201c5cca5b845ce5fc1867d0c6c Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Thu, 16 Oct 2025 15:36:38 +0800 Subject: [PATCH 48/59] fix --- ucm/store/infra/memory/memory_pool.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ucm/store/infra/memory/memory_pool.h b/ucm/store/infra/memory/memory_pool.h index 4c2751bf..fa6c393a 100644 --- a/ucm/store/infra/memory/memory_pool.h +++ b/ucm/store/infra/memory/memory_pool.h @@ -37,10 +37,10 @@ namespace UC { class MemoryPool { public: MemoryPool(uint32_t capacity, uint32_t blockSize) - : capacity_(capacity), + : pool_(new char[capacity]), + capacity_(capacity), blockSize_(blockSize), - slotNum_(capacity / blockSize), - pool_(new char[capacity]) { + slotNum_(capacity / blockSize) { if (!pool_) throw std::bad_alloc(); // 1. 预占满:dummy → 地址 同时写进 addressMap_ 和 LRU for (uint32_t i = 0; i < slotNum_; ++i) { From 609f80ebfe29943ae07c8cd5f1564ff8ef1aa7e5 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Thu, 16 Oct 2025 15:44:00 +0800 Subject: [PATCH 49/59] fix --- ucm/store/test/case/infra/mem_pool_test.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ucm/store/test/case/infra/mem_pool_test.cc b/ucm/store/test/case/infra/mem_pool_test.cc index cd21bc4d..ab3083e1 100644 --- a/ucm/store/test/case/infra/mem_pool_test.cc +++ b/ucm/store/test/case/infra/mem_pool_test.cc @@ -41,7 +41,7 @@ TEST_F(UCMemoryPoolTest, NewBlockAllocateAndCommit) ASSERT_TRUE(memPool.LookupBlock(block1)); } -TEST_F(UCMemoryPoolTest, OutOfCapacity) +TEST_F(UCMemoryPoolTest, EvictOldBlock) { UC::MemoryPool memPool(10, 5); // 初始化内存池 const std::string block1 = "block1"; @@ -51,7 +51,9 @@ TEST_F(UCMemoryPoolTest, OutOfCapacity) ASSERT_NE(memPool.GetAddress(block1), nullptr); ASSERT_EQ(memPool.NewBlock(block2), UC::Status::OK()); ASSERT_NE(memPool.GetAddress(block2), nullptr); - ASSERT_EQ(memPool.NewBlock(block3), UC::Status::Error()); + memPool.CommitBlock(block1, true); + memPool.CommitBlock(block2, true); + ASSERT_EQ(memPool.NewBlock(block3), UC::Status::OK()); ASSERT_NE(memPool.GetAddress(block3), nullptr); ASSERT_EQ(memPool.GetAddress(block1), nullptr); ASSERT_NE(memPool.GetAddress(block2), nullptr); From fc6689cb3816f2bcac7398fb34fbb27fdde0c60b Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Thu, 16 Oct 2025 15:54:40 +0800 Subject: [PATCH 50/59] fix --- ucm/store/infra/memory/memory_pool.h | 4 ++++ ucm/store/test/case/infra/mem_pool_test.cc | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/ucm/store/infra/memory/memory_pool.h b/ucm/store/infra/memory/memory_pool.h index fa6c393a..db636f71 100644 --- a/ucm/store/infra/memory/memory_pool.h +++ b/ucm/store/infra/memory/memory_pool.h @@ -101,6 +101,10 @@ class MemoryPool { return Status::OK(); } + char* GetFirstAddr() { + return pool_; + } + private: /* ---------------- 内部数据 ---------------- */ char* pool_ = nullptr; diff --git a/ucm/store/test/case/infra/mem_pool_test.cc b/ucm/store/test/case/infra/mem_pool_test.cc index ab3083e1..e96ea78e 100644 --- a/ucm/store/test/case/infra/mem_pool_test.cc +++ b/ucm/store/test/case/infra/mem_pool_test.cc @@ -57,4 +57,26 @@ TEST_F(UCMemoryPoolTest, EvictOldBlock) ASSERT_NE(memPool.GetAddress(block3), nullptr); ASSERT_EQ(memPool.GetAddress(block1), nullptr); ASSERT_NE(memPool.GetAddress(block2), nullptr); +} + +TEST_F(UCMemoryPoolTest, OldBlockCommitFalse) +{ + UC::MemoryPool memPool(32, 8); // 初始化内存池 + const std::string block1 = "block1"; + const std::string block2 = "block2"; + const std::string block3 = "block3"; + const std::string block4 = "block4"; + const std::string block5 = "block5"; + ASSERT_EQ(memPool.NewBlock(block1), UC::Status::OK()); + ASSERT_NE(memPool.GetAddress(block1), nullptr); + ASSERT_EQ(memPool.NewBlock(block2), UC::Status::OK()); + ASSERT_NE(memPool.GetAddress(block2), nullptr); + ASSERT_EQ(memPool.NewBlock(block3), UC::Status::OK()); + ASSERT_NE(memPool.GetAddress(block3), nullptr); + memPool.CommitBlock(block1, true); + memPool.CommitBlock(block2, false); + ASSERT_EQ(memPool.NewBlock(block4), UC::Status::OK()); + ASSERT_EQ(static_cast(memPool.GetAddress((block4)) - memPool.GetFirstAddr()), 8); + ASSERT_EQ(memPool.NewBlock(block5), UC::Status::OK()); + ASSERT_EQ(static_cast(memPool.GetAddress((block5)) - memPool.GetFirstAddr()), 24); } \ No newline at end of file From a03d6a747c48f99f7cce74d384e054869af35767 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Thu, 16 Oct 2025 16:16:44 +0800 Subject: [PATCH 51/59] fix --- ucm/store/infra/memory/memory_pool.h | 37 +++++++++++----------- ucm/store/test/case/infra/mem_pool_test.cc | 7 ++++ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/ucm/store/infra/memory/memory_pool.h b/ucm/store/infra/memory/memory_pool.h index db636f71..4699c057 100644 --- a/ucm/store/infra/memory/memory_pool.h +++ b/ucm/store/infra/memory/memory_pool.h @@ -82,21 +82,7 @@ class MemoryPool { availableBlocks_.insert(blockId); touchUnsafe(blockId); } else { - // availableBlocks_.erase(blockId); // 这句大概不需要? - auto it = addressMap_.find(blockId); - char* addr = it->second; - int32_t offset = static_cast(addr - pool_); - std::string dummy = "__slot_" + std::to_string(offset / blockSize_); - addressMap_.erase(blockId); - - auto lit = lruIndex_.find(blockId); - if (lit != lruIndex_.end()) { - lruList_.erase(lit->second); - lruIndex_.erase(lit); - } - lruList_.push_back(dummy); - lruIndex_[dummy] = std::prev(lruList_.end()); - addressMap_[dummy] = addr; + resetSpaceOfBlock(blockId); } return Status::OK(); } @@ -106,7 +92,6 @@ class MemoryPool { } private: - /* ---------------- 内部数据 ---------------- */ char* pool_ = nullptr; uint32_t capacity_; uint32_t blockSize_; @@ -119,8 +104,6 @@ class MemoryPool { ListType lruList_; std::unordered_map lruIndex_; - /* ---------------- 工具函数 ---------------- */ - // 把 blockId 移到 LRU 头 void touchUnsafe(const std::string& blockId) { auto it = lruIndex_.find(blockId); if (it != lruIndex_.end()) { @@ -144,6 +127,24 @@ class MemoryPool { lruList_.pop_back(); return addr; } + + void resetSpaceOfBlock(const std::string blockId) { + // availableBlocks_.erase(blockId); // 这句大概不需要? + auto it = addressMap_.find(blockId); + char* addr = it->second; + int32_t offset = static_cast(addr - pool_); + std::string dummy = "__slot_" + std::to_string(offset / blockSize_); + addressMap_.erase(blockId); + + auto lit = lruIndex_.find(blockId); + if (lit != lruIndex_.end()) { + lruList_.erase(lit->second); + lruIndex_.erase(lit); + } + lruList_.push_back(dummy); + lruIndex_[dummy] = std::prev(lruList_.end()); + addressMap_[dummy] = addr; + } }; } // namespace UC diff --git a/ucm/store/test/case/infra/mem_pool_test.cc b/ucm/store/test/case/infra/mem_pool_test.cc index e96ea78e..694d22bc 100644 --- a/ucm/store/test/case/infra/mem_pool_test.cc +++ b/ucm/store/test/case/infra/mem_pool_test.cc @@ -79,4 +79,11 @@ TEST_F(UCMemoryPoolTest, OldBlockCommitFalse) ASSERT_EQ(static_cast(memPool.GetAddress((block4)) - memPool.GetFirstAddr()), 8); ASSERT_EQ(memPool.NewBlock(block5), UC::Status::OK()); ASSERT_EQ(static_cast(memPool.GetAddress((block5)) - memPool.GetFirstAddr()), 24); + memPool.CommitBlock(block3, true); + memPool.CommitBlock(block4, true); + memPool.CommitBlock(block5, true); + + ASSERT_EQ(memPool.NewBlock(block1), UC::Status::DuplicateKey()); + ASSERT_EQ(memPool.NewBlock(block2), UC::Status::OK()); + ASSERT_EQ(static_cast(memPool.GetAddress((block4)) - memPool.GetFirstAddr()), 0); } \ No newline at end of file From e574023d48332f0cdc3b79a828bab689cfcdf042 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Thu, 16 Oct 2025 16:19:06 +0800 Subject: [PATCH 52/59] fix --- ucm/store/test/case/infra/mem_pool_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ucm/store/test/case/infra/mem_pool_test.cc b/ucm/store/test/case/infra/mem_pool_test.cc index 694d22bc..a6b1e3a3 100644 --- a/ucm/store/test/case/infra/mem_pool_test.cc +++ b/ucm/store/test/case/infra/mem_pool_test.cc @@ -85,5 +85,5 @@ TEST_F(UCMemoryPoolTest, OldBlockCommitFalse) ASSERT_EQ(memPool.NewBlock(block1), UC::Status::DuplicateKey()); ASSERT_EQ(memPool.NewBlock(block2), UC::Status::OK()); - ASSERT_EQ(static_cast(memPool.GetAddress((block4)) - memPool.GetFirstAddr()), 0); + ASSERT_EQ(static_cast(memPool.GetAddress((block2)) - memPool.GetFirstAddr()), 0); } \ No newline at end of file From 27a0b4d6d6d05d9839ac44fa9d7e30d45bc2f79d Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Thu, 16 Oct 2025 16:25:08 +0800 Subject: [PATCH 53/59] fix --- ucm/store/test/case/infra/mem_pool_test.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ucm/store/test/case/infra/mem_pool_test.cc b/ucm/store/test/case/infra/mem_pool_test.cc index a6b1e3a3..98c8453b 100644 --- a/ucm/store/test/case/infra/mem_pool_test.cc +++ b/ucm/store/test/case/infra/mem_pool_test.cc @@ -86,4 +86,25 @@ TEST_F(UCMemoryPoolTest, OldBlockCommitFalse) ASSERT_EQ(memPool.NewBlock(block1), UC::Status::DuplicateKey()); ASSERT_EQ(memPool.NewBlock(block2), UC::Status::OK()); ASSERT_EQ(static_cast(memPool.GetAddress((block2)) - memPool.GetFirstAddr()), 0); +} + +TEST_F(UCMemoryPoolTest, NoCommittedBlock) +{ + UC::MemoryPool memPool(32, 8); // 初始化内存池 + const std::string block1 = "block1"; + const std::string block2 = "block2"; + const std::string block3 = "block3"; + const std::string block4 = "block4"; + const std::string block5 = "block5"; + const std::string block6 = "block6"; + ASSERT_EQ(memPool.NewBlock(block1), UC::Status::OK()); + ASSERT_EQ(memPool.NewBlock(block2), UC::Status::OK()); + ASSERT_EQ(memPool.NewBlock(block3), UC::Status::OK()); + ASSERT_EQ(memPool.NewBlock(block4), UC::Status::OK()); + ASSERT_EQ(memPool.NewBlock(block5), UC::Status::Error()); + memPool.CommitBlock(block1, true); + ASSERT_EQ(memPool.NewBlock(block5), UC::Status::OK()); + ASSERT_EQ(memPool.NewBlock(block6), UC::Status::Error()); + memPool.CommitBlock(block2, false); + ASSERT_EQ(memPool.NewBlock(block6), UC::Status::OK()); } \ No newline at end of file From 432b43f9595d7da5abdf4abf44b77d9c6ef3e494 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Thu, 16 Oct 2025 16:49:10 +0800 Subject: [PATCH 54/59] fix --- ucm/store/infra/memory/memory_pool.h | 2 +- ucm/store/test/case/infra/mem_pool_test.cc | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ucm/store/infra/memory/memory_pool.h b/ucm/store/infra/memory/memory_pool.h index 4699c057..9814236f 100644 --- a/ucm/store/infra/memory/memory_pool.h +++ b/ucm/store/infra/memory/memory_pool.h @@ -128,7 +128,7 @@ class MemoryPool { return addr; } - void resetSpaceOfBlock(const std::string blockId) { + void resetSpaceOfBlock(const std::string& blockId) { // availableBlocks_.erase(blockId); // 这句大概不需要? auto it = addressMap_.find(blockId); char* addr = it->second; diff --git a/ucm/store/test/case/infra/mem_pool_test.cc b/ucm/store/test/case/infra/mem_pool_test.cc index 98c8453b..4ab9cf41 100644 --- a/ucm/store/test/case/infra/mem_pool_test.cc +++ b/ucm/store/test/case/infra/mem_pool_test.cc @@ -57,6 +57,9 @@ TEST_F(UCMemoryPoolTest, EvictOldBlock) ASSERT_NE(memPool.GetAddress(block3), nullptr); ASSERT_EQ(memPool.GetAddress(block1), nullptr); ASSERT_NE(memPool.GetAddress(block2), nullptr); + ASSERT_FALSE(memPool.LookupBlock(block1)); + ASSERT_TRUE(memPool.LookupBlock(block2)); + ASSERT_TRUE(memPool.LookupBlock(block3)); } TEST_F(UCMemoryPoolTest, OldBlockCommitFalse) @@ -75,6 +78,9 @@ TEST_F(UCMemoryPoolTest, OldBlockCommitFalse) ASSERT_NE(memPool.GetAddress(block3), nullptr); memPool.CommitBlock(block1, true); memPool.CommitBlock(block2, false); + ASSERT_TRUE(memPool.LookupBlock(block1)); + ASSERT_FALSE(memPool.LookupBlock(block2)); + ASSERT_FALSE(memPool.LookupBlock(block3)); ASSERT_EQ(memPool.NewBlock(block4), UC::Status::OK()); ASSERT_EQ(static_cast(memPool.GetAddress((block4)) - memPool.GetFirstAddr()), 8); ASSERT_EQ(memPool.NewBlock(block5), UC::Status::OK()); @@ -82,10 +88,19 @@ TEST_F(UCMemoryPoolTest, OldBlockCommitFalse) memPool.CommitBlock(block3, true); memPool.CommitBlock(block4, true); memPool.CommitBlock(block5, true); + ASSERT_TRUE(memPool.LookupBlock(block1)); + ASSERT_FALSE(memPool.LookupBlock(block2)); + ASSERT_TRUE(memPool.LookupBlock(block3)); + ASSERT_TRUE(memPool.LookupBlock(block4)); + ASSERT_TRUE(memPool.LookupBlock(block5)); ASSERT_EQ(memPool.NewBlock(block1), UC::Status::DuplicateKey()); ASSERT_EQ(memPool.NewBlock(block2), UC::Status::OK()); ASSERT_EQ(static_cast(memPool.GetAddress((block2)) - memPool.GetFirstAddr()), 0); + ASSERT_FALSE(memPool.LookupBlock(block1)); + ASSERT_FALSE(memPool.LookupBlock(block2)); + memPool.CommitBlock(block2, true); + ASSERT_TRUE(memPool.LookupBlock(block2)); } TEST_F(UCMemoryPoolTest, NoCommittedBlock) @@ -103,8 +118,14 @@ TEST_F(UCMemoryPoolTest, NoCommittedBlock) ASSERT_EQ(memPool.NewBlock(block4), UC::Status::OK()); ASSERT_EQ(memPool.NewBlock(block5), UC::Status::Error()); memPool.CommitBlock(block1, true); + ASSERT_TRUE(memPool.LookupBlock(block1)); ASSERT_EQ(memPool.NewBlock(block5), UC::Status::OK()); + ASSERT_FALSE(memPool.LookupBlock(block1)); ASSERT_EQ(memPool.NewBlock(block6), UC::Status::Error()); memPool.CommitBlock(block2, false); ASSERT_EQ(memPool.NewBlock(block6), UC::Status::OK()); + ASSERT_NE(memPool.GetAddress((block6)), nullptr); + ASSERT_FALSE(memPool.LookupBlock(block6)); + memPool.CommitBlock(block6, true); + ASSERT_TRUE(memPool.LookupBlock(block6)); } \ No newline at end of file From b38bc2f4f0b3e3722796d158fc39a3045a0a5f86 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Thu, 16 Oct 2025 16:51:41 +0800 Subject: [PATCH 55/59] fix --- ucm/store/test/case/infra/mem_pool_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ucm/store/test/case/infra/mem_pool_test.cc b/ucm/store/test/case/infra/mem_pool_test.cc index 4ab9cf41..846b3a57 100644 --- a/ucm/store/test/case/infra/mem_pool_test.cc +++ b/ucm/store/test/case/infra/mem_pool_test.cc @@ -59,7 +59,7 @@ TEST_F(UCMemoryPoolTest, EvictOldBlock) ASSERT_NE(memPool.GetAddress(block2), nullptr); ASSERT_FALSE(memPool.LookupBlock(block1)); ASSERT_TRUE(memPool.LookupBlock(block2)); - ASSERT_TRUE(memPool.LookupBlock(block3)); + ASSERT_FALSE(memPool.LookupBlock(block3)); } TEST_F(UCMemoryPoolTest, OldBlockCommitFalse) From b64d30b6de6b356254158e55fb841a268d72f4e5 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Thu, 16 Oct 2025 17:08:56 +0800 Subject: [PATCH 56/59] fix --- ucm/store/infra/memory/memory_pool.h | 35 ++++++++++++---------- ucm/store/test/case/infra/mem_pool_test.cc | 7 ++++- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/ucm/store/infra/memory/memory_pool.h b/ucm/store/infra/memory/memory_pool.h index 9814236f..1cc61481 100644 --- a/ucm/store/infra/memory/memory_pool.h +++ b/ucm/store/infra/memory/memory_pool.h @@ -42,28 +42,32 @@ class MemoryPool { blockSize_(blockSize), slotNum_(capacity / blockSize) { if (!pool_) throw std::bad_alloc(); - // 1. 预占满:dummy → 地址 同时写进 addressMap_ 和 LRU for (uint32_t i = 0; i < slotNum_; ++i) { + // 将所有槽位都预先占好,插入LRU队列中。 std::string dummy = "__slot_" + std::to_string(i); char* addr = pool_ + i * blockSize_; - // 填 LRU lruList_.push_front(dummy); lruIndex_[dummy] = lruList_.begin(); - // 填地址映射 addressMap_[dummy] = addr; } } - ~MemoryPool() { delete[] pool_; } + ~MemoryPool() { + delete[] pool_; + } - MemoryPool(const MemoryPool&) = delete; + MemoryPool(const MemoryPool&) = delete; MemoryPool& operator=(const MemoryPool&) = delete; - /* ---------------- 对外接口 ---------------- */ Status NewBlock(const std::string& blockId) { - if (addressMap_.count(blockId)) return Status::DuplicateKey(); - if (lruList_.empty()) return Status::Error(); - char* addr = evictLRU(); + if (addressMap_.count(blockId)) { + return Status::DuplicateKey(); + } + if (lruList_.empty()) { + // 所有空间里的块都正在写,那么就不能够分配 + return Status::Error(); + } + char* addr = LRUEvictOne(); addressMap_[blockId] = addr; return Status::OK(); } @@ -87,6 +91,7 @@ class MemoryPool { return Status::OK(); } + // 单元测试用,外部应该用不到 char* GetFirstAddr() { return pool_; } @@ -108,16 +113,16 @@ class MemoryPool { auto it = lruIndex_.find(blockId); if (it != lruIndex_.end()) { lruList_.splice(lruList_.begin(), lruList_, it->second); - } else { - lruList_.push_front(blockId); + } + else { + lruList_.push_front(blockId); // 访问一次,该块就是最近使用了的,所以放到LRU队列的头部。这就是一般LRU的逻辑 lruIndex_[blockId] = lruList_.begin(); } } - // 踢最久未使用块 - char* evictLRU() { + char* LRUEvictOne() { const std::string& victim = lruList_.back(); - // 真数据块才清可用集合 + // 真实数据块,才从availableBlocks_中删掉 if (victim.rfind("__slot_", 0) != 0) { availableBlocks_.erase(victim); } @@ -141,7 +146,7 @@ class MemoryPool { lruList_.erase(lit->second); lruIndex_.erase(lit); } - lruList_.push_back(dummy); + lruList_.push_back(dummy); // 将一个块commit false后,回收之前分配的内存,并且要将其放到LRU队列的尾部(下次可以写的时候,要马上就写。因为该块的优先级高于已经写了的块) lruIndex_[dummy] = std::prev(lruList_.end()); addressMap_[dummy] = addr; } diff --git a/ucm/store/test/case/infra/mem_pool_test.cc b/ucm/store/test/case/infra/mem_pool_test.cc index 846b3a57..ede7f3cb 100644 --- a/ucm/store/test/case/infra/mem_pool_test.cc +++ b/ucm/store/test/case/infra/mem_pool_test.cc @@ -120,12 +120,17 @@ TEST_F(UCMemoryPoolTest, NoCommittedBlock) memPool.CommitBlock(block1, true); ASSERT_TRUE(memPool.LookupBlock(block1)); ASSERT_EQ(memPool.NewBlock(block5), UC::Status::OK()); + ASSERT_EQ(static_cast(memPool.GetAddress((block5)) - memPool.GetFirstAddr()), 0); ASSERT_FALSE(memPool.LookupBlock(block1)); ASSERT_EQ(memPool.NewBlock(block6), UC::Status::Error()); + ASSERT_EQ(static_cast(memPool.GetAddress((block2)) - memPool.GetFirstAddr()), 8); memPool.CommitBlock(block2, false); + ASSERT_EQ(memPool.GetAddress((block2)), nullptr); + ASSERT_FALSE(memPool.LookupBlock(block1)); ASSERT_EQ(memPool.NewBlock(block6), UC::Status::OK()); - ASSERT_NE(memPool.GetAddress((block6)), nullptr); + ASSERT_EQ(static_cast(memPool.GetAddress((block6)) - memPool.GetFirstAddr()), 8); ASSERT_FALSE(memPool.LookupBlock(block6)); memPool.CommitBlock(block6, true); ASSERT_TRUE(memPool.LookupBlock(block6)); + ASSERT_EQ(static_cast(memPool.GetAddress((block6)) - memPool.GetFirstAddr()), 8); } \ No newline at end of file From 935109e691031bb11499271548e380370682a28b Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Thu, 16 Oct 2025 20:24:54 +0800 Subject: [PATCH 57/59] fix --- .../cc/domain/tsf_task/dram_tsf_task_queue.cc | 3 ++- ucm/store/infra/memory/memory_pool.h | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc index c44567fd..11c471fe 100644 --- a/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc +++ b/ucm/store/dramstore/cc/domain/tsf_task/dram_tsf_task_queue.cc @@ -40,7 +40,8 @@ Status DramTsfTaskQueue::Setup(const int32_t deviceId, DramTsfTaskSet* failureSe this->_device = DeviceFactory::Make(deviceId, 0, 0); // 这里不需要buffer,暂时都先传0吧 if (!this->_device) { return Status::OutOfMemory(); } } - if (!this->_streamOper.Setup([this](DramTsfTask& task) { this->StreamOper(task); })) { + if (!this->_streamOper.Setup([this](DramTsfTask& task) { this->StreamOper(task); }, + [this] { return this->_device->Setup().Success(); } )) { return Status::Error(); } return Status::OK(); diff --git a/ucm/store/infra/memory/memory_pool.h b/ucm/store/infra/memory/memory_pool.h index 1cc61481..6106d27a 100644 --- a/ucm/store/infra/memory/memory_pool.h +++ b/ucm/store/infra/memory/memory_pool.h @@ -39,10 +39,12 @@ class MemoryPool { MemoryPool(uint32_t capacity, uint32_t blockSize) : pool_(new char[capacity]), capacity_(capacity), - blockSize_(blockSize), - slotNum_(capacity / blockSize) { - if (!pool_) throw std::bad_alloc(); - for (uint32_t i = 0; i < slotNum_; ++i) { + blockSize_(blockSize) { + if (!pool_) { + throw std::bad_alloc(); + } + uint32_t slotNum = capacity / blockSize; + for (uint32_t i = 0; i < slotNum; ++i) { // 将所有槽位都预先占好,插入LRU队列中。 std::string dummy = "__slot_" + std::to_string(i); char* addr = pool_ + i * blockSize_; @@ -100,7 +102,6 @@ class MemoryPool { char* pool_ = nullptr; uint32_t capacity_; uint32_t blockSize_; - uint32_t slotNum_; std::unordered_map addressMap_; std::set availableBlocks_; From ce0cbb75ba0786b0b7f833eef57856badf8b04c5 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Thu, 16 Oct 2025 20:40:32 +0800 Subject: [PATCH 58/59] fix --- ucm/store/dramstore/cc/api/dramstore.cc | 6 +++--- ucm/store/dramstore/cc/api/dramstore.h | 6 ++++-- ucm/store/dramstore/cpy/dramstore.py.cc | 2 ++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ucm/store/dramstore/cc/api/dramstore.cc b/ucm/store/dramstore/cc/api/dramstore.cc index b3fe2dbb..e601a9e8 100644 --- a/ucm/store/dramstore/cc/api/dramstore.cc +++ b/ucm/store/dramstore/cc/api/dramstore.cc @@ -37,9 +37,9 @@ class DRAMStoreImpl : public DRAMStore { int32_t blockSize = 128; this->memPool_ = std::make_unique(config.capacity, blockSize).release(); // 初始化memPool的办法是否正确?如果失败的话怎么办? - int32_t streamNumber = 60; // 这个参数是否需要,以及怎么传,还要讨论 - int32_t timeoutMs = 10000; // 这个参数是否需要,以及怎么传,还要讨论 - auto status = this->transMgr_.Setup(config.deviceId, streamNumber, timeoutMs, this->memPool_); + // int32_t streamNumber = 60; // 这个参数是否需要,以及怎么传,还要讨论 + // int32_t timeoutMs = 10000; // 这个参数是否需要,以及怎么传,还要讨论 + auto status = this->transMgr_.Setup(config.deviceId, config.streamNumber, config.timeoutMs, this->memPool_); if (status.Failure()) { UC_ERROR("Failed({}) to setup DramTransferTaskManager.", status); return status.Underlying(); diff --git a/ucm/store/dramstore/cc/api/dramstore.h b/ucm/store/dramstore/cc/api/dramstore.h index 1dc97573..b05c36d0 100644 --- a/ucm/store/dramstore/cc/api/dramstore.h +++ b/ucm/store/dramstore/cc/api/dramstore.h @@ -34,8 +34,10 @@ class DRAMStore : public CCStore { size_t ioSize; size_t capacity; int32_t deviceId; - Config(const size_t ioSize, const size_t capacity) - : ioSize{ioSize}, capacity{capacity}, deviceId{-1} + size_t streamNumber; + size_t timeoutMs; + Config(const size_t ioSize, const size_t capacity, const size_t streamNumber, const size_t timeoutMs) + : ioSize{ioSize}, capacity{capacity}, deviceId{-1}, streamNumber(streamNumber), timeoutMs(timeoutMs) { } }; diff --git a/ucm/store/dramstore/cpy/dramstore.py.cc b/ucm/store/dramstore/cpy/dramstore.py.cc index bc4634a7..3e78c88e 100644 --- a/ucm/store/dramstore/cpy/dramstore.py.cc +++ b/ucm/store/dramstore/cpy/dramstore.py.cc @@ -104,6 +104,8 @@ PYBIND11_MODULE(ucmdramstore, module) config.def_readwrite("ioSize", &UC::DRAMStorePy::Config::ioSize); config.def_readwrite("capacity", &UC::DRAMStorePy::Config::capacity); config.def_readwrite("deviceId", &UC::DRAMStorePy::Config::deviceId); + config.def_readwrite("streamNumber", &UC::DRAMStorePy::Config::streamNumber); + config.def_readwrite("timeoutMs", &UC::DRAMStorePy::Config::timeoutMs); store.def(py::init<>()); store.def("CCStoreImpl", &UC::DRAMStorePy::CCStoreImpl); store.def("Setup", &UC::DRAMStorePy::Setup); From b8c72106b684538d57ef1889bc7bc6ad62645f72 Mon Sep 17 00:00:00 2001 From: Chenyu Zhu Date: Thu, 16 Oct 2025 20:46:19 +0800 Subject: [PATCH 59/59] fix --- ucm/store/dramstore/cpy/dramstore.py.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ucm/store/dramstore/cpy/dramstore.py.cc b/ucm/store/dramstore/cpy/dramstore.py.cc index 3e78c88e..2cf52382 100644 --- a/ucm/store/dramstore/cpy/dramstore.py.cc +++ b/ucm/store/dramstore/cpy/dramstore.py.cc @@ -100,7 +100,7 @@ PYBIND11_MODULE(ucmdramstore, module) module.attr("build_type") = UCM_BUILD_TYPE; auto store = py::class_(module, "DRAMStore"); auto config = py::class_(store, "Config"); - config.def(py::init(), py::arg("ioSize"), py::arg("capacity")); + config.def(py::init(), py::arg("ioSize"), py::arg("capacity"), py::arg("streamNumber"), py::arg("timeoutMs")); config.def_readwrite("ioSize", &UC::DRAMStorePy::Config::ioSize); config.def_readwrite("capacity", &UC::DRAMStorePy::Config::capacity); config.def_readwrite("deviceId", &UC::DRAMStorePy::Config::deviceId);