Merge pull request #158 from arutk/alloc_opt
Relax CAS memory allocation requirements
This commit is contained in:
commit
e97ef51fc5
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
@ -40,24 +39,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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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));
|
||||
|
2
ocf
2
ocf
@ -1 +1 @@
|
||||
Subproject commit 9e515e02712b80f01fed956894326bcaa031a4e9
|
||||
Subproject commit c8e72ad98d627e0aa10e8c9ce34a020452b10610
|
Loading…
Reference in New Issue
Block a user