Lines Matching full:pool

62  * freelists maintained in each pool. NCHUNKS_ORDER of 6 means that the
66 * 63 freelists per pool.
78 int (*evict)(struct zbud_pool *pool, unsigned long handle);
82 * struct zbud_pool - stores metadata for each zbud pool
83 * @lock: protects all pool fields and first|last_chunk fields of any
84 * zbud page in the pool
92 * @pages_nr: number of zbud pages in the pool.
94 * pool creation time.
98 * This structure is allocated at pool creation time and maintains metadata
99 * pertaining to a particular zbud pool.
121 * @buddy: links the zbud page into the unbuddied/buddied lists in the pool
122 * @lru: links the zbud page into the lru list in the pool
172 * Pool lock should be held as this function accesses first|last_chunks
213 * zbud_create_pool() - create a new zbud pool
214 * @gfp: gfp flags when allocating the zbud pool structure
215 * @ops: user-defined operations for the zbud pool
217 * Return: pointer to the new zbud pool or NULL if the metadata allocation
222 struct zbud_pool *pool; in zbud_create_pool() local
225 pool = kzalloc(sizeof(struct zbud_pool), gfp); in zbud_create_pool()
226 if (!pool) in zbud_create_pool()
228 spin_lock_init(&pool->lock); in zbud_create_pool()
230 INIT_LIST_HEAD(&pool->unbuddied[i]); in zbud_create_pool()
231 INIT_LIST_HEAD(&pool->buddied); in zbud_create_pool()
232 INIT_LIST_HEAD(&pool->lru); in zbud_create_pool()
233 pool->pages_nr = 0; in zbud_create_pool()
234 pool->ops = ops; in zbud_create_pool()
235 return pool; in zbud_create_pool()
239 * zbud_destroy_pool() - destroys an existing zbud pool
240 * @pool: the zbud pool to be destroyed
242 * The pool should be emptied before this function is called.
244 static void zbud_destroy_pool(struct zbud_pool *pool) in zbud_destroy_pool() argument
246 kfree(pool); in zbud_destroy_pool()
251 * @pool: zbud pool from which to allocate
253 * @gfp: gfp flags used if the pool needs to grow
256 * This function will attempt to find a free region in the pool large enough to
259 * allocated and added to the pool to satisfy the request.
262 * as zbud pool pages.
265 * gfp arguments are invalid or -ENOMEM if the pool was unable to allocate
268 static int zbud_alloc(struct zbud_pool *pool, size_t size, gfp_t gfp, in zbud_alloc() argument
281 spin_lock(&pool->lock); in zbud_alloc()
285 if (!list_empty(&pool->unbuddied[i])) { in zbud_alloc()
286 zhdr = list_first_entry(&pool->unbuddied[i], in zbud_alloc()
298 spin_unlock(&pool->lock); in zbud_alloc()
302 spin_lock(&pool->lock); in zbud_alloc()
303 pool->pages_nr++; in zbud_alloc()
316 list_add(&zhdr->buddy, &pool->unbuddied[freechunks]); in zbud_alloc()
319 list_add(&zhdr->buddy, &pool->buddied); in zbud_alloc()
325 list_add(&zhdr->lru, &pool->lru); in zbud_alloc()
328 spin_unlock(&pool->lock); in zbud_alloc()
335 * @pool: pool in which the allocation resided
343 static void zbud_free(struct zbud_pool *pool, unsigned long handle) in zbud_free() argument
348 spin_lock(&pool->lock); in zbud_free()
359 spin_unlock(&pool->lock); in zbud_free()
370 pool->pages_nr--; in zbud_free()
374 list_add(&zhdr->buddy, &pool->unbuddied[freechunks]); in zbud_free()
377 spin_unlock(&pool->lock); in zbud_free()
381 * zbud_reclaim_page() - evicts allocations from a pool page and frees it
382 * @pool: pool from which a page will attempt to be evicted
395 * zbud_reclaim_page() will remove a zbud page from the pool LRU list and call
396 * the user-defined eviction handler with the pool and handle as arguments.
415 static int zbud_reclaim_page(struct zbud_pool *pool, unsigned int retries) in zbud_reclaim_page() argument
421 spin_lock(&pool->lock); in zbud_reclaim_page()
422 if (!pool->ops || !pool->ops->evict || list_empty(&pool->lru) || in zbud_reclaim_page()
424 spin_unlock(&pool->lock); in zbud_reclaim_page()
428 zhdr = list_last_entry(&pool->lru, struct zbud_header, lru); in zbud_reclaim_page()
443 spin_unlock(&pool->lock); in zbud_reclaim_page()
447 ret = pool->ops->evict(pool, first_handle); in zbud_reclaim_page()
452 ret = pool->ops->evict(pool, last_handle); in zbud_reclaim_page()
457 spin_lock(&pool->lock); in zbud_reclaim_page()
465 pool->pages_nr--; in zbud_reclaim_page()
466 spin_unlock(&pool->lock); in zbud_reclaim_page()
472 list_add(&zhdr->buddy, &pool->unbuddied[freechunks]); in zbud_reclaim_page()
475 list_add(&zhdr->buddy, &pool->buddied); in zbud_reclaim_page()
479 list_add(&zhdr->lru, &pool->lru); in zbud_reclaim_page()
481 spin_unlock(&pool->lock); in zbud_reclaim_page()
487 * @pool: pool in which the allocation resides
497 static void *zbud_map(struct zbud_pool *pool, unsigned long handle) in zbud_map() argument
504 * @pool: pool in which the allocation resides
507 static void zbud_unmap(struct zbud_pool *pool, unsigned long handle) in zbud_unmap() argument
512 * zbud_get_pool_size() - gets the zbud pool size in pages
513 * @pool: pool whose size is being queried
515 * Returns: size in pages of the given pool. The pool lock need not be
518 static u64 zbud_get_pool_size(struct zbud_pool *pool) in zbud_get_pool_size() argument
520 return pool->pages_nr; in zbud_get_pool_size()
527 static int zbud_zpool_evict(struct zbud_pool *pool, unsigned long handle) in zbud_zpool_evict() argument
529 if (pool->zpool && pool->zpool_ops && pool->zpool_ops->evict) in zbud_zpool_evict()
530 return pool->zpool_ops->evict(pool->zpool, handle); in zbud_zpool_evict()
543 struct zbud_pool *pool; in zbud_zpool_create() local
545 pool = zbud_create_pool(gfp, zpool_ops ? &zbud_zpool_ops : NULL); in zbud_zpool_create()
546 if (pool) { in zbud_zpool_create()
547 pool->zpool = zpool; in zbud_zpool_create()
548 pool->zpool_ops = zpool_ops; in zbud_zpool_create()
550 return pool; in zbud_zpool_create()
553 static void zbud_zpool_destroy(void *pool) in zbud_zpool_destroy() argument
555 zbud_destroy_pool(pool); in zbud_zpool_destroy()
558 static int zbud_zpool_malloc(void *pool, size_t size, gfp_t gfp, in zbud_zpool_malloc() argument
561 return zbud_alloc(pool, size, gfp, handle); in zbud_zpool_malloc()
563 static void zbud_zpool_free(void *pool, unsigned long handle) in zbud_zpool_free() argument
565 zbud_free(pool, handle); in zbud_zpool_free()
568 static int zbud_zpool_shrink(void *pool, unsigned int pages, in zbud_zpool_shrink() argument
575 ret = zbud_reclaim_page(pool, 8); in zbud_zpool_shrink()
587 static void *zbud_zpool_map(void *pool, unsigned long handle, in zbud_zpool_map() argument
590 return zbud_map(pool, handle); in zbud_zpool_map()
592 static void zbud_zpool_unmap(void *pool, unsigned long handle) in zbud_zpool_unmap() argument
594 zbud_unmap(pool, handle); in zbud_zpool_unmap()
597 static u64 zbud_zpool_total_size(void *pool) in zbud_zpool_total_size() argument
599 return zbud_get_pool_size(pool) * PAGE_SIZE; in zbud_zpool_total_size()