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