rpms/postgresql/devel postgresql-oom-adj.patch, NONE, 1.1 postgresql.init, 1.26, 1.27 postgresql.spec, 1.125, 1.126
Tom Lane
tgl at fedoraproject.org
Mon Jan 11 18:11:25 UTC 2010
Author: tgl
Update of /cvs/pkgs/rpms/postgresql/devel
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv4730
Modified Files:
postgresql.init postgresql.spec
Added Files:
postgresql-oom-adj.patch
Log Message:
Work around unintelligent kernel OOM-kill algorithm.
postgresql-oom-adj.patch:
fork_process.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
--- NEW FILE postgresql-oom-adj.patch ---
Back-ported patch from Postgres devel head: reset oom_adj to zero in any
postmaster child process. This allows us to disable OOM kill on the postmaster
(see the init script) without affecting OOM behavior for child processes.
diff -Naur postgresql-8.4.2.orig/src/backend/postmaster/fork_process.c postgresql-8.4.2/src/backend/postmaster/fork_process.c
--- postgresql-8.4.2.orig/src/backend/postmaster/fork_process.c 2009-01-01 12:23:46.000000000 -0500
+++ postgresql-8.4.2/src/backend/postmaster/fork_process.c 2010-01-11 12:28:17.000000000 -0500
@@ -12,7 +12,9 @@
#include "postgres.h"
#include "postmaster/fork_process.h"
+#include <fcntl.h>
#include <time.h>
+#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
@@ -60,6 +62,38 @@
setitimer(ITIMER_PROF, &prof_itimer, NULL);
#endif
+ /*
+ * By default, Linux tends to kill the postmaster in out-of-memory
+ * situations, because it blames the postmaster for the sum of child
+ * process sizes *including shared memory*. (This is unbelievably
+ * stupid, but the kernel hackers seem uninterested in improving it.)
+ * Therefore it's often a good idea to protect the postmaster by
+ * setting its oom_adj value negative (which has to be done in a
+ * root-owned startup script). If you just do that much, all child
+ * processes will also be protected against OOM kill, which might not
+ * be desirable. You can then choose to build with LINUX_OOM_ADJ
+ * #defined to 0, or some other value that you want child processes
+ * to adopt here.
+ */
+#ifdef LINUX_OOM_ADJ
+ {
+ /*
+ * 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);
+
+ /* We ignore all errors */
+ 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 */
}
return result;
Index: postgresql.init
===================================================================
RCS file: /cvs/pkgs/rpms/postgresql/devel/postgresql.init,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -p -r1.26 -r1.27
--- postgresql.init 22 Sep 2009 00:45:57 -0000 1.26
+++ postgresql.init 11 Jan 2010 18:11:25 -0000 1.27
@@ -108,6 +108,8 @@ PGENGINE=/usr/bin
PGPORT=5432
PGDATA=/var/lib/pgsql/data
PGLOG=/var/lib/pgsql/pgstartup.log
+# Value to set as postmaster process's oom_adj
+PG_OOM_ADJ=-17
# Override defaults from /etc/sysconfig/pgsql if file is present
[ -f /etc/sysconfig/pgsql/${NAME} ] && . /etc/sysconfig/pgsql/${NAME}
@@ -177,6 +179,7 @@ start(){
fi
echo -n "$PSQL_START"
+ test x"$PG_OOM_ADJ" != x && echo "$PG_OOM_ADJ" > /proc/self/oom_adj
$SU -l postgres -c "$PGENGINE/postmaster -p '$PGPORT' -D '$PGDATA' ${PGOPTS} &" >> "$PGLOG" 2>&1 < /dev/null
sleep 2
pid=`pidof -s "$PGENGINE/postmaster"`
Index: postgresql.spec
===================================================================
RCS file: /cvs/pkgs/rpms/postgresql/devel/postgresql.spec,v
retrieving revision 1.125
retrieving revision 1.126
diff -u -p -r1.125 -r1.126
--- postgresql.spec 9 Jan 2010 05:23:05 -0000 1.125
+++ postgresql.spec 11 Jan 2010 18:11:25 -0000 1.126
@@ -53,7 +53,7 @@ Summary: PostgreSQL client programs
Name: postgresql
%global majorversion 8.4
Version: 8.4.2
-Release: 3%{?dist}
+Release: 4%{?dist}
# PostgreSQL calls their license simplified BSD, but the requirements are
# more similar to other MIT licenses.
License: MIT
@@ -74,6 +74,7 @@ Source17: http://www.postgresql.org/docs
Patch1: rpm-pgsql.patch
Patch2: postgresql-ac-version.patch
Patch3: postgresql-logging.patch
+Patch4: postgresql-oom-adj.patch
Patch6: postgresql-perl-rpath.patch
BuildRequires: perl(ExtUtils::MakeMaker) glibc-devel bison flex autoconf gawk
@@ -272,6 +273,7 @@ system, including regression tests and b
%patch1 -p1
%patch2 -p1
%patch3 -p1
+%patch4 -p1
%patch6 -p1
autoconf
@@ -281,10 +283,11 @@ cp -p %{SOURCE17} .
%build
CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS
-CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS
# Strip out -ffast-math from CFLAGS....
CFLAGS=`echo $CFLAGS|xargs -n 1|grep -v ffast-math|xargs -n 100`
+# Add LINUX_OOM_ADJ=0 to ensure child processes reset postmaster's oom_adj
+CFLAGS="$CFLAGS -DLINUX_OOM_ADJ=0"
# let's try removing this kluge, it may just be a workaround for bz#520916
# # use -O1 on sparc64 and alpha
# %ifarch sparc64 alpha
@@ -693,6 +696,11 @@ rm -rf $RPM_BUILD_ROOT
%endif
%changelog
+* Mon Jan 11 2010 Tom Lane <tgl at redhat.com> 8.4.2-4
+- Arrange for the postmaster, but not any of its child processes, to be run
+ with oom_adj -17. This compensates for the OOM killer not being smart about
+ accounting for shared memory usage.
+
* Sat Jan 9 2010 Tom Lane <tgl at redhat.com> 8.4.2-3
- Remove the postgresql-python and postgresql-tcl subpackages. These files
are now broken out as their own packages (PyGreSQL and tcl-pgtcl,
More information about the scm-commits
mailing list