From 71f1f1b55691e4130cf0c7a6e05216a3cbd72ca2 Mon Sep 17 00:00:00 2001 From: Francisco Date: Thu, 8 Apr 2021 13:45:44 +0100 Subject: [PATCH] enb - log warning when rnti-specific memory block is full --- lib/include/srsran/adt/pool/circular_stack_pool.h | 11 +++++++++-- lib/include/srsran/adt/pool/linear_allocator.h | 13 +++++++------ srsenb/src/main.cc | 1 + 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/include/srsran/adt/pool/circular_stack_pool.h b/lib/include/srsran/adt/pool/circular_stack_pool.h index 6c1dbdd61..ac9a3e82f 100644 --- a/lib/include/srsran/adt/pool/circular_stack_pool.h +++ b/lib/include/srsran/adt/pool/circular_stack_pool.h @@ -39,7 +39,8 @@ class circular_stack_pool public: circular_stack_pool(size_t nof_objs_per_batch, size_t stack_size, size_t batch_thres, int initial_size = -1) : - central_cache(std::min(NofStacks, nof_objs_per_batch), stack_size, batch_thres, initial_size) + central_cache(std::min(NofStacks, nof_objs_per_batch), stack_size, batch_thres, initial_size), + logger(srslog::fetch_basic_logger("POOL")) {} circular_stack_pool(circular_stack_pool&&) = delete; circular_stack_pool(const circular_stack_pool&) = delete; @@ -66,13 +67,18 @@ public: if (not elem.alloc.is_init()) { void* block = central_cache.allocate_node(central_cache.get_node_max_size()); if (block == nullptr) { + logger.warning("Failed to allocate memory block from central cache"); return nullptr; } elem.key = key; elem.alloc = linear_allocator(block, central_cache.get_node_max_size()); } void* ptr = elem.alloc.allocate(size, alignment); - elem.count++; + if (ptr == nullptr) { + logger.warning("No space left in memory block with key=%zd of circular stack pool", key); + } else { + elem.count++; + } return ptr; } @@ -98,6 +104,7 @@ public: private: srsran::circular_array pools; srsran::background_mem_pool central_cache; + srslog::basic_logger& logger; }; } // namespace srsran diff --git a/lib/include/srsran/adt/pool/linear_allocator.h b/lib/include/srsran/adt/pool/linear_allocator.h index 89d4ec9e5..bcfc05044 100644 --- a/lib/include/srsran/adt/pool/linear_allocator.h +++ b/lib/include/srsran/adt/pool/linear_allocator.h @@ -43,12 +43,13 @@ public: void* allocate(size_t sz, size_t alignment) { - void* alloc_start = align_to(cur, alignment); - cur = static_cast(alloc_start) + sz; - srsran_assert(cur <= end, - "Linear Allocator buffer of size=%zd was exceeded (current size=%zd)", - size(), - nof_bytes_allocated()); + void* alloc_start = align_to(cur, alignment); + uint8_t* new_cur = static_cast(alloc_start) + sz; + if (new_cur > end) { + // Cannot fit allocation in memory block + return nullptr; + } + cur = new_cur; return alloc_start; } diff --git a/srsenb/src/main.cc b/srsenb/src/main.cc index 0d7cd4e26..e0b853fbd 100644 --- a/srsenb/src/main.cc +++ b/srsenb/src/main.cc @@ -514,6 +514,7 @@ int main(int argc, char* argv[]) srslog::init(); srslog::fetch_basic_logger("ALL").set_level(srslog::basic_levels::warning); + srslog::fetch_basic_logger("POOL").set_level(srslog::basic_levels::warning); srsran::log_args(argc, argv, "ENB"); srsran::check_scaling_governor(args.rf.device_name);