diff options
author | Ilya Dryomov <ilya.dryomov@inktank.com> | 2014-01-09 13:08:21 -0500 |
---|---|---|
committer | Ilya Dryomov <ilya.dryomov@inktank.com> | 2014-01-26 05:34:23 -0500 |
commit | eeb0bed5572b1282009dfc2635604df5a35d1a02 (patch) | |
tree | 6b90792affac20b326daa59a59227766f746ee2f /net/ceph/buffer.c | |
parent | 80213a84a96c3040f5824bce646a184d5dd3dd2b (diff) |
libceph: add ceph_kv{malloc,free}() and switch to them
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>
Diffstat (limited to 'net/ceph/buffer.c')
-rw-r--r-- | net/ceph/buffer.c | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/net/ceph/buffer.c b/net/ceph/buffer.c index bf3e6a13c215..621b5f65407f 100644 --- a/net/ceph/buffer.c +++ b/net/ceph/buffer.c | |||
@@ -6,6 +6,7 @@ | |||
6 | 6 | ||
7 | #include <linux/ceph/buffer.h> | 7 | #include <linux/ceph/buffer.h> |
8 | #include <linux/ceph/decode.h> | 8 | #include <linux/ceph/decode.h> |
9 | #include <linux/ceph/libceph.h> /* for ceph_kv{malloc,free} */ | ||
9 | 10 | ||
10 | struct ceph_buffer *ceph_buffer_new(size_t len, gfp_t gfp) | 11 | struct ceph_buffer *ceph_buffer_new(size_t len, gfp_t gfp) |
11 | { | 12 | { |
@@ -15,16 +16,10 @@ struct ceph_buffer *ceph_buffer_new(size_t len, gfp_t gfp) | |||
15 | if (!b) | 16 | if (!b) |
16 | return NULL; | 17 | return NULL; |
17 | 18 | ||
18 | b->vec.iov_base = kmalloc(len, gfp | __GFP_NOWARN); | 19 | b->vec.iov_base = ceph_kvmalloc(len, gfp); |
19 | if (b->vec.iov_base) { | 20 | if (!b->vec.iov_base) { |
20 | b->is_vmalloc = false; | 21 | kfree(b); |
21 | } else { | 22 | return NULL; |
22 | b->vec.iov_base = __vmalloc(len, gfp | __GFP_HIGHMEM, PAGE_KERNEL); | ||
23 | if (!b->vec.iov_base) { | ||
24 | kfree(b); | ||
25 | return NULL; | ||
26 | } | ||
27 | b->is_vmalloc = true; | ||
28 | } | 23 | } |
29 | 24 | ||
30 | kref_init(&b->kref); | 25 | kref_init(&b->kref); |
@@ -40,12 +35,7 @@ void ceph_buffer_release(struct kref *kref) | |||
40 | struct ceph_buffer *b = container_of(kref, struct ceph_buffer, kref); | 35 | struct ceph_buffer *b = container_of(kref, struct ceph_buffer, kref); |
41 | 36 | ||
42 | dout("buffer_release %p\n", b); | 37 | dout("buffer_release %p\n", b); |
43 | if (b->vec.iov_base) { | 38 | ceph_kvfree(b->vec.iov_base); |
44 | if (b->is_vmalloc) | ||
45 | vfree(b->vec.iov_base); | ||
46 | else | ||
47 | kfree(b->vec.iov_base); | ||
48 | } | ||
49 | kfree(b); | 39 | kfree(b); |
50 | } | 40 | } |
51 | EXPORT_SYMBOL(ceph_buffer_release); | 41 | EXPORT_SYMBOL(ceph_buffer_release); |