@Override
    public BufferBuilder requestBufferBlocking(Object owner) {
        checkIsInitialized();

        reclaimBuffersIfNeeded(0);

        MemorySegment memorySegment = bufferQueue.poll();
        if (memorySegment == null) {
            memorySegment = requestBufferBlockingFromPool();
        }
        if (memorySegment == null) {
            memorySegment = checkNotNull(requestBufferBlockingFromQueue());
        }

        incNumRequestedBuffer(owner);
        return new BufferBuilder(
                checkNotNull(memorySegment), segment -> recycleBuffer(owner, segment));
    }
@Test
    void testRecycleBuffersAfterPoolSizeDecreased() throws IOException {
        int numBuffers = 10;

        BufferPool bufferPool = globalPool.createBufferPool(1, numBuffers);
        TieredStorageMemoryManagerImpl storageMemoryManager =
                createStorageMemoryManager(
                        bufferPool,
                        Collections.singletonList(new TieredStorageMemorySpec(this, 0)));
        for (int i = 0; i < numBuffers; i++) {
            BufferBuilder builder = storageMemoryManager.requestBufferBlocking(this);
            requestedBuffers.add(builder);
        }

        bufferPool.setNumBuffers(numBuffers / 2);

        for (int i = 0; i < numBuffers; i++) {
            recycleBufferBuilder(requestedBuffers.get(i));
            assertThat(bufferPool.bestEffortGetNumOfUsedBuffers())
                    .isEqualTo(Math.max(numBuffers / 2, numBuffers - (i + 1)));
        }
    }