drm/ttm, drm/xe: Shrinker support
Subsystems (5)
Thomas Hellström
maintainercover drm/ttm, drm/xe: Shrinker support
Thomas Hellström (8):
drm/ttm: Allow TTM LRU list nodes of different types drm/ttm: Use LRU hitches
drm/ttm, drm/amdgpu, drm/xe: Consider hitch moves within bulk sublist
moves
drm/ttm: Allow continued swapout after -ENOSPC falure drm/ttm: Add a virtual base class for graphics memory backup drm/ttm/pool: Provide a helper to shrink pages.
drm/xe, drm/ttm: Provide a generic LRU walker helper drm/xe: Add a shrinker for xe bos
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 + drivers/gpu/drm/ttm/Makefile | 2 +- drivers/gpu/drm/ttm/ttm_backup_shmem.c | 122 ++++++++ drivers/gpu/drm/ttm/ttm_bo.c | 1 + drivers/gpu/drm/ttm/ttm_device.c | 33 ++- drivers/gpu/drm/ttm/ttm_pool.c | 387 ++++++++++++++++++++++++- drivers/gpu/drm/ttm/ttm_resource.c | 231 ++++++++++++--- drivers/gpu/drm/ttm/ttm_tt.c | 32 ++ drivers/gpu/drm/xe/Makefile | 2 + drivers/gpu/drm/xe/xe_bo.c | 106 +++++-- drivers/gpu/drm/xe/xe_bo.h | 3 + drivers/gpu/drm/xe/xe_device.c | 8 + drivers/gpu/drm/xe/xe_device_types.h | 2 + drivers/gpu/drm/xe/xe_shrinker.c | 204 +++++++++++++ drivers/gpu/drm/xe/xe_shrinker.h | 18 ++ drivers/gpu/drm/xe/xe_ttm_helpers.c | 166 +++++++++++ drivers/gpu/drm/xe/xe_ttm_helpers.h | 36 +++ drivers/gpu/drm/xe/xe_vm.c | 4 + include/drm/ttm/ttm_backup.h | 48 +++ include/drm/ttm/ttm_device.h | 2 + include/drm/ttm/ttm_pool.h | 4 + include/drm/ttm/ttm_resource.h | 96 +++++- include/drm/ttm/ttm_tt.h | 12 + 23 files changed, 1432 insertions(+), 91 deletions(-) create mode 100644 drivers/gpu/drm/ttm/ttm_backup_shmem.c create mode 100644 drivers/gpu/drm/xe/xe_shrinker.c create mode 100644 drivers/gpu/drm/xe/xe_shrinker.h create mode 100644 drivers/gpu/drm/xe/xe_ttm_helpers.c create mode 100644 drivers/gpu/drm/xe/xe_ttm_helpers.h create mode 100644 include/drm/ttm/ttm_backup.h
Signature · 1 line
2.44.0
Thomas Hellström
maintainerPATCH 4/8 drm/ttm: Allow continued swapout after -ENOSPC falure
The -ENOSPC failure from ttm_bo_swapout() meant that the lru_lock was dropped and simply restarting the iteration meant we'd likely hit the same error again on the same resource. Now that we can restart the iteration even if the lock was dropped, do that.
--- drivers/gpu/drm/ttm/ttm_device.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
drivers/gpu/drm/ttm/ttm_device.c +13 -8
@@ -168,15 +168,20 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx, num_pages =PFN_UP (bo->base.size); ret =ttm_bo_swapout (bo, ctx, gfp_flags); -/* ttm_bo_swapout has dropped the lru_lock */ -if (!ret) { -ttm_resource_cursor_fini (&cursor); -return num_pages; - } -if (ret != -EBUSY ) { -ttm_resource_cursor_fini (&cursor); -return ret; +/* Couldn't swap out, and retained the lru_lock */ +if (ret == -EBUSY ) +continue ; +/* Couldn't swap out and dropped the lru_lock */ +if (ret == -ENOSPC ) { +spin_lock (&bdev->lru_lock); +continue ; } +/* +* Dropped the lock and either succeeded or +* hit an error that forces us to break. +*/ +ttm_resource_cursor_fini (&cursor); +return ret ? ret : num_pages; } }ttm_resource_cursor_fini_locked (&cursor);
Signature · 1 line
2.44.0
Thomas Hellström
maintainerPATCH 5/8 drm/ttm: Add a virtual base class for graphics memory backup
In reply to Thomas HellströmInitially intended for experimenting with different backup solutions (shmem vs direct swap cache insertion), abstract the backup destination using a virtual base class.
Also provide a sample implementation for shmem.
While when settling on a preferred backup solution, one could perhaps skip the abstraction, this functionality may actually come in handy for configurable dedicated graphics memory backup to fast nvme files or similar, whithout affecting swap-space. Could indeed be useful for VRAM backup on S4 and other cases.
--- drivers/gpu/drm/ttm/Makefile | 2 +- drivers/gpu/drm/ttm/ttm_backup_shmem.c | 122 +++++++++++++++++++++++++ include/drm/ttm/ttm_backup.h | 48 ++++++++++ 3 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/ttm/ttm_backup_shmem.c create mode 100644 include/drm/ttm/ttm_backup.h
drivers/gpu/drm/ttm/Makefile +1 -1
@@ -4,7 +4,7 @@ ttm-y := ttm_tt.o ttm_bo.o ttm_bo_util.o ttm_bo_vm.o ttm_module.o \ ttm_execbuf_util.o ttm_range_manager.o ttm_resource.o ttm_pool.o \ - ttm_device.o ttm_sys_manager.o + ttm_device.o ttm_sys_manager.o ttm_backup_shmem.o ttm-$(CONFIG_AGP) += ttm_agp_backend.o obj-$(CONFIG_DRM_TTM) += ttm.o
drivers/gpu/drm/ttm/ttm_backup_shmem.c new file +122 -0
122 lines not on this page · raw message
include/drm/ttm/ttm_backup.h new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
2.44.0
Thomas Hellström
maintainerPATCH 3/8 drm/ttm, drm/amdgpu, drm/xe: Consider hitch moves within bulk sublist moves
In reply to Thomas HellströmTo address the problem with hitches moving when bulk move sublists are lru-bumped, register the list cursors with the ttm_lru_bulk_move structure when traversing its list, and when lru-bumping the list, move the cursor hitch to the tail. This also means it's mandatory for drivers to call ttm_lru_bulk_move_init() and ttm_lru_bulk_move_fini() when initializing and finalizing the bulk move structure, so add those calls to the amdgpu- and xe driver.
Compared to v1 this is slightly more code but less fragile and hopefully easier to understand.
v2:
- Completely rework the functionality
v3:
- Avoid a NULL pointer dereference assigning manager->mem_type v4:
- Remove some leftover code causing build problems
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 ++ drivers/gpu/drm/ttm/ttm_resource.c | 90 +++++++++++++++++++++++++- drivers/gpu/drm/xe/xe_vm.c | 4 ++ include/drm/ttm/ttm_device.h | 2 + include/drm/ttm/ttm_resource.h | 55 ++++++++++------ 5 files changed, 134 insertions(+), 21 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -0
@@ -2368,6 +2368,8 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (r)return r; +ttm_lru_bulk_move_init (&vm->lru_bulk_move); + vm->is_compute_context = false; vm->use_cpu_for_update = !!(adev->vm_manager.vm_update_mode &
@@ -2431,6 +2433,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, error_free_delayed:dma_fence_put (vm->last_tlb_flush);dma_fence_put (vm->last_unlocked); +ttm_lru_bulk_move_fini (&adev->mman.bdev, &vm->lru_bulk_move);amdgpu_vm_fini_entities (vm);return r;
@@ -2587,6 +2590,7 @@ void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm) } } +ttm_lru_bulk_move_fini (&adev->mman.bdev, &vm->lru_bulk_move); }/**
drivers/gpu/drm/ttm/ttm_resource.c +89 -1
149 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm.c +4 -0
@@ -1332,6 +1332,8 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)INIT_WORK (&vm->destroy_work, vm_destroy_work_func); +ttm_lru_bulk_move_init (&vm->lru_bulk_move); +INIT_LIST_HEAD (&vm->preempt.exec_queues); vm->preempt.min_run_period_ms =10 ;/* FIXME: Wire up to uAPI */
@@ -1449,6 +1451,7 @@ struct xe_vm *xe_vm_create(struct xe_device *xe, u32 flags)mutex_destroy (&vm->snap_mutex);for_each_tile (tile, xe, id)xe_range_fence_tree_fini (&vm->rftree[id]); +ttm_lru_bulk_move_fini (&xe->ttm, &vm->lru_bulk_move);kfree (vm);if (!(flags &XE_VM_FLAG_MIGRATION ))xe_device_mem_access_put (xe);
@@ -1589,6 +1592,7 @@ static void vm_destroy_work_func(struct work_struct *w)trace_xe_vm_free (vm);dma_fence_put (vm->rebind_fence); +ttm_lru_bulk_move_fini (&xe->ttm, &vm->lru_bulk_move);kfree (vm); }
include/drm/ttm/ttm_device.h +2 -0
@@ -285,6 +285,8 @@ static inline void ttm_set_driver_manager(struct ttm_device *bdev, int type, {BUILD_BUG_ON (__builtin_constant_p (type) && type >=TTM_NUM_MEM_TYPES ); bdev->man_drv[type] = manager; +if (manager) + manager->mem_type = type; } int ttm_device_init(struct ttm_device *bdev, const struct ttm_device_funcs *funcs,
include/drm/ttm/ttm_resource.h +35 -20
88 lines not on this page · raw message
Signature · 1 line
2.44.0
Thomas Hellström
maintainerPATCH 6/8 drm/ttm/pool: Provide a helper to shrink pages.
In reply to Thomas HellströmProvide a helper to shrink ttm_tt page-vectors on a per-page basis. A ttm_backup backend could then in theory get away with allocating a single temporary page for each struct ttm_tt.
This is accompanied by splitting larger pages before trying to back them up.
In the future we could allow ttm_backup to handle backing up large pages as well, but currently there's no benefit in doing that, since the shmem backup backend would have to split those anyway to avoid allocating too much temporary memory, and if the backend instead inserts pages into the swap-cache, those are split on reclaim by the core.
Due to potential backup- and recover errors, allow partially swapped out struct ttm_tt's, although mark them as swapped out stopping them from being swapped out a second time. More details in the ttm_pool.c DOC section.
--- drivers/gpu/drm/ttm/ttm_pool.c | 387 +++++++++++++++++++++++++++++++-- drivers/gpu/drm/ttm/ttm_tt.c | 32 +++ include/drm/ttm/ttm_pool.h | 4 + include/drm/ttm/ttm_tt.h | 12 + 4 files changed, 422 insertions(+), 13 deletions(-)
drivers/gpu/drm/ttm/ttm_pool.c +374 -13
@@ -41,6 +41,7 @@#include <asm/set_memory.h> #endif +#include <drm/ttm/ttm_backup.h> #include <drm/ttm/ttm_pool.h> #include <drm/ttm/ttm_tt.h> #include <drm/ttm/ttm_bo.h>
@@ -58,6 +59,32 @@ struct ttm_pool_dma {unsigned long vaddr; }; +/** +* struct ttm_pool_tt_restore - State representing restore from swap. +* @alloced_pages: Total number of already allocated pages for the ttm_tt. +* @restored_pages: Number of (sub) pages restored from swap for this +* chunk of 1 << @order pages. +* @first_page: The ttm page ptr representing for @old_pages[0]. +* @caching_divide: Page pointer where subsequent pages are cached. +* @old_pages: Backup copy of page pointers that were replaced by the new +* page allocation. +* @pool: The pool used for page allocation while restoring. +* @order: The order of the last page allocated while restoring. +* +* Recovery from swap space might fail when we've recovered less than the +* full ttm_tt. In order not to loose any data (yet), keep information +* around that allows us to restart a failed ttm swap-space recovery. +*/ +struct ttm_pool_tt_restore { +pgoff_t alloced_pages; +pgoff_t restored_pages; +struct page **first_page; +struct page **caching_divide; +struct ttm_pool *pool; +unsigned int order; +struct page *old_pages[]; +}; +static unsigned long page_pool_size;MODULE_PARM_DESC (page_pool_size,"Number of pages in the WC/UC/DMA pool" );
@@ -348,11 +375,100 @@ static unsigned int ttm_pool_page_order(struct ttm_pool *pool, struct page *p)return p->private; } +/* +* To be able to insert single pages into the swap cache directly, +* we need to split multi-order page allocations and make them look +* like single page-allocations. +*/ +static void ttm_pool_split_for_swap (struct ttm_pool *pool,struct page *p) +{ +unsigned int order =ttm_pool_page_order (pool, p); +pgoff_t nr; + +if (!order) +return ; + +split_page (p, order); + nr =1UL << order; +while (nr--) + (p++)->private =0 ; +} + +/** +* DOC: Partial shrinking and restoration of a struct ttm_tt. +* +* Swapout using swap_backup_folio() and swapin using swap_copy_folio() may fail. +* The former most likely due to lack of swap-space or memory, the latter due +* to lack of memory or because of signal interruption during waits. +* +* Swapout failure is easily handled by using a ttm_tt pages vector that holds +* both swap entries and page pointers. This has to be taken into account when +* restoring such a ttm_tt from swap, and when freeing it while swapped out. +* When restoring, for simplicity, new pages are actually allocated from the +* pool and the contents of any old pages are copied in and then the old pages +* are released. +* +* For swapin failures, the struct ttm_pool_tt_restore holds sufficient state +* to be able to resume an interrupted restore, and that structure is freed once +* the restoration is complete. If the struct ttm_tt is destroyed while there +* is a valid struct ttm_pool_tt_restore attached, that is also properly taken +* care of. +*/ + +static bool ttm_pool_restore_valid (const struct ttm_pool_tt_restore *restore) +{ +return restore && restore->restored_pages < (1 << restore->order); +} + +static int ttm_pool_swapin (struct ttm_pool_tt_restore *restore, +struct ttm_backup *backup, +struct ttm_operation_ctx *ctx) +{ +unsigned int i, nr =1 << restore->order; +int ret =0 ; + +if (!ttm_pool_restore_valid (restore)) +return 0 ; + +for (i = restore->restored_pages; i < nr; ++i) { +struct page *p = restore->old_pages[i]; + +if (ttm_backup_page_ptr_is_handle (p)) { +unsigned long handle =ttm_backup_page_ptr_to_handle (p); + +if (handle ==0 ) +continue ; + + ret = backup->ops->copy_page (backup, restore->first_page[i], + handle, ctx->interruptible); +if (ret) +break ; + + backup->ops->drop (backup, handle); + }else if (p) { +/* +* We could probably avoid splitting the old page +* using clever logic, but ATM we don't care. +*/ +ttm_pool_split_for_swap (restore->pool, p); +copy_highpage (restore->first_page[i], p); +__free_pages (p,0 ); + } + + restore->restored_pages++; + restore->old_pages[i] =NULL ; +cond_resched (); + } + +return ret; +} +/* Called when we got a page, either from a pool or newly allocated */ static int ttm_pool_page_allocated (struct ttm_pool *pool,unsigned int order,struct page *p,dma_addr_t **dma_addr,unsigned long *num_pages, -struct page ***pages) +struct page ***pages, +struct ttm_pool_tt_restore *restore) {unsigned int i;int r;
@@ -363,6 +479,16 @@ static int ttm_pool_page_allocated(struct ttm_pool *pool, unsigned int order,return r; } +if (restore) { +memcpy (restore->old_pages, *pages, + (1 << order) *sizeof (*restore->old_pages)); +memset (*pages,0 , (1 << order) *sizeof (**pages)); + restore->order = order; + restore->restored_pages =0 ; + restore->first_page = *pages; + restore->alloced_pages +=1UL << order; + } + *num_pages -=1 << order;for (i =1 << order; i; --i, ++(*pages), ++p) **pages = p;
@@ -388,22 +514,39 @@ static void ttm_pool_free_range(struct ttm_pool *pool, struct ttm_tt *tt, pgoff_t start_page, pgoff_t end_page) {struct page **pages = &tt->pages[start_page]; +struct ttm_backup *backup = tt->backup;unsigned int order;pgoff_t i, nr;for (i = start_page; i < end_page; i += nr, pages += nr) {struct ttm_pool_type *pt =NULL ; +struct page *p = *pages; + +if (ttm_backup_page_ptr_is_handle (p)) { +unsigned long handle =ttm_backup_page_ptr_to_handle (p); + + nr =1 ; +if (handle !=0 ) + backup->ops->drop (backup, handle); +continue ; + } - order =ttm_pool_page_order (pool, *pages); - nr = (1UL << order); -if (tt->dma_address) -ttm_pool_unmap (pool, tt->dma_address[i], nr); +if (pool) { + order =ttm_pool_page_order (pool, p); + nr = (1UL << order); +if (tt->dma_address) +ttm_pool_unmap (pool, tt->dma_address[i], nr); + + pt =ttm_pool_select_type (pool, caching, order); + }else { + order = p->private; + nr = (1UL << order); + } - pt =ttm_pool_select_type (pool, caching, order);if (pt) -ttm_pool_type_give (pt, *pages); +ttm_pool_type_give (pt, p);else -ttm_pool_free_page (pool, caching, order, *pages); +ttm_pool_free_page (pool, caching, order, p); } }
@@ -447,9 +590,37 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,else gfp_flags |=GFP_HIGHUSER ; - for (order = min_t(unsigned int, MAX_PAGE_ORDER, __fls(num_pages)); - num_pages; - order = min_t(unsigned int, order, __fls(num_pages))) { + order = min_t(unsigned int, MAX_PAGE_ORDER, __fls(num_pages)); + +if (tt->page_flags &TTM_TT_FLAG_PRIV_SHRUNKEN ) { +if (!tt->restore) { +gfp_t gfp =GFP_KERNEL | __GFP_NOWARN; + +if (ctx->gfp_retry_mayfail) + gfp |= __GFP_RETRY_MAYFAIL; + + tt->restore = +kvzalloc (struct_size (tt->restore, old_pages, + (size_t )1 << order), gfp); +/* RFC: Possibly loop on -ENOMEM and reduce order. */ +if (!tt->restore) +return -ENOMEM ; + }else if (ttm_pool_restore_valid (tt->restore)) { +struct ttm_pool_tt_restore *restore = tt->restore; + + num_pages -= restore->alloced_pages; + order = min_t(unsigned int, order, __fls(num_pages)); + pages += restore->alloced_pages; + r =ttm_pool_swapin (restore, tt->backup, ctx); +if (r) +return r; + caching = restore->caching_divide; + } + + tt->restore->pool = pool; + } + + for (; num_pages; order = min_t(unsigned int, order, __fls(num_pages))) {struct ttm_pool_type *pt; page_caching = tt->caching;
@@ -466,11 +637,18 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt, r =ttm_pool_page_allocated (pool, order, p, &dma_addr, &num_pages, - &pages); + &pages, + tt->restore);if (r) goto error_free_page; caching = pages; +if (ttm_pool_restore_valid (tt->restore)) { + r =ttm_pool_swapin (tt->restore, tt->backup, ctx); +if (r) + goto error_free_all; + } +if (num_pages < (1 << order))break ;
@@ -490,9 +668,17 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt, caching = pages; } r =ttm_pool_page_allocated (pool, order, p, &dma_addr, - &num_pages, &pages); + &num_pages, &pages, + tt->restore);if (r) goto error_free_page; + +if (ttm_pool_restore_valid (tt->restore)) { + r =ttm_pool_swapin (tt->restore, tt->backup, ctx); +if (r) + goto error_free_all; + } +if (PageHighMem (p)) caching = pages; }
@@ -511,12 +697,26 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,if (r) goto error_free_all; +if (tt->restore) { +kvfree (tt->restore); + tt->restore =NULL ; + } + +if (tt->page_flags &TTM_TT_FLAG_PRIV_SHRUNKEN ) + tt->page_flags &= ~(TTM_TT_FLAG_PRIV_SHRUNKEN | +TTM_TT_FLAG_SWAPPED ); +return 0 ; error_free_page:ttm_pool_free_page (pool, page_caching, order, p); error_free_all: +if (tt->page_flags &TTM_TT_FLAG_PRIV_SHRUNKEN ) { + tt->restore->caching_divide = caching; +return r; + } + num_pages = tt->num_pages - num_pages; caching_divide = caching - tt->pages;ttm_pool_free_range (pool, tt, tt->caching,0 , caching_divide);
@@ -543,6 +743,167 @@ void ttm_pool_free(struct ttm_pool *pool, struct ttm_tt *tt) }EXPORT_SYMBOL (ttm_pool_free); +/** +* ttm_pool_release_shrunken() - Release content of a swapped-out struct ttm_tt +* @tt: The struct ttm_tt. +* +* Release swap entries with associated content or any remaining pages of +* a swapped-out struct ttm_tt. +*/ +void ttm_pool_release_shrunken (struct ttm_tt *tt) +{ +struct ttm_backup *backup = tt->backup; +struct ttm_pool_tt_restore *restore; +pgoff_t i, start_page =0 ; +unsigned long handle; + +if (!(tt->page_flags &TTM_TT_FLAG_PRIV_SHRUNKEN )) +return ; + + restore = tt->restore; + +if (ttm_pool_restore_valid (restore)) { +pgoff_t nr =1UL << restore->order; + +for (i = restore->restored_pages; i < nr; ++i) { +struct page *p = restore->old_pages[i]; + +if (ttm_backup_page_ptr_is_handle (p)) { + handle =ttm_backup_page_ptr_to_handle (p); +if (handle ==0 ) +continue ; + + backup->ops->drop (backup, handle); + }else if (p) { +ttm_pool_split_for_swap (restore->pool, p); +__free_pages (p,0 ); + } + } + } + +if (restore) { +pgoff_t mid = restore->caching_divide - tt->pages; + + start_page = restore->alloced_pages; +/* Pages that might be dma-mapped and non-cached */ +ttm_pool_free_range (restore->pool, tt, tt->caching, +0 , mid); +/* Pages that might be dma-mapped but cached */ +ttm_pool_free_range (restore->pool, tt, ttm_cached, + mid, restore->alloced_pages); + } + +/* Shrunken pages. Cached and not dma-mapped. */ +ttm_pool_free_range (NULL , tt, ttm_cached, start_page, tt->num_pages); + +if (restore) { +kvfree (restore); + tt->restore =NULL ; + } + + tt->page_flags &= ~(TTM_TT_FLAG_PRIV_SHRUNKEN |TTM_TT_FLAG_SWAPPED ); +} + +/** +* ttm_pool_shrink_tt() - Swap out or purge a struct ttm_tt +* @pool: The pool used when allocating the struct ttm_tt. +* @ttm: The struct ttm_tt. +* +* Swap out or purge a struct ttm_tt. If @ttm is marked purgeable, then +* all pages will be freed directly to the system rather than to the pool +* they were allocated from, making the function behave similarly to +* ttm_pool_free(). If @ttm is not marked purgeable, the pages will be +* inserted into the swap cache instead, exchanged for a swap entry. +* A subsequent call to ttm_pool_alloc() will then read back the content and +* a subsequent call to ttm_pool_release_shrunken() will drop it. +* If swapout of a page fails for whatever reason, @ttm will still be +* partially swapped out, retaining those pages for which swapout fails. +* +* @Return: Number of pages actually swapped out or freed, or negative +* error code on error. +*/ +long ttm_pool_shrink_tt (struct ttm_pool *pool,struct ttm_tt *ttm,bool purge) +{ +struct ttm_backup *backup = ttm->backup; +struct page *page; +unsigned long handle; +gfp_t alloc_gfp; +gfp_t gfp; +int ret =0 ; +pgoff_t shrunken =0 ; +pgoff_t i, num_pages; + +if ((!get_nr_swap_pages () && purge) || + pool->use_dma_alloc || + (ttm->page_flags &TTM_TT_FLAG_PRIV_SHRUNKEN )) +return -EBUSY ; + +#ifdef CONFIG_X86 +/* Anything returned to the system needs to be cached. */ +if (ttm->caching != ttm_cached) +set_pages_array_wb (ttm->pages, ttm->num_pages); +#endif + +if (ttm->dma_address || purge) { +for (i =0 ; i < ttm->num_pages; i += num_pages) { +unsigned int order; + + page = ttm->pages[i]; +if (unlikely (!page)) +continue ; + + order =1UL <<ttm_pool_page_order (pool, page); + num_pages =1UL << order; +if (ttm->dma_address) +ttm_pool_unmap (pool, ttm->dma_address[i], + num_pages); +if (purge) { + shrunken += num_pages; +__free_pages (page, order); +memset (ttm->pages + i,0 , + num_pages *sizeof (*ttm->pages)); + } + } + } + +if (purge) +return shrunken; + +if (pool->use_dma32) + gfp =GFP_DMA32 ; +else + gfp =GFP_HIGHUSER ; + + alloc_gfp =GFP_KERNEL | __GFP_HIGH | __GFP_NOWARN | __GFP_RETRY_MAYFAIL; + +for (i =0 ; i < ttm->num_pages; ++i) { + page = ttm->pages[i]; +if (unlikely (!page)) +continue ; + +ttm_pool_split_for_swap (pool, page); + +set_page_dirty_lock (page); + handle = backup->ops->backup_page (backup, page, false, i, gfp, alloc_gfp); +if (handle) { + ttm->pages[i] =ttm_backup_handle_to_page_ptr (handle); +put_page (page); + shrunken++; + }else { +/* We allow partially shrunken tts */ + ret = -ENOMEM ; +break ; + } +cond_resched (); + } + +if (shrunken) + ttm->page_flags |= (TTM_TT_FLAG_PRIV_SHRUNKEN | +TTM_TT_FLAG_SWAPPED ); + +return shrunken ? shrunken : ret; +} +/** * ttm_pool_init - Initialize a pool *
drivers/gpu/drm/ttm/ttm_tt.c +32 -0
@@ -39,6 +39,7 @@#include <drm/drm_cache.h> #include <drm/drm_device.h> #include <drm/drm_util.h> +#include <drm/ttm/ttm_backup.h> #include <drm/ttm/ttm_bo.h> #include <drm/ttm/ttm_tt.h>
@@ -157,6 +158,7 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm, ttm->swap_storage =NULL ; ttm->sg = bo->sg; ttm->caching = caching; + ttm->restore =NULL ; } int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo,
@@ -181,6 +183,12 @@ void ttm_tt_fini(struct ttm_tt *ttm)fput (ttm->swap_storage); ttm->swap_storage =NULL ; +ttm_pool_release_shrunken (ttm); +if (ttm->backup) { + ttm->backup->ops->fini (ttm->backup); + ttm->backup =NULL ; + } +if (ttm->pages)kvfree (ttm->pages);else
@@ -251,6 +259,30 @@ int ttm_tt_swapin(struct ttm_tt *ttm)return ret; } +/** +* ttm_tt_shrink() - Helper for the driver bo_shrink() method. +* @bdev: The TTM device. +* @tt: The struct ttm_tt. +* +* Helper for a TTM driver to use from the bo_shrink() method to shrink +* a struct ttm_tt, after it has done the necessary unbinding. This function +* will update the page accounting and call ttm_pool_shrink_tt to free pages +* or move them to the swap cache. +* +* Return: Number of pages freed or swapped out, or negative error code on +* error. +*/ +long ttm_tt_shrink (struct ttm_device *bdev,struct ttm_tt *tt,bool purge) +{ +long ret =ttm_pool_shrink_tt (&bdev->pool, tt, purge); + +if (ret >0 ) + tt->page_flags &= ~TTM_TT_FLAG_PRIV_POPULATED ; + +return ret; +} +EXPORT_SYMBOL (ttm_tt_shrink); +/** * ttm_tt_swapout - swap out tt object *
include/drm/ttm/ttm_pool.h +4 -0
@@ -89,6 +89,10 @@ void ttm_pool_fini(struct ttm_pool *pool);int ttm_pool_debugfs (struct ttm_pool *pool,struct seq_file *m); +void ttm_pool_release_shrunken (struct ttm_tt *tt); + +long ttm_pool_shrink_tt (struct ttm_pool *pool,struct ttm_tt *ttm,bool purge); +int ttm_pool_mgr_init (unsigned long num_pages);void ttm_pool_mgr_fini (void );
include/drm/ttm/ttm_tt.h +12 -0
@@ -32,11 +32,13 @@#include <drm/ttm/ttm_caching.h> #include <drm/ttm/ttm_kmap_iter.h> +struct ttm_backup ;struct ttm_device ;struct ttm_tt ;struct ttm_resource ;struct ttm_buffer_object ;struct ttm_operation_ctx ; +struct ttm_pool_tt_restore ;/** * struct ttm_tt - This is a structure holding the pages, caching- and aperture
@@ -85,6 +87,10 @@ struct ttm_tt {* fault handling abuses the DMA api a bit and dma_map_attrs can't be * used to assure pgprot always matches. * +* TTM_TT_FLAG_PRIV_SHRUNKEN: TTM internal only. This is set if the +* struct ttm_tt has been (possibly partially) swapped out to the +* swap cache. +* * TTM_TT_FLAG_PRIV_POPULATED: TTM internal only. DO NOT USE. This is * set by TTM after ttm_tt_populate() has successfully returned, and is * then unset when TTM calls ttm_tt_unpopulate().
@@ -96,6 +102,7 @@ struct ttm_tt {#define TTM_TT_FLAG_DECRYPTED BIT(4)#define TTM_TT_FLAG_PRIV_POPULATED BIT(5) +#define TTM_TT_FLAG_PRIV_SHRUNKEN BIT(6)uint32_t page_flags;/** @num_pages: Number of pages in the page array. */ uint32_t num_pages;
@@ -105,11 +112,13 @@ struct ttm_tt {dma_addr_t *dma_address;/** @swap_storage: Pointer to shmem struct file for swap storage. */ struct file *swap_storage; +struct ttm_backup *backup;/** * @caching: The current caching state of the pages, see enum * ttm_caching. */ enum ttm_caching caching; +struct ttm_pool_tt_restore *restore; };/**
@@ -230,6 +239,9 @@ void ttm_tt_mgr_init(unsigned long num_pages, unsigned long num_dma32_pages);struct ttm_kmap_iter *ttm_kmap_iter_tt_init (struct ttm_kmap_iter_tt *iter_tt,struct ttm_tt *tt);unsigned long ttm_tt_pages_limit (void ); + +long ttm_tt_shrink (struct ttm_device *bdev,struct ttm_tt *tt,bool purge); +#if IS_ENABLED (CONFIG_AGP )#include <linux/agp_backend.h>
Signature · 1 line
2.44.0
Thomas Hellström
maintainerPATCH 7/8 drm/xe, drm/ttm: Provide a generic LRU walker helper
In reply to Thomas HellströmExport the needed functions from TTM and provide a generic LRU walker in xe, in the spirit of drm_gem_lru_scan() but building on the restartable TTM LRU functionality.
The LRU walker optionally supports locking objects as part of a drm_exec locking transaction, and can thus be used for both exhaustive eviction and shrinking. And, in fact, direct shrinking in the case where we fail to populate system memory objects and want to retry by shrinking purgeable or evictable local objects, which a shrinker is not capable of doing.
The LRU walker helper can easily be moved to TTM when / if used by other drivers.
--- drivers/gpu/drm/ttm/ttm_resource.c | 3 + drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_ttm_helpers.c | 106 ++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_ttm_helpers.h | 33 +++++++++ 4 files changed, 143 insertions(+) create mode 100644 drivers/gpu/drm/xe/xe_ttm_helpers.c create mode 100644 drivers/gpu/drm/xe/xe_ttm_helpers.h
drivers/gpu/drm/ttm/ttm_resource.c +3 -0
@@ -106,6 +106,7 @@ void ttm_resource_cursor_fini(struct ttm_resource_cursor *cursor)ttm_resource_cursor_fini_locked (cursor);spin_unlock (lru_lock); } +EXPORT_SYMBOL (ttm_resource_cursor_fini);/** * ttm_lru_bulk_move_init - initialize a bulk move structure
@@ -635,6 +636,7 @@ ttm_resource_manager_next(struct ttm_resource_cursor *cursor)return NULL ; } +EXPORT_SYMBOL (ttm_resource_manager_next);/** * ttm_resource_manager_first() - Start iterating over the resources
@@ -661,6 +663,7 @@ ttm_resource_manager_first(struct ttm_resource_manager *man,return ttm_resource_manager_next (cursor); } +EXPORT_SYMBOL (ttm_resource_manager_first); static void ttm_kmap_iter_iomap_map_local(struct ttm_kmap_iter *iter, struct iosys_map *dmap,
drivers/gpu/drm/xe/Makefile +1 -0
@@ -132,6 +132,7 @@ xe-y += xe_bb.o \ xe_tile.o \ xe_tile_sysfs.o \ xe_trace.o \ + xe_ttm_helpers.o \ xe_ttm_sys_mgr.o \ xe_ttm_stolen_mgr.o \ xe_ttm_vram_mgr.o \
drivers/gpu/drm/xe/xe_ttm_helpers.c new file +106 -0
106 lines not on this page · raw message
drivers/gpu/drm/xe/xe_ttm_helpers.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2024 Intel Corporation +*/ + +#ifndef _XE_TTM_HELPERS_H_ +#define _XE_TTM_HELPERS_H_ + +#include <linux/types.h> + +struct drm_exec ; +struct ttm_device ; +struct ttm_buffer_object ; +struct ttm_operation_ctx ; +struct ttm_resource_manager ; + +struct xe_ttm_lru_walk ; +struct xe_ttm_lru_walk_ops { +bool (*allow_bo)(struct xe_ttm_lru_walk *walk,struct ttm_buffer_object *bo, +unsigned int mem_type); +long (*process_bo)(struct xe_ttm_lru_walk *walk,struct ttm_buffer_object *bo); +}; + +struct xe_ttm_lru_walk { +const struct xe_ttm_lru_walk_ops *ops; +struct ttm_operation_ctx *ctx; +struct drm_exec *exec; +}; + +long xe_ttm_lru_walk_for_evict (struct xe_ttm_lru_walk *walk,struct ttm_device *bdev, +struct ttm_resource_manager *man,unsigned int mem_type, +long target); +#endif
Signature · 1 line
2.44.0
Thomas Hellström
maintainerPATCH 2/8 drm/ttm: Use LRU hitches
In reply to Thomas HellströmHave iterators insert themselves into the list they are iterating over using hitch list nodes. Since only the iterator owner can remove these list nodes from the list, it's safe to unlock the list and when continuing, use them as a starting point. Due to the way LRU bumping works in TTM, newly added items will not be missed, and bumped items will be iterated over a second time before reaching the end of the list.
The exception is list with bulk move sublists. When bumping a sublist, a hitch that is part of that sublist will also be moved and we might miss items if restarting from it. This will be addressed in a later patch.
v2:
- Updated ttm_resource_cursor_fini() documentation.
--- drivers/gpu/drm/ttm/ttm_bo.c | 1 + drivers/gpu/drm/ttm/ttm_device.c | 9 ++- drivers/gpu/drm/ttm/ttm_resource.c | 94 ++++++++++++++++++++---------- include/drm/ttm/ttm_resource.h | 16 +++-- 4 files changed, 82 insertions(+), 38 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +1 -0
@@ -622,6 +622,7 @@ int ttm_mem_evict_first(struct ttm_device *bdev,if (locked)dma_resv_unlock (res->bo->base.resv); } +ttm_resource_cursor_fini_locked (&cursor);if (!bo) {if (busy_bo && !ttm_bo_get_unless_zero (busy_bo))
drivers/gpu/drm/ttm/ttm_device.c +7 -2
@@ -169,12 +169,17 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx, num_pages =PFN_UP (bo->base.size); ret =ttm_bo_swapout (bo, ctx, gfp_flags);/* ttm_bo_swapout has dropped the lru_lock */ -if (!ret) +if (!ret) { +ttm_resource_cursor_fini (&cursor);return num_pages; -if (ret != -EBUSY ) + } +if (ret != -EBUSY ) { +ttm_resource_cursor_fini (&cursor);return ret; + } } } +ttm_resource_cursor_fini_locked (&cursor);spin_unlock (&bdev->lru_lock);return 0 ; }
drivers/gpu/drm/ttm/ttm_resource.c +63 -31
131 lines not on this page · raw message
include/drm/ttm/ttm_resource.h +11 -5
@@ -271,15 +271,23 @@ ttm_lru_item_to_res(struct ttm_lru_item *item)/** * struct ttm_resource_cursor -* +* @man: The resource manager currently being iterated over +* @hitch: A hitch list node inserted before the next resource +* to iterate over. * @priority: the current priority * * Cursor to iterate over the resources in a manager. */ struct ttm_resource_cursor { +struct ttm_resource_manager *man; +struct ttm_lru_item hitch;unsigned int priority; }; +void ttm_resource_cursor_fini_locked (struct ttm_resource_cursor *cursor); + +void ttm_resource_cursor_fini (struct ttm_resource_cursor *cursor); +/** * struct ttm_lru_bulk_move_pos *
@@ -438,9 +446,7 @@ struct ttm_resource * ttm_resource_manager_first(struct ttm_resource_manager *man, struct ttm_resource_cursor *cursor);struct ttm_resource * -ttm_resource_manager_next (struct ttm_resource_manager *man, -struct ttm_resource_cursor *cursor, -struct ttm_resource *res); +ttm_resource_manager_next (struct ttm_resource_cursor *cursor);/** * ttm_resource_manager_for_each_res - iterate over all resources
@@ -452,7 +458,7 @@ ttm_resource_manager_next(struct ttm_resource_manager *man,*/ #define ttm_resource_manager_for_each_res (man, cursor, res) \ for (res = ttm_resource_manager_first(man, cursor); res; \ - res = ttm_resource_manager_next(man, cursor, res)) + res = ttm_resource_manager_next(cursor))struct ttm_kmap_iter * ttm_kmap_iter_iomap_init(struct ttm_kmap_iter_iomap *iter_io,
Signature · 1 line
2.44.0
Thomas Hellström
maintainerPATCH 8/8 drm/xe: Add a shrinker for xe bos
In reply to Thomas HellströmRather than relying on the TTM watermark accounting add a shrinker for xe_bos in TT or system memory.
Leverage the newly added TTM per-page shrinking and shmem backup support.
Although xe doesn't fully support WONTNEED (purgeable) bos yet, introduce and add shrinker support for purgeable ttm_tts.
--- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_bo.c | 106 +++++++++++--- drivers/gpu/drm/xe/xe_bo.h | 3 + drivers/gpu/drm/xe/xe_device.c | 8 ++ drivers/gpu/drm/xe/xe_device_types.h | 2 + drivers/gpu/drm/xe/xe_shrinker.c | 204 +++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_shrinker.h | 18 +++ drivers/gpu/drm/xe/xe_ttm_helpers.c | 60 ++++++++ drivers/gpu/drm/xe/xe_ttm_helpers.h | 3 + 9 files changed, 388 insertions(+), 17 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_shrinker.c create mode 100644 drivers/gpu/drm/xe/xe_shrinker.h
drivers/gpu/drm/xe/Makefile +1 -0
@@ -127,6 +127,7 @@ xe-y += xe_bb.o \ xe_ring_ops.o \ xe_sa.o \ xe_sched_job.o \ + xe_shrinker.o \ xe_step.o \ xe_sync.o \ xe_tile.o \
drivers/gpu/drm/xe/xe_bo.c +89 -17
223 lines not on this page · raw message
drivers/gpu/drm/xe/xe_bo.h +3 -0
@@ -93,6 +93,7 @@#define XE_BO_PROPS_INVALID (-1)struct sg_table ; +struct xe_ttm_lru_walk ;struct xe_bo *xe_bo_alloc (void );void xe_bo_free (struct xe_bo *bo);
@@ -344,6 +345,8 @@ static inline unsigned int xe_sg_segment_size(struct device *dev)#define i915_gem_object_flush_if_display (obj) ((void)(obj)) +long xe_bo_shrinker_process (struct xe_ttm_lru_walk *walk,struct ttm_buffer_object *bo); +#if IS_ENABLED (CONFIG_DRM_XE_KUNIT_TEST )/** * xe_bo_is_mem_type - Whether the bo currently resides in the given
drivers/gpu/drm/xe/xe_device.c +8 -0
@@ -38,6 +38,7 @@#include "xe_pcode.h" #include "xe_pm.h" #include "xe_query.h" +#include "xe_shrinker.h" #include "xe_sriov.h" #include "xe_tile.h" #include "xe_ttm_stolen_mgr.h"
@@ -232,6 +233,9 @@ static void xe_device_destroy(struct drm_device *dev, void *dummy)if (xe->unordered_wq)destroy_workqueue (xe->unordered_wq); +if (!IS_ERR_OR_NULL (xe->mem.shrinker)) +xe_shrinker_destroy (xe->mem.shrinker); +ttm_device_fini (&xe->ttm); }
@@ -261,6 +265,10 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,if (err) goto err; + xe->mem.shrinker =xe_shrinker_create (xe); +if (IS_ERR (xe->mem.shrinker)) +return ERR_CAST (xe->mem.shrinker); + xe->info.devid = pdev->device; xe->info.revid = pdev->revision; xe->info.force_execlist = xe_modparam.force_execlist;
drivers/gpu/drm/xe/xe_device_types.h +2 -0
@@ -315,6 +315,8 @@ struct xe_device {struct xe_mem_region vram;/** @mem.sys_mgr: system TTM manager */ struct ttm_resource_manager sys_mgr; +/** @mem.sys_mgr: system memory shrinker. */ +struct xe_shrinker *shrinker; } mem;/** @sriov: device level virtualization data */
drivers/gpu/drm/xe/xe_shrinker.c new file +204 -0
204 lines not on this page · raw message
drivers/gpu/drm/xe/xe_shrinker.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Copyright © 2024 Intel Corporation +*/ + +#ifndef _XE_SHRINKER_H_ +#define _XE_SHRINKER_H_ + +struct xe_shrinker ; +struct xe_device ; + +void xe_shrinker_mod_pages (struct xe_shrinker *shrinker,long shrinkable,long purgeable); + +struct xe_shrinker *xe_shrinker_create (struct xe_device *xe); + +void xe_shrinker_destroy (struct xe_shrinker *shrinker); + +#endif
drivers/gpu/drm/xe/xe_ttm_helpers.c +60 -0
66 lines not on this page · raw message
drivers/gpu/drm/xe/xe_ttm_helpers.h +3 -0
@@ -27,6 +27,9 @@ struct xe_ttm_lru_walk {struct drm_exec *exec; }; +long xe_ttm_bo_try_shrink (struct xe_ttm_lru_walk *walk,struct ttm_buffer_object *bo, +bool purge); +long xe_ttm_lru_walk_for_evict (struct xe_ttm_lru_walk *walk,struct ttm_device *bdev,struct ttm_resource_manager *man,unsigned int mem_type,long target);
Signature · 1 line
2.44.0
Thomas Hellström
maintainerPATCH 1/8 drm/ttm: Allow TTM LRU list nodes of different types
In reply to Thomas HellströmTo be able to handle list unlocking while traversing the LRU list, we want the iterators not only to point to the next position of the list traversal, but to insert themselves as list nodes at that point to work around the fact that the next node might otherwise disappear from the list while the iterator is pointing to it.
These list nodes need to be easily distinguishable from other list nodes so that others traversing the list can skip over them.
So declare a struct ttm_lru_item, with a struct list_head member and a type enum. This will slightly increase the size of a struct ttm_resource.
v2:
- Update enum ttm_lru_item_type documentation.
--- drivers/gpu/drm/ttm/ttm_device.c | 13 ++++-- drivers/gpu/drm/ttm/ttm_resource.c | 70 ++++++++++++++++++++++-------- include/drm/ttm/ttm_resource.h | 51 +++++++++++++++++++++- 3 files changed, 110 insertions(+), 24 deletions(-)
drivers/gpu/drm/ttm/ttm_device.c +9 -4
@@ -270,17 +270,22 @@ EXPORT_SYMBOL(ttm_device_fini);static void ttm_device_clear_lru_dma_mappings (struct ttm_device *bdev,struct list_head *list) { -struct ttm_resource *res; +struct ttm_lru_item *lru;spin_lock (&bdev->lru_lock); -while ((res =list_first_entry_or_null (list,typeof (*res), lru))) { -struct ttm_buffer_object *bo = res->bo; +while ((lru =list_first_entry_or_null (list,typeof (*lru), link))) { +struct ttm_buffer_object *bo; + +if (!ttm_lru_item_is_res (lru)) +continue ; + + bo =ttm_lru_item_to_res (lru)->bo;/* Take ref against racing releases once lru_lock is unlocked */ if (!ttm_bo_get_unless_zero (bo))continue ; -list_del_init (&res->lru); +list_del_init (&bo->resource->lru.link);spin_unlock (&bdev->lru_lock);if (bo->ttm)
drivers/gpu/drm/ttm/ttm_resource.c +51 -19
143 lines not on this page · raw message
include/drm/ttm/ttm_resource.h +50 -1
65 lines not on this page · raw message
Signature · 1 line
2.44.0
Patchwork
CI✓ CI.Patch_applied: success for drm/ttm, drm/xe: Shrinker support
In reply to Thomas Hellström== Series Details ==
== Series Details ==
Series: drm/ttm, drm/xe: Shrinker support
URL : https://patchwork.freedesktop.org/series/131695/
State : success
== Summary ==
=== Applying kernel patches on branch 'drm-tip' with base: ===
Base commit: 426c7cf8b01f drm-tip: 2024y-03m-27d-11h-14m-14s UTC integration manifest === git am output follows ===
Applying: drm/ttm: Allow TTM LRU list nodes of different types
Applying: drm/ttm: Use LRU hitches
Applying: drm/ttm, drm/amdgpu, drm/xe: Consider hitch moves within bulk sublist moves
Applying: drm/ttm: Allow continued swapout after -ENOSPC falure
Applying: drm/ttm: Add a virtual base class for graphics memory backup
Applying: drm/ttm/pool: Provide a helper to shrink pages.
Applying: drm/xe, drm/ttm: Provide a generic LRU walker helper
Applying: drm/xe: Add a shrinker for xe bos
Patchwork
CI✗ CI.checkpatch: warning for drm/ttm, drm/xe: Shrinker support
In reply to Thomas Hellström== Series Details ==
== Series Details ==
Series: drm/ttm, drm/xe: Shrinker support
URL : https://patchwork.freedesktop.org/series/131695/
State : warning
== Summary ==
+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master 10b531c2aeb176a1a539b4a77216232f97719cec
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit a75bf375727b650534aec619354356fd1902f4e7
Author: Thomas Hellström <[email protected]> Date: Wed Mar 27 17:05:36 2024 +0100
drm/xe: Add a shrinker for xe bos
Rather than relying on the TTM watermark accounting add a shrinker for xe_bos in TT or system memory.
Leverage the newly added TTM per-page shrinking and shmem backup support.
Although xe doesn't fully support WONTNEED (purgeable) bos yet, introduce and add shrinker support for purgeable ttm_tts.
+ /mt/dim checkpatch 426c7cf8b01f87def935a357bfd76712c4f03016 drm-intel 3fefcf8de6d0 drm/ttm: Allow TTM LRU list nodes of different types51ac3feac7e7 drm/ttm: Use LRU hitches607c80a531e4 drm/ttm, drm/amdgpu, drm/xe: Consider hitch moves within bulk sublist moves f4012c9f6975 drm/ttm: Allow continued swapout after -ENOSPC falure4d825ae7c888 drm/ttm: Add a virtual base class for graphics memory backup Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
-:38: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #38:
new file mode 100644
total: 0 errors, 1 warnings, 0 checks, 178 lines checked18884d795b6f drm/ttm/pool: Provide a helper to shrink pages.96f9105a3054 drm/xe, drm/ttm: Provide a generic LRU walker helper
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
-:66: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #66:
new file mode 100644
total: 0 errors, 1 warnings, 0 checks, 167 lines checkeda75bf375727b drm/xe: Add a shrinker for xe bos
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
Traceback (most recent call last):
File "scripts/spdxcheck.py", line 6, in <module>
from ply import lex, yacc
ModuleNotFoundError: No module named 'ply'
-:340: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #340:
new file mode 100644
total: 0 errors, 1 warnings, 0 checks, 576 lines checked
Patchwork
CI✗ CI.KUnit: failure for drm/ttm, drm/xe: Shrinker support
In reply to Thomas Hellström== Series Details ==
== Series Details ==
Series: drm/ttm, drm/xe: Shrinker support
URL : https://patchwork.freedesktop.org/series/131695/
State : failure
== Summary ==
+ trap cleanup EXIT
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig ERROR:root:../arch/x86/um/user-offsets.c:17:6: warning: no previous prototype for ‘foo’ [-Wmissing-prototypes] 17 | void foo(void)
| ^~~
In file included from ../arch/um/kernel/asm-offsets.c:1:../arch/x86/um/shared/sysdep/kernel-offsets.h:9:6: warning: no previous prototype for ‘foo’ [-Wmissing-prototypes]
9 | void foo(void)
| ^~~../arch/x86/um/bugs_64.c:9:6: warning: no previous prototype for ‘arch_check_bugs’ [-Wmissing-prototypes]
9 | void arch_check_bugs(void)
| ^~~~~~~~~~~~~~~../arch/x86/um/bugs_64.c:13:6: warning: no previous prototype for ‘arch_examine_signal’ [-Wmissing-prototypes]
13 | void arch_examine_signal(int sig, struct uml_pt_regs *regs)
| ^~~~~~~~~~~~~~~~~~~
../arch/x86/um/fault.c:18:5: warning: no previous prototype for ‘arch_fixup’ [-Wmissing-prototypes]
18 | int arch_fixup(unsigned long address, struct uml_pt_regs *regs)
| ^~~~~~~~~~
../arch/x86/um/os-Linux/registers.c:146:15: warning: no previous prototype for ‘get_thread_reg’ [-Wmissing-prototypes]
146 | unsigned long get_thread_reg(int reg, jmp_buf *buf)
| ^~~~~~~~~~~~~~
../arch/um/os-Linux/skas/process.c:107:6: warning: no previous prototype for ‘wait_stub_done’ [-Wmissing-prototypes]
107 | void wait_stub_done(int pid)
| ^~~~~~~~~~~~~~
../arch/um/os-Linux/skas/process.c:683:6: warning: no previous prototype for ‘__switch_mm’ [-Wmissing-prototypes]
683 | void __switch_mm(struct mm_id *mm_idp)
| ^~~~~~~~~~~
../arch/x86/um/vdso/um_vdso.c:16:5: warning: no previous prototype for ‘__vdso_clock_gettime’ [-Wmissing-prototypes]
16 | int __vdso_clock_gettime(clockid_t clock, struct __kernel_old_timespec *ts)
| ^~~~~~~~~~~~~~~~~~~~
../arch/x86/um/vdso/um_vdso.c:30:5: warning: no previous prototype for ‘__vdso_gettimeofday’ [-Wmissing-prototypes]
30 | int __vdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
| ^~~~~~~~~~~~~~~~~~~
../arch/x86/um/vdso/um_vdso.c:44:21: warning: no previous prototype for ‘__vdso_time’ [-Wmissing-prototypes]
44 | __kernel_old_time_t __vdso_time(__kernel_old_time_t *t)
| ^~~~~~~~~~~
../arch/x86/um/vdso/um_vdso.c:57:1: warning: no previous prototype for ‘__vdso_getcpu’ [-Wmissing-prototypes]
57 | __vdso_getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *unused)
| ^~~~~~~~~~~~~../arch/x86/um/os-Linux/mcontext.c:7:6: warning: no previous prototype for ‘get_regs_from_mc’ [-Wmissing-prototypes]
7 | void get_regs_from_mc(struct uml_pt_regs *regs, mcontext_t *mc)
| ^~~~~~~~~~~~~~~~../arch/um/os-Linux/main.c:187:7: warning: no previous prototype for ‘__wrap_malloc’ [-Wmissing-prototypes]
187 | void *__wrap_malloc(int size)
| ^~~~~~~~~~~~~
../arch/um/os-Linux/main.c:208:7: warning: no previous prototype for ‘__wrap_calloc’ [-Wmissing-prototypes]
208 | void *__wrap_calloc(int n, int size)
| ^~~~~~~~~~~~~
../arch/um/os-Linux/main.c:222:6: warning: no previous prototype for ‘__wrap_free’ [-Wmissing-prototypes]
222 | void __wrap_free(void *ptr)
| ^~~~~~~~~~~
../arch/um/kernel/skas/process.c:36:12: warning: no previous prototype for ‘start_uml’ [-Wmissing-prototypes]
36 | int __init start_uml(void)
| ^~~~~~~~~
../arch/um/os-Linux/mem.c:28:6: warning: no previous prototype for ‘kasan_map_memory’ [-Wmissing-prototypes]
28 | void kasan_map_memory(void *start, size_t len)
| ^~~~~~~~~~~~~~~~
../arch/um/os-Linux/mem.c:212:13: warning: no previous prototype for ‘check_tmpexec’ [-Wmissing-prototypes]
212 | void __init check_tmpexec(void)
| ^~~~~~~~~~~~~
../arch/um/kernel/skas/mmu.c:17:5: warning: no previous prototype for ‘init_new_context’ [-Wmissing-prototypes]
17 | int init_new_context(struct task_struct *task, struct mm_struct *mm)
| ^~~~~~~~~~~~~~~~
../arch/um/kernel/skas/mmu.c:60:6: warning: no previous prototype for ‘destroy_context’ [-Wmissing-prototypes]
60 | void destroy_context(struct mm_struct *mm)
| ^~~~~~~~~~~~~~~
../arch/um/os-Linux/signal.c:75:6: warning: no previous prototype for ‘sig_handler’ [-Wmissing-prototypes]
75 | void sig_handler(int sig, struct siginfo *si, mcontext_t *mc)
| ^~~~~~~~~~~
../arch/um/os-Linux/signal.c:111:6: warning: no previous prototype for ‘timer_alarm_handler’ [-Wmissing-prototypes]
111 | void timer_alarm_handler(int sig, struct siginfo *unused_si, mcontext_t *mc)
| ^~~~~~~~~~~~~~~~~~~
../arch/um/os-Linux/start_up.c:301:12: warning: no previous prototype for ‘parse_iomem’ [-Wmissing-prototypes]
301 | int __init parse_iomem(char *str, int *add)
| ^~~~~~~~~~~
../arch/x86/um/ptrace_64.c:111:5: warning: no previous prototype for ‘poke_user’ [-Wmissing-prototypes]
111 | int poke_user(struct task_struct *child, long addr, long data)
| ^~~~~~~~~
../arch/x86/um/ptrace_64.c:171:5: warning: no previous prototype for ‘peek_user’ [-Wmissing-prototypes]
171 | int peek_user(struct task_struct *child, long addr, long data)
| ^~~~~~~~~
../arch/x86/um/signal.c:560:6: warning: no previous prototype for ‘sys_rt_sigreturn’ [-Wmissing-prototypes]
560 | long sys_rt_sigreturn(void)
| ^~~~~~~~~~~~~~~~
../arch/um/kernel/mem.c:202:8: warning: no previous prototype for ‘pgd_alloc’ [-Wmissing-prototypes]
202 | pgd_t *pgd_alloc(struct mm_struct *mm)
| ^~~~~~~~~
../arch/um/kernel/mem.c:215:7: warning: no previous prototype for ‘uml_kmalloc’ [-Wmissing-prototypes]
215 | void *uml_kmalloc(int size, int flags)
| ^~~~~~~~~~~
../arch/um/kernel/process.c:51:5: warning: no previous prototype for ‘pid_to_processor_id’ [-Wmissing-prototypes]
51 | int pid_to_processor_id(int pid)
| ^~~~~~~~~~~~~~~~~~~
../arch/um/kernel/process.c:87:7: warning: no previous prototype for ‘__switch_to’ [-Wmissing-prototypes]
87 | void *__switch_to(struct task_struct *from, struct task_struct *to)
| ^~~~~~~~~~~
../arch/um/kernel/process.c:140:6: warning: no previous prototype for ‘fork_handler’ [-Wmissing-prototypes]
140 | void fork_handler(void)
| ^~~~~~~~~~~~
../arch/um/kernel/process.c:217:6: warning: no previous prototype for ‘arch_cpu_idle’ [-Wmissing-prototypes]
217 | void arch_cpu_idle(void)
| ^~~~~~~~~~~~~
../arch/um/kernel/process.c:253:5: warning: no previous prototype for ‘copy_to_user_proc’ [-Wmissing-prototypes]
253 | int copy_to_user_proc(void __user *to, void *from, int size)
| ^~~~~~~~~~~~~~~~~
../arch/um/kernel/process.c:263:5: warning: no previous prototype for ‘clear_user_proc’ [-Wmissing-prototypes]
263 | int clear_user_proc(void __user *buf, int size)
| ^~~~~~~~~~~~~~~
../arch/um/kernel/process.c:271:6: warning: no previous prototype for ‘set_using_sysemu’ [-Wmissing-prototypes]
271 | void set_using_sysemu(int value)
| ^~~~~~~~~~~~~~~~
../arch/um/kernel/process.c:278:5: warning: no previous prototype for ‘get_using_sysemu’ [-Wmissing-prototypes]
278 | int get_using_sysemu(void)
| ^~~~~~~~~~~~~~~~
../arch/um/kernel/process.c:316:12: warning: no previous prototype for ‘make_proc_sysemu’ [-Wmissing-prototypes]
316 | int __init make_proc_sysemu(void)
| ^~~~~~~~~~~~~~~~
../arch/um/kernel/process.c:348:15: warning: no previous prototype for ‘arch_align_stack’ [-Wmissing-prototypes]
348 | unsigned long arch_align_stack(unsigned long sp)
| ^~~~~~~~~~~~~~~~
../arch/um/kernel/reboot.c:45:6: warning: no previous prototype for ‘machine_restart’ [-Wmissing-prototypes]
45 | void machine_restart(char * __unused)
| ^~~~~~~~~~~~~~~
../arch/um/kernel/reboot.c:51:6: warning: no previous prototype for ‘machine_power_off’ [-Wmissing-prototypes]
51 | void machine_power_off(void)
| ^~~~~~~~~~~~~~~~~
../arch/um/kernel/reboot.c:57:6: warning: no previous prototype for ‘machine_halt’ [-Wmissing-prototypes]
57 | void machine_halt(void)
| ^~~~~~~~~~~~
../arch/x86/um/syscalls_64.c:48:6: warning: no previous prototype for ‘arch_switch_to’ [-Wmissing-prototypes]
48 | void arch_switch_to(struct task_struct *to)
| ^~~~~~~~~~~~~~
../arch/um/kernel/tlb.c:579:6: warning: no previous prototype for ‘flush_tlb_mm_range’ [-Wmissing-prototypes]
579 | void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start,
| ^~~~~~~~~~~~~~~~~~
../arch/um/kernel/tlb.c:594:6: warning: no previous prototype for ‘force_flush_all’ [-Wmissing-prototypes]
594 | void force_flush_all(void)
| ^~~~~~~~~~~~~~~
../arch/um/kernel/um_arch.c:408:19: warning: no previous prototype for ‘read_initrd’ [-Wmissing-prototypes]
408 | int __init __weak read_initrd(void)
| ^~~~~~~~~~~
../arch/um/kernel/um_arch.c:461:7: warning: no previous prototype for ‘text_poke’ [-Wmissing-prototypes]
461 | void *text_poke(void *addr, const void *opcode, size_t len)
| ^~~~~~~~~
../arch/um/kernel/um_arch.c:473:6: warning: no previous prototype for ‘text_poke_sync’ [-Wmissing-prototypes]
473 | void text_poke_sync(void)
| ^~~~~~~~~~~~~~
../arch/um/kernel/kmsg_dump.c:60:12: warning: no previous prototype for ‘kmsg_dumper_stdout_init’ [-Wmissing-prototypes]
60 | int __init kmsg_dumper_stdout_init(void)
| ^~~~~~~~~~~~~~~~~~~~~~~../drivers/gpu/drm/ttm/ttm_pool.c: In function ‘ttm_pool_swapin’:../drivers/gpu/drm/ttm/ttm_pool.c:443:38: error: macro "copy_page" passed 4 arguments, but takes just 2
443 | handle, ctx->interruptible);
| ^
In file included from ../arch/um/include/asm/thread_info.h:15,
from ../include/linux/thread_info.h:60,
from ../include/asm-generic/preempt.h:5,
from ./arch/um/include/generated/asm/preempt.h:1,
from ../include/linux/preempt.h:79,
from ../include/linux/spinlock.h:56,
from ../include/linux/mmzone.h:8,
from ../include/linux/gfp.h:7,
from ../include/linux/umh.h:4,
from ../include/linux/kmod.h:9,
from ../include/linux/module.h:17,
from ../drivers/gpu/drm/ttm/ttm_pool.c:34:
../arch/um/include/asm/page.h:30: note: macro "copy_page" defined here
30 | #define copy_page(to,from) memcpy((void *)(to), (void *)(from), PAGE_SIZE)
| ../drivers/gpu/drm/ttm/ttm_pool.c:442:8: warning: assignment to ‘int’ from ‘int (* const)(struct ttm_backup *, struct page *, long unsigned int, bool)’ {aka ‘int (* const)(struct ttm_backup *, struct page *, long unsigned int, _Bool)’} makes integer from pointer without a cast [-Wint-conversion]
442 | ret = backup->ops->copy_page(backup, restore->first_page[i],
| ^
make[7]: *** [../scripts/Makefile.build:244: drivers/gpu/drm/ttm/ttm_pool.o] Error 1
make[7]: *** Waiting for unfinished jobs....
make[6]: *** [../scripts/Makefile.build:485: drivers/gpu/drm/ttm] Error 2
make[6]: *** Waiting for unfinished jobs....../lib/iomap.c:156:5: warning: no previous prototype for ‘ioread64_lo_hi’ [-Wmissing-prototypes]
156 | u64 ioread64_lo_hi(const void __iomem *addr)
| ^~~~~~~~~~~~~~
../lib/iomap.c:163:5: warning: no previous prototype for ‘ioread64_hi_lo’ [-Wmissing-prototypes]
163 | u64 ioread64_hi_lo(const void __iomem *addr)
| ^~~~~~~~~~~~~~
../lib/iomap.c:170:5: warning: no previous prototype for ‘ioread64be_lo_hi’ [-Wmissing-prototypes]
170 | u64 ioread64be_lo_hi(const void __iomem *addr)
| ^~~~~~~~~~~~~~~~
../lib/iomap.c:178:5: warning: no previous prototype for ‘ioread64be_hi_lo’ [-Wmissing-prototypes]
178 | u64 ioread64be_hi_lo(const void __iomem *addr)
| ^~~~~~~~~~~~~~~~
../lib/iomap.c:264:6: warning: no previous prototype for ‘iowrite64_lo_hi’ [-Wmissing-prototypes]
264 | void iowrite64_lo_hi(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~
../lib/iomap.c:272:6: warning: no previous prototype for ‘iowrite64_hi_lo’ [-Wmissing-prototypes]
272 | void iowrite64_hi_lo(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~
../lib/iomap.c:280:6: warning: no previous prototype for ‘iowrite64be_lo_hi’ [-Wmissing-prototypes]
280 | void iowrite64be_lo_hi(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~~~
../lib/iomap.c:288:6: warning: no previous prototype for ‘iowrite64be_hi_lo’ [-Wmissing-prototypes]
288 | void iowrite64be_hi_lo(u64 val, void __iomem *addr)
| ^~~~~~~~~~~~~~~~~make[5]: *** [../scripts/Makefile.build:485: drivers/gpu/drm] Error 2 make[4]: *** [../scripts/Makefile.build:485: drivers/gpu] Error 2 make[3]: *** [../scripts/Makefile.build:485: drivers] Error 2 make[2]: *** [/kernel/Makefile:1919: .] Error 2
make[1]: *** [/kernel/Makefile:240: __sub-make] Error 2
make: *** [Makefile:240: __sub-make] Error 2
[16:11:43] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig [16:11:47] Building KUnit Kernel ... Populating config with: $ make ARCH=um O=.kunit olddefconfig Building with: $ make ARCH=um O=.kunit --jobs=48 + cleanup ++ stat -c %u:%g /kernel + chown -R 1003:1003 /kernel