- cleanup = u_vector_add(&pool->mmap_cleanups);
- if (!cleanup)
- return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
-
- *cleanup = ANV_MMAP_CLEANUP_INIT;
-
- uint32_t newbo_size = size - pool->size;
- if (use_softpin) {
- gem_handle = anv_gem_create(pool->device, newbo_size);
- map = anv_gem_mmap(pool->device, gem_handle, 0, newbo_size, 0);
- if (map == MAP_FAILED)
- return vk_errorf(pool->device->instance, pool->device,
- VK_ERROR_MEMORY_MAP_FAILED, "gem mmap failed: %m");
- assert(center_bo_offset == 0);
- } else {
- /* Just leak the old map until we destroy the pool. We can't munmap it
- * without races or imposing locking on the block allocate fast path. On
- * the whole the leaked maps adds up to less than the size of the
- * current map. MAP_POPULATE seems like the right thing to do, but we
- * should try to get some numbers.
- */
- map = mmap(NULL, size, PROT_READ | PROT_WRITE,
- MAP_SHARED | MAP_POPULATE, pool->fd,
- BLOCK_POOL_MEMFD_CENTER - center_bo_offset);
- if (map == MAP_FAILED)
- return vk_errorf(pool->device->instance, pool->device,
- VK_ERROR_MEMORY_MAP_FAILED, "mmap failed: %m");
-
- /* Now that we mapped the new memory, we can write the new
- * center_bo_offset back into pool and update pool->map. */
- pool->center_bo_offset = center_bo_offset;
- pool->map = map + center_bo_offset;
- gem_handle = anv_gem_userptr(pool->device, map, size);
- if (gem_handle == 0) {
- munmap(map, size);
- return vk_errorf(pool->device->instance, pool->device,
- VK_ERROR_TOO_MANY_OBJECTS, "userptr failed: %m");
- }
- }
-
- cleanup->map = map;
- cleanup->size = use_softpin ? newbo_size : size;
- cleanup->gem_handle = gem_handle;
-
- /* Regular objects are created I915_CACHING_CACHED on LLC platforms and
- * I915_CACHING_NONE on non-LLC platforms. However, userptr objects are
- * always created as I915_CACHING_CACHED, which on non-LLC means
- * snooped.
- *
- * On platforms that support softpin, we are not going to use userptr
- * anymore, but we still want to rely on the snooped states. So make sure
- * everything is set to I915_CACHING_CACHED.
- */
- if (!pool->device->info.has_llc)
- anv_gem_set_caching(pool->device, gem_handle, I915_CACHING_CACHED);
-
- /* For block pool BOs we have to be a bit careful about where we place them