Re: [PATCH v2 9/9] drm/xe: Add a shrinker for xe bos
Hi Thomas, kernel test robot noticed the following build warnings: [auto build test WARNING on drm-xe/drm-xe-next] [also build test WARNING on drm-intel/for-linux-next-fixes drm-tip/drm-tip linus/master v6.9-rc4 next-20240417] [cannot apply to drm-misc/drm-misc-next drm/drm-next drm-exynos/exynos-drm-next drm-intel/for-linux-next] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Thomas-Hellstr-m/drm-ttm-Allow-TTM-LRU-list-nodes-of-different-types/20240416-181717 base: https://gitlab.freedesktop.org/drm/xe/kernel.git drm-xe-next patch link: https://lore.kernel.org/r/20240416100730.-10-thomas.hellstrom%40linux.intel.com patch subject: [PATCH v2 9/9] drm/xe: Add a shrinker for xe bos config: powerpc-randconfig-001-20240417 (https://download.01.org/0day-ci/archive/20240417/202404172100.qxirere7-...@intel.com/config) compiler: powerpc-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240417/202404172100.qxirere7-...@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202404172100.qxirere7-...@intel.com/ All warnings (new ones prefixed by >>): In file included from include/asm-generic/bug.h:22, from arch/powerpc/include/asm/bug.h:116, from include/linux/bug.h:5, from include/linux/mmdebug.h:5, from include/linux/mm.h:6, from include/linux/pagemap.h:8, from include/drm/ttm/ttm_tt.h:30, from drivers/gpu/drm/xe/xe_bo.h:9, from drivers/gpu/drm/xe/xe_bo.c:6: drivers/gpu/drm/xe/tests/xe_bo.c: In function 'shrink_test_run_device': include/linux/kern_levels.h:5:25: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'size_t' {aka 'unsigned int'} [-Wformat=] 5 | #define KERN_SOH"\001" /* ASCII Start Of Header */ | ^~ include/linux/printk.h:429:25: note: in definition of macro 'printk_index_wrap' 429 | _p_func(_fmt, ##__VA_ARGS__); \ | ^~~~ include/kunit/test.h:527:17: note: in expansion of macro 'printk' 527 | printk(lvl fmt, ##__VA_ARGS__); \ | ^~ include/kunit/test.h:533:9: note: in expansion of macro 'kunit_log' 533 | kunit_log(lvl, test, KUNIT_SUBTEST_INDENT "# %s: " fmt, \ | ^ include/kunit/test.h:546:9: note: in expansion of macro 'kunit_printk' 546 | kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__) | ^~~~ include/linux/kern_levels.h:14:25: note: in expansion of macro 'KERN_SOH' 14 | #define KERN_INFO KERN_SOH "6"/* informational */ | ^~~~ include/kunit/test.h:546:22: note: in expansion of macro 'KERN_INFO' 546 | kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__) | ^ drivers/gpu/drm/xe/tests/xe_bo.c:381:9: note: in expansion of macro 'kunit_info' 381 | kunit_info(test, "Free ram is %lu bytes. Will allocate twice of that.\n", | ^~ In file included from drivers/gpu/drm/xe/tests/xe_bo.c:6, from drivers/gpu/drm/xe/xe_bo.c:2420: >> include/kunit/test.h:50:41: warning: format '%lu' expects argument of type >> 'long unsigned int', but argument 4 has type 'size_t' {aka 'unsigned int'} >> [-Wformat=] 50 | #define KUNIT_SUBTEST_INDENT"" | ^~ include/kunit/test.h:528:57: note: in definition of macro 'kunit_log' 528 | kunit_log_append((test_or_suite)->log, fmt, \ | ^~~ include/kunit/test.h:533:30: note: in expansion of macro 'KUNIT_SUBTEST_INDENT' 533 | kunit_log(lvl, test, KUNIT_SUBTEST_INDENT "# %s: " fmt, \ | ^~~~ include/kunit/test.h:546:9: note: in expansion of macro 'kunit_printk' 546 | kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__) | ^~~~ drivers/gpu/drm/xe/tests/xe_bo.c:381:9: note: in expansion of macro 'kunit_info' 381 | kunit_info(test, "Free ram is %lu bytes. Wi
Re: [PATCH v2 9/9] drm/xe: Add a shrinker for xe bos
Hi Thomas, kernel test robot noticed the following build warnings: [auto build test WARNING on drm-xe/drm-xe-next] [also build test WARNING on drm-intel/for-linux-next-fixes drm-tip/drm-tip linus/master v6.9-rc4 next-20240416] [cannot apply to drm-misc/drm-misc-next drm/drm-next drm-exynos/exynos-drm-next drm-intel/for-linux-next] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Thomas-Hellstr-m/drm-ttm-Allow-TTM-LRU-list-nodes-of-different-types/20240416-181717 base: https://gitlab.freedesktop.org/drm/xe/kernel.git drm-xe-next patch link: https://lore.kernel.org/r/20240416100730.-10-thomas.hellstrom%40linux.intel.com patch subject: [PATCH v2 9/9] drm/xe: Add a shrinker for xe bos config: i386-buildonly-randconfig-001-20240417 (https://download.01.org/0day-ci/archive/20240417/202404170528.tbjgqkcr-...@intel.com/config) compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240417/202404170528.tbjgqkcr-...@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot | Closes: https://lore.kernel.org/oe-kbuild-all/202404170528.tbjgqkcr-...@intel.com/ All warnings (new ones prefixed by >>): In file included from drivers/gpu/drm/xe/xe_bo.c:2420: >> drivers/gpu/drm/xe/tests/xe_bo.c:382:6: warning: format specifies type >> 'unsigned long' but the argument has type 'size_t' (aka 'unsigned int') >> [-Wformat] 381 | kunit_info(test, "Free ram is %lu bytes. Will allocate twice of that.\n", | ~~~ | %zu 382 |total); |^ include/kunit/test.h:546:39: note: expanded from macro 'kunit_info' 546 | kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__) | ~~~^~~ include/kunit/test.h:534:21: note: expanded from macro 'kunit_printk' 533 | kunit_log(lvl, test, KUNIT_SUBTEST_INDENT "# %s: " fmt, \ |~~~ 534 | (test)->name, ##__VA_ARGS__) | ^~~ include/kunit/test.h:527:21: note: expanded from macro 'kunit_log' 527 | printk(lvl fmt, ##__VA_ARGS__); \ |~~~^~~ include/linux/printk.h:457:60: note: expanded from macro 'printk' 457 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__) | ~~~ ^~~ include/linux/printk.h:429:19: note: expanded from macro 'printk_index_wrap' 429 | _p_func(_fmt, ##__VA_ARGS__); \ | ^~~ In file included from drivers/gpu/drm/xe/xe_bo.c:2420: >> drivers/gpu/drm/xe/tests/xe_bo.c:382:6: warning: format specifies type >> 'unsigned long' but the argument has type 'size_t' (aka 'unsigned int') >> [-Wformat] 381 | kunit_info(test, "Free ram is %lu bytes. Will allocate twice of that.\n", | ~~~ | %zu 382 |total); |^ include/kunit/test.h:546:39: note: expanded from macro 'kunit_info' 546 | kunit_printk(KERN_INFO, test, fmt, ##__VA_ARGS__) | ~~~^~~ include/kunit/test.h:534:21: note: expanded from macro 'kunit_printk' 533 | kunit_log(lvl, test, KUNIT_SUBTEST_INDENT "# %s: " fmt, \ |~~~ 534 | (test)->name, ##__VA_ARGS__) | ^~~ include/kunit/test.h:529:8: note: expanded from macro 'kunit_log' 528 | kunit_log_append((test_or_suite)->log, fmt, \ | ~~~ 529 | ##__VA_ARGS__); \ |^~~ 2 warnings generated. vim +382 drivers/gpu/drm/xe/tests/xe_bo.c 362 363 /* 364 * Try to create system bos corresponding to twice the amount
[PATCH v2 9/9] 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. v2: - Cleanups bugfixes and a KUNIT shrinker test. - Add writeback support, and activate if kswapd. Signed-off-by: Thomas Hellström --- drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/tests/xe_bo.c | 118 ++ drivers/gpu/drm/xe/tests/xe_bo_test.c | 1 + drivers/gpu/drm/xe/tests/xe_bo_test.h | 1 + drivers/gpu/drm/xe/xe_bo.c| 145 +++-- drivers/gpu/drm/xe/xe_bo.h| 4 + drivers/gpu/drm/xe/xe_device.c| 8 + drivers/gpu/drm/xe/xe_device_types.h | 2 + drivers/gpu/drm/xe/xe_shrinker.c | 226 ++ drivers/gpu/drm/xe/xe_shrinker.h | 18 ++ drivers/gpu/drm/xe/xe_ttm_helpers.c | 75 + drivers/gpu/drm/xe/xe_ttm_helpers.h | 3 + 12 files changed, 585 insertions(+), 17 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_shrinker.c create mode 100644 drivers/gpu/drm/xe/xe_shrinker.h diff --git a/drivers/gpu/drm/xe/Makefile b/drivers/gpu/drm/xe/Makefile index 50613f0fe635..99ce034d7e2a 100644 --- a/drivers/gpu/drm/xe/Makefile +++ b/drivers/gpu/drm/xe/Makefile @@ -130,6 +130,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 \ diff --git a/drivers/gpu/drm/xe/tests/xe_bo.c b/drivers/gpu/drm/xe/tests/xe_bo.c index 9f3c02826464..7576d362020f 100644 --- a/drivers/gpu/drm/xe/tests/xe_bo.c +++ b/drivers/gpu/drm/xe/tests/xe_bo.c @@ -6,6 +6,8 @@ #include #include +#include + #include "tests/xe_bo_test.h" #include "tests/xe_pci_test.h" #include "tests/xe_test.h" @@ -350,3 +352,119 @@ void xe_bo_evict_kunit(struct kunit *test) xe_call_for_each_device(evict_test_run_device); } EXPORT_SYMBOL_IF_KUNIT(xe_bo_evict_kunit); + +struct xe_bo_link { + struct list_head link; + struct xe_bo *bo; +}; + +#define XE_BO_SHRINK_SIZE ((unsigned long)SZ_64M) + +/* + * Try to create system bos corresponding to twice the amount + * of available system memory to test shrinker functionality. + * If no swap space is available to accommodate the + * memory overcommit, mark bos purgeable. + */ +static int shrink_test_run_device(struct xe_device *xe) +{ + struct kunit *test = xe_cur_kunit(); + LIST_HEAD(bos); + struct xe_bo_link *link, *next; + struct sysinfo si; + size_t total, alloced; + unsigned int interrupted = 0, successful = 0; + + si_meminfo(); + total = si.freeram * si.mem_unit; + + kunit_info(test, "Free ram is %lu bytes. Will allocate twice of that.\n", + total); + + total <<= 1; + for (alloced = 0; alloced < total ; alloced += XE_BO_SHRINK_SIZE) { + struct xe_bo *bo; + unsigned int mem_type; + + link = kzalloc(sizeof(*link), GFP_KERNEL); + if (!link) { + KUNIT_FAIL(test, "Unexpeced link allocation failure\n"); + break; + } + + INIT_LIST_HEAD(>link); + + /* We can create bos using WC caching here. But it is slower. */ + bo = xe_bo_create_user(xe, NULL, NULL, XE_BO_SHRINK_SIZE, + DRM_XE_GEM_CPU_CACHING_WB, + ttm_bo_type_device, + XE_BO_FLAG_SYSTEM); + if (IS_ERR(bo)) { + if (bo != ERR_PTR(-ENOMEM) && bo != ERR_PTR(-ENOSPC) && + bo != ERR_PTR(-EINTR) && bo != ERR_PTR(-ERESTARTSYS)) + KUNIT_FAIL(test, "Error creating bo: %pe\n", bo); + kfree(link); + break; + } + link->bo = bo; + list_add_tail(>link, ); + xe_bo_lock(bo, false); + + /* +* If we're low on swap entries, we can't shrink unless the bo +* is marked purgeable. +*/ + if (get_nr_swap_pages() < (XE_BO_SHRINK_SIZE >> PAGE_SHIFT) * 128) { + struct xe_ttm_tt *xe_tt = + container_of(bo->ttm.ttm, typeof(*xe_tt), ttm); + long num_pages = xe_tt->ttm.num_pages; + + xe_tt->purgeable = true; + xe_shrinker_mod_pages(xe->mem.shrinker, -num_pages, + num_pages); + } + + mem_type = bo->ttm.resource->mem_type; + xe_bo_unlock(bo); + if (mem_type != XE_PL_TT) +