2 * Copyright (c) Red Hat Inc.
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, sub license,
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:
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
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 NON-INFRINGEMENT. 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
21 * DEALINGS IN THE SOFTWARE.
23 * Authors: Dave Airlie <airlied@redhat.com>
24 * Jerome Glisse <jglisse@redhat.com>
25 * Pauli Nieminen <suokkos@gmail.com>
28 * Copyright (c) 2013 The FreeBSD Foundation
29 * All rights reserved.
31 * Portions of this software were developed by Konstantin Belousov
32 * <kib@FreeBSD.org> under sponsorship from the FreeBSD Foundation.
35 /* simple list based uncached page pool
36 * - Pool collects resently freed pages for reuse
37 * - Use page->lru to keep a free list
38 * - doesn't track currently in use pages
41 #define pr_fmt(fmt) "[TTM] " fmt
43 #include <linux/list.h>
44 #include <linux/spinlock.h>
45 #include <linux/highmem.h>
46 #include <linux/mm_types.h>
47 #include <linux/module.h>
49 #include <linux/seq_file.h> /* for seq_printf */
50 #include <linux/dma-mapping.h>
52 #include <linux/atomic.h>
54 #include <drm/ttm/ttm_bo_driver.h>
55 #include <drm/ttm/ttm_page_alloc.h>
57 #include <sys/eventhandler.h>
58 #include <vm/vm_page2.h>
60 #if IS_ENABLED(CONFIG_AGP)
64 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
65 #define SMALL_ALLOCATION 16
66 #define FREE_ALL_PAGES (~0U)
67 /* times are in msecs */
68 #define PAGE_FREE_INTERVAL 1000
71 * struct ttm_page_pool - Pool to reuse recently allocated uc/wc pages.
73 * @lock: Protects the shared pool from concurrnet access. Must be used with
74 * irqsave/irqrestore variants because pool allocator maybe called from
76 * @fill_lock: Prevent concurrent calls to fill.
77 * @list: Pool of free uc/wc pages for fast reuse.
78 * @gfp_flags: Flags to pass for alloc_page.
79 * @npages: Number of pages in pool.
81 struct ttm_page_pool {
89 unsigned long nrefills;
93 * Limits for the pool. They are handled without locks because only place where
94 * they may change is in sysfs store. They won't have immediate effect anyway
95 * so forcing serialization to access them is pointless.
98 struct ttm_pool_opts {
107 * struct ttm_pool_manager - Holds memory pools for fst allocation
109 * Manager is read only object for pool code so it doesn't need locking.
111 * @free_interval: minimum number of jiffies between freeing pages from pool.
112 * @page_alloc_inited: reference counting for pool allocation.
113 * @work: Work that is used to shrink the pool. Work is only run when there is
114 * some pages to free.
115 * @small_allocation: Limit in number of pages what is small allocation.
117 * @pools: All pool objects in use.
119 struct ttm_pool_manager {
121 struct shrinker mm_shrink;
122 eventhandler_tag lowmem_handler;
123 struct ttm_pool_opts options;
126 struct ttm_page_pool pools[NUM_POOLS];
128 struct ttm_page_pool wc_pool;
129 struct ttm_page_pool uc_pool;
130 struct ttm_page_pool wc_pool_dma32;
131 struct ttm_page_pool uc_pool_dma32;
136 static struct attribute ttm_page_pool_max = {
137 .name = "pool_max_size",
138 .mode = S_IRUGO | S_IWUSR
140 static struct attribute ttm_page_pool_small = {
141 .name = "pool_small_allocation",
142 .mode = S_IRUGO | S_IWUSR
144 static struct attribute ttm_page_pool_alloc_size = {
145 .name = "pool_allocation_size",
146 .mode = S_IRUGO | S_IWUSR
149 static struct attribute *ttm_pool_attrs[] = {
151 &ttm_page_pool_small,
152 &ttm_page_pool_alloc_size,
156 static void ttm_pool_kobj_release(struct kobject *kobj)
158 struct ttm_pool_manager *m =
159 container_of(kobj, struct ttm_pool_manager, kobj);
163 static ssize_t ttm_pool_store(struct kobject *kobj,
164 struct attribute *attr, const char *buffer, size_t size)
166 struct ttm_pool_manager *m =
167 container_of(kobj, struct ttm_pool_manager, kobj);
170 chars = ksscanf(buffer, "%u", &val);
174 /* Convert kb to number of pages */
175 val = val / (PAGE_SIZE >> 10);
177 if (attr == &ttm_page_pool_max)
178 m->options.max_size = val;
179 else if (attr == &ttm_page_pool_small)
180 m->options.small = val;
181 else if (attr == &ttm_page_pool_alloc_size) {
182 if (val > NUM_PAGES_TO_ALLOC*8) {
183 pr_err("Setting allocation size to %lu is not allowed. Recommended size is %lu\n",
184 NUM_PAGES_TO_ALLOC*(PAGE_SIZE >> 7),
185 NUM_PAGES_TO_ALLOC*(PAGE_SIZE >> 10));
187 } else if (val > NUM_PAGES_TO_ALLOC) {
188 pr_warn("Setting allocation size to larger than %lu is not recommended\n",
189 NUM_PAGES_TO_ALLOC*(PAGE_SIZE >> 10));
191 m->options.alloc_size = val;
197 static ssize_t ttm_pool_show(struct kobject *kobj,
198 struct attribute *attr, char *buffer)
200 struct ttm_pool_manager *m =
201 container_of(kobj, struct ttm_pool_manager, kobj);
204 if (attr == &ttm_page_pool_max)
205 val = m->options.max_size;
206 else if (attr == &ttm_page_pool_small)
207 val = m->options.small;
208 else if (attr == &ttm_page_pool_alloc_size)
209 val = m->options.alloc_size;
211 val = val * (PAGE_SIZE >> 10);
213 return ksnprintf(buffer, PAGE_SIZE, "%u\n", val);
216 static const struct sysfs_ops ttm_pool_sysfs_ops = {
217 .show = &ttm_pool_show,
218 .store = &ttm_pool_store,
221 static struct kobj_type ttm_pool_kobj_type = {
222 .release = &ttm_pool_kobj_release,
223 .sysfs_ops = &ttm_pool_sysfs_ops,
224 .default_attrs = ttm_pool_attrs,
227 static struct ttm_pool_manager *_manager;
230 static int set_pages_array_wb(struct page **pages, int addrinarray)
232 #if IS_ENABLED(CONFIG_AGP)
235 for (i = 0; i < addrinarray; i++)
236 unmap_page_from_agp(pages[i]);
241 static int set_pages_array_wc(struct page **pages, int addrinarray)
243 #if IS_ENABLED(CONFIG_AGP)
246 for (i = 0; i < addrinarray; i++)
247 map_page_into_agp(pages[i]);
252 static int set_pages_array_uc(struct page **pages, int addrinarray)
254 #if IS_ENABLED(CONFIG_AGP)
257 for (i = 0; i < addrinarray; i++)
258 map_page_into_agp(pages[i]);
265 * Select the right pool or requested caching state and ttm flags. */
266 static struct ttm_page_pool *ttm_get_pool(int flags,
267 enum ttm_caching_state cstate)
271 if (cstate == tt_cached)
279 if (flags & TTM_PAGE_FLAG_DMA32)
282 return &_manager->pools[pool_index];
285 /* set memory back to wb and free the pages. */
286 static void ttm_pages_put(struct page *pages[], unsigned npages)
289 if (set_pages_array_wb(pages, npages))
290 pr_err("Failed to set %d pages to wb!\n", npages);
291 for (i = 0; i < npages; ++i) {
292 __free_page(pages[i]);
296 static void ttm_pool_update_free_locked(struct ttm_page_pool *pool,
297 unsigned freed_pages)
299 pool->npages -= freed_pages;
300 pool->nfrees += freed_pages;
304 * Free pages from pool.
306 * To prevent hogging the ttm_swap process we only free NUM_PAGES_TO_ALLOC
307 * number of pages in one go.
309 * @pool: to free the pages from
310 * @free_all: If set to true will free all pages in pool
311 * @use_static: Safe to use static buffer
313 static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,
316 static struct page *static_buf[NUM_PAGES_TO_ALLOC];
317 unsigned long irq_flags;
318 struct vm_page *p, *p1;
319 struct page **pages_to_free;
320 unsigned freed_pages = 0,
321 npages_to_free = nr_free;
324 if (NUM_PAGES_TO_ALLOC < nr_free)
325 npages_to_free = NUM_PAGES_TO_ALLOC;
328 pages_to_free = static_buf;
330 pages_to_free = kmalloc(npages_to_free * sizeof(struct page *),
332 if (!pages_to_free) {
333 pr_err("Failed to allocate memory for pool free operation\n");
338 spin_lock_irqsave(&pool->lock, irq_flags);
340 TAILQ_FOREACH_REVERSE_MUTABLE(p, &pool->list, pglist, pageq, p1) {
341 if (freed_pages >= npages_to_free)
344 pages_to_free[freed_pages++] = (struct page *)p;
345 /* We can only remove NUM_PAGES_TO_ALLOC at a time. */
346 if (freed_pages >= NUM_PAGES_TO_ALLOC) {
347 /* remove range of pages from the pool */
348 for (i = 0; i < freed_pages; i++)
349 TAILQ_REMOVE(&pool->list, (struct vm_page *)pages_to_free[i], pageq);
351 ttm_pool_update_free_locked(pool, freed_pages);
353 * Because changing page caching is costly
354 * we unlock the pool to prevent stalling.
356 spin_unlock_irqrestore(&pool->lock, irq_flags);
358 ttm_pages_put(pages_to_free, freed_pages);
359 if (likely(nr_free != FREE_ALL_PAGES))
360 nr_free -= freed_pages;
362 if (NUM_PAGES_TO_ALLOC >= nr_free)
363 npages_to_free = nr_free;
365 npages_to_free = NUM_PAGES_TO_ALLOC;
369 /* free all so restart the processing */
373 /* Not allowed to fall through or break because
374 * following context is inside spinlock while we are
382 /* remove range of pages from the pool */
384 for (i = 0; i < freed_pages; i++)
385 TAILQ_REMOVE(&pool->list, (struct vm_page *)pages_to_free[i], pageq);
387 ttm_pool_update_free_locked(pool, freed_pages);
388 nr_free -= freed_pages;
391 spin_unlock_irqrestore(&pool->lock, irq_flags);
394 ttm_pages_put(pages_to_free, freed_pages);
396 if (pages_to_free != static_buf)
397 kfree(pages_to_free);
402 * Callback for mm to request pool to reduce number of page held.
404 * XXX: (dchinner) Deadlock warning!
406 * This code is crying out for a shrinker per pool....
409 ttm_pool_shrink_scan(void *arg)
412 static struct shrink_control __sc;
413 struct shrink_control *sc = &__sc;
415 static DEFINE_MUTEX(lock);
416 static unsigned start_pool;
418 unsigned pool_offset;
419 struct ttm_page_pool *pool;
420 int shrink_pages = 100; /* XXXKIB */
421 unsigned long freed = 0;
424 sc->gfp_mask = M_WAITOK;
427 if (!mutex_trylock(&lock))
429 pool_offset = ++start_pool % NUM_POOLS;
430 /* select start pool in round robin fashion */
431 for (i = 0; i < NUM_POOLS; ++i) {
432 unsigned nr_free = shrink_pages;
433 if (shrink_pages == 0)
435 pool = &_manager->pools[(i + pool_offset)%NUM_POOLS];
436 /* OK to use static buffer since global mutex is held. */
437 shrink_pages = ttm_page_pool_free(pool, nr_free, true);
438 freed += nr_free - shrink_pages;
446 ttm_pool_shrink_count(struct shrinker *shrink, struct shrink_control *sc)
449 unsigned long count = 0;
451 for (i = 0; i < NUM_POOLS; ++i)
452 count += _manager->pools[i].npages;
457 static void ttm_pool_mm_shrink_init(struct ttm_pool_manager *manager)
459 manager->mm_shrink.count_objects = ttm_pool_shrink_count;
460 manager->lowmem_handler = EVENTHANDLER_REGISTER(vm_lowmem,
461 ttm_pool_shrink_scan, manager, EVENTHANDLER_PRI_ANY);
464 static void ttm_pool_mm_shrink_fini(struct ttm_pool_manager *manager)
466 EVENTHANDLER_DEREGISTER(vm_lowmem, manager->lowmem_handler);
469 static int ttm_set_pages_caching(struct page **pages,
470 enum ttm_caching_state cstate, unsigned cpages)
473 /* Set page caching */
476 r = set_pages_array_uc(pages, cpages);
478 pr_err("Failed to set %d pages to uc!\n", cpages);
481 r = set_pages_array_wc(pages, cpages);
483 pr_err("Failed to set %d pages to wc!\n", cpages);
492 * Free pages the pages that failed to change the caching state. If there is
493 * any pages that have changed their caching state already put them to the
496 static void ttm_handle_caching_state_failure(struct pglist *pages,
497 int ttm_flags, enum ttm_caching_state cstate,
498 struct page **failed_pages, unsigned cpages)
501 /* Failed pages have to be freed */
502 for (i = 0; i < cpages; ++i) {
503 TAILQ_REMOVE(pages, (struct vm_page *)failed_pages[i], pageq);
504 __free_page(failed_pages[i]);
509 * Allocate new pages with correct caching.
511 * This function is reentrant if caller updates count depending on number of
512 * pages returned in pages array.
514 static int ttm_alloc_new_pages(struct pglist *pages, gfp_t gfp_flags,
515 int ttm_flags, enum ttm_caching_state cstate, unsigned count)
517 struct page **caching_array;
521 unsigned max_cpages = min(count,
522 (unsigned)(PAGE_SIZE/sizeof(struct page *)));
524 /* allocate array for page caching change */
525 caching_array = kmalloc(max_cpages*sizeof(struct page *), M_DRM, M_WAITOK);
527 if (!caching_array) {
528 pr_err("Unable to allocate table for new pages\n");
532 for (i = 0, cpages = 0; i < count; ++i) {
533 p = alloc_page(gfp_flags);
536 pr_err("Unable to get page %u\n", i);
538 /* store already allocated pages in the pool after
539 * setting the caching state */
541 r = ttm_set_pages_caching(caching_array,
544 ttm_handle_caching_state_failure(pages,
546 caching_array, cpages);
552 #ifdef CONFIG_HIGHMEM
553 /* gfp flags of highmem page should never be dma32 so we
554 * we should be fine in such case
559 caching_array[cpages++] = p;
560 if (cpages == max_cpages) {
562 r = ttm_set_pages_caching(caching_array,
565 ttm_handle_caching_state_failure(pages,
567 caching_array, cpages);
574 TAILQ_INSERT_HEAD(pages, (struct vm_page *)p, pageq);
578 r = ttm_set_pages_caching(caching_array, cstate, cpages);
580 ttm_handle_caching_state_failure(pages,
582 caching_array, cpages);
585 kfree(caching_array);
591 * Fill the given pool if there aren't enough pages and the requested number of
594 static void ttm_page_pool_fill_locked(struct ttm_page_pool *pool,
595 int ttm_flags, enum ttm_caching_state cstate, unsigned count,
596 unsigned long *irq_flags)
602 * Only allow one pool fill operation at a time.
603 * If pool doesn't have enough pages for the allocation new pages are
604 * allocated from outside of pool.
609 pool->fill_lock = true;
611 /* If allocation request is small and there are not enough
612 * pages in a pool we fill the pool up first. */
613 if (count < _manager->options.small
614 && count > pool->npages) {
615 struct pglist new_pages;
616 unsigned alloc_size = _manager->options.alloc_size;
619 * Can't change page caching if in irqsave context. We have to
620 * drop the pool->lock.
622 spin_unlock_irqrestore(&pool->lock, *irq_flags);
624 TAILQ_INIT(&new_pages);
625 r = ttm_alloc_new_pages(&new_pages, pool->gfp_flags, ttm_flags,
627 spin_lock_irqsave(&pool->lock, *irq_flags);
630 TAILQ_CONCAT(&pool->list, &new_pages, pageq);
632 pool->npages += alloc_size;
634 pr_err("Failed to fill pool (%p)\n", pool);
635 /* If we have any pages left put them to the pool. */
636 TAILQ_FOREACH(p, &pool->list, pageq) {
639 TAILQ_CONCAT(&pool->list, &new_pages, pageq);
640 pool->npages += cpages;
644 pool->fill_lock = false;
648 * Cut 'count' number of pages from the pool and put them on the return list.
650 * @return count of pages still required to fulfill the request.
652 static unsigned ttm_page_pool_get_pages(struct ttm_page_pool *pool,
653 struct pglist *pages,
655 enum ttm_caching_state cstate,
658 unsigned long irq_flags;
662 spin_lock_irqsave(&pool->lock, irq_flags);
663 ttm_page_pool_fill_locked(pool, ttm_flags, cstate, count, &irq_flags);
665 if (count >= pool->npages) {
666 /* take all pages from the pool */
667 TAILQ_CONCAT(pages, &pool->list, pageq);
668 count -= pool->npages;
672 for (i = 0; i < count; i++) {
673 p = TAILQ_FIRST(&pool->list);
674 TAILQ_REMOVE(&pool->list, p, pageq);
675 TAILQ_INSERT_TAIL(pages, p, pageq);
677 pool->npages -= count;
680 spin_unlock_irqrestore(&pool->lock, irq_flags);
684 /* Put all pages in pages list to correct pool to wait for reuse */
685 static void ttm_put_pages(struct page **pages, unsigned npages, int flags,
686 enum ttm_caching_state cstate)
688 unsigned long irq_flags;
689 struct ttm_page_pool *pool = ttm_get_pool(flags, cstate);
691 struct vm_page *page;
694 /* No pool for this memory type so free the pages */
695 for (i = 0; i < npages; i++) {
698 if (page_count(pages[i]) != 1)
699 pr_err("Erroneous page count. Leaking pages.\n");
701 __free_page(pages[i]);
708 spin_lock_irqsave(&pool->lock, irq_flags);
709 for (i = 0; i < npages; i++) {
711 page = (struct vm_page *)pages[i];
712 TAILQ_INSERT_TAIL(&pool->list, page, pageq);
717 /* Check that we don't go over the pool limit */
719 if (pool->npages > _manager->options.max_size) {
720 npages = pool->npages - _manager->options.max_size;
721 /* free at least NUM_PAGES_TO_ALLOC number of pages
722 * to reduce calls to set_memory_wb */
723 if (npages < NUM_PAGES_TO_ALLOC)
724 npages = NUM_PAGES_TO_ALLOC;
726 spin_unlock_irqrestore(&pool->lock, irq_flags);
728 ttm_page_pool_free(pool, npages, false);
732 * On success pages list will hold count number of correctly
735 static int ttm_get_pages(struct page **pages, unsigned npages, int flags,
736 enum ttm_caching_state cstate)
738 struct ttm_page_pool *pool = ttm_get_pool(flags, cstate);
740 struct vm_page *p = NULL;
741 gfp_t gfp_flags = GFP_USER;
745 /* set zero flag for page allocation if required */
746 if (flags & TTM_PAGE_FLAG_ZERO_ALLOC)
747 gfp_flags |= __GFP_ZERO;
749 /* No pool for cached pages */
751 if (flags & TTM_PAGE_FLAG_DMA32)
752 gfp_flags |= GFP_DMA32;
754 gfp_flags |= GFP_HIGHUSER;
756 for (r = 0; r < npages; ++r) {
757 p = (struct vm_page *)alloc_page(gfp_flags);
760 pr_err("Unable to allocate page\n");
763 pages[r] = (struct page *)p;
768 /* combine zero flag to pool flags */
769 gfp_flags |= pool->gfp_flags;
771 /* First we take pages from the pool */
773 npages = ttm_page_pool_get_pages(pool, &plist, flags, cstate, npages);
775 TAILQ_FOREACH(p, &plist, pageq) {
776 pages[count++] = (struct page *)p;
779 /* clear the pages coming from the pool if requested */
780 if (flags & TTM_PAGE_FLAG_ZERO_ALLOC) {
781 TAILQ_FOREACH(p, &plist, pageq) {
782 pmap_zero_page(VM_PAGE_TO_PHYS(p));
786 /* If pool didn't have enough pages allocate new one. */
788 /* ttm_alloc_new_pages doesn't reference pool so we can run
789 * multiple requests in parallel.
792 r = ttm_alloc_new_pages(&plist, gfp_flags, flags, cstate, npages);
793 TAILQ_FOREACH(p, &plist, pageq) {
794 pages[count++] = (struct page *)p;
797 /* If there is any pages in the list put them back to
799 pr_err("Failed to allocate extra pages for large request\n");
800 ttm_put_pages(pages, count, flags, cstate);
808 static void ttm_page_pool_init_locked(struct ttm_page_pool *pool, gfp_t flags,
811 lockinit(&pool->lock, "ttmpool", 0, LK_CANRECURSE);
812 pool->fill_lock = false;
813 TAILQ_INIT(&pool->list);
814 pool->npages = pool->nfrees = 0;
815 pool->gfp_flags = flags;
819 int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages)
825 pr_info("Initializing pool allocator\n");
827 _manager = kzalloc(sizeof(*_manager), GFP_KERNEL);
829 ttm_page_pool_init_locked(&_manager->wc_pool, GFP_HIGHUSER, "wc");
831 ttm_page_pool_init_locked(&_manager->uc_pool, GFP_HIGHUSER, "uc");
833 ttm_page_pool_init_locked(&_manager->wc_pool_dma32,
834 GFP_USER | GFP_DMA32, "wc dma");
836 ttm_page_pool_init_locked(&_manager->uc_pool_dma32,
837 GFP_USER | GFP_DMA32, "uc dma");
839 _manager->options.max_size = max_pages;
840 _manager->options.small = SMALL_ALLOCATION;
841 _manager->options.alloc_size = NUM_PAGES_TO_ALLOC;
843 ret = kobject_init_and_add(&_manager->kobj, &ttm_pool_kobj_type,
844 &glob->kobj, "pool");
845 if (unlikely(ret != 0)) {
846 kobject_put(&_manager->kobj);
851 ttm_pool_mm_shrink_init(_manager);
856 void ttm_page_alloc_fini(void)
860 pr_info("Finalizing pool allocator\n");
861 ttm_pool_mm_shrink_fini(_manager);
863 /* OK to use static buffer since global mutex is no longer used. */
864 for (i = 0; i < NUM_POOLS; ++i)
865 ttm_page_pool_free(&_manager->pools[i], FREE_ALL_PAGES, true);
867 kobject_put(&_manager->kobj);
871 int ttm_pool_populate(struct ttm_tt *ttm)
873 struct ttm_mem_global *mem_glob = ttm->glob->mem_glob;
877 if (ttm->state != tt_unpopulated)
880 for (i = 0; i < ttm->num_pages; ++i) {
881 ret = ttm_get_pages(&ttm->pages[i], 1,
885 ttm_pool_unpopulate(ttm);
889 ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i],
891 if (unlikely(ret != 0)) {
892 ttm_pool_unpopulate(ttm);
897 if (unlikely(ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)) {
898 ret = ttm_tt_swapin(ttm);
899 if (unlikely(ret != 0)) {
900 ttm_pool_unpopulate(ttm);
905 ttm->state = tt_unbound;
908 EXPORT_SYMBOL(ttm_pool_populate);
910 void ttm_pool_unpopulate(struct ttm_tt *ttm)
914 for (i = 0; i < ttm->num_pages; ++i) {
916 ttm_mem_global_free_page(ttm->glob->mem_glob,
918 ttm_put_pages(&ttm->pages[i], 1,
923 ttm->state = tt_unpopulated;
925 EXPORT_SYMBOL(ttm_pool_unpopulate);
928 int ttm_page_alloc_debugfs(struct seq_file *m, void *data)
930 struct ttm_page_pool *p;
932 char *h[] = {"pool", "refills", "pages freed", "size"};
934 seq_printf(m, "No pool allocator running.\n");
937 seq_printf(m, "%6s %12s %13s %8s\n",
938 h[0], h[1], h[2], h[3]);
939 for (i = 0; i < NUM_POOLS; ++i) {
940 p = &_manager->pools[i];
942 seq_printf(m, "%6s %12ld %13ld %8d\n",
943 p->name, p->nrefills,
944 p->nfrees, p->npages);
949 EXPORT_SYMBOL(ttm_page_alloc_debugfs);