提交 4a8b270c 编写于 作者: H HexToString

add free memory

上级 1fb36f54
...@@ -501,6 +501,7 @@ class FluidInferEngine : public CloneDBReloadableInferEngine<EngineCore> { ...@@ -501,6 +501,7 @@ class FluidInferEngine : public CloneDBReloadableInferEngine<EngineCore> {
paddle::PaddleBuf paddleBuf(databuf_char, databuf_size); paddle::PaddleBuf paddleBuf(databuf_char, databuf_size);
tensor_out.data = paddleBuf; tensor_out.data = paddleBuf;
tensorVector_out_pointer->push_back(tensor_out); tensorVector_out_pointer->push_back(tensor_out);
MempoolWrapper::instance().free(databuf_char, databuf_size);
} }
return 0; return 0;
} }
......
...@@ -112,6 +112,23 @@ void* MempoolWrapper::malloc(size_t size) { ...@@ -112,6 +112,23 @@ void* MempoolWrapper::malloc(size_t size) {
return mempool->malloc(size); return mempool->malloc(size);
} }
void MempoolWrapper::free(void* p, size_t size) {
MempoolRegion* mempool_region =
(MempoolRegion*)THREAD_GETSPECIFIC(_bspec_key);
if (mempool_region == NULL) {
LOG(WARNING) << "THREAD_GETSPECIFIC() returned NULL";
return;
}
im::Mempool* mempool = mempool_region->mempool();
if (!mempool) {
LOG(WARNING) << "Cannot free memory:" << size
<< ", since mempool is not thread initialized";
return;
}
return mempool->free(p,size);
}
} // namespace predictor } // namespace predictor
} // namespace paddle_serving } // namespace paddle_serving
} // namespace baidu } // namespace baidu
...@@ -38,6 +38,8 @@ class MempoolWrapper { ...@@ -38,6 +38,8 @@ class MempoolWrapper {
void* malloc(size_t size); void* malloc(size_t size);
void free(void* p, size_t size);
private: private:
// im::fugue::memory::Region _region; // im::fugue::memory::Region _region;
THREAD_KEY_T _bspec_key; THREAD_KEY_T _bspec_key;
......
...@@ -24,7 +24,7 @@ namespace fugue { ...@@ -24,7 +24,7 @@ namespace fugue {
namespace memory { namespace memory {
void Region::init() { void Region::init() {
_big_mem_capacity = 32 * 1024 * 1024; _big_mem_capacity = 64 * 1024 * 1024;//64MB
_big_mem_start = new char[_big_mem_capacity]; _big_mem_start = new char[_big_mem_capacity];
} }
......
...@@ -264,7 +264,7 @@ struct BlockReference { ...@@ -264,7 +264,7 @@ struct BlockReference {
// total number is 32*1024 // total number is 32*1024
class BlockFreeList { class BlockFreeList {
public: public:
static const int MAX_BLOCK_COUNT = 32 * 1024; static const int MAX_BLOCK_COUNT = 256 * 1024;
typedef lockfree::FreeList<Block, MAX_BLOCK_COUNT> BlockFreeListType; typedef lockfree::FreeList<Block, MAX_BLOCK_COUNT> BlockFreeListType;
static BlockFreeListType* instance() { static BlockFreeListType* instance() {
static BlockFreeListType singleton; static BlockFreeListType singleton;
...@@ -340,7 +340,9 @@ class Region { ...@@ -340,7 +340,9 @@ class Region {
static const int BIG_MEM_THRESHOLD = static const int BIG_MEM_THRESHOLD =
2 * 1024 * 2 * 1024 *
1024; // 2MB,means when you need less than 2M, get memory from Block. 1024; // 2MB,means when you need less than 2M, get memory from Block.
static const int BIGNODE_MEM_THRESHOLD = 4 * 1024 * 1024; // 4MB
// 64MB,means when you need less than 64MB, get memory from BigMemory instead of BigNode
static const int BIGNODE_MEM_THRESHOLD = (64 * 1024 * 1024 + 1);
static const int COUNTER_SIZE = static const int COUNTER_SIZE =
BIGNODE_MEM_THRESHOLD / BIG_MEM_THRESHOLD + 1; // this is not used BIGNODE_MEM_THRESHOLD / BIG_MEM_THRESHOLD + 1; // this is not used
...@@ -421,7 +423,8 @@ class Mempool { ...@@ -421,7 +423,8 @@ class Mempool {
} }
// 可能返回的是单独Region中malloc的内存。 // 可能返回的是单独Region中malloc的内存。
// 也可能是Block,例如new_size=1M, old_data原本的指针头就在1.2M处,old_size = // 也可能是Block,例如new_size=1M, old_data原本的指针头就在1.2M处,old_size
// =
// 0.5M // 0.5M
// 此时,_free_size = 0.3M,new_size<2M,但是required = 1-0.5 >0.3 // 此时,_free_size = 0.3M,new_size<2M,但是required = 1-0.5 >0.3
// 分配出来的就是Block,但是该Block没有并很完美的利用完全。 // 分配出来的就是Block,但是该Block没有并很完美的利用完全。
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册