Re: [PATCH] Use new oom_score_adj without a new compile-time constant - Mailing list pgsql-hackers
From | Dan McGee |
---|---|
Subject | Re: [PATCH] Use new oom_score_adj without a new compile-time constant |
Date | |
Msg-id | CAEik5nPuNBHZgOGX3-baU=WKD353Hrw5qnWrw8dr6iViQ6553A@mail.gmail.com Whole thread Raw |
In response to | [PATCH] Use new oom_score_adj without a new compile-time constant (Dan McGee <dan@archlinux.org>) |
Responses |
Re: [PATCH] Use new oom_score_adj without a new
compile-time constant
|
List | pgsql-hackers |
On Mon, Sep 19, 2011 at 3:11 PM, Dan McGee <dan@archlinux.org> wrote: > This is one way to prevent the kernel warning message without having to > introduce a new constant. Scale the old oom_adj-style value the same way > the kernel internally does it and use that instead if oom_score_adj is > available for writing. > > Signed-off-by: Dan McGee <dan@archlinux.org> > --- > > This addresses some of the concerns raised on the ML and will at least keep > those of us running modern kernels happy. > > Alternatively one could switch the symbol used to be the new style and have the > old one computed; however this is a pain for legacy vs. current versions. > > src/backend/postmaster/fork_process.c | 22 +++++++++++++++++++++- > 1 files changed, 21 insertions(+), 1 deletions(-) > > diff --git a/src/backend/postmaster/fork_process.c b/src/backend/postmaster/fork_process.c > index b2fe9a1..3cded54 100644 > --- a/src/backend/postmaster/fork_process.c > +++ b/src/backend/postmaster/fork_process.c > @@ -81,16 +81,36 @@ fork_process(void) > * Use open() not stdio, to ensure we control the open flags. Some > * Linux security environments reject anything but O_WRONLY. > */ > - int fd = open("/proc/self/oom_adj", O_WRONLY, 0); > + int fd = open("/proc/self/oom_score_adj", O_WRONLY, 0); > > /* We ignore all errors */ > if (fd >= 0) > { > char buf[16]; > + int oom_score_adj; > > + /* > + * The compile-time value is the old style oom_adj; > + * scale it the same way the kernel does to > + * convert to the new style oom_score_adj. This > + * should become a constant at compile time. > + * Valid values range from -17 (never kill) to > + * 15; no attempt of validation is done. > + */ > + oom_score_adj = LINUX_OOM_ADJ * 1000 / 17; > snprintf(buf, sizeof(buf), "%d\n", LINUX_OOM_ADJ); Of course it would help to actually use the computed value here; this should be: snprintf(buf,sizeof(buf), "%d\n", oom_score_adj); > (void) write(fd, buf, strlen(buf)); > close(fd); > + } else if (errno == EEXIST) { > + int fd = open("/proc/self/oom_adj", O_WRONLY, 0); > + if (fd >= 0) > + { > + char buf[16]; > + > + snprintf(buf, sizeof(buf), "%d\n", LINUX_OOM_ADJ); > + (void) write(fd, buf, strlen(buf)); > + close(fd); > + } > } > } > #endif /* LINUX_OOM_ADJ */ > -- > 1.7.6.1 > >
pgsql-hackers by date: