anv/allocator: Take the device mutex when growing a block pool
[mesa.git] / src / vulkan / anv_allocator.c
1 /*
2 * Copyright © 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #define _DEFAULT_SOURCE
25
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <values.h>
30 #include <assert.h>
31 #include <linux/futex.h>
32 #include <linux/memfd.h>
33 #include <sys/time.h>
34 #include <sys/mman.h>
35 #include <sys/syscall.h>
36
37 #include "anv_private.h"
38
39 #ifdef HAVE_VALGRIND
40 #define VG_NOACCESS_READ(__ptr) ({ \
41 VALGRIND_MAKE_MEM_DEFINED((__ptr), sizeof(*(__ptr))); \
42 __typeof(*(__ptr)) __val = *(__ptr); \
43 VALGRIND_MAKE_MEM_NOACCESS((__ptr), sizeof(*(__ptr)));\
44 __val; \
45 })
46 #define VG_NOACCESS_WRITE(__ptr, __val) ({ \
47 VALGRIND_MAKE_MEM_UNDEFINED((__ptr), sizeof(*(__ptr))); \
48 *(__ptr) = (__val); \
49 VALGRIND_MAKE_MEM_NOACCESS((__ptr), sizeof(*(__ptr))); \
50 })
51 #else
52 #define VG_NOACCESS_READ(__ptr) (*(__ptr))
53 #define VG_NOACCESS_WRITE(__ptr, __val) (*(__ptr) = (__val))
54 #endif
55
56 /* Design goals:
57 *
58 * - Lock free (except when resizing underlying bos)
59 *
60 * - Constant time allocation with typically only one atomic
61 *
62 * - Multiple allocation sizes without fragmentation
63 *
64 * - Can grow while keeping addresses and offset of contents stable
65 *
66 * - All allocations within one bo so we can point one of the
67 * STATE_BASE_ADDRESS pointers at it.
68 *
69 * The overall design is a two-level allocator: top level is a fixed size, big
70 * block (8k) allocator, which operates out of a bo. Allocation is done by
71 * either pulling a block from the free list or growing the used range of the
72 * bo. Growing the range may run out of space in the bo which we then need to
73 * grow. Growing the bo is tricky in a multi-threaded, lockless environment:
74 * we need to keep all pointers and contents in the old map valid. GEM bos in
75 * general can't grow, but we use a trick: we create a memfd and use ftruncate
76 * to grow it as necessary. We mmap the new size and then create a gem bo for
77 * it using the new gem userptr ioctl. Without heavy-handed locking around
78 * our allocation fast-path, there isn't really a way to munmap the old mmap,
79 * so we just keep it around until garbage collection time. While the block
80 * allocator is lockless for normal operations, we block other threads trying
81 * to allocate while we're growing the map. It sholdn't happen often, and
82 * growing is fast anyway.
83 *
84 * At the next level we can use various sub-allocators. The state pool is a
85 * pool of smaller, fixed size objects, which operates much like the block
86 * pool. It uses a free list for freeing objects, but when it runs out of
87 * space it just allocates a new block from the block pool. This allocator is
88 * intended for longer lived state objects such as SURFACE_STATE and most
89 * other persistent state objects in the API. We may need to track more info
90 * with these object and a pointer back to the CPU object (eg VkImage). In
91 * those cases we just allocate a slightly bigger object and put the extra
92 * state after the GPU state object.
93 *
94 * The state stream allocator works similar to how the i965 DRI driver streams
95 * all its state. Even with Vulkan, we need to emit transient state (whether
96 * surface state base or dynamic state base), and for that we can just get a
97 * block and fill it up. These cases are local to a command buffer and the
98 * sub-allocator need not be thread safe. The streaming allocator gets a new
99 * block when it runs out of space and chains them together so they can be
100 * easily freed.
101 */
102
103 /* Allocations are always at least 64 byte aligned, so 1 is an invalid value.
104 * We use it to indicate the free list is empty. */
105 #define EMPTY 1
106
107 struct anv_mmap_cleanup {
108 void *map;
109 size_t size;
110 uint32_t gem_handle;
111 };
112
113 #define ANV_MMAP_CLEANUP_INIT ((struct anv_mmap_cleanup){0})
114
115 static inline long
116 sys_futex(void *addr1, int op, int val1,
117 struct timespec *timeout, void *addr2, int val3)
118 {
119 return syscall(SYS_futex, addr1, op, val1, timeout, addr2, val3);
120 }
121
122 static inline int
123 futex_wake(uint32_t *addr, int count)
124 {
125 return sys_futex(addr, FUTEX_WAKE, count, NULL, NULL, 0);
126 }
127
128 static inline int
129 futex_wait(uint32_t *addr, int32_t value)
130 {
131 return sys_futex(addr, FUTEX_WAIT, value, NULL, NULL, 0);
132 }
133
134 static inline int
135 memfd_create(const char *name, unsigned int flags)
136 {
137 return syscall(SYS_memfd_create, name, flags);
138 }
139
140 static inline uint32_t
141 ilog2_round_up(uint32_t value)
142 {
143 assert(value != 0);
144 return 32 - __builtin_clz(value - 1);
145 }
146
147 static inline uint32_t
148 round_to_power_of_two(uint32_t value)
149 {
150 return 1 << ilog2_round_up(value);
151 }
152
153 static bool
154 anv_free_list_pop(union anv_free_list *list, void **map, uint32_t *offset)
155 {
156 union anv_free_list current, new, old;
157
158 current.u64 = list->u64;
159 while (current.offset != EMPTY) {
160 /* We have to add a memory barrier here so that the list head (and
161 * offset) gets read before we read the map pointer. This way we
162 * know that the map pointer is valid for the given offset at the
163 * point where we read it.
164 */
165 __sync_synchronize();
166
167 uint32_t *next_ptr = *map + current.offset;
168 new.offset = VG_NOACCESS_READ(next_ptr);
169 new.count = current.count + 1;
170 old.u64 = __sync_val_compare_and_swap(&list->u64, current.u64, new.u64);
171 if (old.u64 == current.u64) {
172 *offset = current.offset;
173 return true;
174 }
175 current = old;
176 }
177
178 return false;
179 }
180
181 static void
182 anv_free_list_push(union anv_free_list *list, void *map, uint32_t offset)
183 {
184 union anv_free_list current, old, new;
185 uint32_t *next_ptr = map + offset;
186
187 old = *list;
188 do {
189 current = old;
190 VG_NOACCESS_WRITE(next_ptr, current.offset);
191 new.offset = offset;
192 new.count = current.count + 1;
193 old.u64 = __sync_val_compare_and_swap(&list->u64, current.u64, new.u64);
194 } while (old.u64 != current.u64);
195 }
196
197 /* All pointers in the ptr_free_list are assumed to be page-aligned. This
198 * means that the bottom 12 bits should all be zero.
199 */
200 #define PFL_COUNT(x) ((uintptr_t)(x) & 0xfff)
201 #define PFL_PTR(x) ((void *)((uintptr_t)(x) & ~0xfff))
202 #define PFL_PACK(ptr, count) ({ \
203 assert(((uintptr_t)(ptr) & 0xfff) == 0); \
204 (void *)((uintptr_t)(ptr) | (uintptr_t)((count) & 0xfff)); \
205 })
206
207 static bool
208 anv_ptr_free_list_pop(void **list, void **elem)
209 {
210 void *current = *list;
211 while (PFL_PTR(current) != NULL) {
212 void **next_ptr = PFL_PTR(current);
213 void *new_ptr = VG_NOACCESS_READ(next_ptr);
214 unsigned new_count = PFL_COUNT(current) + 1;
215 void *new = PFL_PACK(new_ptr, new_count);
216 void *old = __sync_val_compare_and_swap(list, current, new);
217 if (old == current) {
218 *elem = PFL_PTR(current);
219 return true;
220 }
221 current = old;
222 }
223
224 return false;
225 }
226
227 static void
228 anv_ptr_free_list_push(void **list, void *elem)
229 {
230 void *old, *current;
231 void **next_ptr = elem;
232
233 old = *list;
234 do {
235 current = old;
236 VG_NOACCESS_WRITE(next_ptr, PFL_PTR(current));
237 unsigned new_count = PFL_COUNT(current) + 1;
238 void *new = PFL_PACK(elem, new_count);
239 old = __sync_val_compare_and_swap(list, current, new);
240 } while (old != current);
241 }
242
243 static uint32_t
244 anv_block_pool_grow(struct anv_block_pool *pool, uint32_t old_size);
245
246 void
247 anv_block_pool_init(struct anv_block_pool *pool,
248 struct anv_device *device, uint32_t block_size)
249 {
250 assert(util_is_power_of_two(block_size));
251
252 pool->device = device;
253 pool->bo.gem_handle = 0;
254 pool->bo.offset = 0;
255 pool->block_size = block_size;
256 pool->free_list = ANV_FREE_LIST_EMPTY;
257 anv_vector_init(&pool->mmap_cleanups,
258 round_to_power_of_two(sizeof(struct anv_mmap_cleanup)), 128);
259
260 /* Immediately grow the pool so we'll have a backing bo. */
261 pool->state.next = 0;
262 pool->state.end = anv_block_pool_grow(pool, 0);
263 }
264
265 void
266 anv_block_pool_finish(struct anv_block_pool *pool)
267 {
268 struct anv_mmap_cleanup *cleanup;
269
270 anv_vector_foreach(cleanup, &pool->mmap_cleanups) {
271 if (cleanup->map)
272 munmap(cleanup->map, cleanup->size);
273 if (cleanup->gem_handle)
274 anv_gem_close(pool->device, cleanup->gem_handle);
275 }
276
277 anv_vector_finish(&pool->mmap_cleanups);
278
279 close(pool->fd);
280 }
281
282 static uint32_t
283 anv_block_pool_grow(struct anv_block_pool *pool, uint32_t old_size)
284 {
285 size_t size;
286 void *map;
287 int gem_handle;
288 struct anv_mmap_cleanup *cleanup;
289
290 pthread_mutex_lock(&pool->device->mutex);
291
292 if (old_size == 0) {
293 size = 32 * pool->block_size;
294 } else {
295 size = old_size * 2;
296 }
297
298 cleanup = anv_vector_add(&pool->mmap_cleanups);
299 if (!cleanup)
300 goto fail;
301 *cleanup = ANV_MMAP_CLEANUP_INIT;
302
303 if (old_size == 0)
304 pool->fd = memfd_create("block pool", MFD_CLOEXEC);
305
306 if (pool->fd == -1)
307 goto fail;
308
309 if (ftruncate(pool->fd, size) == -1)
310 goto fail;
311
312 /* First try to see if mremap can grow the map in place. */
313 map = MAP_FAILED;
314 if (old_size > 0)
315 map = mremap(pool->map, old_size, size, 0);
316 if (map == MAP_FAILED) {
317 /* Just leak the old map until we destroy the pool. We can't munmap it
318 * without races or imposing locking on the block allocate fast path. On
319 * the whole the leaked maps adds up to less than the size of the
320 * current map. MAP_POPULATE seems like the right thing to do, but we
321 * should try to get some numbers.
322 */
323 map = mmap(NULL, size, PROT_READ | PROT_WRITE,
324 MAP_SHARED | MAP_POPULATE, pool->fd, 0);
325 cleanup->map = map;
326 cleanup->size = size;
327 }
328 if (map == MAP_FAILED)
329 goto fail;
330
331 gem_handle = anv_gem_userptr(pool->device, map, size);
332 if (gem_handle == 0)
333 goto fail;
334 cleanup->gem_handle = gem_handle;
335
336 /* Now that we successfull allocated everything, we can write the new
337 * values back into pool. */
338 pool->map = map;
339 pool->bo.gem_handle = gem_handle;
340 pool->bo.size = size;
341 pool->bo.map = map;
342 pool->bo.index = 0;
343
344 pthread_mutex_unlock(&pool->device->mutex);
345
346 return size;
347
348 fail:
349 pthread_mutex_unlock(&pool->device->mutex);
350 return 0;
351 }
352
353 uint32_t
354 anv_block_pool_alloc(struct anv_block_pool *pool)
355 {
356 uint32_t offset;
357 struct anv_block_state state, old, new;
358
359 /* Try free list first. */
360 if (anv_free_list_pop(&pool->free_list, &pool->map, &offset)) {
361 assert(pool->map);
362 return offset;
363 }
364
365 restart:
366 state.u64 = __sync_fetch_and_add(&pool->state.u64, pool->block_size);
367 if (state.next < state.end) {
368 assert(pool->map);
369 return state.next;
370 } else if (state.next == state.end) {
371 /* We allocated the first block outside the pool, we have to grow it.
372 * pool->next_block acts a mutex: threads who try to allocate now will
373 * get block indexes above the current limit and hit futex_wait
374 * below. */
375 new.next = state.next + pool->block_size;
376 new.end = anv_block_pool_grow(pool, state.end);
377 assert(new.end > 0);
378 old.u64 = __sync_lock_test_and_set(&pool->state.u64, new.u64);
379 if (old.next != state.next)
380 futex_wake(&pool->state.end, INT_MAX);
381 return state.next;
382 } else {
383 futex_wait(&pool->state.end, state.end);
384 goto restart;
385 }
386 }
387
388 void
389 anv_block_pool_free(struct anv_block_pool *pool, uint32_t offset)
390 {
391 anv_free_list_push(&pool->free_list, pool->map, offset);
392 }
393
394 static void
395 anv_fixed_size_state_pool_init(struct anv_fixed_size_state_pool *pool,
396 size_t state_size)
397 {
398 /* At least a cache line and must divide the block size. */
399 assert(state_size >= 64 && util_is_power_of_two(state_size));
400
401 pool->state_size = state_size;
402 pool->free_list = ANV_FREE_LIST_EMPTY;
403 pool->block.next = 0;
404 pool->block.end = 0;
405 }
406
407 static uint32_t
408 anv_fixed_size_state_pool_alloc(struct anv_fixed_size_state_pool *pool,
409 struct anv_block_pool *block_pool)
410 {
411 uint32_t offset;
412 struct anv_block_state block, old, new;
413
414 /* Try free list first. */
415 if (anv_free_list_pop(&pool->free_list, &block_pool->map, &offset))
416 return offset;
417
418 /* If free list was empty (or somebody raced us and took the items) we
419 * allocate a new item from the end of the block */
420 restart:
421 block.u64 = __sync_fetch_and_add(&pool->block.u64, pool->state_size);
422
423 if (block.next < block.end) {
424 return block.next;
425 } else if (block.next == block.end) {
426 offset = anv_block_pool_alloc(block_pool);
427 new.next = offset + pool->state_size;
428 new.end = offset + block_pool->block_size;
429 old.u64 = __sync_lock_test_and_set(&pool->block.u64, new.u64);
430 if (old.next != block.next)
431 futex_wake(&pool->block.end, INT_MAX);
432 return offset;
433 } else {
434 futex_wait(&pool->block.end, block.end);
435 goto restart;
436 }
437 }
438
439 static void
440 anv_fixed_size_state_pool_free(struct anv_fixed_size_state_pool *pool,
441 struct anv_block_pool *block_pool,
442 uint32_t offset)
443 {
444 anv_free_list_push(&pool->free_list, block_pool->map, offset);
445 }
446
447 void
448 anv_state_pool_init(struct anv_state_pool *pool,
449 struct anv_block_pool *block_pool)
450 {
451 pool->block_pool = block_pool;
452 for (unsigned i = 0; i < ANV_STATE_BUCKETS; i++) {
453 size_t size = 1 << (ANV_MIN_STATE_SIZE_LOG2 + i);
454 anv_fixed_size_state_pool_init(&pool->buckets[i], size);
455 }
456 VG(VALGRIND_CREATE_MEMPOOL(pool, 0, false));
457 }
458
459 void
460 anv_state_pool_finish(struct anv_state_pool *pool)
461 {
462 VG(VALGRIND_DESTROY_MEMPOOL(pool));
463 }
464
465 struct anv_state
466 anv_state_pool_alloc(struct anv_state_pool *pool, size_t size, size_t align)
467 {
468 unsigned size_log2 = ilog2_round_up(size < align ? align : size);
469 assert(size_log2 <= ANV_MAX_STATE_SIZE_LOG2);
470 if (size_log2 < ANV_MIN_STATE_SIZE_LOG2)
471 size_log2 = ANV_MIN_STATE_SIZE_LOG2;
472 unsigned bucket = size_log2 - ANV_MIN_STATE_SIZE_LOG2;
473
474 struct anv_state state;
475 state.alloc_size = 1 << size_log2;
476 state.offset = anv_fixed_size_state_pool_alloc(&pool->buckets[bucket],
477 pool->block_pool);
478 state.map = pool->block_pool->map + state.offset;
479 VG(VALGRIND_MEMPOOL_ALLOC(pool, state.map, size));
480 return state;
481 }
482
483 void
484 anv_state_pool_free(struct anv_state_pool *pool, struct anv_state state)
485 {
486 assert(util_is_power_of_two(state.alloc_size));
487 unsigned size_log2 = ilog2_round_up(state.alloc_size);
488 assert(size_log2 >= ANV_MIN_STATE_SIZE_LOG2 &&
489 size_log2 <= ANV_MAX_STATE_SIZE_LOG2);
490 unsigned bucket = size_log2 - ANV_MIN_STATE_SIZE_LOG2;
491
492 VG(VALGRIND_MEMPOOL_FREE(pool, state.map));
493 anv_fixed_size_state_pool_free(&pool->buckets[bucket],
494 pool->block_pool, state.offset);
495 }
496
497 #define NULL_BLOCK 1
498 struct stream_block {
499 uint32_t next;
500
501 /* The map for the BO at the time the block was givne to us */
502 void *current_map;
503
504 #ifdef HAVE_VALGRIND
505 void *_vg_ptr;
506 #endif
507 };
508
509 /* The state stream allocator is a one-shot, single threaded allocator for
510 * variable sized blocks. We use it for allocating dynamic state.
511 */
512 void
513 anv_state_stream_init(struct anv_state_stream *stream,
514 struct anv_block_pool *block_pool)
515 {
516 stream->block_pool = block_pool;
517 stream->next = 0;
518 stream->end = 0;
519 stream->current_block = NULL_BLOCK;
520
521 VG(VALGRIND_CREATE_MEMPOOL(stream, 0, false));
522 }
523
524 void
525 anv_state_stream_finish(struct anv_state_stream *stream)
526 {
527 struct stream_block *sb;
528 uint32_t block, next_block;
529
530 block = stream->current_block;
531 while (block != NULL_BLOCK) {
532 sb = stream->block_pool->map + block;
533 next_block = VG_NOACCESS_READ(&sb->next);
534 VG(VALGRIND_MEMPOOL_FREE(stream, VG_NOACCESS_READ(&sb->_vg_ptr)));
535 anv_block_pool_free(stream->block_pool, block);
536 block = next_block;
537 }
538
539 VG(VALGRIND_DESTROY_MEMPOOL(stream));
540 }
541
542 struct anv_state
543 anv_state_stream_alloc(struct anv_state_stream *stream,
544 uint32_t size, uint32_t alignment)
545 {
546 struct stream_block *sb;
547 struct anv_state state;
548 uint32_t block;
549
550 state.offset = align_u32(stream->next, alignment);
551 if (state.offset + size > stream->end) {
552 block = anv_block_pool_alloc(stream->block_pool);
553 void *current_map = stream->block_pool->map;
554 sb = current_map + block;
555 VG_NOACCESS_WRITE(&sb->current_map, current_map);
556 VG_NOACCESS_WRITE(&sb->next, stream->current_block);
557 VG(VG_NOACCESS_WRITE(&sb->_vg_ptr, 0));
558 stream->current_block = block;
559 stream->next = block + sizeof(*sb);
560 stream->end = block + stream->block_pool->block_size;
561 state.offset = align_u32(stream->next, alignment);
562 assert(state.offset + size <= stream->end);
563 }
564
565 sb = stream->block_pool->map + stream->current_block;
566 void *current_map = VG_NOACCESS_READ(&sb->current_map);
567
568 state.map = current_map + state.offset;
569 state.alloc_size = size;
570
571 #ifdef HAVE_VALGRIND
572 void *vg_ptr = VG_NOACCESS_READ(&sb->_vg_ptr);
573 if (vg_ptr == NULL) {
574 vg_ptr = state.map;
575 VG_NOACCESS_WRITE(&sb->_vg_ptr, vg_ptr);
576 VALGRIND_MEMPOOL_ALLOC(stream, vg_ptr, size);
577 } else {
578 ptrdiff_t vg_offset = vg_ptr - current_map;
579 assert(vg_offset >= stream->current_block &&
580 vg_offset < stream->end);
581 VALGRIND_MEMPOOL_CHANGE(stream, vg_ptr, vg_ptr,
582 (state.offset + size) - vg_offset);
583 }
584 #endif
585
586 stream->next = state.offset + size;
587
588 return state;
589 }
590
591 struct bo_pool_bo_link {
592 struct bo_pool_bo_link *next;
593 struct anv_bo bo;
594 };
595
596 void
597 anv_bo_pool_init(struct anv_bo_pool *pool,
598 struct anv_device *device, uint32_t bo_size)
599 {
600 pool->device = device;
601 pool->bo_size = bo_size;
602 pool->free_list = NULL;
603
604 VG(VALGRIND_CREATE_MEMPOOL(pool, 0, false));
605 }
606
607 void
608 anv_bo_pool_finish(struct anv_bo_pool *pool)
609 {
610 struct bo_pool_bo_link *link = PFL_PTR(pool->free_list);
611 while (link != NULL) {
612 struct bo_pool_bo_link link_copy = VG_NOACCESS_READ(link);
613
614 anv_gem_munmap(link_copy.bo.map, pool->bo_size);
615 anv_gem_close(pool->device, link_copy.bo.gem_handle);
616 link = link_copy.next;
617 }
618
619 VG(VALGRIND_DESTROY_MEMPOOL(pool));
620 }
621
622 VkResult
623 anv_bo_pool_alloc(struct anv_bo_pool *pool, struct anv_bo *bo)
624 {
625 VkResult result;
626
627 void *next_free_void;
628 if (anv_ptr_free_list_pop(&pool->free_list, &next_free_void)) {
629 struct bo_pool_bo_link *next_free = next_free_void;
630 *bo = VG_NOACCESS_READ(&next_free->bo);
631 assert(bo->map == next_free);
632 assert(bo->size == pool->bo_size);
633
634 VG(VALGRIND_MEMPOOL_ALLOC(pool, bo->map, pool->bo_size));
635
636 return VK_SUCCESS;
637 }
638
639 struct anv_bo new_bo;
640
641 result = anv_bo_init_new(&new_bo, pool->device, pool->bo_size);
642 if (result != VK_SUCCESS)
643 return result;
644
645 assert(new_bo.size == pool->bo_size);
646
647 new_bo.map = anv_gem_mmap(pool->device, new_bo.gem_handle, 0, pool->bo_size);
648 if (new_bo.map == NULL) {
649 anv_gem_close(pool->device, new_bo.gem_handle);
650 return vk_error(VK_ERROR_MEMORY_MAP_FAILED);
651 }
652
653 *bo = new_bo;
654
655 VG(VALGRIND_MEMPOOL_ALLOC(pool, bo->map, pool->bo_size));
656
657 return VK_SUCCESS;
658 }
659
660 void
661 anv_bo_pool_free(struct anv_bo_pool *pool, const struct anv_bo *bo)
662 {
663 struct bo_pool_bo_link *link = bo->map;
664 link->bo = *bo;
665
666 VG(VALGRIND_MEMPOOL_FREE(pool, bo->map));
667 anv_ptr_free_list_push(&pool->free_list, link);
668 }