[PATCH] Use new oom_score_adj without a new compile-time constant

Поиск
Список
Период
Сортировка
От Dan McGee
Тема [PATCH] Use new oom_score_adj without a new compile-time constant
Дата
Msg-id 1316463078-1068-1-git-send-email-dan@archlinux.org
обсуждение исходный текст
Ответ на Re: /proc/self/oom_adj is deprecated in newer Linux kernels  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: [PATCH] Use new oom_score_adj without a new compile-time constant
Список pgsql-hackers
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);               (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 по дате отправления:

Предыдущее
От: Matthew Wilcox
Дата:
Сообщение: Re: Improve lseek scalability v3
Следующее
От: Dan McGee
Дата:
Сообщение: Re: [PATCH] Use new oom_score_adj without a new compile-time constant