From e91e58ef66758d32ca84b7d6c1e501f99c0ffb20 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Fri, 18 Oct 2019 19:18:19 -0400 Subject: [PATCH 1/4] Revert "env: implement vmalloc with GFP flags" This reverts commit c5165838e558b010af93beebfa1c3359b8c6fe8b. --- modules/cas_cache/ocf_env.h | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/modules/cas_cache/ocf_env.h b/modules/cas_cache/ocf_env.h index 7e30513..3237d44 100644 --- a/modules/cas_cache/ocf_env.h +++ b/modules/cas_cache/ocf_env.h @@ -40,24 +40,14 @@ static inline void env_free(const void *ptr) kfree(ptr); } -static inline void *env_vmalloc_flags(size_t size, int flags) -{ - return __vmalloc(size, flags | __GFP_HIGHMEM, PAGE_KERNEL); -} - -static inline void *env_vzalloc_flags(size_t size, int flags) -{ - return env_vmalloc_flags(size, flags | __GFP_ZERO); -} - static inline void *env_vmalloc(size_t size) { - return env_vmalloc_flags(size, GFP_KERNEL); + return vmalloc(size); } static inline void *env_vzalloc(size_t size) { - return env_vzalloc_flags(size, GFP_KERNEL); + return vzalloc(size); } static inline void env_vfree(const void *ptr) From f9f00df57663b06cb3eac3ce773c36da3a86f8aa Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Fri, 18 Oct 2019 19:02:17 -0400 Subject: [PATCH 2/4] Use vmalloc instead of kmalloc in mem pools Signed-off-by: Adam Rutkowski --- modules/cas_cache/utils/utils_mpool.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/cas_cache/utils/utils_mpool.c b/modules/cas_cache/utils/utils_mpool.c index dfc6e0e..c3cc25f 100644 --- a/modules/cas_cache/utils/utils_mpool.c +++ b/modules/cas_cache/utils/utils_mpool.c @@ -85,7 +85,9 @@ void *cas_mpool_new_f(struct cas_mpool *mpool, uint32_t count, int flags) if (allocator) items = env_allocator_new(allocator); else - items = env_zalloc(mpool->hdr_size + (mpool->item_size * count), flags); + items = __vmalloc(mpool->hdr_size + (mpool->item_size * count), + flags | __GFP_ZERO | __GFP_HIGHMEM, + PAGE_KERNEL); #ifdef ZERO_OR_NULL_PTR if (ZERO_OR_NULL_PTR(items)) @@ -110,5 +112,5 @@ void cas_mpool_del(struct cas_mpool *mpool, if (allocator) env_allocator_del(allocator, items); else - env_free(items); + cas_vfree(items); } From 9b8fdde201292346810a803398f3bd0f292c4d4f Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Fri, 18 Oct 2019 19:16:20 -0400 Subject: [PATCH 3/4] Relax allocations requirements CAS does not need atomic alocations virtually anywhere. GFP_NOIO should be sufficient in IO path. When allocation buffers during module initialization use GFP_KERNEL. Signed-off-by: Adam Rutkowski --- modules/cas_cache/context.c | 2 +- modules/cas_cache/ocf_env.c | 14 +++++++------- modules/cas_cache/ocf_env.h | 1 - modules/cas_cache/volume/vol_atomic_dev_bottom.c | 2 +- modules/cas_cache/volume/vol_block_dev_top.c | 8 ++++---- modules/cas_disk/exp_obj.c | 4 ++-- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/modules/cas_cache/context.c b/modules/cas_cache/context.c index 8579286..e8f01e2 100644 --- a/modules/cas_cache/context.c +++ b/modules/cas_cache/context.c @@ -55,7 +55,7 @@ void *_cas_alloc_page_rpool(void *allocator_ctx, int cpu) { struct page *page; - page = alloc_page(GFP_NOIO | __GFP_NORETRY); + page = alloc_page(GFP_KERNEL); if (!page) return NULL; diff --git a/modules/cas_cache/ocf_env.c b/modules/cas_cache/ocf_env.c index cc2dd7b..7e4eea4 100644 --- a/modules/cas_cache/ocf_env.c +++ b/modules/cas_cache/ocf_env.c @@ -34,7 +34,7 @@ static inline size_t env_allocator_align(size_t size) } struct _env_allocator_item { - uint32_t flags; + uint32_t from_rpool; uint32_t cpu; char data[]; }; @@ -49,7 +49,7 @@ void *env_allocator_new(env_allocator *allocator) memset(item->data, 0, allocator->item_size - sizeof(struct _env_allocator_item)); } else { - item = kmem_cache_zalloc(allocator->kmem_cache, GFP_ATOMIC); + item = kmem_cache_zalloc(allocator->kmem_cache, GFP_NOIO); } if (item) { @@ -66,11 +66,10 @@ void *env_allocator_new_rpool(void *allocator_ctx, int cpu) env_allocator *allocator = (env_allocator*) allocator_ctx; struct _env_allocator_item *item; - item = kmem_cache_zalloc(allocator->kmem_cache, GFP_NOIO | - __GFP_NORETRY); + item = kmem_cache_zalloc(allocator->kmem_cache, GFP_KERNEL); if (item) { - item->flags = (GFP_NOIO | __GFP_NORETRY); + item->from_rpool = 1; item->cpu = cpu; } @@ -176,9 +175,10 @@ void env_allocator_del(env_allocator *allocator, void *obj) atomic_dec(&allocator->count); - if (item->flags == (GFP_NOIO | __GFP_NORETRY) && - !cas_rpool_try_put(allocator->rpool, item, item->cpu)) + if (item->from_rpool && !cas_rpool_try_put(allocator->rpool, item, + item->cpu)) { return; + } kmem_cache_free(allocator->kmem_cache, item); } diff --git a/modules/cas_cache/ocf_env.h b/modules/cas_cache/ocf_env.h index 3237d44..e72cc3a 100644 --- a/modules/cas_cache/ocf_env.h +++ b/modules/cas_cache/ocf_env.h @@ -18,7 +18,6 @@ #define ENV_MEM_NORMAL GFP_KERNEL #define ENV_MEM_NOIO GFP_NOIO -#define ENV_MEM_ATOMIC GFP_ATOMIC static inline uint64_t env_get_free_memory(void) { diff --git a/modules/cas_cache/volume/vol_atomic_dev_bottom.c b/modules/cas_cache/volume/vol_atomic_dev_bottom.c index 6229b58..a1ea6a2 100644 --- a/modules/cas_cache/volume/vol_atomic_dev_bottom.c +++ b/modules/cas_cache/volume/vol_atomic_dev_bottom.c @@ -721,7 +721,7 @@ static int cas_atomic_submit_discard_bio(struct cas_atomic_io *atom) int offset; unsigned long *cmd_addr = blk_mq_rq_to_pdu(req); - nvm_discard = kmalloc(sizeof(*nvm_discard), GFP_ATOMIC); + nvm_discard = kmalloc(sizeof(*nvm_discard), GFP_NOIO); if (!nvm_discard) { return -ENOMEM; } diff --git a/modules/cas_cache/volume/vol_block_dev_top.c b/modules/cas_cache/volume/vol_block_dev_top.c index 6d11ca2..b6456b5 100644 --- a/modules/cas_cache/volume/vol_block_dev_top.c +++ b/modules/cas_cache/volume/vol_block_dev_top.c @@ -187,7 +187,7 @@ static int _blockdev_alloc_many_requests(ocf_core_t core, flags = 0; } - data = cas_alloc_blk_data(bio_segments(bio), GFP_ATOMIC); + data = cas_alloc_blk_data(bio_segments(bio), GFP_NOIO); if (!data) { CAS_PRINT_RL(KERN_CRIT "BIO data vector allocation error\n"); error = -ENOMEM; @@ -420,7 +420,7 @@ static int __block_dev_queue_rq(struct request *rq, ocf_core_t core) } if (single_io) { - data = cas_alloc_blk_data(size, GFP_ATOMIC); + data = cas_alloc_blk_data(size, GFP_NOIO); if (data == NULL) { CAS_PRINT_RL(KERN_CRIT "Out of memory. Ending IO processing.\n"); @@ -445,7 +445,7 @@ static int __block_dev_queue_rq(struct request *rq, ocf_core_t core) } else { struct list_head list = LIST_HEAD_INIT(list); - data = cas_alloc_blk_data(0, GFP_ATOMIC); + data = cas_alloc_blk_data(0, GFP_NOIO); if (data == NULL) { printk(KERN_CRIT "Out of memory. Ending IO processing.\n"); @@ -753,7 +753,7 @@ static int _blockdev_make_request_fast(struct casdsk_disk *dsk, return CASDSK_BIO_HANDLED; } - data = cas_alloc_blk_data(bio_segments(bio), GFP_ATOMIC); + data = cas_alloc_blk_data(bio_segments(bio), GFP_NOIO); if (!data) { CAS_PRINT_RL(KERN_CRIT "BIO data vector allocation error\n"); CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-ENOMEM)); diff --git a/modules/cas_disk/exp_obj.c b/modules/cas_disk/exp_obj.c index da536ac..a8982cc 100644 --- a/modules/cas_disk/exp_obj.c +++ b/modules/cas_disk/exp_obj.c @@ -108,13 +108,13 @@ static inline void _casdsk_exp_obj_handle_bio_pt(struct casdsk_disk *dsk, struct bio *cloned_bio; struct casdsk_exp_obj_pt_io_ctx *io; - io = kmem_cache_zalloc(casdsk_module->pt_io_ctx_cache, GFP_ATOMIC); + io = kmem_cache_zalloc(casdsk_module->pt_io_ctx_cache, GFP_NOIO); if (!io) { CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-ENOMEM)); return; } - cloned_bio = cas_bio_clone(bio, GFP_ATOMIC); + cloned_bio = cas_bio_clone(bio, GFP_NOIO); if (!cloned_bio) { kmem_cache_free(casdsk_module->pt_io_ctx_cache, io); CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-ENOMEM)); From 0e62561072c35401f1b2ce6177300764d5e9514b Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Mon, 21 Oct 2019 13:58:02 -0400 Subject: [PATCH 4/4] OCF update (vmalloc based mempools compatibility) Signed-off-by: Adam Rutkowski --- ocf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocf b/ocf index 9e515e0..c8e72ad 160000 --- a/ocf +++ b/ocf @@ -1 +1 @@ -Subproject commit 9e515e02712b80f01fed956894326bcaa031a4e9 +Subproject commit c8e72ad98d627e0aa10e8c9ce34a020452b10610