+
+/* 512 MB (K32) or 2 GB (K64) hard limit on size of the mbuf pool */
+#if !defined(__LP64__)
+#define MAX_MBUF_POOL (512 << MBSHIFT)
+#else
+#define MAX_MBUF_POOL (2ULL << GBSHIFT)
+#endif /* !__LP64__ */
+#define MAX_NCL (MAX_MBUF_POOL >> MCLSHIFT)
+
+#if SOCKETS
+/*
+ * this has been broken out into a separate routine that
+ * can be called from the x86 early vm initialization to
+ * determine how much lo memory to reserve on systems with
+ * DMA hardware that can't fully address all of the physical
+ * memory that is present.
+ */
+unsigned int
+bsd_mbuf_cluster_reserve(boolean_t *overridden)
+{
+ int mbuf_pool = 0;
+ static boolean_t was_overridden = FALSE;
+
+ /* If called more than once, return the previously calculated size */
+ if (mbuf_poolsz != 0) {
+ goto done;
+ }
+
+ /*
+ * Some of these are parsed in parse_bsd_args(), but for x86 we get
+ * here early from i386_vm_init() and so we parse them now, in order
+ * to correctly compute the size of the low-memory VM pool. It is
+ * redundant but rather harmless.
+ */
+ (void) PE_parse_boot_argn("ncl", &ncl, sizeof(ncl));
+ (void) PE_parse_boot_argn("mbuf_pool", &mbuf_pool, sizeof(mbuf_pool));
+
+ /*
+ * Convert "mbuf_pool" from MB to # of 2KB clusters; it is
+ * equivalent to "ncl", except that it uses different unit.
+ */
+ if (mbuf_pool != 0) {
+ ncl = (mbuf_pool << MBSHIFT) >> MCLSHIFT;
+ }
+
+ if (sane_size > (64 * 1024 * 1024) || ncl != 0) {
+ if (ncl || serverperfmode) {
+ was_overridden = TRUE;
+ }
+
+ if ((nmbclusters = ncl) == 0) {
+ /* Auto-configure the mbuf pool size */
+ nmbclusters = mbuf_default_ncl(mem_actual);
+ } else {
+ /* Make sure it's not odd in case ncl is manually set */
+ if (nmbclusters & 0x1) {
+ --nmbclusters;
+ }
+
+ /* And obey the upper limit */
+ if (nmbclusters > MAX_NCL) {
+ nmbclusters = MAX_NCL;
+ }
+ }
+
+ /* Round it down to nearest multiple of PAGE_SIZE */
+ nmbclusters = (unsigned int)P2ROUNDDOWN(nmbclusters, NCLPG);
+ }
+ mbuf_poolsz = nmbclusters << MCLSHIFT;
+done:
+ if (overridden) {
+ *overridden = was_overridden;
+ }
+
+ return mbuf_poolsz;
+}
+#endif
+
+#if defined(__LP64__)
+extern int tcp_tcbhashsize;
+extern int max_cached_sock_count;
+#endif
+
+
+void
+bsd_scale_setup(int scale)
+{
+#if defined(__LP64__)
+ if ((scale > 0) && (serverperfmode == 0)) {
+ maxproc *= scale;
+ maxprocperuid = (maxproc * 2) / 3;
+ if (scale > 2) {
+ maxfiles *= scale;
+ maxfilesperproc = maxfiles / 2;
+ }
+ }
+ /* Apply server scaling rules */
+ if ((scale > 0) && (serverperfmode != 0)) {
+ maxproc = 2500 * scale;
+ hard_maxproc = maxproc;
+ /* no fp usage */
+ maxprocperuid = (maxproc * 3) / 4;
+ maxfiles = (150000 * scale);
+ maxfilesperproc = maxfiles / 2;
+ desiredvnodes = maxfiles;
+ vnodes_sized = 1;
+ tcp_tfo_backlog = 100 * scale;
+ if (scale > 4) {
+ /* clip somaxconn at 32G level */
+ somaxconn = 2048;
+ /*
+ * For scale > 4 (> 32G), clip
+ * tcp_tcbhashsize to 32K
+ */
+ tcp_tcbhashsize = 32 * 1024;
+
+ if (scale > 7) {
+ /* clip at 64G level */
+ max_cached_sock_count = 165000;
+ } else {
+ max_cached_sock_count = 60000 + ((scale - 1) * 15000);
+ }
+ } else {
+ somaxconn = 512 * scale;
+ tcp_tcbhashsize = 4 * 1024 * scale;
+ max_cached_sock_count = 60000 + ((scale - 1) * 15000);
+ }
+ }
+
+ if (maxproc > hard_maxproc) {
+ hard_maxproc = maxproc;
+ }
+#endif
+ bsd_exec_setup(scale);
+}