From: Gleb C. <lna...@ya...> - 2023-12-27 15:03:04
|
Commit: fd88df1 GitHub URL: https://github.com/SCST-project/scst/commit/fd88df1e253f8d20a01b2ffb52842cc4bffabe2e Author: Gleb Chesnokov Date: 2023-12-27T18:02:30+03:00 Log Message: ----------- scst_mem: Port to Linux kernel v6.7 Support for the following mm layer changes in the Linux kernel v6.7: - c42d50aefd17 ("mm: shrinker: add infrastructure for dynamically allocating shrinker") Modified Paths: -------------- scst/src/scst_mem.c | 54 +++++++++++---- scst/src/scst_mem.h | 2 +- 2 files changed, 43 insertions(+), 13 deletions(-) =================================================================== diff --git a/scst/src/scst_mem.c b/scst/src/scst_mem.c index af5cd48..9814fa7 100644 --- a/scst/src/scst_mem.c +++ b/scst/src/scst_mem.c @@ -78,7 +78,11 @@ static atomic_t sgv_releases_on_hiwmk_failed = ATOMIC_INIT(0); static atomic_t sgv_other_total_alloc = ATOMIC_INIT(0); #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 7, 0) static struct shrinker sgv_shrinker; +#else +static struct shrinker *sgv_shrinker; +#endif static struct kmem_cache *sgv_pool_cachep; @@ -1711,8 +1715,43 @@ void sgv_pool_del(struct sgv_pool *pool) } EXPORT_SYMBOL_GPL(sgv_pool_del); +static int __init scst_sgv_shrinker_init(void) +{ +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 7, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 0) + sgv_shrinker.count_objects = sgv_can_be_shrunk; + sgv_shrinker.scan_objects = sgv_scan_shrink; +#else + sgv_shrinker.shrink = sgv_shrink; +#endif + sgv_shrinker.seeks = DEFAULT_SEEKS; + + return register_shrinker(&sgv_shrinker, "scst-sgv"); +#else + sgv_shrinker = shrinker_alloc(0, "scst-sgv"); + if (unlikely(!sgv_shrinker)) + return -ENOMEM; + + sgv_shrinker->count_objects = sgv_can_be_shrunk; + sgv_shrinker->scan_objects = sgv_scan_shrink; + + shrinker_register(sgv_shrinker); + + return 0; +#endif +} + +static void scst_sgv_shrinker_exit(void) +{ +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 7, 0) + unregister_shrinker(&sgv_shrinker); +#else + shrinker_free(sgv_shrinker); +#endif +} + /* Both parameters in pages */ -int scst_sgv_pools_init(unsigned long mem_hwmark, unsigned long mem_lwmark) +int __init scst_sgv_pools_init(unsigned long mem_hwmark, unsigned long mem_lwmark) { int res = 0, i; @@ -1791,15 +1830,7 @@ int scst_sgv_pools_init(unsigned long mem_hwmark, unsigned long mem_lwmark) goto out_free_per_cpu_dma; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 0) - sgv_shrinker.count_objects = sgv_can_be_shrunk; - sgv_shrinker.scan_objects = sgv_scan_shrink; -#else - sgv_shrinker.shrink = sgv_shrink; -#endif - sgv_shrinker.seeks = DEFAULT_SEEKS; - - res = register_shrinker(&sgv_shrinker, "scst-sgv"); + res = scst_sgv_shrinker_init(); if (unlikely(res)) goto out_free_per_cpu_dma; @@ -1841,7 +1872,7 @@ void scst_sgv_pools_deinit(void) TRACE_ENTRY(); - unregister_shrinker(&sgv_shrinker); + scst_sgv_shrinker_exit(); sgv_pool_destroy(sgv_dma_pool_main); for (i = 0; i < nr_cpu_ids; i++) @@ -1870,7 +1901,6 @@ void scst_sgv_pools_deinit(void) return; } - static ssize_t sgv_sysfs_stat_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { diff --git a/scst/src/scst_mem.h b/scst/src/scst_mem.h index 9b5439c..cfffb69 100644 --- a/scst/src/scst_mem.h +++ b/scst/src/scst_mem.h @@ -138,7 +138,7 @@ static inline struct scatterlist *sgv_pool_sg(struct sgv_pool_obj *obj) return obj->sg_entries; } -int scst_sgv_pools_init(unsigned long mem_hwmark, unsigned long mem_lwmark); +int __init scst_sgv_pools_init(unsigned long mem_hwmark, unsigned long mem_lwmark); void scst_sgv_pools_deinit(void); |