Peter, can you let me know what you think?

-Alfred

On 11/7/12 11:46 PM, Peter Wemm wrote:
On Wed, Nov 7, 2012 at 10:24 PM, Alfred Perlstein <bri...@mu.org> wrote:
[[ + peter ]]

Folks, I spent quite a bit of time trying to figure out how to resolve
maxusers scaling in a happy way for all.

I think I came up with a solution.

This solution should work for i386, and other 32 bit platforms, as well as
scaling well for 64 bit (or higher) platforms that have virtually unlimited
AND 64bit with limited kernel address space.

Here is how it works:

We calculate the maxusers value based on physical memory, and then clamp it
down if physical memory exceeds kernel addressable memory.

The algorithm actually remains the same for all architectures, with the
exception that machines with large kernel address space it is no longer
clamped at 384.

I've attached a test program that lets you play with various values for
VM_MIN_KERNEL_ADDRESS, VM_MAX_KERNEL_ADDRESS and physpages.  (argv[1, 2, 3]
respectively.)

Please give me your feedback.
This is still bogus.  VM_MIN_KERNEL_ADDRESS and VM_MAX_KERNEL_ADDRESS
have no bearing on how much space should be allocated for mbuf
clusters on amd64.  If anything, you want dmapbase / dmapend if you
want a practical cap for amd64.  Even then, jumbo clusters are >4K so
they come out of kva rather than direct map.

maxusers is the wrong thing for this.  maxusers should, if anything,
be used to set things like kern.maxproc.  Preferably it should be
deleted entirely and sysctl.conf should be used to change
kern.maxproc.

Setting limits for the mbuf / cluster pool should be a MD parameter.

Trying to scale maxusers based on physical ram in order to get mbuf
cluster limits set as a side effect is just plain wrong.

It makes no more sense than trying to set nmbclusters based on
PRINTF_BUFR_SIZE, and then trying to scale PRINTF_BUFR_SIZE in order
to get desirable second and third order side effects.

Scale nmbclusters based on physical ram, with a MD method for capping
it for when there are MD limits (eg: disproportionately small kva on
an i386 PAE machine).  Don't use maxusers.

--- Begin Message ---
Author: alfred
Date: Thu Nov  8 20:15:12 2012
New Revision: 242783
URL: http://svnweb.freebsd.org/changeset/base/242783

Log:
  Divorce autotune nmbclusters from maxusers.
  Provide arch specific override maximum.
  
  Suggested by: peter

Modified:
  user/alfred/9-alfred/sys/i386/include/vmparam.h
  user/alfred/9-alfred/sys/kern/kern_mbuf.c

Modified: user/alfred/9-alfred/sys/i386/include/vmparam.h
==============================================================================
--- user/alfred/9-alfred/sys/i386/include/vmparam.h     Thu Nov  8 18:11:31 
2012        (r242782)
+++ user/alfred/9-alfred/sys/i386/include/vmparam.h     Thu Nov  8 20:15:12 
2012        (r242783)
@@ -202,4 +202,9 @@
 
 #define        ZERO_REGION_SIZE        (64 * 1024)     /* 64KB */
 
+#ifndef MAX_AUTOTUNE_NMBCLUSTERS
+/* old maxusers max value. */
+#define MAX_AUTOTUNE_NMBCLUSTERS (1024 + 384 * 64)
+#endif
+
 #endif /* _MACHINE_VMPARAM_H_ */

Modified: user/alfred/9-alfred/sys/kern/kern_mbuf.c
==============================================================================
--- user/alfred/9-alfred/sys/kern/kern_mbuf.c   Thu Nov  8 18:11:31 2012        
(r242782)
+++ user/alfred/9-alfred/sys/kern/kern_mbuf.c   Thu Nov  8 20:15:12 2012        
(r242783)
@@ -102,6 +102,30 @@ int nmbjumbo9;                     /* limits number of 9k 
 int nmbjumbo16;                        /* limits number of 16k jumbo clusters 
*/
 struct mbstat mbstat;
 
+static int 
+nmbclusters_from_physpages(void)
+{
+       long factor;
+       long rv;
+    
+       factor = physmem / (2 * 1024 * 1024 / PAGE_SIZE);
+       if (factor < 32)
+               factor = 32;
+       /* after 384, switch scale to 1/4 */
+       if (factor > 384)
+               factor = 384 + (factor - 384) / 4;
+       rv = 1024 + factor * 64;
+       /*
+        * allow a platform specific override to prevent exhausting
+        * kernel memory on large memory + small address space machines.
+        */
+#ifdef MAX_AUTOTUNE_NMBCLUSTERS
+       if (rv > MAX_AUTOTUNE_NMBCLUSTERS)
+               rv = MAX_AUTOTUNE_NMBCLUSTERS
+#endif
+       return (rv);
+}
+
 /*
  * tunable_mbinit() has to be run before init_maxsockets() thus
  * the SYSINIT order below is SI_ORDER_MIDDLE while init_maxsockets()
@@ -114,7 +138,7 @@ tunable_mbinit(void *dummy)
        /* This has to be done before VM init. */
        TUNABLE_INT_FETCH("kern.ipc.nmbclusters", &nmbclusters);
        if (nmbclusters == 0)
-               nmbclusters = 1024 + maxusers * 64;
+               nmbclusters = nmbclusters_from_physpages();
 
        TUNABLE_INT_FETCH("kern.ipc.nmbjumbop", &nmbjumbop);
        if (nmbjumbop == 0)

--- End Message ---
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to