X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/89b3af67bb32e691275bf6fa803d1834b2284115..36401178fd6817c043cc00b0c00c7f723e58efae:/bsd/dev/unix_startup.c diff --git a/bsd/dev/unix_startup.c b/bsd/dev/unix_startup.c index daef72f73..d3df77196 100644 --- a/bsd/dev/unix_startup.c +++ b/bsd/dev/unix_startup.c @@ -49,10 +49,12 @@ extern vm_map_t mb_map; +#if INET || INET6 extern u_long tcp_sendspace; extern u_long tcp_recvspace; +#endif -void bsd_bufferinit(void); +void bsd_bufferinit(void) __attribute__((section("__TEXT, initcode"))); extern void md_prepare_for_shutdown(int, int, char *); int bsd_mbuf_cluster_reserve(void); @@ -63,17 +65,17 @@ int bsd_mbuf_cluster_reserve(void); #ifdef NBUF int max_nbuf_headers = NBUF; -int niobuf = NBUF / 2; +int niobuf_headers = NBUF / 2; int nbuf_hashelements = NBUF; -int nbuf = NBUF; +int nbuf_headers = NBUF; #else int max_nbuf_headers = 0; -int niobuf = 0; +int niobuf_headers = 0; int nbuf_hashelements = 0; -int nbuf = 0; +int nbuf_headers = 0; #endif -SYSCTL_INT (_kern, OID_AUTO, nbuf, CTLFLAG_RD, &nbuf, 0, ""); +SYSCTL_INT (_kern, OID_AUTO, nbuf, CTLFLAG_RD, &nbuf_headers, 0, ""); SYSCTL_INT (_kern, OID_AUTO, maxnbuf, CTLFLAG_RW, &max_nbuf_headers, 0, ""); __private_extern__ int customnbuf = 0; @@ -84,7 +86,7 @@ vm_map_t buffer_map; vm_map_t bufferhdr_map; -extern void bsd_startupearly(void); +extern void bsd_startupearly(void) __attribute__((section("__TEXT, initcode"))); void bsd_startupearly(void) @@ -98,8 +100,8 @@ bsd_startupearly(void) max_nbuf_headers = atop(sane_size / 50); /* Get 2% of ram, but no more than we can map */ if ((customnbuf == 0) && (max_nbuf_headers > 16384)) max_nbuf_headers = 16384; - if (max_nbuf_headers < 256) - max_nbuf_headers = 256; + if (max_nbuf_headers < CONFIG_MIN_NBUF) + max_nbuf_headers = CONFIG_MIN_NBUF; /* clip the number of hash elements to 200000 */ if ( (customnbuf == 0 ) && nbuf_hashelements == 0) { @@ -109,14 +111,14 @@ bsd_startupearly(void) } else nbuf_hashelements = max_nbuf_headers; - if (niobuf == 0) - niobuf = max_nbuf_headers; - if (niobuf > 4096) - niobuf = 4096; - if (niobuf < 128) - niobuf = 128; + if (niobuf_headers == 0) + niobuf_headers = max_nbuf_headers; + if (niobuf_headers > 4096) + niobuf_headers = 4096; + if (niobuf_headers < CONFIG_MIN_NIOBUF) + niobuf_headers = CONFIG_MIN_NIOBUF; - size = (max_nbuf_headers + niobuf) * sizeof(struct buf); + size = (max_nbuf_headers + niobuf_headers) * sizeof(struct buf); size = round_page(size); ret = kmem_suballoc(kernel_map, @@ -138,24 +140,28 @@ bsd_startupearly(void) if (ret != KERN_SUCCESS) panic("Failed to allocate bufferhdr_map"); - buf = (struct buf *) firstaddr; - bzero(buf, size); + buf_headers = (struct buf *) firstaddr; + bzero(buf_headers, size); +#if SOCKETS { int scale; nmbclusters = bsd_mbuf_cluster_reserve() / MCLBYTES; +#if INET || INET6 if ((scale = nmbclusters / NMBCLUSTERS) > 1) { tcp_sendspace *= scale; tcp_recvspace *= scale; - if (tcp_sendspace > (32 * 1024)) - tcp_sendspace = 32 * 1024; - if (tcp_recvspace > (32 * 1024)) - tcp_recvspace = 32 * 1024; + if (tcp_sendspace > (64 * 1024)) + tcp_sendspace = 64 * 1024; + if (tcp_recvspace > (64 * 1024)) + tcp_recvspace = 64 * 1024; } +#endif /* INET || INET6 */ } +#endif /* SOCKETS */ /* * Size vnodes based on memory @@ -163,10 +169,12 @@ bsd_startupearly(void) * This is the calculation that is used by launchd in tiger * we are clipping the max based on 16G * ie ((16*1024*1024*1024)/(64 *1024)) + 1024 = 263168; + * CONFIG_VNODES is set to 263168 for "medium" configurations (the default) + * but can be smaller or larger. */ desiredvnodes = (sane_size/65536) + 1024; - if (desiredvnodes > 263168) - desiredvnodes = 263168; + if (desiredvnodes > CONFIG_VNODES) + desiredvnodes = CONFIG_VNODES; } void @@ -178,6 +186,7 @@ bsd_bufferinit(void) bsd_startupearly(); +#if SOCKETS ret = kmem_suballoc(kernel_map, (vm_offset_t *) & mbutl, (vm_size_t) (nmbclusters * MCLBYTES), @@ -187,6 +196,7 @@ bsd_bufferinit(void) if (ret != KERN_SUCCESS) panic("Failed to allocate mb_map\n"); +#endif /* SOCKETS */ /* * Set up buffers, so they can be used to read disk labels. @@ -194,6 +204,7 @@ bsd_bufferinit(void) bufinit(); } + /* * this has been broken out into a separate routine that * can be called from the x86 early vm initialization to @@ -204,12 +215,15 @@ bsd_bufferinit(void) int bsd_mbuf_cluster_reserve(void) { - if (sane_size > (64 * 1024 * 1024) || ncl) { + if (sane_size > (64 * 1024 * 1024) || ncl) { if ((nmbclusters = ncl) == 0) { if ((nmbclusters = ((sane_size / 16)/MCLBYTES)) > 32768) nmbclusters = 32768; } + /* Make sure it's not odd in case ncl is manually set */ + if (nmbclusters & 0x1) + --nmbclusters; } return (nmbclusters * MCLBYTES);