From 582de0677da4be19fc6f873625c58c45d069ab1c Mon Sep 17 00:00:00 2001 From: Vijay Bellur Date: Thu, 22 Apr 2010 13:33:09 +0000 Subject: Memory accounting changes Memory accounting Changes. Thanks to Vinayak Hegde and Csaba Henk for their contributions. Signed-off-by: Vijay Bellur Signed-off-by: Anand V. Avati BUG: 329 (Replacing memory allocation functions with mem-type functions) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=329 --- scheduler/nufa/src/nufa-mem-types.h | 33 +++++++++++++++++++++++ scheduler/nufa/src/nufa.c | 54 ++++++++++++++++++++++++++----------- 2 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 scheduler/nufa/src/nufa-mem-types.h (limited to 'scheduler/nufa') diff --git a/scheduler/nufa/src/nufa-mem-types.h b/scheduler/nufa/src/nufa-mem-types.h new file mode 100644 index 000000000..d8ce993da --- /dev/null +++ b/scheduler/nufa/src/nufa-mem-types.h @@ -0,0 +1,33 @@ +/* + Copyright (c) 2008-2009 Gluster, Inc. + 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 + . +*/ + + +#ifndef __NUFA_MEM_TYPES_H__ +#define __NUFA_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_locks_mem_types_ { + gf_nufa_mt_nufa_struct = gf_common_mt_end + 1, + gf_nufa_mt_nufa_sched_struct, + gf_nufa_mt_int32_t, + gf_nufa_mt_end +}; +#endif + diff --git a/scheduler/nufa/src/nufa.c b/scheduler/nufa/src/nufa.c index 92b70ca75..f089782cd 100644 --- a/scheduler/nufa/src/nufa.c +++ b/scheduler/nufa/src/nufa.c @@ -26,6 +26,7 @@ #include "scheduler.h" #include "common-utils.h" +#include "nufa-mem-types.h" struct nufa_sched_struct { xlator_t *xl; @@ -63,7 +64,8 @@ nufa_init (xlator_t *xl) xlator_list_t *trav_xl = xl->children; struct nufa_struct *nufa_buf = NULL; - nufa_buf = CALLOC (1, sizeof (struct nufa_struct)); + nufa_buf = GF_CALLOC (1, sizeof (struct nufa_struct), + gf_nufa_mt_nufa_struct); ERR_ABORT (nufa_buf); data = dict_get (xl->options, "scheduler.limits.min-free-disk"); @@ -112,9 +114,11 @@ nufa_init (xlator_t *xl) } nufa_buf->child_count = index; nufa_buf->sched_index = 0; - nufa_buf->array = CALLOC (index, sizeof (struct nufa_sched_struct)); + nufa_buf->array = GF_CALLOC (index, sizeof (struct nufa_sched_struct), + gf_nufa_mt_nufa_sched_struct); ERR_ABORT (nufa_buf->array); - nufa_buf->local_array = CALLOC (index, sizeof (int32_t)); + nufa_buf->local_array = GF_CALLOC (index, sizeof (int32_t), + gf_nufa_mt_int32_t); ERR_ABORT (nufa_buf->array); trav_xl = xl->children; @@ -123,9 +127,9 @@ nufa_init (xlator_t *xl) /* Error */ gf_log ("nufa", GF_LOG_ERROR, "No 'local-volume-name' option given in volume file"); - FREE (nufa_buf->array); - FREE (nufa_buf->local_array); - FREE (nufa_buf); + GF_FREE (nufa_buf->array); + GF_FREE (nufa_buf->local_array); + GF_FREE (nufa_buf); return -1; } @@ -147,7 +151,7 @@ nufa_init (xlator_t *xl) int32_t array_index = 0; char *child = NULL; char *tmp = NULL; - char *childs_data = strdup (local_name->data); + char *childs_data = gf_strdup (local_name->data); child = strtok_r (childs_data, ",", &tmp); while (child) { @@ -168,9 +172,9 @@ nufa_init (xlator_t *xl) gf_log ("nufa", GF_LOG_ERROR, "option 'scheduler.local-volume-name' " "%s is wrong", child); - FREE (nufa_buf->array); - FREE (nufa_buf->local_array); - FREE (nufa_buf); + GF_FREE (nufa_buf->array); + GF_FREE (nufa_buf->local_array); + GF_FREE (nufa_buf); return -1; } else { nufa_buf->local_array[array_index++] = index; @@ -178,7 +182,7 @@ nufa_init (xlator_t *xl) } child = strtok_r (NULL, ",", &tmp); } - free (childs_data); + GF_FREE (childs_data); } LOCK_INIT (&nufa_buf->nufa_lock); @@ -193,9 +197,9 @@ nufa_fini (xlator_t *xl) (struct nufa_struct *)*((long *)xl->private); LOCK_DESTROY (&nufa_buf->nufa_lock); - FREE (nufa_buf->local_array); - FREE (nufa_buf->array); - FREE (nufa_buf); + GF_FREE (nufa_buf->local_array); + GF_FREE (nufa_buf->array); + GF_FREE (nufa_buf); } static int32_t @@ -379,12 +383,32 @@ nufa_notify (xlator_t *xl, int32_t event, void *data) } +int32_t +nufa_mem_acct_init (xlator_t *this) +{ + int ret = -1; + + if (!this) + return ret; + + ret = xlator_mem_acct_init (this, gf_nufa_mt_end + 1); + + if (ret != 0) { + gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" + "failed"); + return ret; + } + + return ret; +} + struct sched_ops sched = { .init = nufa_init, .fini = nufa_fini, .update = nufa_update, .schedule = nufa_schedule, - .notify = nufa_notify + .notify = nufa_notify, + .mem_acct_init = nufa_mem_acct_init, }; struct volume_options options[] = { -- cgit