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