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/features/locks | |
| 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/features/locks')
| -rw-r--r-- | xlators/features/locks/src/common.c | 49 | ||||
| -rw-r--r-- | xlators/features/locks/src/entrylk.c | 29 | ||||
| -rw-r--r-- | xlators/features/locks/src/inodelk.c | 9 | ||||
| -rw-r--r-- | xlators/features/locks/src/locks-mem-types.h | 39 | ||||
| -rw-r--r-- | xlators/features/locks/src/locks.h | 1 | ||||
| -rw-r--r-- | xlators/features/locks/src/posix.c | 60 | 
6 files changed, 132 insertions, 55 deletions
diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c index 83800ff5aeb..9568c2a5e9c 100644 --- a/xlators/features/locks/src/common.c +++ b/xlators/features/locks/src/common.c @@ -48,12 +48,13 @@ allocate_domain (const char *volume)  {          pl_dom_list_t *dom = NULL; -        dom = CALLOC (1, sizeof (*dom)); +        dom = GF_CALLOC (1, sizeof (*dom), +                         gf_locks_mt_pl_dom_list_t);          if (!dom)                  return NULL; -        dom->domain = strdup(volume); +        dom->domain = gf_strdup(volume);  	if (!dom->domain) {  		gf_log ("posix-locks", GF_LOG_TRACE,  			"Out of Memory"); @@ -151,7 +152,7 @@ pl_print_lockee (char *str, int size, fd_t *fd, loc_t *loc)          }          if (loc && loc->path) { -                ipath = strdup (loc->path); +                ipath = gf_strdup (loc->path);          } else {                  ret = inode_path (inode, NULL, &ipath);                  if (ret <= 0) @@ -163,7 +164,7 @@ pl_print_lockee (char *str, int size, fd_t *fd, loc_t *loc)                    ipath ? ipath : "<nul>");          if (ipath) -                FREE (ipath); +                GF_FREE (ipath);  } @@ -418,7 +419,8 @@ pl_inode_get (xlator_t *this, inode_t *inode)                  pl_inode = (pl_inode_t *)(long)tmp_pl_inode;  		goto out;          } -	pl_inode = CALLOC (1, sizeof (*pl_inode)); +	pl_inode = GF_CALLOC (1, sizeof (*pl_inode), +                              gf_locks_mt_pl_inode_t);  	if (!pl_inode) {  		gf_log (this->name, GF_LOG_ERROR,  			"Out of memory."); @@ -454,7 +456,8 @@ new_posix_lock (struct flock *flock, transport_t *transport, pid_t client_pid,  {  	posix_lock_t *lock = NULL; -	lock = CALLOC (1, sizeof (posix_lock_t)); +	lock = GF_CALLOC (1, sizeof (posix_lock_t), +                          gf_locks_mt_posix_lock_t);  	if (!lock) {  		return NULL;  	} @@ -490,7 +493,7 @@ __delete_lock (pl_inode_t *pl_inode, posix_lock_t *lock)  void  __destroy_lock (posix_lock_t *lock)  { -	free (lock); +	GF_FREE (lock);  } @@ -567,7 +570,8 @@ add_locks (posix_lock_t *l1, posix_lock_t *l2)  {  	posix_lock_t *sum = NULL; -	sum = CALLOC (1, sizeof (posix_lock_t)); +	sum = GF_CALLOC (1, sizeof (posix_lock_t), +                         gf_locks_mt_posix_lock_t);  	if (!sum)  		return NULL; @@ -591,7 +595,8 @@ subtract_locks (posix_lock_t *big, posix_lock_t *small)  	if ((big->fl_start == small->fl_start) &&   	    (big->fl_end   == small->fl_end)) {    		/* both edges coincide with big */ -		v.locks[0] = CALLOC (1, sizeof (posix_lock_t)); +		v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t), +                                        gf_locks_mt_posix_lock_t);  		ERR_ABORT (v.locks[0]);  		memcpy (v.locks[0], big, sizeof (posix_lock_t));  		v.locks[0]->fl_type = small->fl_type; @@ -599,11 +604,14 @@ subtract_locks (posix_lock_t *big, posix_lock_t *small)  	else if ((small->fl_start > big->fl_start) &&  		 (small->fl_end   < big->fl_end)) {  		/* both edges lie inside big */ -		v.locks[0] = CALLOC (1, sizeof (posix_lock_t)); +		v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t), +                                        gf_locks_mt_posix_lock_t);  		ERR_ABORT (v.locks[0]); -		v.locks[1] = CALLOC (1, sizeof (posix_lock_t)); +		v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t), +                                        gf_locks_mt_posix_lock_t);  		ERR_ABORT (v.locks[1]); -		v.locks[2] = CALLOC (1, sizeof (posix_lock_t)); +		v.locks[2] = GF_CALLOC (1, sizeof (posix_lock_t), +                                        gf_locks_mt_posix_lock_t);  		ERR_ABORT (v.locks[2]);  		memcpy (v.locks[0], big, sizeof (posix_lock_t)); @@ -615,9 +623,11 @@ subtract_locks (posix_lock_t *big, posix_lock_t *small)  	}  	/* one edge coincides with big */  	else if (small->fl_start == big->fl_start) { -		v.locks[0] = CALLOC (1, sizeof (posix_lock_t)); +		v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t), +                                        gf_locks_mt_posix_lock_t);  		ERR_ABORT (v.locks[0]); -		v.locks[1] = CALLOC (1, sizeof (posix_lock_t)); +		v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t), +                                        gf_locks_mt_posix_lock_t);  		ERR_ABORT (v.locks[1]);  		memcpy (v.locks[0], big, sizeof (posix_lock_t)); @@ -626,9 +636,11 @@ subtract_locks (posix_lock_t *big, posix_lock_t *small)  		memcpy (v.locks[1], small, sizeof (posix_lock_t));  	}  	else if (small->fl_end   == big->fl_end) { -		v.locks[0] = CALLOC (1, sizeof (posix_lock_t)); +		v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t), +                                        gf_locks_mt_posix_lock_t);  		ERR_ABORT (v.locks[0]); -		v.locks[1] = CALLOC (1, sizeof (posix_lock_t)); +		v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t), +                                        gf_locks_mt_posix_lock_t);  		ERR_ABORT (v.locks[1]);  		memcpy (v.locks[0], big, sizeof (posix_lock_t)); @@ -800,7 +812,8 @@ __grant_blocked_locks (xlator_t *this, pl_inode_t *pl_inode, struct list_head *g                  list_del_init (&l->list);                  if (__is_lock_grantable (pl_inode, l)) { -                        conf = CALLOC (1, sizeof (*conf)); +			conf = GF_CALLOC (1, sizeof (*conf), +                                          gf_locks_mt_posix_lock_t);                          if (!conf) {                                  l->blocked = 1; @@ -855,7 +868,7 @@ grant_blocked_locks (xlator_t *this, pl_inode_t *pl_inode)                  STACK_UNWIND (lock->frame, 0, 0, &lock->user_flock); -                FREE (lock); +                GF_FREE (lock);          }          return; diff --git a/xlators/features/locks/src/entrylk.c b/xlators/features/locks/src/entrylk.c index b83044b7f28..e4b9bb5687e 100644 --- a/xlators/features/locks/src/entrylk.c +++ b/xlators/features/locks/src/entrylk.c @@ -40,12 +40,13 @@ new_entrylk_lock (pl_inode_t *pinode, const char *basename, entrylk_type type,  {  	pl_entry_lock_t *newlock = NULL; -	newlock = CALLOC (1, sizeof (pl_entry_lock_t)); +	newlock = GF_CALLOC (1, sizeof (pl_entry_lock_t), +                             gf_locks_mt_pl_entry_lock_t);  	if (!newlock) {  		goto out;  	} -	newlock->basename       = basename ? strdup (basename) : NULL; +	newlock->basename       = basename ? gf_strdup (basename) : NULL;  	newlock->type           = type;  	newlock->trans          = trans;  	newlock->volume         = volume; @@ -457,8 +458,8 @@ __grant_blocked_entry_locks (xlator_t *this, pl_inode_t *pl_inode,  			list_add (&bl->blocked_locks, granted);  		} else {  			if (bl->basename) -				FREE (bl->basename); -			FREE (bl); +				GF_FREE ((char *)bl->basename); +			GF_FREE (bl);  		}  	}  	return; @@ -490,12 +491,12 @@ grant_blocked_entry_locks (xlator_t *this, pl_inode_t *pl_inode,  		STACK_UNWIND_STRICT (entrylk, lock->frame, 0, 0); -		FREE (lock->basename); -		FREE (lock); +		GF_FREE ((char *)lock->basename); +		GF_FREE (lock);  	} -	FREE (unlocked->basename); -	FREE (unlocked); +	GF_FREE ((char *)unlocked->basename); +	GF_FREE (unlocked);  	return;  } @@ -545,8 +546,8 @@ release_entry_locks_for_transport (xlator_t *this, pl_inode_t *pinode,                                  "releasing lock on  held by "                                  "{transport=%p}",trans); -			FREE (lock->basename); -			FREE (lock); +			GF_FREE ((char *)lock->basename); +			GF_FREE (lock);  		}  		__grant_blocked_entry_locks (this, pinode, dom, &granted); @@ -561,8 +562,8 @@ release_entry_locks_for_transport (xlator_t *this, pl_inode_t *pinode,                  STACK_UNWIND_STRICT (entrylk, lock->frame, -1, EAGAIN);                  if (lock->basename) -                        FREE (lock->basename); -                FREE (lock); +                        GF_FREE ((char *)lock->basename); +                GF_FREE (lock);          } @@ -572,8 +573,8 @@ release_entry_locks_for_transport (xlator_t *this, pl_inode_t *pinode,  		STACK_UNWIND_STRICT (entrylk, lock->frame, 0, 0);  		if (lock->basename) -			FREE (lock->basename); -		FREE (lock); +			GF_FREE ((char *)lock->basename); +		GF_FREE (lock);  	}  	return 0; diff --git a/xlators/features/locks/src/inodelk.c b/xlators/features/locks/src/inodelk.c index 50a5996d74a..64028d079c3 100644 --- a/xlators/features/locks/src/inodelk.c +++ b/xlators/features/locks/src/inodelk.c @@ -42,7 +42,7 @@ __delete_inode_lock (pl_inode_lock_t *lock)  void  __destroy_inode_lock (pl_inode_lock_t *lock)  { -	FREE (lock); +	GF_FREE (lock);  }  /* Check if 2 inodelks are conflicting on type. Only 2 shared locks don't conflict */ @@ -439,7 +439,7 @@ release_inode_locks_of_transport (xlator_t *this, pl_dom_list_t *dom,          }  unlock:          if (path) -                FREE (path); +                GF_FREE (path);          pthread_mutex_unlock (&pinode->mutex); @@ -447,7 +447,7 @@ unlock:                  list_del_init (&l->blocked_locks);                  STACK_UNWIND_STRICT (inodelk, l->frame, -1, EAGAIN); -                FREE (l); +                GF_FREE (l);          }  	grant_blocked_inode_locks (this, pinode, dom); @@ -515,7 +515,8 @@ new_inode_lock (struct flock *flock, transport_t *transport, pid_t client_pid,  {  	pl_inode_lock_t *lock = NULL; -	lock = CALLOC (1, sizeof (*lock)); +	lock = GF_CALLOC (1, sizeof (*lock), +                          gf_locks_mt_pl_inode_lock_t);  	if (!lock) {  		return NULL;  	} diff --git a/xlators/features/locks/src/locks-mem-types.h b/xlators/features/locks/src/locks-mem-types.h new file mode 100644 index 00000000000..cf50240863b --- /dev/null +++ b/xlators/features/locks/src/locks-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 __LOCKS_MEM_TYPES_H__ +#define __LOCKS_MEM_TYPES_H__ + +#include "mem-types.h" + +enum gf_locks_mem_types_ { +        gf_locks_mt_pl_dom_list_t = gf_common_mt_end + 1, +        gf_locks_mt_pl_inode_t, +        gf_locks_mt_posix_lock_t, +        gf_locks_mt_pl_entry_lock_t, +        gf_locks_mt_pl_inode_lock_t, +        gf_locks_mt_truncate_ops, +        gf_locks_mt_pl_rw_req_t, +        gf_locks_mt_posix_locks_private_t, +        gf_locks_mt_pl_local_t, +        gf_locks_mt_end +}; +#endif + diff --git a/xlators/features/locks/src/locks.h b/xlators/features/locks/src/locks.h index e89092811a6..01764484a0c 100644 --- a/xlators/features/locks/src/locks.h +++ b/xlators/features/locks/src/locks.h @@ -29,6 +29,7 @@  #include "transport.h"  #include "stack.h"  #include "call-stub.h" +#include "locks-mem-types.h"  struct __pl_fd; diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c index 2e6afd9fca6..83b3eb34039 100644 --- a/xlators/features/locks/src/posix.c +++ b/xlators/features/locks/src/posix.c @@ -180,7 +180,8 @@ pl_truncate (call_frame_t *frame, xlator_t *this,  {          struct _truncate_ops *local = NULL; -        local = CALLOC (1, sizeof (struct _truncate_ops)); +	local = GF_CALLOC (1, sizeof (struct _truncate_ops), +                           gf_locks_mt_truncate_ops);          if (!local) {                  gf_log (this->name, GF_LOG_ERROR,                          "Out of memory."); @@ -211,7 +212,8 @@ pl_ftruncate (call_frame_t *frame, xlator_t *this,  {          struct _truncate_ops *local = NULL; -        local = CALLOC (1, sizeof (struct _truncate_ops)); +	local = GF_CALLOC (1, sizeof (struct _truncate_ops), +                           gf_locks_mt_truncate_ops);          if (!local) {                  gf_log (this->name, GF_LOG_ERROR,                          "Out of memory."); @@ -522,7 +524,7 @@ do_blocked_rw (pl_inode_t *pl_inode)          list_for_each_entry_safe (rw, tmp, &wind_list, list) {                  list_del_init (&rw->list);                  call_resume (rw->stub); -                free (rw); +                GF_FREE (rw);          }          return; @@ -601,7 +603,8 @@ pl_readv (call_frame_t *frame, xlator_t *this,                                  goto unlock;                          } -                        rw = CALLOC (1, sizeof (*rw)); +			rw = GF_CALLOC (1, sizeof (*rw), +                                        gf_locks_mt_pl_rw_req_t);                          if (!rw) {                                  gf_log (this->name, GF_LOG_ERROR,                                          "Out of memory."); @@ -617,7 +620,7 @@ pl_readv (call_frame_t *frame, xlator_t *this,                                          "Out of memory.");                                  op_errno = ENOMEM;                                  op_ret = -1; -                                free (rw); +                                GF_FREE (rw);                                  goto unlock;                          } @@ -698,7 +701,8 @@ pl_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,                                  goto unlock;                          } -                        rw = CALLOC (1, sizeof (*rw)); +			rw = GF_CALLOC (1, sizeof (*rw), +                                        gf_locks_mt_pl_rw_req_t);                          if (!rw) {                                  gf_log (this->name, GF_LOG_ERROR,                                          "Out of memory."); @@ -715,7 +719,7 @@ pl_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,                                          "Out of memory.");                                  op_errno = ENOMEM;                                  op_ret = -1; -                                free (rw); +                                GF_FREE (rw);                                  goto unlock;                          } @@ -876,7 +880,7 @@ pl_forget (xlator_t *this,  						  list) {  				list_del (&rw_req->list); -				FREE (rw_req); +				GF_FREE (rw_req);  			}  		} @@ -920,8 +924,8 @@ pl_forget (xlator_t *this,  					list_del_init (&entry_l->domain_list);  					if (entry_l->basename) -						FREE (entry_l->basename); -					FREE (entry_l); +						GF_FREE ((char *)entry_l->basename); +					GF_FREE (entry_l);  				}  				list_splice_init (&dom->blocked_entrylks, &entrylks_released); @@ -930,8 +934,8 @@ pl_forget (xlator_t *this,  			list_del (&dom->inode_list);  			gf_log ("posix-locks", GF_LOG_TRACE,  				" Cleaning up domain: %s", dom->domain); -			FREE (dom->domain); -			FREE (dom); +			GF_FREE ((char *)(dom->domain)); +			GF_FREE (dom);  		}  	} @@ -953,12 +957,12 @@ pl_forget (xlator_t *this,  		STACK_UNWIND_STRICT (entrylk, entry_l->frame, -1, 0);  		if (entry_l->basename) -			FREE (entry_l->basename); -		FREE (entry_l); +			GF_FREE ((char *)entry_l->basename); +		GF_FREE (entry_l);  	} -        FREE (pl_inode); +        GF_FREE (pl_inode);          return 0;  } @@ -1117,7 +1121,7 @@ pl_lookup_cbk (call_frame_t *frame,          frame->local = NULL;          if (local != NULL) -                FREE (local); +                GF_FREE (local);  out:  	STACK_UNWIND (frame, @@ -1143,7 +1147,7 @@ pl_lookup (call_frame_t *frame,          VALIDATE_OR_GOTO (this, out);          VALIDATE_OR_GOTO (loc, out); -        local = CALLOC (1, sizeof (*local)); +        local = GF_CALLOC (1, sizeof (*local), gf_locks_mt_pl_local_t);          if (!local) {                  ret = -1;                  gf_log (this->name, GF_LOG_ERROR, @@ -1437,7 +1441,24 @@ pl_dump_inode (xlator_t *this)          return 0;  } +int32_t +mem_acct_init (xlator_t *this) +{ +        int     ret = -1; + +        if (!this) +                return ret; + +        ret = xlator_mem_acct_init (this, gf_locks_mt_end + 1); +         +        if (ret != 0) { +                gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" +                                "failed"); +                return ret; +        } +        return ret; +}  int  init (xlator_t *this) @@ -1469,7 +1490,8 @@ init (xlator_t *this)                  return -1;          } -        priv = CALLOC (1, sizeof (*priv)); +	priv = GF_CALLOC (1, sizeof (*priv), +                          gf_locks_mt_posix_locks_private_t);          mandatory = dict_get (this->options, "mandatory-locks");          if (mandatory) @@ -1497,7 +1519,7 @@ fini (xlator_t *this)          posix_locks_private_t *priv = NULL;          priv = this->private; -        free (priv); +        GF_FREE (priv);          return 0;  }  | 
