[ntp:hackers] [PATCH] - ntpd Exiting:out of memory.

Jim Houston jim.houston at comcast.net
Wed Jun 15 09:39:34 PDT 2005


Hi Everyone,

When I run ntpd on Linux and use the drop root option I almost
always get a "Exiting:out of memory" failure.

This is caused by Linux setting a very small default value
for RLIMIT_MEMLOCK.  On the RH EL3 systems its only 32K bytes.
This means that any malloc call after ntpd drops root privlege
are likely to fail because the RLIMIT_MEMLOCK limit prevents
locking more memory.

The attached patch sets both the rl_cur and rl_max values to 
32M bytes.  To be useful this value has to be larger than the 
largest ntpd resident set size.  I checked ntpd built for an
AMD opteron.  It was using 19M bytes.

Jim Houston - Concurrent Computer Corp.

--- ntp-stable-4.2.0a-20040617/ntpd/ntpd.c.0	2005-06-14 12:02:43.000000000 -0400
+++ ntp-stable-4.2.0a-20040617/ntpd/ntpd.c	2005-06-15 12:12:13.253809589 -0400
@@ -691,6 +691,16 @@
 				"Cannot adjust stack limit for mlockall: %m");
 		    }
 	    }
+	    /*
+	     * The default RLIMIT_MEMLOCK is very low on Linux systems.
+	     * Unless we increase this limit malloc calls are likely to
+	     * fail if we drop root privlege.  To be useful the value
+	     * has to be larger than the largest ntpd resident set size.
+	     */
+	    rl.rlim_cur = rl.rlim_max = 32*1024*1024;
+	    if (setrlimit(RLIMIT_MEMLOCK, &rl) == -1) {
+	    	msyslog(LOG_ERR, "Cannot set RLIMIT_MEMLOCK: %m");
+	    }
 	}
 # endif /* HAVE_SETRLIMIT */
 	/*






More information about the hackers mailing list