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