- return IRIS_MEMZONE_SHADER;
-}
-
-static uint64_t
-bucket_vma_alloc(struct iris_bufmgr *bufmgr,
- struct bo_cache_bucket *bucket,
- enum iris_memory_zone memzone)
-{
- struct util_dynarray *vma_list = &bucket->vma_list[memzone];
- struct vma_bucket_node *node;
-
- if (vma_list->size == 0) {
- /* This bucket allocator is out of space - allocate a new block of
- * memory for 64 blocks from a larger allocator (either a larger
- * bucket or util_vma).
- *
- * We align the address to the node size (64 blocks) so that
- * bucket_vma_free can easily compute the starting address of this
- * block by rounding any address we return down to the node size.
- *
- * Set the first bit used, and return the start address.
- */
- const uint64_t node_size = 64ull * bucket->size;
- node = util_dynarray_grow(vma_list, sizeof(struct vma_bucket_node));
-
- if (unlikely(!node))
- return 0ull;
-
- uint64_t addr = vma_alloc(bufmgr, memzone, node_size, node_size);
- node->start_address = gen_48b_address(addr);
- node->bitmap = ~1ull;
- return node->start_address;
- }
-
- /* Pick any bit from any node - they're all the right size and free. */
- node = util_dynarray_top_ptr(vma_list, struct vma_bucket_node);
- int bit = ffsll(node->bitmap) - 1;
- assert(bit >= 0 && bit <= 63);
-
- /* Reserve the memory by clearing the bit. */
- assert((node->bitmap & (1ull << bit)) != 0ull);
- node->bitmap &= ~(1ull << bit);
-
- uint64_t addr = node->start_address + bit * bucket->size;
-
- /* If this node is now completely full, remove it from the free list. */
- if (node->bitmap == 0ull) {
- (void) util_dynarray_pop(vma_list, struct vma_bucket_node);
- }
-
- return addr;
-}
-
-static void
-bucket_vma_free(struct bo_cache_bucket *bucket, uint64_t address)
-{
- enum iris_memory_zone memzone = memzone_for_address(address);
- struct util_dynarray *vma_list = &bucket->vma_list[memzone];
- const uint64_t node_bytes = 64ull * bucket->size;
- struct vma_bucket_node *node = NULL;
-
- /* bucket_vma_alloc allocates 64 blocks at a time, and aligns it to
- * that 64 block size. So, we can round down to get the starting address.
- */
- uint64_t start = (address / node_bytes) * node_bytes;
-
- /* Dividing the offset from start by bucket size gives us the bit index. */
- int bit = (address - start) / bucket->size;
-
- assert(start + bit * bucket->size == address);
-
- util_dynarray_foreach(vma_list, struct vma_bucket_node, cur) {
- if (cur->start_address == start) {
- node = cur;
- break;
- }
- }
-
- if (!node) {
- /* No node - the whole group of 64 blocks must have been in-use. */
- node = util_dynarray_grow(vma_list, sizeof(struct vma_bucket_node));
-
- if (unlikely(!node))
- return; /* bogus, leaks some GPU VMA, but nothing we can do... */
-
- node->start_address = start;
- node->bitmap = 0ull;
- }
-
- /* Set the bit to return the memory. */
- assert((node->bitmap & (1ull << bit)) == 0ull);
- node->bitmap |= 1ull << bit;
-
- /* The block might be entirely free now, and if so, we could return it
- * to the larger allocator. But we may as well hang on to it, in case
- * we get more allocations at this block size.
- */
-}
-
-static struct bo_cache_bucket *
-get_bucket_allocator(struct iris_bufmgr *bufmgr, uint64_t size)
-{
- /* Skip using the bucket allocator for very large sizes, as it allocates
- * 64 of them and this can balloon rather quickly.
- */
- if (size > 1024 * PAGE_SIZE)
- return NULL;
-
- struct bo_cache_bucket *bucket = bucket_for_size(bufmgr, size);
-
- if (bucket && bucket->size == size)
- return bucket;