core: bring a cmdline option to set memory-accounting

currently this is implemented as a command line option, and not
as an easier translator option. this is because as of now, before
even the volume files are parsed, we would need memory accounting
enabled. there is scope for improving this behavior, but for now,
this approach solves the problem.

Also, this feature's major consumers are the testers who are
looking for leaks, hence option is hidden from usage output.

Change-Id: I09a5b13743ae43ff42c251989f921319e94cabe3
Signed-off-by: Amar Tumballi <amarts@redhat.com>
BUG: 799199
Reviewed-on: http://review.gluster.com/2856
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vijay@gluster.com>
This commit is contained in:
Amar Tumballi 2012-03-15 14:00:13 +05:30 committed by Vijay Bellur
parent eb8a9aae19
commit 5e50175f56
10 changed files with 91 additions and 42 deletions

View File

@ -185,6 +185,8 @@ static struct argp_option gf_options[] = {
"Dump fuse traffic to PATH"},
{"volfile-check", ARGP_VOLFILE_CHECK_KEY, 0, 0,
"Enable strict volume file checking"},
{"mem-accounting", ARGP_MEM_ACCOUNTING_KEY, 0, OPTION_HIDDEN,
"Enable internal memory accounting"},
{0, 0, 0, 0, "Miscellaneous Options:"},
{0, }
};
@ -501,6 +503,7 @@ out:
static error_t
parse_opts (int key, char *arg, struct argp_state *state)
{
glusterfs_ctx_t *ctx = NULL;
cmd_args_t *cmd_args = NULL;
uint32_t n = 0;
double d = 0.0;
@ -763,6 +766,12 @@ parse_opts (int key, char *arg, struct argp_state *state)
argp_failure (state, -1, 0,
"unknown brick (listen) port %s", arg);
break;
case ARGP_MEM_ACCOUNTING_KEY:
/* TODO: it should have got handled much earlier */
ctx = glusterfs_ctx_get ();
ctx->mem_accounting = 1;
break;
}
return 0;
@ -1102,6 +1111,17 @@ logging_init (glusterfs_ctx_t *ctx)
return 0;
}
void
gf_check_and_set_mem_acct (int argc, char *argv[], glusterfs_ctx_t *ctx)
{
int i = 0;
for (i = 0; i < argc; i++) {
if (strcmp (argv[i], "--mem-accounting") == 0) {
ctx->mem_accounting = 1;
break;
}
}
}
int
parse_cmdline (int argc, char *argv[], glusterfs_ctx_t *ctx)
@ -1582,7 +1602,10 @@ main (int argc, char *argv[])
"ERROR: glusterfs context not initialized");
return ENOMEM;
}
#ifndef DEBUG
/* Enable memory accounting on the fly based on argument */
gf_check_and_set_mem_acct (argc, argv, ctx);
#endif
ret = glusterfs_ctx_defaults_init (ctx);
if (ret)
goto out;

View File

