summaryrefslogtreecommitdiffstats
path: root/scheduler/random/src/random.c
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/src/random.c
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/src/random.c')
-rw-r--r--scheduler/random/src/random.c34
1 files changed, 28 insertions, 6 deletions
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[] = {