diff options
author | Vijay Bellur <vijay@gluster.com> | 2010-04-22 13:33:09 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2010-04-23 06:32:52 -0700 |
commit | 582de0677da4be19fc6f873625c58c45d069ab1c (patch) | |
tree | f10cb3e26e1f92f6ea91034e6f7bb925790dd9bc /transport/socket/src | |
parent | 72baa17282f5cf749fa743fd601c7b728ece4fa2 (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/socket/src')
-rw-r--r-- | transport/socket/src/socket-mem-types.h | 36 | ||||
-rw-r--r-- | transport/socket/src/socket.c | 38 | ||||
-rw-r--r-- | transport/socket/src/socket.h | 1 |
3 files changed, 67 insertions, 8 deletions
diff --git a/transport/socket/src/socket-mem-types.h b/transport/socket/src/socket-mem-types.h new file mode 100644 index 000000000..f50f4a75d --- /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 28b828f29..7f7f8093a 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 44715697d..bc6d3b27c 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 |