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

Hitoshi Mitake mitake.hitoshi at gmail.com
Fri Jul 5 07:58:22 CEST 2013


At Fri, 5 Jul 2013 13:55:08 +0800,
Liu Yuan wrote:
> 
> On Fri, Jul 05, 2013 at 02:43:13PM +0900, Hitoshi Mitake wrote:
> > At Fri, 5 Jul 2013 13:31:35 +0800,
> > Liu Yuan wrote:
> > > 
> > > On Fri, Jul 05, 2013 at 02:27:47PM +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>
> > > > ---
> > > >  sheep/sheep.c |   28 ++++++++++++++++++++++++++++
> > > >  1 file changed, 28 insertions(+)
> > > > 
> > > > diff --git a/sheep/sheep.c b/sheep/sheep.c
> > > > index 84bd269..ac9cc2a 100644
> > > > --- a/sheep/sheep.c
> > > > +++ b/sheep/sheep.c
> > > > @@ -371,6 +371,30 @@ static int create_work_queues(void)
> > > >  	return 0;
> > > >  }
> > > >  
> > > > +static int avoid_oom_killer(void)
> > > 
> > > kill_oom_killer is better?
> > 
> > I don't think so. The function is only for avoiding OOM killer by a
> > caller process. The name kill_oom_killer() implies stopping OOM killer
> > globally.
> > 
> > > 
> > > > +{
> > > > +	int fd, ret = 0;
> > > > +	char path[PATH_MAX];
> > > > +
> > > > +	/* Avoid oom-killer */
> > > 
> > > This comment is meaningless.
> > 
> > Sorry, I'll remove it later.
> > 
> > > 
> > > > +	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;
> > > > +	}
> > > > +
> > > > +	if (xwrite(fd, "-1000\n", 6) != 6) {
> > > 
> > > Please explain what does -1000 means why you choose it.
> > 
> > -1000 is OOM_SCORE_ADJ_MIN and this value is for avoiding OOM killer
> > certainly. I'll add a comment for describing this value in v2.
> > 
> 
> Completely prevent sheep process from being oom-killed? Or just a higher
> priority to be less likely choosen?

The value prevents OOM killing completely.

Thanks,
Hitoshi



More information about the sheepdog mailing list