[sheepdog] [PATCH v4] sheep: avoid the OOM killer
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Fri Jul 5 08:40:45 CEST 2013
At Fri, 5 Jul 2013 15:30:10 +0900,
Hitoshi Mitake wrote:
>
> +int disable_oom_killing(void)
> +{
> + int fd, ret = 0;
> + char path[PATH_MAX], score_str[8];
> +
> + /*
> + * Processes of Linux which wrote a string representation of
> + * OOM_SCORE_ADJ_MIN to /proc/<their pid>/oom_score_adj are excluded by
> + * the target list of the OOM killer certainly.
> + */
> +
> + snprintf(path, PATH_MAX, "/proc/%d/oom_score_adj", getpid());
Using /proc/self/oom_score_adj is simpler.
> + fd = open(path, O_WRONLY);
> + if (fd < 0) {
> + sd_eprintf("opening %s failed, %m", path);
> + ret = -1;
> + goto out;
> + }
> +
> + snprintf(score_str, 8, "%d\n", OOM_SCORE_ADJ_MIN);
Use sizeof(score_str).
> +
> + if (xwrite(fd, score_str, strlen(score_str)) != 6) {
Please don't use a magic number. OOM_SCORE_ADJ_MIN is -16 on my
environment and this code doesn't work.
BTW, I wonder if we should set oom_score_adj inside the program. I
don't how other programs disable OOM, but, perhaps, should we set this
in /etc/init.d/sheepdog?
Thanks,
Kazutaka
More information about the sheepdog
mailing list