summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleksandr Natalenko <oleksandr@natalenko.name>2016-05-17 16:45:44 +0300
committerJeff Darcy <jdarcy@redhat.com>2016-06-01 06:27:10 -0700
commitcb8f5e01f639cb6e8715b33bb725210cb0493887 (patch)
tree620b53fdd26efad56b90e0c9eff1f145ddf66c84
parenta89a9d266c439800286f281655d67f4e362dec32 (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. Change-Id: Iff13c2f4cb28457871c6ebeff6130bce4a8bf543 BUG: 1336818 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>
-rw-r--r--glusterfsd/src/glusterfsd.c69
-rw-r--r--glusterfsd/src/glusterfsd.h3
-rw-r--r--libglusterfs/src/glusterfs.h1
-rw-r--r--tests/bugs/fuse/bug-1336818.t52
-rwxr-xr-xxlators/mount/fuse/utils/mount.glusterfs.in7
5 files changed, 132 insertions, 0 deletions
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
index 3324d0b2aeb..d8bc01337b7 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;
@@ -2190,6 +2216,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)
{
@@ -2362,6 +2425,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);
diff --git a/glusterfsd/src/glusterfsd.h b/glusterfsd/src/glusterfsd.h
index 2a95683b33a..e442bede5db 100644
--- a/glusterfsd/src/glusterfsd.h
+++ b/glusterfsd/src/glusterfsd.h
@@ -93,6 +93,9 @@ enum argp_option_keys {
ARGP_GLOBAL_TIMER_WHEEL = 173,
ARGP_RESOLVE_GIDS_KEY = 174,
ARGP_CAPABILITY_KEY = 175,
+#ifdef GF_LINUX_HOST_OS
+ ARGP_OOM_SCORE_ADJ_KEY = 176,
+#endif
};
struct _gfd_vol_top_priv_t {
diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h
index 99e3b2c5aea..d5fde68d76a 100644
--- a/libglusterfs/src/glusterfs.h
+++ b/libglusterfs/src/glusterfs.h
@@ -340,6 +340,7 @@ struct _cmd_args {
int acl;
int selinux;
int capability;
+ char *oom_score_adj;
int enable_ino32;
int worm;
int mac_compat;
diff --git a/tests/bugs/fuse/bug-1336818.t b/tests/bugs/fuse/bug-1336818.t
new file mode 100644
index 00000000000..53286521742
--- /dev/null
+++ b/tests/bugs/fuse/bug-1336818.t
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+#Test case: OOM score adjust
+
+. $(dirname $0)/../../include.rc
+. $(dirname $0)/../../volume.rc
+
+cleanup;
+
+# Prepare
+TEST glusterd
+TEST pidof glusterd
+TEST $CLI volume info;
+
+TEST $CLI volume create $V0 $H0:$B0/brick1;
+EXPECT 'Created' volinfo_field $V0 'Status';
+
+TEST $CLI volume start $V0;
+EXPECT 'Started' volinfo_field $V0 'Status';
+
+# Basic check
+TEST glusterfs -s $H0 --volfile-id $V0 $M0
+TEST umount $M0
+
+# Check valid value (< 0)
+TEST glusterfs --oom-score-adj=-1000 -s $H0 --volfile-id $V0 $M0
+TEST umount $M0
+
+# Check valid value (> 0)
+TEST glusterfs --oom-score-adj=1000 -s $H0 --volfile-id $V0 $M0
+TEST umount $M0
+
+# Check valid value (= 0)
+TEST glusterfs --oom-score-adj=0 -s $H0 --volfile-id $V0 $M0
+TEST umount $M0
+
+# Check invalid value (no value given)
+TEST ! glusterfs --oom-score-adj -s $H0 --volfile-id $V0 $M0
+
+# Check invalid value (< OOM_SCORE_ADJ_MIN)
+TEST ! glusterfs --oom-score-adj=-1001 -s $H0 --volfile-id $V0 $M0
+
+# Check invalid value (> OOM_SCORE_ADJ_MAX)
+TEST ! glusterfs --oom-score-adj=1001 -s $H0 --volfile-id $V0 $M0
+
+# Check invalid value (float)
+TEST ! glusterfs --oom-score-adj=12.34 -s $H0 --volfile-id $V0 $M0
+
+# Check invalid value (non-integer string)
+TEST ! glusterfs --oom-score-adj=qwerty -s $H0 --volfile-id $V0 $M0
+
+cleanup;
diff --git a/xlators/mount/fuse/utils/mount.glusterfs.in b/xlators/mount/fuse/utils/mount.glusterfs.in
index 0fc0cf4a4e3..6c4cdfed062 100755
--- a/xlators/mount/fuse/utils/mount.glusterfs.in
+++ b/xlators/mount/fuse/utils/mount.glusterfs.in
@@ -230,6 +230,10 @@ start_glusterfs ()
cmd_line=$(echo "$cmd_line --congestion-threshold=$cong_threshold");
fi
+ if [ -n "$oom_score_adj" ]; then
+ cmd_line=$(echo "$cmd_line --oom-score-adj=$oom_score_adj");
+ fi
+
if [ -n "$fuse_mountopts" ]; then
cmd_line=$(echo "$cmd_line --fuse-mountopts=$fuse_mountopts");
fi
@@ -444,6 +448,9 @@ with_options()
"congestion-threshold")
cong_threshold=$value
;;
+ "oom-score-adj")
+ oom_score_adj=$value
+ ;;
"xlator-option")
xlator_option=$value
;;