From c441f58dedc465f59060296815a0bc7f9aeb743f Mon Sep 17 00:00:00 2001 From: todd stecher Date: Tue, 17 Feb 2009 16:16:35 -0800 Subject: S3: Allow SMBD processes to survive in low memory condidtions 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 | 28 ++++++++++++++++++++++++++++ source3/include/includes.h | 4 ++++ source3/smbd/server.c | 7 +++++++ 3 files changed, 39 insertions(+) diff --git a/source3/configure.in b/source3/configure.in index 691d0a80bc..57d475fcc5 100644 --- a/source3/configure.in +++ b/source3/configure.in @@ -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 + ],[ + 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 diff --git a/source3/include/includes.h b/source3/include/includes.h index a9f813b7f8..1906830d48 100644 --- a/source3/include/includes.h +++ b/source3/include/includes.h @@ -241,6 +241,10 @@ typedef int ber_int_t; #include #endif +#ifdef WITH_MADVISE_PROTECTED +#include +#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 diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 075e44d319..76dab96ad9 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -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 -- cgit