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