summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@gluster.com>2011-06-29 00:34:58 +0000
committerAnand Avati <avati@gluster.com>2011-07-11 22:07:14 -0700
commit1ac5e8cc356d245ebe7e0d9065592024495f3e54 (patch)
tree5f14f0c86f5aa3ae75a4e3bd5ff464a3610b0cf4 /xlators
parent6cebcc568fba79e3496972fc50ae55a7812859ee (diff)
nfs-rpc: Use mempool for allocating connection object
Signed-off-by: Shehjar Tikoo <shehjart@gluster.com> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 3039 (NFS RPC leaks memory in client connection creation on showmount -e) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=3039
Diffstat (limited to 'xlators')
-rw-r--r--xlators/nfs/lib/src/rpcsvc.c19
-rw-r--r--xlators/nfs/lib/src/rpcsvc.h3
2 files changed, 19 insertions, 3 deletions
diff --git a/xlators/nfs/lib/src/rpcsvc.c b/xlators/nfs/lib/src/rpcsvc.c
index 0831cf4..6e0e020 100644
--- a/xlators/nfs/lib/src/rpcsvc.c
+++ b/xlators/nfs/lib/src/rpcsvc.c
@@ -162,6 +162,7 @@ nfs_rpcsvc_init (glusterfs_ctx_t *ctx, dict_t *options)
{
rpcsvc_t *svc = NULL;
int ret = -1;
+ int poolsize = 0;
if ((!ctx) || (!options))
return NULL;
@@ -189,16 +190,28 @@ nfs_rpcsvc_init (glusterfs_ctx_t *ctx, dict_t *options)
}
ret = -1;
+ poolsize = RPCSVC_POOLCOUNT_MULT * RPCSVC_DEFAULT_MEMFACTOR;
+ svc->connpool = mem_pool_new (rpcsvc_conn_t, poolsize);
+ if (!svc->connpool) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to allocate connpool");
+ goto free_svc;
+ }
+
svc->defaultstage = nfs_rpcsvc_stage_init (svc);
if (!svc->defaultstage) {
gf_log (GF_RPCSVC, GF_LOG_ERROR,"RPC service init failed.");
- goto free_svc;
+ goto free_connpool;
}
svc->options = options;
svc->ctx = ctx;
gf_log (GF_RPCSVC, GF_LOG_DEBUG, "RPC service inited.");
ret = 0;
+
+free_connpool:
+ if (ret == -1)
+ mem_pool_destroy (svc->connpool);
+
free_svc:
if (ret == -1) {
GF_FREE (svc);
@@ -661,7 +674,7 @@ nfs_rpcsvc_conn_init (rpcsvc_t *svc, int sockfd)
int ret = -1;
unsigned int poolcount = 0;
- conn = GF_CALLOC (1, sizeof(*conn), gf_common_mt_rpcsvc_conn_t);
+ conn = mem_get (svc->connpool);
if (!conn) {
gf_log (GF_RPCSVC, GF_LOG_ERROR, "memory allocation failed");
return NULL;
@@ -717,7 +730,7 @@ nfs_rpcsvc_conn_destroy (rpcsvc_conn_t *conn)
mem_pool_destroy (conn->rxpool);
/* Need to destory record state, txlists etc. */
- GF_FREE (conn);
+ mem_put (((rpcsvc_t *)conn->stage->svc)->connpool, conn);
gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Connection destroyed");
}
diff --git a/xlators/nfs/lib/src/rpcsvc.h b/xlators/nfs/lib/src/rpcsvc.h
index 4e7c818..5ce3ba8 100644
--- a/xlators/nfs/lib/src/rpcsvc.h
+++ b/xlators/nfs/lib/src/rpcsvc.h
@@ -526,6 +526,9 @@ typedef struct rpc_svc_state {
gf_boolean_t register_portmap;
struct list_head allprograms;
+
+ /* Mempool for incoming connection objects. */
+ struct mem_pool *connpool;
} rpcsvc_t;