| 601 | } |
| 602 | |
| 603 | Status BufferPool::Client::PrepareToAllocateBuffer( |
| 604 | int64_t len, bool reserved, bool* success) { |
| 605 | if (success != nullptr) *success = false; |
| 606 | // Don't need to hold the client's 'lock_' yet because 'reservation_' operations are |
| 607 | // threadsafe. |
| 608 | if (reserved) { |
| 609 | // The client must have already reserved the memory. |
| 610 | reservation_.AllocateFrom(len); |
| 611 | } else { |
| 612 | DCHECK(success != nullptr); |
| 613 | // The client may not have reserved the memory. |
| 614 | if (!reservation_.IncreaseReservationToFitAndAllocate(len)) return Status::OK(); |
| 615 | } |
| 616 | |
| 617 | { |
| 618 | unique_lock<mutex> lock(lock_); |
| 619 | // Clean enough pages to allow allocation to proceed without violating our eviction |
| 620 | // policy. |
| 621 | Status status = CleanPages(&lock, len); |
| 622 | if (!status.ok()) { |
| 623 | // Reverse the allocation. |
| 624 | reservation_.ReleaseTo(len); |
| 625 | return status; |
| 626 | } |
| 627 | buffers_allocated_bytes_ += len; |
| 628 | DCHECK_CONSISTENCY(); |
| 629 | } |
| 630 | if (success != nullptr) *success = true; |
| 631 | return Status::OK(); |
| 632 | } |
| 633 | |
| 634 | Status BufferPool::Client::DecreaseReservationTo( |
| 635 | int64_t max_decrease, int64_t target_bytes) { |
no test coverage detected