[sheepdog] [PATCH v4] sheep: avoid the OOM killer

Hitoshi Mitake mitake.hitoshi at gmail.com
Fri Jul 5 08:58:19 CEST 2013


At Fri, 05 Jul 2013 15:40:45 +0900,
MORITA Kazutaka wrote:
> 
> 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.

Thanks, I'll use the pathname in the next version.

> 
> > +	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).

I'll do so in the next version.

> 
> > +
> > +	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.

-16 must be OOM_ADJUST_MIN, the value is for /proc/self/oom_adj. And
oom_adj is deprecated so we should use oom_score_adj. They are
similar but different things.

But expecting 6 as a return value of xwrite() is clearly my
mistake. And it seems that we need to support both of oom_adj and
oom_score_adj. I'll fix it in the next version.

> 
> 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?

I'm mocking tgt's way. The cost of setting the value to proc files
would not be so different in both ways.

Thanks,
Hitoshi



More information about the sheepdog mailing list