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