1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-24 21:49:29 +03:00

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.
This commit is contained in:
todd stecher
2009-02-17 16:16:35 -08:00
committed by Steven Danneman
parent cdcd525a05
commit c441f58ded
3 changed files with 39 additions and 0 deletions

View 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

View 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

View 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