]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. |
3 | * | |
2d21ac55 A |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
1c79356b A |
27 | */ |
28 | /* | |
29 | * Copyright (c) 1992,7 NeXT Computer, Inc. | |
30 | * | |
31 | * Unix data structure initialization. | |
91447636 | 32 | * |
1c79356b A |
33 | */ |
34 | ||
35 | #include <mach/mach_types.h> | |
36 | ||
37 | #include <vm/vm_kern.h> | |
38 | #include <mach/vm_prot.h> | |
39 | ||
40 | #include <sys/param.h> | |
91447636 | 41 | #include <sys/buf_internal.h> |
1c79356b A |
42 | #include <sys/clist.h> |
43 | #include <sys/mbuf.h> | |
44 | #include <sys/systm.h> | |
45 | #include <sys/tty.h> | |
0c530ab8 A |
46 | #include <sys/vnode.h> |
47 | #include <sys/sysctl.h> | |
1c79356b A |
48 | #include <dev/ppc/cons.h> |
49 | ||
91447636 A |
50 | extern vm_map_t mb_map; |
51 | ||
2d21ac55 | 52 | #if INET || INET6 |
91447636 A |
53 | extern u_long tcp_sendspace; |
54 | extern u_long tcp_recvspace; | |
2d21ac55 | 55 | #endif |
91447636 | 56 | |
2d21ac55 | 57 | void bsd_bufferinit(void) __attribute__((section("__TEXT, initcode"))); |
91447636 | 58 | extern void md_prepare_for_shutdown(int, int, char *); |
1c79356b | 59 | |
0c530ab8 A |
60 | int bsd_mbuf_cluster_reserve(void); |
61 | ||
1c79356b A |
62 | /* |
63 | * Declare these as initialized data so we can patch them. | |
64 | */ | |
65 | ||
66 | #ifdef NBUF | |
0c530ab8 | 67 | int max_nbuf_headers = NBUF; |
2d21ac55 | 68 | int niobuf_headers = NBUF / 2; |
0c530ab8 | 69 | int nbuf_hashelements = NBUF; |
2d21ac55 | 70 | int nbuf_headers = NBUF; |
1c79356b | 71 | #else |
0c530ab8 | 72 | int max_nbuf_headers = 0; |
2d21ac55 | 73 | int niobuf_headers = 0; |
0c530ab8 | 74 | int nbuf_hashelements = 0; |
2d21ac55 | 75 | int nbuf_headers = 0; |
6601e61a | 76 | #endif |
4452a7af | 77 | |
2d21ac55 | 78 | SYSCTL_INT (_kern, OID_AUTO, nbuf, CTLFLAG_RD, &nbuf_headers, 0, ""); |
0c530ab8 A |
79 | SYSCTL_INT (_kern, OID_AUTO, maxnbuf, CTLFLAG_RW, &max_nbuf_headers, 0, ""); |
80 | ||
81 | __private_extern__ int customnbuf = 0; | |
91447636 A |
82 | int srv = 0; /* Flag indicates a server boot when set */ |
83 | int ncl = 0; | |
84 | ||
85 | vm_map_t buffer_map; | |
86 | vm_map_t bufferhdr_map; | |
1c79356b | 87 | |
91447636 | 88 | |
2d21ac55 | 89 | extern void bsd_startupearly(void) __attribute__((section("__TEXT, initcode"))); |
1c79356b A |
90 | |
91 | void | |
91447636 | 92 | bsd_startupearly(void) |
1c79356b | 93 | { |
91447636 A |
94 | vm_offset_t firstaddr; |
95 | vm_size_t size; | |
96 | kern_return_t ret; | |
1c79356b | 97 | |
0c530ab8 A |
98 | /* clip the number of buf headers upto 16k */ |
99 | if (max_nbuf_headers == 0) | |
100 | max_nbuf_headers = atop(sane_size / 50); /* Get 2% of ram, but no more than we can map */ | |
101 | if ((customnbuf == 0) && (max_nbuf_headers > 16384)) | |
102 | max_nbuf_headers = 16384; | |
2d21ac55 A |
103 | if (max_nbuf_headers < CONFIG_MIN_NBUF) |
104 | max_nbuf_headers = CONFIG_MIN_NBUF; | |
0c530ab8 A |
105 | |
106 | /* clip the number of hash elements to 200000 */ | |
107 | if ( (customnbuf == 0 ) && nbuf_hashelements == 0) { | |
108 | nbuf_hashelements = atop(sane_size / 50); | |
109 | if (nbuf_hashelements > 200000) | |
110 | nbuf_hashelements = 200000; | |
111 | } else | |
112 | nbuf_hashelements = max_nbuf_headers; | |
1c79356b | 113 | |
2d21ac55 A |
114 | if (niobuf_headers == 0) |
115 | niobuf_headers = max_nbuf_headers; | |
116 | if (niobuf_headers > 4096) | |
117 | niobuf_headers = 4096; | |
118 | if (niobuf_headers < CONFIG_MIN_NIOBUF) | |
119 | niobuf_headers = CONFIG_MIN_NIOBUF; | |
1c79356b | 120 | |
2d21ac55 | 121 | size = (max_nbuf_headers + niobuf_headers) * sizeof(struct buf); |
91447636 | 122 | size = round_page(size); |
1c79356b A |
123 | |
124 | ret = kmem_suballoc(kernel_map, | |
91447636 A |
125 | &firstaddr, |
126 | size, | |
127 | FALSE, | |
128 | VM_FLAGS_ANYWHERE, | |
129 | &bufferhdr_map); | |
1c79356b | 130 | |
91447636 | 131 | if (ret != KERN_SUCCESS) |
1c79356b | 132 | panic("Failed to create bufferhdr_map"); |
91447636 | 133 | |
1c79356b | 134 | ret = kernel_memory_allocate(bufferhdr_map, |
91447636 A |
135 | &firstaddr, |
136 | size, | |
137 | 0, | |
138 | KMA_HERE | KMA_KOBJECT); | |
1c79356b A |
139 | |
140 | if (ret != KERN_SUCCESS) | |
141 | panic("Failed to allocate bufferhdr_map"); | |
142 | ||
2d21ac55 A |
143 | buf_headers = (struct buf *) firstaddr; |
144 | bzero(buf_headers, size); | |
1c79356b | 145 | |
2d21ac55 | 146 | #if SOCKETS |
0c530ab8 | 147 | { |
91447636 | 148 | int scale; |
1c79356b | 149 | |
0c530ab8 A |
150 | nmbclusters = bsd_mbuf_cluster_reserve() / MCLBYTES; |
151 | ||
2d21ac55 | 152 | #if INET || INET6 |
1c79356b A |
153 | if ((scale = nmbclusters / NMBCLUSTERS) > 1) { |
154 | tcp_sendspace *= scale; | |
155 | tcp_recvspace *= scale; | |
156 | ||
2d21ac55 A |
157 | if (tcp_sendspace > (64 * 1024)) |
158 | tcp_sendspace = 64 * 1024; | |
159 | if (tcp_recvspace > (64 * 1024)) | |
160 | tcp_recvspace = 64 * 1024; | |
1c79356b | 161 | } |
2d21ac55 | 162 | #endif /* INET || INET6 */ |
1c79356b | 163 | } |
2d21ac55 | 164 | #endif /* SOCKETS */ |
0c530ab8 A |
165 | |
166 | /* | |
167 | * Size vnodes based on memory | |
168 | * Number vnodes is (memsize/64k) + 1024 | |
169 | * This is the calculation that is used by launchd in tiger | |
170 | * we are clipping the max based on 16G | |
171 | * ie ((16*1024*1024*1024)/(64 *1024)) + 1024 = 263168; | |
2d21ac55 A |
172 | * CONFIG_VNODES is set to 263168 for "medium" configurations (the default) |
173 | * but can be smaller or larger. | |
0c530ab8 A |
174 | */ |
175 | desiredvnodes = (sane_size/65536) + 1024; | |
2d21ac55 A |
176 | if (desiredvnodes > CONFIG_VNODES) |
177 | desiredvnodes = CONFIG_VNODES; | |
1c79356b A |
178 | } |
179 | ||
180 | void | |
91447636 | 181 | bsd_bufferinit(void) |
1c79356b | 182 | { |
91447636 | 183 | kern_return_t ret; |
1c79356b | 184 | |
91447636 | 185 | cons.t_dev = makedev(12, 0); |
1c79356b A |
186 | |
187 | bsd_startupearly(); | |
188 | ||
2d21ac55 | 189 | #if SOCKETS |
91447636 A |
190 | ret = kmem_suballoc(kernel_map, |
191 | (vm_offset_t *) & mbutl, | |
192 | (vm_size_t) (nmbclusters * MCLBYTES), | |
193 | FALSE, | |
194 | VM_FLAGS_ANYWHERE, | |
195 | &mb_map); | |
1c79356b | 196 | |
91447636 | 197 | if (ret != KERN_SUCCESS) |
1c79356b | 198 | panic("Failed to allocate mb_map\n"); |
2d21ac55 | 199 | #endif /* SOCKETS */ |
0b4e3aa0 | 200 | |
91447636 A |
201 | /* |
202 | * Set up buffers, so they can be used to read disk labels. | |
203 | */ | |
204 | bufinit(); | |
0b4e3aa0 | 205 | } |
0c530ab8 | 206 | |
2d21ac55 | 207 | |
0c530ab8 A |
208 | /* |
209 | * this has been broken out into a separate routine that | |
210 | * can be called from the x86 early vm initialization to | |
211 | * determine how much lo memory to reserve on systems with | |
212 | * DMA hardware that can't fully address all of the physical | |
213 | * memory that is present. | |
214 | */ | |
215 | int | |
216 | bsd_mbuf_cluster_reserve(void) | |
217 | { | |
2d21ac55 | 218 | if (sane_size > (64 * 1024 * 1024) || ncl) { |
0c530ab8 A |
219 | |
220 | if ((nmbclusters = ncl) == 0) { | |
221 | if ((nmbclusters = ((sane_size / 16)/MCLBYTES)) > 32768) | |
222 | nmbclusters = 32768; | |
223 | } | |
2d21ac55 A |
224 | /* Make sure it's not odd in case ncl is manually set */ |
225 | if (nmbclusters & 0x1) | |
226 | --nmbclusters; | |
0c530ab8 A |
227 | } |
228 | ||
229 | return (nmbclusters * MCLBYTES); | |
230 | } |