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 /xlators/performance/io-cache | |
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 'xlators/performance/io-cache')
-rw-r--r-- | xlators/performance/io-cache/src/io-cache.c | 77 | ||||
-rw-r--r-- | xlators/performance/io-cache/src/ioc-inode.c | 10 | ||||
-rw-r--r-- | xlators/performance/io-cache/src/ioc-mem-types.h | 40 | ||||
-rw-r--r-- | xlators/performance/io-cache/src/page.c | 39 |
4 files changed, 120 insertions, 46 deletions
diff --git a/xlators/performance/io-cache/src/io-cache.c b/xlators/performance/io-cache/src/io-cache.c index 9bf20be5b..9f402f1da 100644 --- a/xlators/performance/io-cache/src/io-cache.c +++ b/xlators/performance/io-cache/src/io-cache.c @@ -27,6 +27,7 @@ #include "dict.h" #include "xlator.h" #include "io-cache.h" +#include "ioc-mem-types.h" #include <assert.h> #include <sys/time.h> @@ -259,7 +260,8 @@ ioc_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, ioc_local_t *local = NULL; int32_t op_errno = -1, ret = -1; - local = CALLOC (1, sizeof (*local)); + local = GF_CALLOC (1, sizeof (*local), + gf_ioc_mt_ioc_local_t); if (local == NULL) { op_errno = ENOMEM; gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -401,7 +403,8 @@ ioc_wait_on_inode (ioc_inode_t *ioc_inode, ioc_page_t *page) } if (!page_found) { - waiter = CALLOC (1, sizeof (ioc_waitq_t)); + waiter = GF_CALLOC (1, sizeof (ioc_waitq_t), + gf_ioc_mt_ioc_waitq_t); if (waiter == NULL) { gf_log (ioc_inode->table->xl->name, GF_LOG_ERROR, "out of memory"); @@ -436,7 +439,8 @@ ioc_cache_validate (call_frame_t *frame, ioc_inode_t *ioc_inode, fd_t *fd, int32_t ret = 0; local = frame->local; - validate_local = CALLOC (1, sizeof (ioc_local_t)); + validate_local = GF_CALLOC (1, sizeof (ioc_local_t), + gf_ioc_mt_ioc_local_t); if (validate_local == NULL) { ret = -1; local->op_ret = -1; @@ -451,7 +455,7 @@ ioc_cache_validate (call_frame_t *frame, ioc_inode_t *ioc_inode, fd_t *fd, ret = -1; local->op_ret = -1; local->op_errno = ENOMEM; - FREE (validate_local); + GF_FREE (validate_local); gf_log (ioc_inode->table->xl->name, GF_LOG_ERROR, "out of memory"); goto out; @@ -563,7 +567,7 @@ ioc_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, } } - FREE (local); + GF_FREE (local); frame->local = NULL; STACK_UNWIND_STRICT (open, frame, op_ret, op_errno, fd); @@ -641,7 +645,7 @@ ioc_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } frame->local = NULL; - FREE (local); + GF_FREE (local); STACK_UNWIND_STRICT (create, frame, op_ret, op_errno, fd, inode, buf, preparent, postparent); @@ -664,7 +668,7 @@ ioc_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, ioc_local_t *local = NULL; - local = CALLOC (1, sizeof (ioc_local_t)); + local = GF_CALLOC (1, sizeof (ioc_local_t), gf_ioc_mt_ioc_local_t); if (local == NULL) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); STACK_UNWIND_STRICT (open, frame, -1, ENOMEM, NULL); @@ -698,8 +702,8 @@ ioc_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, mode_t mode, fd_t *fd) { ioc_local_t *local = NULL; - - local = CALLOC (1, sizeof (ioc_local_t)); + + local = GF_CALLOC (1, sizeof (ioc_local_t), gf_ioc_mt_ioc_local_t); if (local == NULL) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); STACK_UNWIND_STRICT (create, frame, -1, ENOMEM, NULL, NULL, @@ -1021,7 +1025,8 @@ ioc_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, return 0; } - local = (ioc_local_t *) CALLOC (1, sizeof (ioc_local_t)); + local = (ioc_local_t *) GF_CALLOC (1, sizeof (ioc_local_t), + gf_ioc_mt_ioc_local_t); if (local == NULL) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); op_errno = ENOMEM; @@ -1105,7 +1110,7 @@ ioc_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, ioc_local_t *local = NULL; uint64_t ioc_inode = 0; - local = CALLOC (1, sizeof (ioc_local_t)); + local = GF_CALLOC (1, sizeof (ioc_local_t), gf_ioc_mt_ioc_local_t); if (local == NULL) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); @@ -1270,7 +1275,7 @@ ioc_get_priority_list (const char *opt_str, struct list_head *first) char *string = NULL; struct ioc_priority *curr = NULL, *tmp = NULL; - string = strdup (opt_str); + string = gf_strdup (opt_str); if (string == NULL) { max_pri = -1; goto out; @@ -1284,7 +1289,8 @@ ioc_get_priority_list (const char *opt_str, struct list_head *first) */ stripe_str = strtok_r (string, ",", &tmp_str); while (stripe_str) { - curr = CALLOC (1, sizeof (struct ioc_priority)); + curr = GF_CALLOC (1, sizeof (struct ioc_priority), + gf_ioc_mt_ioc_priority); if (curr == NULL) { max_pri = -1; goto out; @@ -1292,7 +1298,7 @@ ioc_get_priority_list (const char *opt_str, struct list_head *first) list_add_tail (&curr->list, first); - dup_str = strdup (stripe_str); + dup_str = gf_strdup (stripe_str); if (dup_str == NULL) { max_pri = -1; goto out; @@ -1315,7 +1321,7 @@ ioc_get_priority_list (const char *opt_str, struct list_head *first) pattern, priority); - curr->pattern = strdup (pattern); + curr->pattern = gf_strdup (pattern); if (curr->pattern == NULL) { max_pri = -1; goto out; @@ -1329,31 +1335,50 @@ ioc_get_priority_list (const char *opt_str, struct list_head *first) max_pri = max (max_pri, curr->priority); } - free (dup_str); + GF_FREE (dup_str); dup_str = NULL; stripe_str = strtok_r (NULL, ",", &tmp_str); } out: if (string != NULL) { - free (string); + GF_FREE (string); } if (dup_str != NULL) { - free (dup_str); + GF_FREE (dup_str); } if (max_pri == -1) { list_for_each_entry_safe (curr, tmp, first, list) { list_del_init (&curr->list); - free (curr->pattern); - free (curr); + GF_FREE (curr->pattern); + GF_FREE (curr); } } return max_pri; } +int32_t +mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_ioc_mt_end + 1); + + if (ret != 0) { + gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" + "failed"); + return ret; + } + + return ret; +} + /* * init - * @this: @@ -1381,7 +1406,7 @@ init (xlator_t *this) "dangling volume. check volfile "); } - table = (void *) CALLOC (1, sizeof (*table)); + table = (void *) GF_CALLOC (1, sizeof (*table), gf_ioc_mt_ioc_table_t); if (table == NULL) { gf_log (this->name, GF_LOG_ERROR, "out of memory"); goto out; @@ -1477,7 +1502,9 @@ init (xlator_t *this) goto out; } - table->inode_lru = CALLOC (table->max_pri, sizeof (struct list_head)); + table->inode_lru = GF_CALLOC (table->max_pri, + sizeof (struct list_head), + gf_ioc_mt_list_head); if (table->inode_lru == NULL) { goto out; } @@ -1495,8 +1522,8 @@ init (xlator_t *this) out: if (ret == -1) { if (table != NULL) { - free (table->inode_lru); - free (table); + GF_FREE (table->inode_lru); + GF_FREE (table); } } @@ -1518,7 +1545,7 @@ fini (xlator_t *this) return; pthread_mutex_destroy (&table->table_lock); - FREE (table); + GF_FREE (table); this->private = NULL; return; diff --git a/xlators/performance/io-cache/src/ioc-inode.c b/xlators/performance/io-cache/src/ioc-inode.c index 763f329db..561913481 100644 --- a/xlators/performance/io-cache/src/ioc-inode.c +++ b/xlators/performance/io-cache/src/ioc-inode.c @@ -23,6 +23,7 @@ #endif #include "io-cache.h" +#include "ioc-mem-types.h" extern int ioc_log2_page_size; @@ -51,7 +52,7 @@ ptr_to_str (void *ptr) { int ret = 0; char *str = NULL; - ret = asprintf (&str, "%p", ptr); + ret = gf_asprintf (&str, "%p", ptr); if (-1 == ret) { gf_log ("ioc", GF_LOG_ERROR, "asprintf failed while converting ptr to str"); @@ -137,7 +138,7 @@ ioc_inode_wakeup (call_frame_t *frame, ioc_inode_t *ioc_inode, waiter = waiter->next; waited->data = NULL; - free (waited); + GF_FREE (waited); } } @@ -157,7 +158,8 @@ ioc_inode_update (ioc_table_t *table, inode_t *inode, uint32_t weight) ioc_inode_t *ioc_inode = NULL; unsigned long no_of_pages = 0; - ioc_inode = CALLOC (1, sizeof (ioc_inode_t)); + ioc_inode = GF_CALLOC (1, sizeof (ioc_inode_t), + gf_ioc_mt_ioc_inode_t); if (ioc_inode == NULL) { goto out; } @@ -213,5 +215,5 @@ ioc_inode_destroy (ioc_inode_t *ioc_inode) rbthash_table_destroy (ioc_inode->cache.page_table); pthread_mutex_destroy (&ioc_inode->inode_lock); - free (ioc_inode); + GF_FREE (ioc_inode); } diff --git a/xlators/performance/io-cache/src/ioc-mem-types.h b/xlators/performance/io-cache/src/ioc-mem-types.h new file mode 100644 index 000000000..d1da65ca1 --- /dev/null +++ b/xlators/performance/io-cache/src/ioc-mem-types.h @@ -0,0 +1,40 @@ +/* + Copyright (c) 2007-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 __IOC_MT_H__ +#define __IOC_MT_H__ + +#include "mem-types.h" + +enum gf_ioc_mem_types_ { + gf_ioc_mt_iovec = gf_common_mt_end + 1, + gf_ioc_mt_ioc_table_t, + gf_ioc_mt_char, + gf_ioc_mt_ioc_local_t, + gf_ioc_mt_ioc_waitq_t, + gf_ioc_mt_ioc_priority, + gf_ioc_mt_list_head, + gf_ioc_mt_call_pool_t, + gf_ioc_mt_ioc_inode_t, + gf_ioc_mt_ioc_fill_t, + gf_ioc_mt_ioc_newpage_t, + gf_ioc_mt_end +}; +#endif + diff --git a/xlators/performance/io-cache/src/page.c b/xlators/performance/io-cache/src/page.c index 28be2b358..7209abb08 100644 --- a/xlators/performance/io-cache/src/page.c +++ b/xlators/performance/io-cache/src/page.c @@ -27,6 +27,7 @@ #include "dict.h" #include "xlator.h" #include "io-cache.h" +#include "ioc-mem-types.h" #include <assert.h> #include <sys/time.h> @@ -86,7 +87,7 @@ ioc_page_destroy (ioc_page_t *page) if (page->vector){ iobref_unref (page->iobref); - free (page->vector); + GF_FREE (page->vector); page->vector = NULL; } @@ -95,7 +96,7 @@ ioc_page_destroy (ioc_page_t *page) if (page_size != -1) { pthread_mutex_destroy (&page->page_lock); - free (page); + GF_FREE (page); } return page_size; @@ -194,7 +195,8 @@ ioc_page_create (ioc_inode_t *ioc_inode, off_t offset) table = ioc_inode->table; rounded_offset = floor (offset, table->page_size); - newpage = CALLOC (1, sizeof (*newpage)); + newpage = GF_CALLOC (1, sizeof (*newpage), + gf_ioc_mt_ioc_newpage_t); if (newpage == NULL) { goto out; } @@ -202,7 +204,7 @@ ioc_page_create (ioc_inode_t *ioc_inode, off_t offset) if (ioc_inode) { table = ioc_inode->table; } else { - free (newpage); + GF_FREE (newpage); newpage = NULL; goto out; } @@ -241,7 +243,7 @@ ioc_wait_on_page (ioc_page_t *page, call_frame_t *frame, off_t offset, ioc_waitq_t *waitq = NULL; ioc_local_t *local = frame->local; - waitq = CALLOC (1, sizeof (*waitq)); + waitq = GF_CALLOC (1, sizeof (*waitq), gf_ioc_mt_ioc_waitq_t); if (waitq == NULL) { local->op_ret = -1; local->op_errno = ENOMEM; @@ -322,7 +324,7 @@ ioc_waitq_return (ioc_waitq_t *waitq) frame = trav->data; ioc_frame_return (frame); - free (trav); + GF_FREE (trav); } } @@ -394,7 +396,7 @@ ioc_fault_cbk (call_frame_t *frame, void *cookie, xlator_t *this, } else { if (page->vector) { iobref_unref (page->iobref); - free (page->vector); + GF_FREE (page->vector); page->vector = NULL; } @@ -507,7 +509,8 @@ ioc_page_fault (ioc_inode_t *ioc_inode, call_frame_t *frame, fd_t *fd, goto err; } - fault_local = CALLOC (1, sizeof (ioc_local_t)); + fault_local = GF_CALLOC (1, sizeof (ioc_local_t), + gf_ioc_mt_ioc_local_t); if (fault_local == NULL) { op_ret = -1; op_errno = ENOMEM; @@ -603,7 +606,8 @@ ioc_frame_fill (ioc_page_t *page, call_frame_t *frame, off_t offset, copy_size, src_offset, dst_offset); { - new = CALLOC (1, sizeof (*new)); + new = GF_CALLOC (1, sizeof (*new), + gf_ioc_mt_ioc_fill_t); if (new == NULL) { local->op_ret = -1; local->op_errno = ENOMEM; @@ -622,14 +626,15 @@ ioc_frame_fill (ioc_page_t *page, call_frame_t *frame, off_t offset, src_offset + copy_size, NULL); - new->vector = CALLOC (new->count, - sizeof (struct iovec)); + new->vector = GF_CALLOC (new->count, + sizeof (struct iovec), + gf_ioc_mt_iovec); if (new->vector == NULL) { local->op_ret = -1; local->op_errno = ENOMEM; iobref_unref (new->iobref); - FREE (new); + GF_FREE (new); ret = -1; gf_log (page->inode->table->xl->name, @@ -722,7 +727,7 @@ ioc_frame_unwind (call_frame_t *frame) count += fill->count; } - vector = CALLOC (count, sizeof (*vector)); + vector = GF_CALLOC (count, sizeof (*vector), gf_ioc_mt_iovec); if (vector == NULL) { op_ret = -1; op_errno = ENOMEM; @@ -743,8 +748,8 @@ ioc_frame_unwind (call_frame_t *frame) list_del (&fill->list); iobref_unref (fill->iobref); - free (fill->vector); - free (fill); + GF_FREE (fill->vector); + GF_FREE (fill); } if (op_ret != -1) { @@ -764,12 +769,12 @@ ioc_frame_unwind (call_frame_t *frame) } if (vector != NULL) { - free (vector); + GF_FREE (vector); vector = NULL; } pthread_mutex_destroy (&local->local_lock); - free (local); + GF_FREE (local); return; } |