diff mbox series

[v3,01/15] libceph: introduce ceph_extract_encoded_string_kvmalloc

Message ID 1564393377-28949-2-git-send-email-dongsheng.yang@easystack.cn (mailing list archive)
State New, archived
Headers show
Series rbd journaling feature | expand

Commit Message

Dongsheng Yang July 29, 2019, 9:42 a.m. UTC
When we are going to extract the encoded string, there
would be a large string encoded.

Especially in the journaling case, if we use the default
journal object size, 16M, there could be a 16M string
encoded in this object.

Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
---
 include/linux/ceph/decode.h | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

Comments

Ilya Dryomov Aug. 19, 2019, 7:26 a.m. UTC | #1
On Mon, Jul 29, 2019 at 11:43 AM Dongsheng Yang
<dongsheng.yang@easystack.cn> wrote:
>
> When we are going to extract the encoded string, there
> would be a large string encoded.
>
> Especially in the journaling case, if we use the default
> journal object size, 16M, there could be a 16M string
> encoded in this object.
>
> Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
> ---
>  include/linux/ceph/decode.h | 21 ++++++++++++++++++---
>  1 file changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/ceph/decode.h b/include/linux/ceph/decode.h
> index 450384f..555879f 100644
> --- a/include/linux/ceph/decode.h
> +++ b/include/linux/ceph/decode.h
> @@ -104,8 +104,11 @@ static inline bool ceph_has_room(void **p, void *end, size_t n)
>   *     beyond the "end" pointer provided (-ERANGE)
>   *   - memory could not be allocated for the result (-ENOMEM)
>   */
> -static inline char *ceph_extract_encoded_string(void **p, void *end,
> -                                               size_t *lenp, gfp_t gfp)
> +typedef void * (mem_alloc_t)(size_t size, gfp_t flags);
> +extern void *ceph_kvmalloc(size_t size, gfp_t flags);
> +static inline char *extract_encoded_string(void **p, void *end,
> +                                          mem_alloc_t alloc_fn,
> +                                          size_t *lenp, gfp_t gfp)
>  {
>         u32 len;
>         void *sp = *p;
> @@ -115,7 +118,7 @@ static inline char *ceph_extract_encoded_string(void **p, void *end,
>         if (!ceph_has_room(&sp, end, len))
>                 goto bad;
>
> -       buf = kmalloc(len + 1, gfp);
> +       buf = alloc_fn(len + 1, gfp);
>         if (!buf)
>                 return ERR_PTR(-ENOMEM);
>
> @@ -133,6 +136,18 @@ static inline char *ceph_extract_encoded_string(void **p, void *end,
>         return ERR_PTR(-ERANGE);
>  }
>
> +static inline char *ceph_extract_encoded_string(void **p, void *end,
> +                                               size_t *lenp, gfp_t gfp)
> +{
> +       return extract_encoded_string(p, end, kmalloc, lenp, gfp);
> +}
> +
> +static inline char *ceph_extract_encoded_string_kvmalloc(void **p, void *end,
> +                                                        size_t *lenp, gfp_t gfp)
> +{
> +       return extract_encoded_string(p, end, ceph_kvmalloc, lenp, gfp);
> +}
> +
>  /*
>   * skip helpers
>   */

This is only for replaying, right?

Thanks,

                Ilya
Dongsheng Yang Aug. 26, 2019, 2:53 a.m. UTC | #2
On 08/19/2019 03:26 PM, Ilya Dryomov wrote:
> On Mon, Jul 29, 2019 at 11:43 AM Dongsheng Yang
> <dongsheng.yang@easystack.cn>  wrote:
>> When we are going to extract the encoded string, there
>> would be a large string encoded.
>>
>> Especially in the journaling case, if we use the default
>> journal object size, 16M, there could be a 16M string
>> encoded in this object.
>>
>> Signed-off-by: Dongsheng Yang<dongsheng.yang@easystack.cn>
>> ---
>>   include/linux/ceph/decode.h | 21 ++++++++++++++++++---
>>   1 file changed, 18 insertions(+), 3 deletions(-)
>>
>> diff --git a/include/linux/ceph/decode.h b/include/linux/ceph/decode.h
>> index 450384f..555879f 100644
>> --- a/include/linux/ceph/decode.h
>> +++ b/include/linux/ceph/decode.h
>> @@ -104,8 +104,11 @@ static inline bool ceph_has_room(void **p, void *end, size_t n)
>>    *     beyond the "end" pointer provided (-ERANGE)
>>    *   - memory could not be allocated for the result (-ENOMEM)
>>    */
>> -static inline char *ceph_extract_encoded_string(void **p, void *end,
>> -                                               size_t *lenp, gfp_t gfp)
>> +typedef void * (mem_alloc_t)(size_t size, gfp_t flags);
>> +extern void *ceph_kvmalloc(size_t size, gfp_t flags);
>> +static inline char *extract_encoded_string(void **p, void *end,
>> +                                          mem_alloc_t alloc_fn,
>> +                                          size_t *lenp, gfp_t gfp)
>>   {
>>          u32 len;
>>          void *sp = *p;
>> @@ -115,7 +118,7 @@ static inline char *ceph_extract_encoded_string(void **p, void *end,
>>          if (!ceph_has_room(&sp, end, len))
>>                  goto bad;
>>
>> -       buf = kmalloc(len + 1, gfp);
>> +       buf = alloc_fn(len + 1, gfp);
>>          if (!buf)
>>                  return ERR_PTR(-ENOMEM);
>>
>> @@ -133,6 +136,18 @@ static inline char *ceph_extract_encoded_string(void **p, void *end,
>>          return ERR_PTR(-ERANGE);
>>   }
>>
>> +static inline char *ceph_extract_encoded_string(void **p, void *end,
>> +                                               size_t *lenp, gfp_t gfp)
>> +{
>> +       return extract_encoded_string(p, end, kmalloc, lenp, gfp);
>> +}
>> +
>> +static inline char *ceph_extract_encoded_string_kvmalloc(void **p, void *end,
>> +                                                        size_t *lenp, gfp_t gfp)
>> +{
>> +       return extract_encoded_string(p, end, ceph_kvmalloc, lenp, gfp);
>> +}
>> +
>>   /*
>>    * skip helpers
>>    */
> This is only for replaying, right?

This is for journal fetching, which is a part for replaying. But if we 
don't do replay,
we still need to do journal fetching and journal preprocess to know 
whether there is
uncommitted journal.

Thanx
> Thanks,
>
>                  Ilya
>
diff mbox series

Patch

diff --git a/include/linux/ceph/decode.h b/include/linux/ceph/decode.h
index 450384f..555879f 100644
--- a/include/linux/ceph/decode.h
+++ b/include/linux/ceph/decode.h
@@ -104,8 +104,11 @@  static inline bool ceph_has_room(void **p, void *end, size_t n)
  *     beyond the "end" pointer provided (-ERANGE)
  *   - memory could not be allocated for the result (-ENOMEM)
  */
-static inline char *ceph_extract_encoded_string(void **p, void *end,
-						size_t *lenp, gfp_t gfp)
+typedef void * (mem_alloc_t)(size_t size, gfp_t flags);
+extern void *ceph_kvmalloc(size_t size, gfp_t flags);
+static inline char *extract_encoded_string(void **p, void *end,
+					   mem_alloc_t alloc_fn,
+					   size_t *lenp, gfp_t gfp)
 {
 	u32 len;
 	void *sp = *p;
@@ -115,7 +118,7 @@  static inline char *ceph_extract_encoded_string(void **p, void *end,
 	if (!ceph_has_room(&sp, end, len))
 		goto bad;
 
-	buf = kmalloc(len + 1, gfp);
+	buf = alloc_fn(len + 1, gfp);
 	if (!buf)
 		return ERR_PTR(-ENOMEM);
 
@@ -133,6 +136,18 @@  static inline char *ceph_extract_encoded_string(void **p, void *end,
 	return ERR_PTR(-ERANGE);
 }
 
+static inline char *ceph_extract_encoded_string(void **p, void *end,
+						size_t *lenp, gfp_t gfp)
+{
+	return extract_encoded_string(p, end, kmalloc, lenp, gfp);
+}
+
+static inline char *ceph_extract_encoded_string_kvmalloc(void **p, void *end,
+							 size_t *lenp, gfp_t gfp)
+{
+	return extract_encoded_string(p, end, ceph_kvmalloc, lenp, gfp);
+}
+
 /*
  * skip helpers
  */