50dc83
From 77a3cac0c8aed9e084296719926a534128c31dee Mon Sep 17 00:00:00 2001
50dc83
From: Yaniv Kaul <ykaul@redhat.com>
50dc83
Date: Wed, 27 Feb 2019 15:48:42 +0200
50dc83
Subject: [PATCH 210/221] mem-pool.{c|h}: minor changes
50dc83
50dc83
1. Removed some code that was not needed. It did not really do anything.
50dc83
2. CALLOC -> MALLOC in one place.
50dc83
50dc83
Compile-tested only!
50dc83
50dc83
Upstream patch:
50dc83
> BUG: 1193929
50dc83
> Upstream patch link: https://review.gluster.org/c/glusterfs/+/22274
50dc83
> Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
50dc83
> Change-Id: I4419161e1bb636158e32b5d33044b06f1eef2449
50dc83
50dc83
Change-Id: I4419161e1bb636158e32b5d33044b06f1eef2449
50dc83
Updates: bz#1722801
50dc83
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
50dc83
Reviewed-on: https://code.engineering.redhat.com/gerrit/174712
50dc83
Tested-by: RHGS Build Bot <nigelb@redhat.com>
50dc83
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
50dc83
---
50dc83
 libglusterfs/src/mem-pool.c | 37 ++++++++++++-------------------------
50dc83
 1 file changed, 12 insertions(+), 25 deletions(-)
50dc83
50dc83
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
50dc83
index ab78804..ca25ffc 100644
50dc83
--- a/libglusterfs/src/mem-pool.c
50dc83
+++ b/libglusterfs/src/mem-pool.c
50dc83
@@ -643,7 +643,7 @@ mem_pool_new_fn(glusterfs_ctx_t *ctx, unsigned long sizeof_type,
50dc83
     }
50dc83
     pool = &pools[power - POOL_SMALLEST];
50dc83
 
50dc83
-    new = GF_CALLOC(sizeof(struct mem_pool), 1, gf_common_mt_mem_pool);
50dc83
+    new = GF_MALLOC(sizeof(struct mem_pool), gf_common_mt_mem_pool);
50dc83
     if (!new)
50dc83
         return NULL;
50dc83
 
50dc83
@@ -671,15 +671,7 @@ mem_pool_new_fn(glusterfs_ctx_t *ctx, unsigned long sizeof_type,
50dc83
 void *
50dc83
 mem_get0(struct mem_pool *mem_pool)
50dc83
 {
50dc83
-    void *ptr = NULL;
50dc83
-
50dc83
-    if (!mem_pool) {
50dc83
-        gf_msg_callingfn("mem-pool", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG,
50dc83
-                         "invalid argument");
50dc83
-        return NULL;
50dc83
-    }
50dc83
-
50dc83
-    ptr = mem_get(mem_pool);
50dc83
+    void *ptr = mem_get(mem_pool);
50dc83
     if (ptr) {
50dc83
 #if defined(GF_DISABLE_MEMPOOL)
50dc83
         memset(ptr, 0, mem_pool->sizeof_type);
50dc83
@@ -736,12 +728,14 @@ mem_get_pool_list(void)
50dc83
 }
50dc83
 
50dc83
 pooled_obj_hdr_t *
50dc83
-mem_get_from_pool(struct mem_pool *mem_pool, struct mem_pool_shared *pool,
50dc83
-                  gf_boolean_t *hit)
50dc83
+mem_get_from_pool(struct mem_pool *mem_pool, struct mem_pool_shared *pool)
50dc83
 {
50dc83
     per_thread_pool_list_t *pool_list;
50dc83
     per_thread_pool_t *pt_pool;
50dc83
     pooled_obj_hdr_t *retval;
50dc83
+#ifdef DEBUG
50dc83
+    gf_boolean_t hit = _gf_true;
50dc83
+#endif
50dc83
 
50dc83
     pool_list = mem_get_pool_list();
50dc83
     if (!pool_list || pool_list->poison) {
50dc83
@@ -755,10 +749,6 @@ mem_get_from_pool(struct mem_pool *mem_pool, struct mem_pool_shared *pool,
50dc83
         pt_pool = &pool_list->pools[pool->power_of_two - POOL_SMALLEST];
50dc83
     }
50dc83
 
50dc83
-#ifdef DEBUG
50dc83
-    *hit = _gf_true;
50dc83
-#endif
50dc83
-
50dc83
     (void)pthread_spin_lock(&pool_list->lock);
50dc83
 
50dc83
     retval = pt_pool->hot_list;
50dc83
@@ -778,7 +768,7 @@ mem_get_from_pool(struct mem_pool *mem_pool, struct mem_pool_shared *pool,
50dc83
             retval = malloc((1 << pt_pool->parent->power_of_two) +
50dc83
                             sizeof(pooled_obj_hdr_t));
50dc83
 #ifdef DEBUG
50dc83
-            *hit = _gf_false;
50dc83
+            hit = _gf_false;
50dc83
 #endif
50dc83
         }
50dc83
     }
50dc83
@@ -788,7 +778,7 @@ mem_get_from_pool(struct mem_pool *mem_pool, struct mem_pool_shared *pool,
50dc83
             retval->pool = mem_pool;
50dc83
             retval->power_of_two = mem_pool->pool->power_of_two;
50dc83
 #ifdef DEBUG
50dc83
-            if (*hit == _gf_true)
50dc83
+            if (hit == _gf_true)
50dc83
                 GF_ATOMIC_INC(mem_pool->hit);
50dc83
             else
50dc83
                 GF_ATOMIC_INC(mem_pool->miss);
50dc83
@@ -807,19 +797,16 @@ mem_get_from_pool(struct mem_pool *mem_pool, struct mem_pool_shared *pool,
50dc83
 void *
50dc83
 mem_get(struct mem_pool *mem_pool)
50dc83
 {
50dc83
-#if defined(GF_DISABLE_MEMPOOL)
50dc83
-    return GF_MALLOC(mem_pool->sizeof_type, gf_common_mt_mem_pool);
50dc83
-#else
50dc83
-    pooled_obj_hdr_t *retval;
50dc83
-    gf_boolean_t hit;
50dc83
-
50dc83
     if (!mem_pool) {
50dc83
         gf_msg_callingfn("mem-pool", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG,
50dc83
                          "invalid argument");
50dc83
         return NULL;
50dc83
     }
50dc83
 
50dc83
-    retval = mem_get_from_pool(mem_pool, NULL, &hit);
50dc83
+#if defined(GF_DISABLE_MEMPOOL)
50dc83
+    return GF_MALLOC(mem_pool->sizeof_type, gf_common_mt_mem_pool);
50dc83
+#else
50dc83
+    pooled_obj_hdr_t *retval = mem_get_from_pool(mem_pool, NULL);
50dc83
     if (!retval) {
50dc83
         return NULL;
50dc83
     }
50dc83
-- 
50dc83
1.8.3.1
50dc83