@ -80,6 +80,7 @@ enum argp_option_keys {
ARGP_ACL_KEY = 154,
ARGP_WORM_KEY = 155,
ARGP_USER_MAP_ROOT_KEY = 156,
ARGP_MEM_ACCOUNTING_KEY = 157,
};
struct _gfd_vol_top_priv_t {

View File

@ -376,6 +376,8 @@ struct _glusterfs_ctx {
struct mem_pool *dict_pair_pool;
struct mem_pool *dict_data_pool;
int mem_accounting; /* if value is other than 0, it
will be set */
};
typedef struct _glusterfs_ctx glusterfs_ctx_t;

View File

@ -50,26 +50,31 @@ gf_mem_acct_is_enabled ()
void
gf_mem_acct_enable_set ()
{
char *opt = NULL;
long val = -1;
#ifdef DEBUG
gf_mem_acct_enable = 1;
return;
#endif
glusterfs_ctx_t *ctx = NULL;
char *opt = NULL;
long val = -1;
gf_mem_acct_enable = 0;
ctx = glusterfs_ctx_get ();
if (ctx->mem_accounting) {
gf_mem_acct_enable = 1;
return;
}
opt = getenv (GLUSTERFS_ENV_MEM_ACCT_STR);
if (opt) {
val = strtol (opt, NULL, 0);
if (val)
gf_mem_acct_enable = 1;
}
if (!opt)
return;
val = strtol (opt, NULL, 0);
if (val)
gf_mem_acct_enable = 0;
else
gf_mem_acct_enable = 1;
return;
}
void

View File

@ -391,11 +391,25 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr)
global_opt = _gf_false;
sprintf (str, "key%d", count);
ret = dict_get_str (dict, str, &key);
if (ret)
break;
sprintf (str, "value%d", count);
ret = dict_get_str (dict, str, &value);
if (ret) {
gf_log (this->name, GF_LOG_ERROR,
"invalid key,value pair in 'volume set'");
ret = -1;
goto out;
}
if (strcmp (key, "memory-accounting") == 0) {
gf_log (this->name, GF_LOG_INFO,
"enabling memory accounting for volume %s",
volname);
ret = 0;
goto out;
}
exists = glusterd_check_option_exists (key, &key_fixed);
if (exists == -1) {
ret = -1;
@ -416,16 +430,6 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr)
goto out;
}
sprintf (str, "value%d", count);
ret = dict_get_str (dict, str, &value);
if (ret) {
gf_log (this->name, GF_LOG_ERROR,
"invalid key,value pair in 'volume set'");
ret = -1;
goto out;
}
if (key_fixed)
key = key_fixed;
@ -1008,24 +1012,9 @@ glusterd_op_set_volume (dict_t *dict)
global_opt = _gf_false;
sprintf (str, "key%d", count);
ret = dict_get_str (dict, str, &key);
if (ret)
break;
if (!ret) {
ret = glusterd_check_option_exists (key, &key_fixed);
GF_ASSERT (ret);
if (ret == -1) {
key_fixed = NULL;
goto out;
}
ret = 0;
}
ret = glusterd_check_globaloption (key);
if (ret)
global_opt = _gf_true;
sprintf (str, "value%d", count);
ret = dict_get_str (dict, str, &value);
if (ret) {
@ -1035,6 +1024,22 @@ glusterd_op_set_volume (dict_t *dict)
goto out;
}
if (strcmp (key, "memory-accounting") == 0) {
ret = gf_string2boolean (value,
&volinfo->memory_accounting);
goto out;
}
ret = glusterd_check_option_exists (key, &key_fixed);
GF_ASSERT (ret);
if (ret == -1) {
key_fixed = NULL;
goto out;
}
ret = glusterd_check_globaloption (key);
if (ret)
global_opt = _gf_true;
if (!global_opt)
value = gf_strdup (value);
@ -1067,7 +1072,7 @@ glusterd_op_set_volume (dict_t *dict)
}
}
if ( count == 1 ) {
if (count == 1) {
gf_log (this->name, GF_LOG_ERROR, "No options received ");
ret = -1;
goto out;

View File

@ -327,6 +327,8 @@ glusterd_handle_defrag_start (glusterd_volinfo_t *volinfo, char *op_errstr,
runner_argprintf (&runner, "%s",pidfile);
runner_add_arg (&runner, "-l");
runner_argprintf (&runner, logfile);
if (volinfo->memory_accounting)
runner_add_arg (&runner, "--mem-accounting");
ret = runner_run_reuse (&runner);
if (ret) {

View File

@ -635,6 +635,8 @@ rb_spawn_dst_brick (glusterd_volinfo_t *volinfo,
priv->workdir, volinfo->volname);
runner_add_arg (&runner, "--xlator-option");
runner_argprintf (&runner, "src-server.listen-port=%d", port);
if (volinfo->memory_accounting)
runner_add_arg (&runner, "--mem-accounting");
ret = runner_run (&runner);
if (ret) {
@ -671,6 +673,8 @@ rb_spawn_glusterfs_client (glusterd_volinfo_t *volinfo,
priv->workdir, volinfo->volname);
runner_argprintf (&runner, "%s/vols/%s/"RB_CLIENT_MOUNTPOINT,
priv->workdir, volinfo->volname);
if (volinfo->memory_accounting)
runner_add_arg (&runner, "--mem-accounting");
ret = runner_run (&runner);
if (ret) {

View File

@ -1236,6 +1236,9 @@ glusterd_volume_start_glusterfs (glusterd_volinfo_t *volinfo,
runner_argprintf (&runner, "%s-server.listen-port=%d",
volinfo->volname, port);
if (volinfo->memory_accounting)
runner_add_arg (&runner, "--mem-accounting");
runner_log (&runner, "", GF_LOG_DEBUG, "Starting GlusterFS");
ret = runner_run (&runner);

View File

@ -1665,6 +1665,8 @@ glusterd_clearlocks_mount (glusterd_volinfo_t *volinfo, char **xl_opts,
runner_add_arg (&runner, "-l");
runner_argprintf (&runner, DEFAULT_LOG_FILE_DIRECTORY
"/%s-clearlocks-mnt.log", volinfo->volname);
if (volinfo->memory_accounting)
runner_add_arg (&runner, "--mem-accounting");
for (i = 0; i < volinfo->brick_count && xl_opts[i]; i++) {
runner_add_arg (&runner, "--xlator-option");

View File

@ -244,6 +244,8 @@ struct glusterd_volinfo_ {
int decommission_in_progress;
xlator_t *xl;
gf_boolean_t memory_accounting;
};
typedef enum gd_node_type_ {