MCPcopy Create free account
hub / github.com/NetSys/bess / DmaMemoryPool

Method DmaMemoryPool

core/memory.cc:269–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

267}
268
269DmaMemoryPool::DmaMemoryPool(size_t size, int socket_id)
270 : initialized_(false), socket_id_(socket_id), total_free_bytes_(0) {
271 CHECK_GT(size, 0);
272 CHECK_GE(socket_id, -1);
273
274 // Try 1GB hugepages first, then 2MB ones.
275 HugepageSize page_size = HugepageSize::k1GB;
276
277 while (total_free_bytes_ < size) {
278 size_t page_bytes = static_cast<size_t>(page_size);
279 void *ptr = AllocHugepageFromSocket(page_size, socket_id);
280
281 if (ptr != nullptr) {
282 total_free_bytes_ += page_bytes;
283 AddRegion(reinterpret_cast<uintptr_t>(ptr), page_bytes);
284 pages_.push_back(ptr);
285 } else {
286 if (page_size == HugepageSize::k1GB) {
287 page_size = HugepageSize::k2MB;
288 } else {
289 break;
290 }
291 }
292 }
293
294 if (total_free_bytes_ >= size) {
295 initialized_ = true;
296 return;
297 }
298
299 // Failed. Give up and clean up.
300 for (auto *ptr : pages_) {
301 FreeHugepage(ptr);
302 }
303 pages_.clear();
304}
305
306DmaMemoryPool::~DmaMemoryPool() {
307 for (auto *ptr : pages_) {

Callers

nothing calls this directly

Calls 3

AllocHugepageFromSocketFunction · 0.85
FreeHugepageFunction · 0.85
clearMethod · 0.80

Tested by

no test coverage detected