>Number:         173332
>Category:       bin
>Synopsis:       [patch] watchdogd wires over 10MB of memory after r239769
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Nov 03 17:20:00 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator:     Ian Lepore
>Release:        FreeBSD 10.0-CURRENT @ r241077
>Organization:
>Environment:
FreeBSD tflex 10.0-CURRENT FreeBSD 10.0-CURRENT #22: Tue Oct 16 15:10:51 UTC 
2012     [email protected]:/usr/obj/arm.arm/usr/src/sys/TFLEX  arm

>Description:
watchdogd was changed in r239769 to use mlockall(2) to wire down the memory 
used by the app so that it can pat the watchdog without any delays caused by 
waiting for its pages to be swapped back in.  This has caused its resident size 
to increase from about 840KB to about 10MB, which is a serious problem on 
small-memory embedded systems.

Most of the memory increase seems to be related to jemalloc allocating vmspace 
in chunks of 8MB at a time.  Normally this is innocuous; even if the app only 
uses a few bytes of allocated memory there's no large downside to having 
over-allocated some vmspace.  However, when mlockall(MCL_FUTURE) is in effect, 
it is no longer a vmspace allocation, physical pages for the entire 8MB region 
are prefaulted and wired.

Another megabyte or so of the growth seems to be related to wiring in pages 
(whether needed or not) from libc and libm.


>How-To-Repeat:

>Fix:
The attached patch reduces the impact of the mlockall() change on small-memory 
embedded systems.  Such systems are often built with "option NO_SWAPPING" which 
eliminates most of the reason the mlockall() change was put in originally.

Note that this is not really a full fix for the problem, it just reduces the  
impact on the most resource-limited systems.


Patch attached with submission follows:

diff -r 5f2e07d3ae42 usr.sbin/watchdogd/watchdogd.c
--- usr.sbin/watchdogd/watchdogd.c      Thu Oct 04 20:42:12 2012 -0600
+++ usr.sbin/watchdogd/watchdogd.c      Sat Nov 03 11:04:31 2012 -0600
@@ -35,6 +35,7 @@
 #include <sys/param.h>
 #include <sys/rtprio.h>
 #include <sys/stat.h>
+#include <sys/sysctl.h>
 #include <sys/time.h>
 #include <sys/watchdog.h>
 
@@ -78,6 +79,7 @@ main(int argc, char *argv[])
        struct rtprio rtp;
        struct pidfh *pfh;
        pid_t otherpid;
+       int len, swap_enabled;
 
        if (getuid() != 0)
                errx(EX_SOFTWARE, "not super user");
@@ -118,8 +120,13 @@ main(int argc, char *argv[])
                pidfile_write(pfh);
                if (madvise(0, 0, MADV_PROTECT) != 0)
                        warn("madvise failed");
-               if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0)
-                       warn("mlockall failed");
+               len = sizeof(swap_enabled);
+               if (sysctlbyname("vm.swap_enabled", &swap_enabled, &len, NULL,
+                   0) == -1)
+                       swap_enabled = 1; /* Assume enabled */
+               if (swap_enabled)
+                       if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0)
+                               warn("mlockall failed");
 
                watchdog_loop();
 


>Release-Note:
>Audit-Trail:
>Unformatted:
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "[email protected]"

Reply via email to