added growth policy for rrc::ue memory pool. Fixed memory leak

master
Francisco Paisana 4 years ago
parent a73cbcdc9d
commit 768a4fa627

@ -39,6 +39,7 @@ public:
// printf("head: %ld\n", (long)head); // printf("head: %ld\n", (long)head);
node* next = ::new (block) node(head); node* next = ::new (block) node(head);
head = next; head = next;
count++;
} }
uint8_t* try_pop() noexcept uint8_t* try_pop() noexcept
@ -48,11 +49,14 @@ public:
} }
node* last_head = head; node* last_head = head;
head = head->prev; head = head->prev;
count--;
return (uint8_t*)last_head; return (uint8_t*)last_head;
} }
bool is_empty() const { return head == nullptr; } bool is_empty() const { return head == nullptr; }
size_t size() const { return count; }
void clear() { head = nullptr; } void clear() { head = nullptr; }
private: private:
@ -63,6 +67,7 @@ private:
}; };
node* head = nullptr; node* head = nullptr;
size_t count = 0;
}; };
/// memblock stack that mutexes pushing/popping /// memblock stack that mutexes pushing/popping
@ -130,9 +135,17 @@ public:
void operator()(void* block) { pool->stack.push(static_cast<uint8_t*>(block)); } void operator()(void* block) { pool->stack.push(static_cast<uint8_t*>(block)); }
single_thread_obj_pool<T>* pool; single_thread_obj_pool<T>* pool;
}; };
using obj_ptr = std::unique_ptr<T, obj_deleter>; using obj_ptr = std::unique_ptr<T, obj_deleter>;
~single_thread_obj_pool()
{
uint8_t* block = stack.try_pop();
while (block != nullptr) {
delete[] block;
block = stack.try_pop();
}
}
/// allocate object /// allocate object
template <typename... Args> template <typename... Args>
obj_ptr make(Args&&... args) obj_ptr make(Args&&... args)
@ -152,6 +165,8 @@ public:
} }
} }
size_t capacity() const { return stack.size(); }
private: private:
memblock_stack stack; memblock_stack stack;
}; };

@ -31,7 +31,7 @@ namespace srsenb {
rrc::rrc(srslte::task_sched_handle task_sched_) : rrc_log("RRC"), task_sched(task_sched_) rrc::rrc(srslte::task_sched_handle task_sched_) : rrc_log("RRC"), task_sched(task_sched_)
{ {
pending_paging.clear(); pending_paging.clear();
ue_pool.reserve(10); ue_pool.reserve(16);
} }
rrc::~rrc() {} rrc::~rrc() {}
@ -152,6 +152,9 @@ void rrc::add_user(uint16_t rnti, const sched_interface::ue_cfg_t& sched_ue_cfg)
if (rnti != SRSLTE_MRNTI) { if (rnti != SRSLTE_MRNTI) {
// only non-eMBMS RNTIs are present in user map // only non-eMBMS RNTIs are present in user map
auto p = users.insert(std::make_pair(rnti, ue_pool.make(this, rnti, sched_ue_cfg))); auto p = users.insert(std::make_pair(rnti, ue_pool.make(this, rnti, sched_ue_cfg)));
if (ue_pool.capacity() <= 4) {
task_sched.defer_task([this]() { ue_pool.reserve(16); });
}
rnti_added = p.second and p.first->second->is_allocated(); rnti_added = p.second and p.first->second->is_allocated();
} }
if (rnti_added) { if (rnti_added) {

Loading…
Cancel
Save