Re: Setting oom_adj on linux?

Поиск
Список
Период
Сортировка
От Alex Hunsaker
Тема Re: Setting oom_adj on linux?
Дата
Msg-id 34d269d41001071558o38b25919k3deb3c5b4d75c655@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Setting oom_adj on linux?  (Alvaro Herrera <alvherre@commandprompt.com>)
Ответы Re: Setting oom_adj on linux?
Список pgsql-hackers
On Mon, Jan 4, 2010 at 09:55, Alvaro Herrera <alvherre@commandprompt.com> wrote:
> Magnus Hagander wrote:
>
>> Right. Which is why I like the idea of disabling the OOM killer for
>> the *postmaster*, but not the regular backends. Gives it a chance to
>> recover. It's not nice, but it's better than nothing.
>
> It doesn't sound like the init script can reenable the killer for the
> child processes though.  So, if there's anything that the core code
> ought to do, is re-enable OOM-killer for postmaster children, after
> being disabled by the initscript.

Exactly.

FWIW here is the patch I run.  Stupid as the patch may be, count it as
a +1 for people in the field doing this.  Hence a reason to think
about doing something in core.  maybe.

This has some oddities like it does not reset oom to 0 for the (wal)
writer process.  Plus assuming you do oom, the stats collector has a
good chance of being hit.  Although normal backends will probably have
a higher score.

[ oom_adj gets set to -17 in the startup script.  I run this on top of
disabling overcommit, color me paranoid ]

*** a/src/backend/postmaster/autovacuum.c
--- b/src/backend/postmaster/autovacuum.c
***************
*** 362,367 **** StartAutoVacLauncher(void)
--- 362,370 ----
  #ifndef EXEC_BACKEND
          case 0:
              /* in postmaster child ... */
+
+             oom_adjust();
+
              /* Close the postmaster's sockets */
              ClosePostmasterPorts(false);

*** a/src/backend/postmaster/fork_process.c
--- b/src/backend/postmaster/fork_process.c
***************
*** 65,68 **** fork_process(void)
--- 65,84 ----
      return result;
  }

+ void
+ oom_adjust(void)
+ {
+     /* adjust oom */
+     FILE *oom = fopen("/proc/self/oom_adj", "w");
+
+     /*
+      * ignore errors we dont really care
+      */
+     if (oom)
+     {
+         fprintf(oom, "0\n");
+         fclose(oom);
+     }
+ }
+
  #endif   /* ! WIN32 */
*** a/src/backend/postmaster/pgarch.c
--- b/src/backend/postmaster/pgarch.c
***************
*** 161,166 **** pgarch_start(void)
--- 161,169 ----
  #ifndef EXEC_BACKEND
          case 0:
              /* in postmaster child ... */
+
+             oom_adjust();
+
              /* Close the postmaster's sockets */
              ClosePostmasterPorts(false);

*** a/src/backend/postmaster/pgstat.c
--- b/src/backend/postmaster/pgstat.c
***************
*** 622,627 **** pgstat_start(void)
--- 622,630 ----
  #ifndef EXEC_BACKEND
          case 0:
              /* in postmaster child ... */
+
+             oom_adjust();
+
              /* Close the postmaster's sockets */
              ClosePostmasterPorts(false);

*** a/src/backend/postmaster/postmaster.c
--- b/src/backend/postmaster/postmaster.c
***************
*** 3056,3061 **** BackendStartup(Port *port)
--- 3056,3063 ----
      {
          free(bn);

+         oom_adjust();
+
          /*
           * Let's clean up ourselves as the postmaster child, and close the
           * postmaster's listen sockets.  (In EXEC_BACKEND case this is all
*** a/src/backend/postmaster/syslogger.c
--- b/src/backend/postmaster/syslogger.c
***************
*** 530,535 **** SysLogger_Start(void)
--- 530,538 ----
  #ifndef EXEC_BACKEND
          case 0:
              /* in postmaster child ... */
+
+             oom_adjust();
+
              /* Close the postmaster's sockets */
              ClosePostmasterPorts(true);

*** a/src/include/postmaster/fork_process.h
--- b/src/include/postmaster/fork_process.h
***************
*** 13,17 ****
--- 13,18 ----
  #define FORK_PROCESS_H

  extern pid_t fork_process(void);
+ extern void oom_adjust(void);

  #endif   /* FORK_PROCESS_H */

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Alex Hunsaker
Дата:
Сообщение: Re: Add .gitignore files to CVS?
Следующее
От: Robert Haas
Дата:
Сообщение: Re: PostgreSQL 8.5 Open Items