mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-23 12:43:55 +08:00
eeb0bed557
Encapsulate kmalloc vs vmalloc memory allocation and freeing logic into two helpers, ceph_kvmalloc() and ceph_kvfree(), and switch to them. ceph_kvmalloc() kmalloc()'s a maximum of 8 pages, anything bigger is vmalloc()'ed with __GFP_HIGHMEM set. This changes the existing behaviour: - for buffers (ceph_buffer_new()), from trying to kmalloc() everything and using vmalloc() just as a fallback - for messages (ceph_msg_new()), from going to vmalloc() for anything bigger than a page - for messages (ceph_msg_new()), from disallowing vmalloc() to use high memory Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com> Reviewed-by: Sage Weil <sage@inktank.com>
59 lines
1.2 KiB
C
59 lines
1.2 KiB
C
|
|
#include <linux/ceph/ceph_debug.h>
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/ceph/buffer.h>
|
|
#include <linux/ceph/decode.h>
|
|
#include <linux/ceph/libceph.h> /* for ceph_kv{malloc,free} */
|
|
|
|
struct ceph_buffer *ceph_buffer_new(size_t len, gfp_t gfp)
|
|
{
|
|
struct ceph_buffer *b;
|
|
|
|
b = kmalloc(sizeof(*b), gfp);
|
|
if (!b)
|
|
return NULL;
|
|
|
|
b->vec.iov_base = ceph_kvmalloc(len, gfp);
|
|
if (!b->vec.iov_base) {
|
|
kfree(b);
|
|
return NULL;
|
|
}
|
|
|
|
kref_init(&b->kref);
|
|
b->alloc_len = len;
|
|
b->vec.iov_len = len;
|
|
dout("buffer_new %p\n", b);
|
|
return b;
|
|
}
|
|
EXPORT_SYMBOL(ceph_buffer_new);
|
|
|
|
void ceph_buffer_release(struct kref *kref)
|
|
{
|
|
struct ceph_buffer *b = container_of(kref, struct ceph_buffer, kref);
|
|
|
|
dout("buffer_release %p\n", b);
|
|
ceph_kvfree(b->vec.iov_base);
|
|
kfree(b);
|
|
}
|
|
EXPORT_SYMBOL(ceph_buffer_release);
|
|
|
|
int ceph_decode_buffer(struct ceph_buffer **b, void **p, void *end)
|
|
{
|
|
size_t len;
|
|
|
|
ceph_decode_need(p, end, sizeof(u32), bad);
|
|
len = ceph_decode_32(p);
|
|
dout("decode_buffer len %d\n", (int)len);
|
|
ceph_decode_need(p, end, len, bad);
|
|
*b = ceph_buffer_new(len, GFP_NOFS);
|
|
if (!*b)
|
|
return -ENOMEM;
|
|
ceph_decode_copy(p, (*b)->vec.iov_base, len);
|
|
return 0;
|
|
bad:
|
|
return -EINVAL;
|
|
}
|