[sheepdog] [PATCH v4] sheep: avoid the OOM killer
Hitoshi Mitake
mitake.hitoshi at gmail.com
Fri Jul 5 12:24:59 CEST 2013
At Fri, 5 Jul 2013 14:58:33 +0800,
Liu Yuan wrote:
>
> On Fri, Jul 05, 2013 at 03:40:45PM +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.
> >
> > > + 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?
> >
>
> I guess no one want to be oom killed and this might be better decided by admin.
> Disable it by sheep would be too intrusive.
>
> I think put it init.d/sheepdog is okay but we'd better introduce sheepdog.conf.
As we discussed at IRC meeting, sheepdog.conf will be a useful
thing. But setting oom_score_adj is a bother work because we need to
grep a PID of a sheep process and every sheep has its logger. Doing it
inside sheep is much simpler.
Thanks,
Hitoshi
More information about the sheepdog
mailing list