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