summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleksandr Natalenko <onatalen@redhat.com>2016-09-28 14:29:23 +0200
committerNiels de Vos <ndevos@redhat.com>2016-10-12 04:01:28 -0700
commit92f6ef8a63411eb80d4cc402b4285f87d745226f (patch)
tree8b9824420150f8dee8bb874f9dfd039e618d5ccb
parentad9a1d1e8430388995f6a3fcd192ada7c9417a8d (diff)
glusterfsd/main: fix OOM adjustment for older kernels
Milind Changire reported that GlusterFS fails to build on RHEL5 because linux/oom.h is unavailable. Milind's initial patch disables OOM adjustment completely for those environments that do not have this header. However, I'd take another approach that: 1) checks for linux/oom.h in compile-time and defines necessary constants if the header is not present; 2) checks for available OOM API in /proc in run-time and uses it accordingly. This allows OOM to be adjusted properly on RHEL5 (the kernel is pretty new to present /proc API for that) as well as RHEL6 (the kernel has many thing backported including new /proc API). > Reviewed-on: http://review.gluster.org/15587 > Smoke: Gluster Build System <jenkins@build.gluster.org> > CentOS-regression: Gluster Build System <jenkins@build.gluster.org> > NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> > Reviewed-by: Niels de Vos <ndevos@redhat.com> > Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name> Change-Id: I1bc610586872d208430575c149a7d0c54bd82370 BUG: 1383694 Signed-off-by: Oleksandr Natalenko <onatalen@redhat.com> Reviewed-on: http://review.gluster.org/15623 Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name> Smoke: Gluster Build System <jenkins@build.gluster.org> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Niels de Vos <ndevos@redhat.com>
-rw-r--r--configure.ac2
-rw-r--r--glusterfsd/src/glusterfsd.c80
-rw-r--r--libglusterfs/src/glusterfs.h6
3 files changed, 70 insertions, 18 deletions
diff --git a/configure.ac b/configure.ac
index 9025114030a..ac46911ab85 100644
--- a/configure.ac
+++ b/configure.ac
@@ -468,6 +468,8 @@ AC_SUBST(ZLIB_LIBS)
AC_CHECK_HEADERS([linux/falloc.h])
+AC_CHECK_HEADERS([linux/oom.h], AC_DEFINE(HAVE_LINUX_OOM_H, 1, [have linux/oom.h]))
+
dnl Mac OS X does not have spinlocks
AC_CHECK_FUNC([pthread_spin_init], [have_spinlock=yes])
if test "x${have_spinlock}" = "xyes"; then
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
index 4a2f7ad5a7f..31bac2f0d7b 100644
--- a/glusterfsd/src/glusterfsd.c
+++ b/glusterfsd/src/glusterfsd.c
@@ -33,7 +33,14 @@
#include <pwd.h>
#ifdef GF_LINUX_HOST_OS
+#ifdef HAVE_LINUX_OOM_H
#include <linux/oom.h>
+#else
+#define OOM_SCORE_ADJ_MIN (-1000)
+#define OOM_SCORE_ADJ_MAX 1000
+#define OOM_DISABLE (-17)
+#define OOM_ADJUST_MAX 15
+#endif
#endif
#ifdef HAVE_MALLOC_H
@@ -777,21 +784,50 @@ out:
}
+#ifdef GF_LINUX_HOST_OS
+static struct oom_api_info {
+ char *oom_api_file;
+ int32_t oom_min;
+ int32_t oom_max;
+} oom_api_info[] = {
+ { "/proc/self/oom_score_adj", OOM_SCORE_ADJ_MIN, OOM_SCORE_ADJ_MAX },
+ { "/proc/self/oom_adj", OOM_DISABLE, OOM_ADJUST_MAX },
+ { NULL, 0, 0 }
+};
+
+
+static struct oom_api_info *
+get_oom_api_info (void)
+{
+ struct oom_api_info *api = NULL;
+
+ for (api = oom_api_info; api->oom_api_file; api++) {
+ if (sys_access (api->oom_api_file, F_OK) != -1) {
+ return api;
+ }
+ }
+
+ return NULL;
+}
+#endif
static error_t
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;
- char tmp_buf[2048] = {0,};
- char *tmp_str = NULL;
- char *port_str = NULL;
- struct passwd *pw = NULL;
- int ret = 0;
+ cmd_args_t *cmd_args = NULL;
+ uint32_t n = 0;
+#ifdef GF_LINUX_HOST_OS
+ int32_t k = 0;
+ struct oom_api_info *api = NULL;
+#endif
+ double d = 0.0;
+ gf_boolean_t b = _gf_false;
+ char *pwd = NULL;
+ char tmp_buf[2048] = {0,};
+ char *tmp_str = NULL;
+ char *port_str = NULL;
+ struct passwd *pw = NULL;
+ int ret = 0;
cmd_args = state->input;
@@ -1136,8 +1172,12 @@ parse_opts (int key, char *arg, struct argp_state *state)
case ARGP_OOM_SCORE_ADJ_KEY:
k = 0;
+ api = get_oom_api_info();
+ if (!api)
+ goto no_oom_api;
+
if (gf_string2int (arg, &k) == 0 &&
- k >= OOM_SCORE_ADJ_MIN && k <= OOM_SCORE_ADJ_MAX) {
+ k >= api->oom_min && k <= api->oom_max) {
cmd_args->oom_score_adj = gf_strdup (arg);
break;
}
@@ -1145,6 +1185,7 @@ parse_opts (int key, char *arg, struct argp_state *state)
argp_failure (state, -1, 0,
"unknown oom_score_adj value %s", arg);
+no_oom_api:
break;
#endif
@@ -2215,17 +2256,22 @@ out:
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;
+ int ret = -1;
+ cmd_args_t *cmd_args = NULL;
+ int fd = -1;
+ size_t oom_score_len = 0;
+ struct oom_api_info *api = NULL;
cmd_args = &ctx->cmd_args;
if (!cmd_args->oom_score_adj)
goto success;
- fd = open ("/proc/self/oom_score_adj", O_WRONLY);
+ api = get_oom_api_info();
+ if (!api)
+ goto out;
+
+ fd = open (api->oom_api_file, O_WRONLY);
if (fd < 0)
goto out;
diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h
index 0cee2ba3868..6e2d370605b 100644
--- a/libglusterfs/src/glusterfs.h
+++ b/libglusterfs/src/glusterfs.h
@@ -345,7 +345,6 @@ struct _cmd_args {
int acl;
int selinux;
int capability;
- char *oom_score_adj;
int enable_ino32;
int worm;
int mac_compat;
@@ -391,6 +390,11 @@ struct _cmd_args {
/* Should management connections use SSL? */
int secure_mgmt;
+
+ /* Linux-only OOM killer adjustment */
+#ifdef GF_LINUX_HOST_OS
+ char *oom_score_adj;
+#endif
};
typedef struct _cmd_args cmd_args_t;