S3: Allow SMBD processes to survive in low memory condidtions
authortodd stecher <todd.stecher@gmail.com>
Wed, 18 Feb 2009 00:16:35 +0000 (16:16 -0800)
committerSteven Danneman <steven.danneman@isilon.com>
Thu, 19 Feb 2009 02:08:32 +0000 (18:08 -0800)
This commit adds a configure argument which allows for setting MADV_PROTECT
in the madvise() API.  With this enabled the kernel won't kill SMBD when
it's running low on memory.

source3/configure.in
source3/include/includes.h
source3/smbd/server.c

index 691d0a80bc406fc8835a226446831fe2fd305d9a..57d475fcc58455e6d5a130131ef1bb3dd3d6ed44 100644 (file)
@@ -4718,6 +4718,34 @@ SMB_LIBRARY(lua, 0)
 SMB_LIBRARY(addns, 0, no, [undefined API])
 
 
+#################################################
+# check to see if we should set the protected madvise flag,
+# which will keep smbd alive in low memory conditions
+AC_MSG_CHECKING(whether to protect smbd from being killed in low memory)
+AC_ARG_WITH(madvise-protect,
+[AS_HELP_STRING([--with-madvise-protect], [Include low memory madvise protection (default=no)])],
+[ case "$withval" in
+  yes)
+    AC_TRY_COMPILE([
+        #include <sys/mman.h>
+        ],[
+        int a = MADV_PROTECT;
+        ],
+        [samba_cv_madvise_protect=yes],
+        [samba_cv_madvise_protect=no])
+    if test x"$samba_cv_madvise_protect" = x"yes"; then
+        AC_MSG_RESULT(yes)
+        AC_DEFINE(WITH_MADVISE_PROTECTED,1,[Whether to include low memory protection support])
+    else
+        AC_MSG_ERROR(Low memory protection supporte requires availability of MADVISE_PROTECT flag.)
+    fi
+    ;;
+  *)
+    AC_MSG_RESULT(no)
+    ;;
+  esac ],
+  AC_MSG_RESULT(no)
+)
 
 #################################################
 # these tests are taken from the GNU fileutils package
index a9f813b7f85a186022660267524beecebf1d54a2..1906830d485aba9b85b3ee212eaf19c868fc1e9e 100644 (file)
@@ -241,6 +241,10 @@ typedef int ber_int_t;
 #include <aio.h>
 #endif
 
+#ifdef WITH_MADVISE_PROTECTED
+#include <sys/mman.h>
+#endif
+
 /* Special macros that are no-ops except when run under Valgrind on
  * x86.  They've moved a little bit from valgrind 1.0.4 to 1.9.4 */
 #if HAVE_VALGRIND_MEMCHECK_H
index 075e44d319827a0c116fec291fe848f216dc6c9d..76dab96ad94ad5847d5feafcd57f8252b5d8c181 100644 (file)
@@ -359,6 +359,10 @@ static void smbd_accept_connection(struct tevent_context *ev,
                /* Child code ... */
                am_parent = 0;
 
+#ifdef WITH_MADVISE_PROTECTED
+               madvise(NULL,0,MADV_PROTECT);
+#endif
+
                /* Stop zombies, the parent explicitly handles
                 * them, counting worker smbds. */
                CatchChild();
@@ -1127,6 +1131,9 @@ extern void build_options(bool screen);
        if (is_daemon && !interactive) {
                DEBUG( 3, ( "Becoming a daemon.\n" ) );
                become_daemon(Fork, no_process_group);
+#ifdef WITH_MADVISE_PROTECTED
+               madvise(NULL,0,MADV_PROTECT);
+#endif
        }
 
 #if HAVE_SETPGID