summaryrefslogtreecommitdiff
path: root/0210-mem-pool.-c-h-minor-changes.patch
blob: c238579b6913cfb1ae1319dc28133863bb41897c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
From 77a3cac0c8aed9e084296719926a534128c31dee Mon Sep 17 00:00:00 2001
From: Yaniv Kaul <ykaul@redhat.com>
Date: Wed, 27 Feb 2019 15:48:42 +0200
Subject: [PATCH 210/221] mem-pool.{c|h}: minor changes

1. Removed some code that was not needed. It did not really do anything.
2. CALLOC -> MALLOC in one place.

Compile-tested only!

Upstream patch:
> BUG: 1193929
> Upstream patch link: https://review.gluster.org/c/glusterfs/+/22274
> Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
> Change-Id: I4419161e1bb636158e32b5d33044b06f1eef2449

Change-Id: I4419161e1bb636158e32b5d33044b06f1eef2449
Updates: bz#1722801
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/174712
Tested-by: RHGS Build Bot <nigelb@redhat.com>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 libglusterfs/src/mem-pool.c | 37 ++++++++++++-------------------------
 1 file changed, 12 insertions(+), 25 deletions(-)

diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
index ab78804..ca25ffc 100644
--- a/libglusterfs/src/mem-pool.c
+++ b/libglusterfs/src/mem-pool.c
@@ -643,7 +643,7 @@ mem_pool_new_fn(glusterfs_ctx_t *ctx, unsigned long sizeof_type,
     }
     pool = &pools[power - POOL_SMALLEST];
 
-    new = GF_CALLOC(sizeof(struct mem_pool), 1, gf_common_mt_mem_pool);
+    new = GF_MALLOC(sizeof(struct mem_pool), gf_common_mt_mem_pool);
     if (!new)
         return NULL;
 
@@ -671,15 +671,7 @@ mem_pool_new_fn(glusterfs_ctx_t *ctx, unsigned long sizeof_type,
 void *
 mem_get0(struct mem_pool *mem_pool)
 {
-    void *ptr = NULL;
-
-    if (!mem_pool) {
-        gf_msg_callingfn("mem-pool", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG,
-                         "invalid argument");
-        return NULL;
-    }
-
-    ptr = mem_get(mem_pool);
+    void *ptr = mem_get(mem_pool);
     if (ptr) {
 #if defined(GF_DISABLE_MEMPOOL)
         memset(ptr, 0, mem_pool->sizeof_type);
@@ -736,12 +728,14 @@ mem_get_pool_list(void)
 }
 
 pooled_obj_hdr_t *
-mem_get_from_pool(struct mem_pool *mem_pool, struct mem_pool_shared *pool,
-                  gf_boolean_t *hit)
+mem_get_from_pool(struct mem_pool *mem_pool, struct mem_pool_shared *pool)
 {
     per_thread_pool_list_t *pool_list;
     per_thread_pool_t *pt_pool;
     pooled_obj_hdr_t *retval;
+#ifdef DEBUG
+    gf_boolean_t hit = _gf_true;
+#endif
 
     pool_list = mem_get_pool_list();
     if (!pool_list || pool_list->poison) {
@@ -755,10 +749,6 @@ mem_get_from_pool(struct mem_pool *mem_pool, struct mem_pool_shared *pool,
         pt_pool = &pool_list->pools[pool->power_of_two - POOL_SMALLEST];
     }
 
-#ifdef DEBUG
-    *hit = _gf_true;
-#endif
-
     (void)pthread_spin_lock(&pool_list->lock);
 
     retval = pt_pool->hot_list;
@@ -778,7 +768,7 @@ mem_get_from_pool(struct mem_pool *mem_pool, struct mem_pool_shared *pool,
             retval = malloc((1 << pt_pool->parent->power_of_two) +
                             sizeof(pooled_obj_hdr_t));
 #ifdef DEBUG
-            *hit = _gf_false;
+            hit = _gf_false;
 #endif
         }
     }
@@ -788,7 +778,7 @@ mem_get_from_pool(struct mem_pool *mem_pool, struct mem_pool_shared *pool,
             retval->pool = mem_pool;
             retval->power_of_two = mem_pool->pool->power_of_two;
 #ifdef DEBUG
-            if (*hit == _gf_true)
+            if (hit == _gf_true)
                 GF_ATOMIC_INC(mem_pool->hit);
             else
                 GF_ATOMIC_INC(mem_pool->miss);
@@ -807,19 +797,16 @@ mem_get_from_pool(struct mem_pool *mem_pool, struct mem_pool_shared *pool,
 void *
 mem_get(struct mem_pool *mem_pool)
 {
-#if defined(GF_DISABLE_MEMPOOL)
-    return GF_MALLOC(mem_pool->sizeof_type, gf_common_mt_mem_pool);
-#else
-    pooled_obj_hdr_t *retval;
-    gf_boolean_t hit;
-
     if (!mem_pool) {
         gf_msg_callingfn("mem-pool", GF_LOG_ERROR, EINVAL, LG_MSG_INVALID_ARG,
                          "invalid argument");
         return NULL;
     }
 
-    retval = mem_get_from_pool(mem_pool, NULL, &hit);
+#if defined(GF_DISABLE_MEMPOOL)
+    return GF_MALLOC(mem_pool->sizeof_type, gf_common_mt_mem_pool);
+#else
+    pooled_obj_hdr_t *retval = mem_get_from_pool(mem_pool, NULL);
     if (!retval) {
         return NULL;
     }
-- 
1.8.3.1