summaryrefslogtreecommitdiffstats
path: root/transport
diff options
context:
space:
mode:
authorVijay Bellur <vijay@gluster.com>2010-04-22 13:33:09 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-04-23 06:32:52 -0700
commit582de0677da4be19fc6f873625c58c45d069ab1c (patch)
treef10cb3e26e1f92f6ea91034e6f7bb925790dd9bc /transport
parent72baa17282f5cf749fa743fd601c7b728ece4fa2 (diff)
Memory accounting changes
Memory accounting Changes. Thanks to Vinayak Hegde and Csaba Henk for their contributions. Signed-off-by: Vijay Bellur <vijay@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 329 (Replacing memory allocation functions with mem-type functions) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=329
Diffstat (limited to 'transport')
-rw-r--r--transport/ib-verbs/src/ib-verbs-mem-types.h39
-rw-r--r--transport/ib-verbs/src/ib-verbs.c78
-rw-r--r--transport/ib-verbs/src/ib-verbs.h1
-rw-r--r--transport/socket/src/socket-mem-types.h36
-rw-r--r--transport/socket/src/socket.c38
-rw-r--r--transport/socket/src/socket.h1
6 files changed, 158 insertions, 35 deletions
diff --git a/transport/ib-verbs/src/ib-verbs-mem-types.h b/transport/ib-verbs/src/ib-verbs-mem-types.h
new file mode 100644
index 00000000000..bac559646fc
--- /dev/null
+++ b/transport/ib-verbs/src/ib-verbs-mem-types.h
@@ -0,0 +1,39 @@
+
+/*
+ Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+#ifndef __IB_VERBS_MEM_TYPES_H__
+#define __IB_VERBS_MEM_TYPES_H__
+
+#include "mem-types.h"
+
+enum gf_ib_verbs_mem_types_ {
+ gf_ibv_mt_ib_verbs_private_t = gf_common_mt_end + 1,
+ gf_ibv_mt_ib_verbs_ioq_t,
+ gf_ibv_mt_transport_t,
+ gf_ibv_mt_ib_verbs_local_t,
+ gf_ibv_mt_ib_verbs_post_t,
+ gf_ibv_mt_char,
+ gf_ibv_mt_qpent,
+ gf_ibv_mt_ib_verbs_device_t,
+ gf_ibv_mt_end
+};
+#endif
+
diff --git a/transport/ib-verbs/src/ib-verbs.c b/transport/ib-verbs/src/ib-verbs.c
index b02e0bd6340..a252a13d884 100644
--- a/transport/ib-verbs/src/ib-verbs.c
+++ b/transport/ib-verbs/src/ib-verbs.c
@@ -156,7 +156,8 @@ ib_verbs_new_post (ib_verbs_device_t *device, int32_t len)
{
ib_verbs_post_t *post;
- post = (ib_verbs_post_t *) CALLOC (1, sizeof (*post));
+ post = (ib_verbs_post_t *) GF_CALLOC (1, sizeof (*post),
+ gf_ibv_mt_ib_verbs_post_t);
if (!post)
return NULL;
@@ -164,7 +165,7 @@ ib_verbs_new_post (ib_verbs_device_t *device, int32_t len)
post->buf = valloc (len);
if (!post->buf) {
- free (post);
+ GF_FREE (post);
return NULL;
}
@@ -174,7 +175,7 @@ ib_verbs_new_post (ib_verbs_device_t *device, int32_t len)
IBV_ACCESS_LOCAL_WRITE);
if (!post->mr) {
free (post->buf);
- free (post);
+ GF_FREE (post);
return NULL;
}
@@ -216,7 +217,7 @@ ib_verbs_destroy_post (ib_verbs_post_t *post)
{
ibv_dereg_mr (post->mr);
free (post->buf);
- free (post);
+ GF_FREE (post);
}
@@ -258,10 +259,10 @@ __ib_verbs_ioq_entry_free (ib_verbs_ioq_t *entry)
iobref_unref (entry->iobref);
/* TODO: use mem-pool */
- free (entry->buf);
+ GF_FREE (entry->buf);
/* TODO: use mem-pool */
- free (entry);
+ GF_FREE (entry);
}
@@ -497,7 +498,7 @@ ib_verbs_ioq_new (char *buf, int len, struct iovec *vector,
ib_verbs_ioq_t *entry = NULL;
/* TODO: use mem-pool */
- entry = CALLOC (1, sizeof (*entry));
+ entry = GF_CALLOC (1, sizeof (*entry), gf_ibv_mt_ib_verbs_ioq_t);
assert (count <= (MAX_IOVEC-2));
@@ -602,7 +603,7 @@ ib_verbs_receive (transport_t *this, char **hdr_p, size_t *hdrlen_p,
copy_from += sizeof (*header);
if (size1) {
- hdr = CALLOC (1, size1);
+ hdr = GF_CALLOC (1, size1, gf_ibv_mt_char);
if (!hdr) {
gf_log (this->xl->name, GF_LOG_ERROR,
"unable to allocate header for peer %s",
@@ -729,7 +730,7 @@ ib_verbs_register_peer (ib_verbs_device_t *device,
pthread_mutex_unlock (&qpreg->lock);
return;
}
- ent = (struct _qpent *) CALLOC (1, sizeof (*ent));
+ ent = (struct _qpent *) GF_CALLOC (1, sizeof (*ent), gf_ibv_mt_qpent);
ERR_ABORT (ent);
/* TODO: ref reg->peer */
ent->peer = peer;
@@ -762,7 +763,7 @@ ib_verbs_unregister_peer (ib_verbs_device_t *device,
ent->prev->next = ent->next;
ent->next->prev = ent->prev;
/* TODO: unref reg->peer */
- free (ent);
+ GF_FREE (ent);
qpreg->count--;
pthread_mutex_unlock (&qpreg->lock);
}
@@ -1476,7 +1477,7 @@ ib_verbs_options_init (transport_t *this)
temp = dict_get (this->xl->options,
"transport.ib-verbs.device-name");
if (temp)
- options->device_name = strdup (temp->data);
+ options->device_name = gf_strdup (temp->data);
return;
}
@@ -1519,7 +1520,8 @@ ib_verbs_get_device (transport_t *this,
if (!trav) {
- trav = CALLOC (1, sizeof (*trav));
+ trav = GF_CALLOC (1, sizeof (*trav),
+ gf_ibv_mt_ib_verbs_device_t);
ERR_ABORT (trav);
priv->device = trav;
@@ -1555,7 +1557,7 @@ ib_verbs_get_device (transport_t *this,
"port: %u", port);
}
- trav->device_name = strdup (device_name);
+ trav->device_name = gf_strdup (device_name);
trav->port = port;
trav->next = ctx->ib;
@@ -1684,7 +1686,7 @@ ib_verbs_init (transport_t *this)
if (!options->device_name) {
if (*dev_list) {
options->device_name =
- strdup (ibv_get_device_name (*dev_list));
+ gf_strdup (ibv_get_device_name (*dev_list));
} else {
gf_log ("transport/ib-verbs", GF_LOG_CRITICAL,
"IB device list is empty. Check for "
@@ -1828,7 +1830,7 @@ ib_verbs_handshake_pollin (transport_t *this)
switch (priv->handshake.incoming.state)
{
case IB_VERBS_HANDSHAKE_START:
- buf = priv->handshake.incoming.buf = CALLOC (1, 256);
+ buf = priv->handshake.incoming.buf = GF_CALLOC (1, 256, gf_ibv_mt_char);
ib_verbs_fill_handshake_data (buf, &priv->handshake.incoming, priv);
buf[0] = 0;
priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_RECEIVING_DATA;
@@ -1941,7 +1943,7 @@ ib_verbs_handshake_pollin (transport_t *this)
(struct sockaddr *) &this->peerinfo.sockaddr,
&sock_len);
- FREE (priv->handshake.incoming.buf);
+ GF_FREE (priv->handshake.incoming.buf);
priv->handshake.incoming.buf = NULL;
priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_COMPLETE;
}
@@ -1981,7 +1983,7 @@ ib_verbs_handshake_pollout (transport_t *this)
switch (priv->handshake.outgoing.state)
{
case IB_VERBS_HANDSHAKE_START:
- buf = priv->handshake.outgoing.buf = CALLOC (1, 256);
+ buf = priv->handshake.outgoing.buf = GF_CALLOC (1, 256, gf_ibv_mt_char);
ib_verbs_fill_handshake_data (buf, &priv->handshake.outgoing, priv);
priv->handshake.outgoing.state = IB_VERBS_HANDSHAKE_SENDING_DATA;
break;
@@ -2031,7 +2033,7 @@ ib_verbs_handshake_pollout (transport_t *this)
}
if (!ret) {
- FREE (priv->handshake.outgoing.buf);
+ GF_FREE (priv->handshake.outgoing.buf);
priv->handshake.outgoing.buf = NULL;
priv->handshake.outgoing.state = IB_VERBS_HANDSHAKE_COMPLETE;
}
@@ -2082,14 +2084,14 @@ ib_verbs_handshake_pollerr (transport_t *this)
}
if (priv->handshake.incoming.buf) {
- FREE (priv->handshake.incoming.buf);
+ GF_FREE (priv->handshake.incoming.buf);
priv->handshake.incoming.buf = NULL;
}
priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_START;
if (priv->handshake.outgoing.buf) {
- FREE (priv->handshake.outgoing.buf);
+ GF_FREE (priv->handshake.outgoing.buf);
priv->handshake.outgoing.buf = NULL;
}
@@ -2352,9 +2354,11 @@ ib_verbs_server_event_handler (int fd, int idx, void *data,
if (!poll_in)
return 0;
- this = CALLOC (1, sizeof (transport_t));
+ this = GF_CALLOC (1, sizeof (transport_t),
+ gf_ibv_mt_transport_t);
ERR_ABORT (this);
- priv = CALLOC (1, sizeof (ib_verbs_private_t));
+ priv = GF_CALLOC (1, sizeof (ib_verbs_private_t),
+ gf_ibv_mt_ib_verbs_private_t);
ERR_ABORT (priv);
this->private = priv;
/* Copy all the ib_verbs related values in priv, from trans_priv
@@ -2381,8 +2385,8 @@ ib_verbs_server_event_handler (int fd, int idx, void *data,
gf_log ("ib-verbs/server", GF_LOG_ERROR,
"accept() failed: %s",
strerror (errno));
- free (this->private);
- free (this);
+ GF_FREE (this->private);
+ GF_FREE (this);
return -1;
}
@@ -2445,7 +2449,7 @@ ib_verbs_listen (transport_t *this)
gf_log ("ib-verbs/server", GF_LOG_CRITICAL,
"init: failed to create socket, error: %s",
strerror (errno));
- free (this->private);
+ GF_FREE (this->private);
ret = -1;
goto err;
}
@@ -2504,7 +2508,8 @@ struct transport_ops tops = {
int32_t
init (transport_t *this)
{
- ib_verbs_private_t *priv = CALLOC (1, sizeof (*priv));
+ ib_verbs_private_t *priv = GF_CALLOC (1, sizeof (*priv),
+ gf_ibv_mt_ib_verbs_private_t);
this->private = priv;
priv->sock = -1;
@@ -2532,10 +2537,29 @@ fini (struct transport *this)
gf_log (this->xl->name, GF_LOG_TRACE,
"called fini on transport: %p",
this);
- free (priv);
+ GF_FREE (priv);
return;
}
+int32_t
+mem_acct_init (xlator_t *this)
+{
+ int ret = -1;
+
+ if (!this)
+ return ret;
+
+ ret = xlator_mem_acct_init (this, gf_common_mt_end + 1);
+
+ if (ret != 0) {
+ gf_log (this->name, GF_LOG_ERROR, "Memory accounting init"
+ "failed");
+ return ret;
+ }
+
+ return ret;
+}
+
/* TODO: expand each option */
struct volume_options options[] = {
{ .key = {"transport.ib-verbs.port",
diff --git a/transport/ib-verbs/src/ib-verbs.h b/transport/ib-verbs/src/ib-verbs.h
index ea016c34d99..c385b62e5cb 100644
--- a/transport/ib-verbs/src/ib-verbs.h
+++ b/transport/ib-verbs/src/ib-verbs.h
@@ -32,6 +32,7 @@
#include "xlator.h"
#include "event.h"
+#include "ib-verbs-mem-types.h"
#include <stdio.h>
#include <list.h>
diff --git a/transport/socket/src/socket-mem-types.h b/transport/socket/src/socket-mem-types.h
new file mode 100644
index 00000000000..f50f4a75de8
--- /dev/null
+++ b/transport/socket/src/socket-mem-types.h
@@ -0,0 +1,36 @@
+
+/*
+ Copyright (c) 2008-2009 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+#ifndef __SOCKET_MEM_TYPES_H__
+#define __SOCKET_MEM_TYPES_H__
+
+#include "mem-types.h"
+
+enum gf_socket_mem_types_ {
+ gf_socket_mt_socket_private_t = gf_common_mt_end + 1,
+ gf_socket_mt_ioq,
+ gf_socket_mt_transport_t,
+ gf_socket_mt_socket_local_t,
+ gf_socket_mt_char,
+ gf_socket_mt_end
+};
+#endif
+
diff --git a/transport/socket/src/socket.c b/transport/socket/src/socket.c
index 28b828f29a2..7f7f8093a7d 100644
--- a/transport/socket/src/socket.c
+++ b/transport/socket/src/socket.c
@@ -273,7 +273,7 @@ __socket_reset (transport_t *this)
/* TODO: use mem-pool on incoming data */
if (priv->incoming.hdr_p)
- free (priv->incoming.hdr_p);
+ GF_FREE (priv->incoming.hdr_p);
if (priv->incoming.iobuf)
iobuf_unref (priv->incoming.iobuf);
@@ -298,7 +298,8 @@ __socket_ioq_new (transport_t *this, char *buf, int len,
priv = this->private;
/* TODO: use mem-pool */
- entry = CALLOC (1, sizeof (*entry));
+ entry = GF_CALLOC (1, sizeof (*entry),
+ gf_common_mt_ioq);
if (!entry)
return NULL;
@@ -346,10 +347,10 @@ __socket_ioq_entry_free (struct ioq *entry)
iobref_unref (entry->iobref);
/* TODO: use mem-pool */
- free (entry->buf);
+ GF_FREE (entry->buf);
/* TODO: use mem-pool */
- free (entry);
+ GF_FREE (entry);
}
@@ -607,7 +608,8 @@ __socket_proto_state_machine (transport_t *this)
priv->incoming.buflen = size2;
/* TODO: use mem-pool */
- priv->incoming.hdr_p = MALLOC (size1);
+ priv->incoming.hdr_p = GF_MALLOC (size1,
+ gf_common_mt_char);
if (size2) {
/* TODO: sanity check size2 < page size
*/
@@ -891,7 +893,8 @@ socket_server_event_handler (int fd, int idx, void *data,
}
}
- new_trans = CALLOC (1, sizeof (*new_trans));
+ new_trans = GF_CALLOC (1, sizeof (*new_trans),
+ gf_common_mt_transport_t);
new_trans->xl = this->xl;
new_trans->fini = this->fini;
@@ -1376,7 +1379,8 @@ socket_init (transport_t *this)
return -1;
}
- priv = CALLOC (1, sizeof (*priv));
+ priv = GF_CALLOC (1, sizeof (*priv),
+ gf_common_mt_socket_private_t);
if (!priv) {
gf_log (this->xl->name, GF_LOG_ERROR,
"calloc (1, %"GF_PRI_SIZET") returned NULL",
@@ -1465,9 +1469,27 @@ fini (transport_t *this)
"transport %p destroyed", this);
pthread_mutex_destroy (&priv->lock);
- FREE (priv);
+ GF_FREE (priv);
}
+int32_t
+mem_acct_init (xlator_t *this)
+{
+ int ret = -1;
+
+ if (!this)
+ return ret;
+
+ ret = xlator_mem_acct_init (this, gf_common_mt_end + 1);
+
+ if (ret != 0) {
+ gf_log (this->name, GF_LOG_ERROR, "Memory accounting init"
+ "failed");
+ return ret;
+ }
+
+ return ret;
+}
int32_t
init (transport_t *this)
diff --git a/transport/socket/src/socket.h b/transport/socket/src/socket.h
index 44715697db1..bc6d3b27c3a 100644
--- a/transport/socket/src/socket.h
+++ b/transport/socket/src/socket.h
@@ -31,6 +31,7 @@
#include "logging.h"
#include "dict.h"
#include "mem-pool.h"
+#include "socket-mem-types.h"
#ifndef MAX_IOVEC
#define MAX_IOVEC 16