diff options
author | Oleksandr Natalenko <oleksandr@natalenko.name> | 2016-05-17 16:45:44 +0300 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2016-06-01 11:14:43 -0700 |
commit | 0673af0f0c7ba64cce6b030b9194b4d35a357cd4 (patch) | |
tree | 9638ddf0ce70f9432c02c8c97b365858c3c2fb22 /glusterfsd/src/glusterfsd.c | |
parent | 6328ea45733852f299e4457bba97f632d8bada60 (diff) |
glusterfsd/main: Add ability to set oom_score_adj
Give the administrator a possibility to set oom_score_adj for glusterfs
process. Applies to Linux only.
This is a backport of cb8f5e01f639cb6e8715b33bb725210cb0493887.
Change-Id: Iff13c2f4cb28457871c6ebeff6130bce4a8bf543
BUG: 1341697
Signed-off-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Reviewed-on: http://review.gluster.org/14399
Smoke: Gluster Build System <jenkins@build.gluster.com>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Reviewed-on: http://review.gluster.org/14605
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'glusterfsd/src/glusterfsd.c')
-rw-r--r-- | glusterfsd/src/glusterfsd.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c index 8de913be199..02fd72bc2c0 100644 --- a/glusterfsd/src/glusterfsd.c +++ b/glusterfsd/src/glusterfsd.c @@ -32,6 +32,10 @@ #include <errno.h> #include <pwd.h> +#ifdef GF_LINUX_HOST_OS +#include <linux/oom.h> +#endif + #ifdef HAVE_MALLOC_H #include <malloc.h> #endif @@ -208,6 +212,11 @@ static struct argp_option gf_options[] = { {"congestion-threshold", ARGP_FUSE_CONGESTION_THRESHOLD_KEY, "N", 0, "Set fuse module's congestion threshold to N " "[default: 48]"}, +#ifdef GF_LINUX_HOST_OS + {"oom-score-adj", ARGP_OOM_SCORE_ADJ_KEY, "INTEGER", 0, + "Set oom_score_adj value for process" + "[default: 0]"}, +#endif {"client-pid", ARGP_CLIENT_PID_KEY, "PID", OPTION_HIDDEN, "client will authenticate itself with process id PID to server"}, {"no-root-squash", ARGP_FUSE_NO_ROOT_SQUASH_KEY, "BOOL", @@ -774,6 +783,7 @@ parse_opts (int key, char *arg, struct argp_state *state) { cmd_args_t *cmd_args = NULL; uint32_t n = 0; + int32_t k = 0; double d = 0.0; gf_boolean_t b = _gf_false; char *pwd = NULL; @@ -1122,6 +1132,22 @@ parse_opts (int key, char *arg, struct argp_state *state) "unknown congestion threshold option %s", arg); break; +#ifdef GF_LINUX_HOST_OS + case ARGP_OOM_SCORE_ADJ_KEY: + k = 0; + + if (gf_string2int (arg, &k) == 0 && + k >= OOM_SCORE_ADJ_MIN && k <= OOM_SCORE_ADJ_MAX) { + cmd_args->oom_score_adj = gf_strdup (arg); + break; + } + + argp_failure (state, -1, 0, + "unknown oom_score_adj value %s", arg); + + break; +#endif + case ARGP_FUSE_MOUNTOPTS_KEY: cmd_args->fuse_mountopts = gf_strdup (arg); break; @@ -2185,6 +2211,43 @@ out: } +#ifdef GF_LINUX_HOST_OS +static int +set_oom_score_adj (glusterfs_ctx_t *ctx) +{ + int ret = -1; + cmd_args_t *cmd_args = NULL; + int fd = -1; + size_t oom_score_len = 0; + + cmd_args = &ctx->cmd_args; + + if (!cmd_args->oom_score_adj) + goto success; + + fd = open ("/proc/self/oom_score_adj", O_WRONLY); + if (fd < 0) + goto out; + + oom_score_len = strlen (cmd_args->oom_score_adj); + if (sys_write (fd, + cmd_args->oom_score_adj, oom_score_len) != oom_score_len) { + sys_close (fd); + goto out; + } + + if (sys_close (fd) < 0) + goto out; + +success: + ret = 0; + +out: + return ret; +} +#endif + + int glusterfs_process_volfp (glusterfs_ctx_t *ctx, FILE *fp) { @@ -2357,6 +2420,12 @@ main (int argc, char *argv[]) if (ret) goto out; +#ifdef GF_LINUX_HOST_OS + ret = set_oom_score_adj (ctx); + if (ret) + goto out; +#endif + ctx->env = syncenv_new (0, 0, 0); if (!ctx->env) { gf_msg ("", GF_LOG_ERROR, 0, glusterfsd_msg_31); |