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

Hitoshi Mitake mitake.hitoshi at gmail.com
Fri Jul 5 08:09:03 CEST 2013


At Fri, 5 Jul 2013 14:04:12 +0800,
Liu Yuan wrote:
> 
> On Fri, Jul 05, 2013 at 02:46:52PM +0900, Hitoshi Mitake wrote:
> > Because sheep provides virtual disks to many VMs, sheep is an
> > important process and it shouldn't be killed by the OOM killer of
> > Linux. This patch implements a mechanism for avoiding the OOM killer.
> > 
> > Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
> > ---
> > 
> > v2:
> >  - remove the meaningless comment
> >  - add a description for the value -1000
> > 
> >  sheep/sheep.c |   33 +++++++++++++++++++++++++++++++++
> >  1 file changed, 33 insertions(+)
> > 
> > diff --git a/sheep/sheep.c b/sheep/sheep.c
> > index 84bd269..335edb4 100644
> > --- a/sheep/sheep.c
> > +++ b/sheep/sheep.c
> > @@ -371,6 +371,35 @@ static int create_work_queues(void)
> >  	return 0;
> >  }
> >  
> > +static int avoid_oom_killer(void)
> 
> I'd suggest name it as more explicitly as disable_oom_killer()

disable_oom_killer() is not an accurate name, too. Because the
function doesn't disable OOM killer. How about disable_oom_killing()?


> 
> > +{
> > +	int fd, ret = 0;
> > +	char path[PATH_MAX];
> > +
> > +	snprintf(path, PATH_MAX, "/proc/%d/oom_score_adj", getpid());
> > +	fd = open(path, O_WRONLY);
> > +	if (fd < 0) {
> > +		sd_iprintf("opening %s failed, %m", path);
> > +		ret = -1;
> > +		goto end;
> > +	}
> > +
> > +	/*
> > +	 * -1000 is defined as OOM_SCORE_ADJ_MIN in the linux kernel. And
> > +	 * processes which wrote OOM_SCORE_ADJ_MIN to
> > +	 * /proc/<their pid>/oom_score_adj are excluded by the target list of
> > +	 * the OOM killer certainly.
> > +	 */
> > +	if (xwrite(fd, "-1000\n", 6) != 6) {
> > +		sd_iprintf("writing to %s failed, %m", path);
> > +		ret = -1;
> > +	}
> > +
> 
> why not #include <linux/oom.h> and use OOM_SCORE_ADJ_MIN? is this hebavior has
> some dependency on the kernel version?

including <linux/oom.h> seems to be better. I'll do so in v3.

Thanks,
Hitoshi



More information about the sheepdog mailing list