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 /scheduler/nufa | |
| 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 'scheduler/nufa')
| -rw-r--r-- | scheduler/nufa/src/nufa-mem-types.h | 33 | ||||
| -rw-r--r-- | scheduler/nufa/src/nufa.c | 54 | 
2 files changed, 72 insertions, 15 deletions
diff --git a/scheduler/nufa/src/nufa-mem-types.h b/scheduler/nufa/src/nufa-mem-types.h new file mode 100644 index 00000000000..d8ce993daf9 --- /dev/null +++ b/scheduler/nufa/src/nufa-mem-types.h @@ -0,0 +1,33 @@ +/* +   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 __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 92b70ca7580..f089782cd8c 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[] = {  | 
