| 775 | CHECK_AND_INC_MEM_OP_STATS(this, Allocs); |
| 776 | if (!out.empty()) { |
| 777 | INC_MEM_OP_STATS(Frees); |
| 778 | } |
| 779 | BOLT_CHECK_GT(numPages, 0); |
| 780 | RECORD_FREE(out); |
| 781 | if (!allocator_->allocateContiguous( |
| 782 | numPages, |
| 783 | nullptr, |
| 784 | out, |
| 785 | [this](uint64_t allocBytes, bool preAlloc) { |
| 786 | if (preAlloc) { |
| 787 | reserve(allocBytes); |
| 788 | } else { |
| 789 | release(allocBytes); |
| 790 | } |
| 791 | }, |
| 792 | maxPages)) { |
| 793 | BOLT_CHECK(out.empty()); |
| 794 | handleAllocationFailure(fmt::format( |
| 795 | "{} failed with {} pages from {} {}", |
| 796 | __FUNCTION__, |
| 797 | numPages, |
| 798 | toString(), |
| 799 | allocator_->getAndClearFailureMessage())); |
| 800 | } |
| 801 | RECORD_ALLOC(out); |
| 802 | BOLT_CHECK(!out.empty()); |
| 803 | BOLT_CHECK_NULL(out.pool()); |
| 804 | out.setPool(this); |
| 805 | } |
| 806 | |
| 807 | void MemoryPoolImpl::freeContiguous(ContiguousAllocation& allocation) { |
| 808 | CHECK_AND_INC_MEM_OP_STATS(this, Frees); |
| 809 | const int64_t bytesToFree = allocation.size(); |
| 810 | RECORD_FREE(allocation); |
| 811 | allocator_->freeContiguous(allocation); |
| 812 | BOLT_CHECK(allocation.empty()); |
| 813 | release(bytesToFree); |
| 814 | } |