Lines Matching refs:pool

35 /* simple list based uncached page pool
58 * @lock: Protects the shared pool from concurrnet access. Must be used with
59 * irqsave/irqrestore variants because pool allocator maybe called from
64 * @npages: Number of pages in pool.
79 * Limits for the pool. They are handled without locks because only place where
95 * Manager is read only object for pool code so it doesn't need locking.
97 * @free_interval: minimum number of jiffies between freeing pages from pool.
98 * @page_alloc_inited: reference counting for pool allocation.
99 * @work: Work that is used to shrink the pool. Work is only run when there is
103 * @pools: All pool objects in use.
308 * Select the right pool or requested caching state and ttm flags. */
340 static void ttm_pool_update_free_locked(struct ttm_page_pool *pool,
343 pool->npages -= freed_pages;
344 pool->nfrees += freed_pages;
348 * Free pages from pool.
353 * @pool: to free the pages from
354 * @free_all: If set to true will free all pages in pool
356 static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free)
371 mtx_lock(&pool->lock);
373 TAILQ_FOREACH_REVERSE_SAFE(p, &pool->list, pglist, plinks.q, p1) {
380 /* remove range of pages from the pool */
382 TAILQ_REMOVE(&pool->list, pages_to_free[i], plinks.q);
384 ttm_pool_update_free_locked(pool, freed_pages);
387 * we unlock the pool to prevent stalling.
389 mtx_unlock(&pool->lock);
415 /* remove range of pages from the pool */
418 TAILQ_REMOVE(&pool->list, pages_to_free[i], plinks.q);
420 ttm_pool_update_free_locked(pool, freed_pages);
424 mtx_unlock(&pool->lock);
445 * Callback for mm to request pool to reduce number of page held.
452 struct ttm_page_pool *pool;
456 /* select start pool in round robin fashion */
461 pool = &_manager->pools[(i + pool_offset)%NUM_POOLS];
462 shrink_pages = ttm_page_pool_free(pool, nr_free);
464 /* return estimated number of unused pages in pool */
506 * pool.
545 /* store already allocated pages in the pool after
598 * Fill the given pool if there aren't enough pages and the requested number of
601 static void ttm_page_pool_fill_locked(struct ttm_page_pool *pool,
608 * Only allow one pool fill operation at a time.
609 * If pool doesn't have enough pages for the allocation new pages are
610 * allocated from outside of pool.
612 if (pool->fill_lock)
615 pool->fill_lock = true;
618 * pages in a pool we fill the pool up first. */
620 && count > pool->npages) {
626 * drop the pool->lock.
628 mtx_unlock(&pool->lock);
631 r = ttm_alloc_new_pages(&new_pages, pool->ttm_page_alloc_flags,
633 mtx_lock(&pool->lock);
636 TAILQ_CONCAT(&pool->list, &new_pages, plinks.q);
637 ++pool->nrefills;
638 pool->npages += alloc_size;
640 printf("[TTM] Failed to fill pool (%p)\n", pool);
641 /* If we have any pages left put them to the pool. */
642 TAILQ_FOREACH(p, &pool->list, plinks.q) {
645 TAILQ_CONCAT(&pool->list, &new_pages, plinks.q);
646 pool->npages += cpages;
650 pool->fill_lock = false;
654 * Cut 'count' number of pages from the pool and put them on the return list.
658 static unsigned ttm_page_pool_get_pages(struct ttm_page_pool *pool,
667 mtx_lock(&pool->lock);
668 ttm_page_pool_fill_locked(pool, ttm_flags, cstate, count);
670 if (count >= pool->npages) {
671 /* take all pages from the pool */
672 TAILQ_CONCAT(pages, &pool->list, plinks.q);
673 count -= pool->npages;
674 pool->npages = 0;
678 p = TAILQ_FIRST(&pool->list);
679 TAILQ_REMOVE(&pool->list, p, plinks.q);
682 pool->npages -= count;
685 mtx_unlock(&pool->lock);
689 /* Put all pages in pages list to correct pool to wait for reuse */
693 struct ttm_page_pool *pool = ttm_get_pool(flags, cstate);
696 if (pool == NULL) {
697 /* No pool for this memory type so free the pages */
707 mtx_lock(&pool->lock);
710 TAILQ_INSERT_TAIL(&pool->list, pages[i], plinks.q);
712 pool->npages++;
715 /* Check that we don't go over the pool limit */
717 if (pool->npages > _manager->options.max_size) {
718 npages = pool->npages - _manager->options.max_size;
724 mtx_unlock(&pool->lock);
726 ttm_page_pool_free(pool, npages);
736 struct ttm_page_pool *pool = ttm_get_pool(flags, cstate);
743 /* No pool for cached pages */
744 if (pool == NULL) {
756 /* combine zero flag to pool flags */
757 gfp_flags = flags | pool->ttm_page_alloc_flags;
759 /* First we take pages from the pool */
761 npages = ttm_page_pool_get_pages(pool, &plist, flags, cstate, npages);
767 /* clear the pages coming from the pool if requested */
774 /* If pool didn't have enough pages allocate new one. */
776 /* ttm_alloc_new_pages doesn't reference pool so we can run
787 * the pool. */
797 static void ttm_page_pool_init_locked(struct ttm_page_pool *pool, int flags,
800 mtx_init(&pool->lock, "ttmpool", NULL, MTX_DEF);
801 pool->fill_lock = false;
802 TAILQ_INIT(&pool->list);
803 pool->npages = pool->nfrees = 0;
804 pool->ttm_page_alloc_flags = flags;
805 pool->name = name;
813 printf("[TTM] Initializing pool allocator\n");
838 printf("[TTM] Finalizing pool allocator\n");
909 char *h[] = {"pool", "refills", "pages freed", "size"};
911 seq_printf(m, "No pool allocator running.\n");