From: | Dan McGee <dan(at)archlinux(dot)org> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: [PATCH] Use new oom_score_adj without a new compile-time constant |
Date: | 2011-09-19 20:36:50 |
Message-ID: | CAEik5nPuNBHZgOGX3-baU=WKD353Hrw5qnWrw8dr6iViQ6553A@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Mon, Sep 19, 2011 at 3:11 PM, Dan McGee <dan(at)archlinux(dot)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(at)archlinux(dot)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
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Greg Smith | 2011-09-19 20:44:17 | Re: Is there really no interest in SQL Standard? |
Previous Message | Dan McGee | 2011-09-19 20:11:18 | [PATCH] Use new oom_score_adj without a new compile-time constant |