@Override
    public boolean ensureCapacity(int numAdditionalBuffers) {
        checkIsInitialized();

        final int numRequestedByGuaranteedReclaimableOwners =
                tieredMemorySpecs.values().stream()
                        .filter(TieredStorageMemorySpec::isGuaranteedReclaimable)
                        .mapToInt(spec -> numOwnerRequestedBuffer(spec.getOwner()))
                        .sum();

        while (bufferQueue.size() + numRequestedByGuaranteedReclaimableOwners
                < numGuaranteedReclaimableBuffers + numAdditionalBuffers) {
            if (numRequestedBuffers.get() >= bufferPool.getNumBuffers()) {
                return false;
            }

            MemorySegment memorySegment = requestBufferBlockingFromPool();
            if (memorySegment == null) {
                return false;
            }
            bufferQueue.add(memorySegment);
        }
        return true;
    }
@Test
    void testEnsureCapacity() throws IOException {
        final int numBuffers = 5;
        final int guaranteedReclaimableBuffers = 3;

        BufferPool bufferPool = globalPool.createBufferPool(numBuffers, numBuffers);
        TieredStorageMemoryManagerImpl storageMemoryManager =
                createStorageMemoryManager(
                        bufferPool,
                        Arrays.asList(
                                new TieredStorageMemorySpec(
                                        new Object(), guaranteedReclaimableBuffers, true),
                                new TieredStorageMemorySpec(this, 0, false)));
        assertThat(storageMemoryManager.ensureCapacity(0)).isTrue();
        assertThat(bufferPool.bestEffortGetNumOfUsedBuffers())
                .isEqualTo(guaranteedReclaimableBuffers);

        assertThat(storageMemoryManager.ensureCapacity(numBuffers - guaranteedReclaimableBuffers))
                .isTrue();
        assertThat(bufferPool.bestEffortGetNumOfUsedBuffers()).isEqualTo(numBuffers);

        assertThat(
                        storageMemoryManager.ensureCapacity(
                                numBuffers - guaranteedReclaimableBuffers + 1))
                .isFalse();
        storageMemoryManager.release();
    }