diff options
| -rw-r--r-- | configure.ac | 2 | ||||
| -rw-r--r-- | glusterfsd/src/glusterfsd.c | 80 | ||||
| -rw-r--r-- | libglusterfs/src/glusterfs.h | 6 | 
3 files changed, 70 insertions, 18 deletions
diff --git a/configure.ac b/configure.ac index b1cc0cc1c3c..8aa07ffbeb9 100644 --- a/configure.ac +++ b/configure.ac @@ -495,6 +495,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 7c07e3d0bfb..9a5edd4ddf4 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 @@ -773,21 +780,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; @@ -1132,8 +1168,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;                  } @@ -1141,6 +1181,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 @@ -2216,17 +2257,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 5777974676f..24b8065b66d 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -350,7 +350,6 @@ struct _cmd_args {          int              acl;          int              selinux;          int              capability; -        char            *oom_score_adj;          int              enable_ino32;          int              worm;          int              mac_compat; @@ -396,6 +395,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;  | 
