summaryrefslogtreecommitdiffstats
path: root/scheduler/random
diff options
context:
space:
mode:
authorVijay Bellur <vijay@gluster.com>2010-04-22 13:33:09 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-04-23 06:32:52 -0700
commit582de0677da4be19fc6f873625c58c45d069ab1c (patch)
treef10cb3e26e1f92f6ea91034e6f7bb925790dd9bc /scheduler/random
parent72baa17282f5cf749fa743fd601c7b728ece4fa2 (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/random')
-rw-r--r--scheduler/random/src/random-mem-types.h32
-rw-r--r--scheduler/random/src/random.c34
2 files changed, 60 insertions, 6 deletions
diff --git a/scheduler/random/src/random-mem-types.h b/scheduler/random/src/random-mem-types.h
new file mode 100644
index 00000000000..612e53dbdb6
--- /dev/null
+++ b/scheduler/random/src/random-mem-types.h
@@ -0,0 +1,32 @@
+/*
+ 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 __RANDOM_MEM_TYPES_H__
+#define __RANDOM_MEM_TYPES_H__
+
+#include "mem-types.h"
+
+enum gf_random_mem_types_ {
+ gf_random_mt_random_struct = gf_common_mt_end + 1,
+ gf_random_mt_random_sched_struct,
+ gf_random_mt_end
+};
+#endif
+
diff --git a/scheduler/random/src/random.c b/scheduler/random/src/random.c
index 07ed45e7318..e6bd34c3d7e 100644
--- a/scheduler/random/src/random.c
+++ b/scheduler/random/src/random.c
@@ -26,6 +26,7 @@
#endif
#include "random.h"
+#include "random-mem-types.h"
#define RANDOM_LIMITS_MIN_FREE_DISK_DEFAULT 15
#define RANDOM_REFRESH_INTERVAL_DEFAULT 10
@@ -39,7 +40,8 @@ random_init (xlator_t *xl)
data_t *limit = NULL;
int32_t index = 0;
- random_buf = CALLOC (1, sizeof (struct random_struct));
+ random_buf = GF_CALLOC (1, sizeof (struct random_struct),
+ gf_random_mt_random_struct);
ERR_ABORT (random_buf);
/* Set the seed for the 'random' function */
@@ -89,8 +91,9 @@ random_init (xlator_t *xl)
trav_xl = trav_xl->next;
}
random_buf->child_count = index;
- random_buf->array = CALLOC (index,
- sizeof (struct random_sched_struct));
+ random_buf->array = GF_CALLOC (index,
+ sizeof (struct random_sched_struct),
+ gf_random_mt_random_sched_struct);
ERR_ABORT (random_buf->array);
trav_xl = xl->children;
index = 0;
@@ -115,8 +118,8 @@ random_fini (xlator_t *xl)
random_buf = (struct random_struct *)*((long *)xl->private);
pthread_mutex_destroy (&random_buf->random_mutex);
- free (random_buf->array);
- free (random_buf);
+ GF_FREE (random_buf->array);
+ GF_FREE (random_buf);
}
@@ -222,6 +225,24 @@ random_schedule (xlator_t *xl, const void *path)
return random_buf->array[rand].xl;
}
+int32_t
+random_mem_acct_init (xlator_t *this)
+{
+ int ret = -1;
+
+ if (!this)
+ return ret;
+
+ ret = xlator_mem_acct_init (this, gf_random_mt_end + 1);
+
+ if (ret != 0) {
+ gf_log (this->name, GF_LOG_ERROR, "Memory accounting init"
+ " failed");
+ return ret;
+ }
+
+ return ret;
+}
/**
* notify
@@ -267,7 +288,8 @@ struct sched_ops sched = {
.fini = random_fini,
.update = random_update,
.schedule = random_schedule,
- .notify = random_notify
+ .notify = random_notify,
+ .mem_acct_init = random_mem_acct_init,
};
struct volume_options options[] = {