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