Merge pull request #158 from arutk/alloc_opt

Relax CAS memory allocation requirements
This commit is contained in:
Michal Rakowski 2019-10-30 14:33:51 +01:00 committed by GitHub
commit e97ef51fc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 22 additions and 31 deletions

View File

@ -55,7 +55,7 @@ void *_cas_alloc_page_rpool(void *allocator_ctx, int cpu)
{ {
struct page *page; struct page *page;
page = alloc_page(GFP_NOIO | __GFP_NORETRY); page = alloc_page(GFP_KERNEL);
if (!page) if (!page)
return NULL; return NULL;

View File

@ -34,7 +34,7 @@ static inline size_t env_allocator_align(size_t size)
} }
struct _env_allocator_item { struct _env_allocator_item {
uint32_t flags; uint32_t from_rpool;
uint32_t cpu; uint32_t cpu;
char data[]; char data[];
}; };
@ -49,7 +49,7 @@ void *env_allocator_new(env_allocator *allocator)
memset(item->data, 0, allocator->item_size - memset(item->data, 0, allocator->item_size -
sizeof(struct _env_allocator_item)); sizeof(struct _env_allocator_item));
} else { } else {
item = kmem_cache_zalloc(allocator->kmem_cache, GFP_ATOMIC); item = kmem_cache_zalloc(allocator->kmem_cache, GFP_NOIO);
} }
if (item) { if (item) {
@ -66,11 +66,10 @@ void *env_allocator_new_rpool(void *allocator_ctx, int cpu)
env_allocator *allocator = (env_allocator*) allocator_ctx; env_allocator *allocator = (env_allocator*) allocator_ctx;
struct _env_allocator_item *item; struct _env_allocator_item *item;
item = kmem_cache_zalloc(allocator->kmem_cache, GFP_NOIO | item = kmem_cache_zalloc(allocator->kmem_cache, GFP_KERNEL);
__GFP_NORETRY);
if (item) { if (item) {
item->flags = (GFP_NOIO | __GFP_NORETRY); item->from_rpool = 1;
item->cpu = cpu; item->cpu = cpu;
} }
@ -176,9 +175,10 @@ void env_allocator_del(env_allocator *allocator, void *obj)
atomic_dec(&allocator->count); atomic_dec(&allocator->count);
if (item->flags == (GFP_NOIO | __GFP_NORETRY) && if (item->from_rpool && !cas_rpool_try_put(allocator->rpool, item,
!cas_rpool_try_put(allocator->rpool, item, item->cpu)) item->cpu)) {
return; return;
}
kmem_cache_free(allocator->kmem_cache, item); kmem_cache_free(allocator->kmem_cache, item);
} }

View File

@ -18,7 +18,6 @@
#define ENV_MEM_NORMAL GFP_KERNEL #define ENV_MEM_NORMAL GFP_KERNEL
#define ENV_MEM_NOIO GFP_NOIO #define ENV_MEM_NOIO GFP_NOIO
#define ENV_MEM_ATOMIC GFP_ATOMIC
static inline uint64_t env_get_free_memory(void) static inline uint64_t env_get_free_memory(void)
{ {
@ -40,24 +39,14 @@ static inline void env_free(const void *ptr)
kfree(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) 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) 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) static inline void env_vfree(const void *ptr)

View File

@ -85,7 +85,9 @@ void *cas_mpool_new_f(struct cas_mpool *mpool, uint32_t count, int flags)
if (allocator) if (allocator)
items = env_allocator_new(allocator); items = env_allocator_new(allocator);
else 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 #ifdef ZERO_OR_NULL_PTR
if (ZERO_OR_NULL_PTR(items)) if (ZERO_OR_NULL_PTR(items))
@ -110,5 +112,5 @@ void cas_mpool_del(struct cas_mpool *mpool,
if (allocator) if (allocator)
env_allocator_del(allocator, items); env_allocator_del(allocator, items);
else else
env_free(items); cas_vfree(items);
} }

View File

@ -721,7 +721,7 @@ static int cas_atomic_submit_discard_bio(struct cas_atomic_io *atom)
int offset; int offset;
unsigned long *cmd_addr = blk_mq_rq_to_pdu(req); 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) { if (!nvm_discard) {
return -ENOMEM; return -ENOMEM;
} }

View File

@ -187,7 +187,7 @@ static int _blockdev_alloc_many_requests(ocf_core_t core,
flags = 0; flags = 0;
} }
data = cas_alloc_blk_data(bio_segments(bio), GFP_ATOMIC); data = cas_alloc_blk_data(bio_segments(bio), GFP_NOIO);
if (!data) { if (!data) {
CAS_PRINT_RL(KERN_CRIT "BIO data vector allocation error\n"); CAS_PRINT_RL(KERN_CRIT "BIO data vector allocation error\n");
error = -ENOMEM; error = -ENOMEM;
@ -420,7 +420,7 @@ static int __block_dev_queue_rq(struct request *rq, ocf_core_t core)
} }
if (single_io) { if (single_io) {
data = cas_alloc_blk_data(size, GFP_ATOMIC); data = cas_alloc_blk_data(size, GFP_NOIO);
if (data == NULL) { if (data == NULL) {
CAS_PRINT_RL(KERN_CRIT CAS_PRINT_RL(KERN_CRIT
"Out of memory. Ending IO processing.\n"); "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 { } else {
struct list_head list = LIST_HEAD_INIT(list); 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) { if (data == NULL) {
printk(KERN_CRIT printk(KERN_CRIT
"Out of memory. Ending IO processing.\n"); "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; 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) { if (!data) {
CAS_PRINT_RL(KERN_CRIT "BIO data vector allocation error\n"); 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)); CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-ENOMEM));

View File

@ -108,13 +108,13 @@ static inline void _casdsk_exp_obj_handle_bio_pt(struct casdsk_disk *dsk,
struct bio *cloned_bio; struct bio *cloned_bio;
struct casdsk_exp_obj_pt_io_ctx *io; 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) { if (!io) {
CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-ENOMEM)); CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-ENOMEM));
return; return;
} }
cloned_bio = cas_bio_clone(bio, GFP_ATOMIC); cloned_bio = cas_bio_clone(bio, GFP_NOIO);
if (!cloned_bio) { if (!cloned_bio) {
kmem_cache_free(casdsk_module->pt_io_ctx_cache, io); kmem_cache_free(casdsk_module->pt_io_ctx_cache, io);
CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-ENOMEM)); CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-ENOMEM));

2
ocf

@ -1 +1 @@
Subproject commit 9e515e02712b80f01fed956894326bcaa031a4e9 Subproject commit c8e72ad98d627e0aa10e8c9ce34a020452b10610