|
|
1.1 root 1: /*
2: * Copyright (c) 2000 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: * HISTORY
28: *
29: * 11 Mar 1997 Eryk Vershen @ NeXT
30: * Modified from hppa version.
31: * 26 May 1992 ? at NeXT
32: * Created from 68k version.
33: */
34:
35: #include <mach_nbc.h>
36: #include <mach/mach_types.h>
37:
38: #include <vm/vm_kern.h>
39: #include <mach/vm_prot.h>
40:
41: #include <sys/param.h>
42: #include <sys/buf.h>
43: #include <sys/clist.h>
44: #include <sys/mbuf.h>
45: #include <sys/systm.h>
46: #include <sys/tty.h>
47: #include <bsd/dev/ppc/cons.h>
48:
49:
50: extern vm_map_t mb_map;
51: /*
52: * Declare these as initialized data so we can patch them.
53: */
54: int niobuf = 0;
55:
56: #ifdef NBUF
57: int nbuf = NBUF;
58: #else
59: int nbuf = 0;
60: #endif
61: #ifdef NMFSBUF
62: int nmfsbuf = NMFSBUF
63: #else
64: int nmfsbuf = 0;
65: #endif
66: #ifdef BUFPAGES
67: int bufpages = BUFPAGES;
68: #else
69: int bufpages = 0;
70: #endif
71:
72: int srv = 0; /* Flag indicates a server boot when set */
73: int ncl = 0;
74:
75: vm_map_t buffer_map;
76: vm_map_t bufferhdr_map;
77:
78:
79: void
80: bsd_startupearly()
81: {
82: vm_offset_t v, firstaddr, trash_offset;
83: vm_size_t size;
84: kern_return_t ret;
85:
86:
87: /*
88: * Since these pages are virtual-size pages (larger
89: * than physical page size), use only one page
90: * per buffer.
91: */
92:
93: if (bufpages == 0) {
94: if (srv) {
95: if (mem_size > (64 * 1024 * 1024)) {
96: bufpages = atop(mem_size) / 2;
97:
98: if ((mem_size - ptoa(bufpages)) < (64 * 1024 * 1024))
99: bufpages = atop(mem_size - (64 * 1024 * 1024));
100: } else {
101: bufpages = atop(mem_size / 100);
102: bufpages = bufpages * 3; /* 3% */
103: }
104: } else {
105: bufpages = atop(mem_size / 100);
106: bufpages = bufpages * 3; /* 3% */
107: }
108: }
109:
110: if (nbuf == 0) {
111: #if PRIVATE_BUFS
112: nbuf = 100;
113: #else PRIVATE_BUFS
114: /* Go for a 1-1 correspondence between the number of buffer
115: * headers and bufpages. Then add some extra (empty) buffer
116: * headers to aid clustering.
117: */
118: if (bufpages > 65536)
119: bufpages = 65536;
120: if ((nbuf = bufpages) < 16)
121: nbuf = 16;
122: nbuf += 64;
123: #endif PRIVATE_BUFS
124: } else if (nbuf > 65536)
125: nbuf = 65536;
126:
127: if (bufpages > nbuf * (MAXBSIZE / page_size))
128: bufpages = nbuf * (MAXBSIZE / page_size);
129:
130: if (niobuf == 0) {
131: niobuf = bufpages / (MAXPHYSIO / page_size);
132: if (niobuf < 128)
133: niobuf = 128;
134: }
135: if (niobuf > 4096)
136: niobuf = 4096;
137:
138: size = (nbuf + niobuf) * sizeof (struct buf);
139: size = round_page(size);
140:
141: ret = kmem_suballoc(kernel_map,
142: &firstaddr,
143: size,
144: FALSE,
145: TRUE,
146: &bufferhdr_map);
147:
148: if (ret != KERN_SUCCESS)
149: panic("Failed to create bufferhdr_map\n");
150:
151: if (kernel_memory_allocate(bufferhdr_map, &firstaddr, size,
152: 0,
153: KMA_HERE | KMA_KOBJECT) != KERN_SUCCESS)
154: panic("Failed to allocate bufferhdr_map\n");
155:
156: buf = (struct buf * )firstaddr;
157: bzero(buf,size);
158:
159:
160: /*
161: * Unless set at the boot command line, mfs gets no more than
162: * half of the system's bufs. Hack to prevent buf starvation
163: * and system hang.
164: */
165: if (nmfsbuf == 0)
166: nmfsbuf = nbuf / 2;
167:
168: if ((mem_size > (64 * 1024 * 1024)) || ncl) {
169: int scale;
170: extern u_long tcp_sendspace;
171: extern u_long tcp_recvspace;
172:
173: if ((nmbclusters = ncl) == 0) {
174: if ((nmbclusters = ((mem_size / 16) / MCLBYTES)) > 8192)
175: nmbclusters = 8192;
176: }
177: if ((scale = nmbclusters / NMBCLUSTERS) > 1) {
178: tcp_sendspace *= scale;
179: tcp_recvspace *= scale;
180:
181: if (tcp_sendspace > (32 * 1024))
182: tcp_sendspace = 32 * 1024;
183: if (tcp_recvspace > (32 * 1024))
184: tcp_recvspace = 32 * 1024;
185: }
186: }
187: }
188:
189: void
190: bsd_bufferinit()
191: {
192: unsigned int i;
193: vm_offset_t v;
194: vm_size_t size;
195: kern_return_t ret;
196: vm_offset_t trash_offset, firstaddr;
197: int base, residual;
198:
199: cons.t_dev = makedev(12, 0);
200:
201:
202: bsd_startupearly();
203:
204: size = round_page(nbuf * MAXBSIZE) + (niobuf * MAXPHYSIO);
205: ret = kmem_suballoc(kernel_map,
206: &firstaddr,
207: size,
208: TRUE,
209: TRUE,
210: &buffer_map);
211:
212: if (ret != KERN_SUCCESS)
213: panic("Failed to create buffer_map\n");
214: buffers = firstaddr;
215: printf("Buffer cache at %x\n",buffers);
216: base = bufpages / nbuf;
217: residual = bufpages % nbuf;
218:
219: for (i = 0; i < nbuf; i++) {
220: vm_size_t thisbsize;
221: vm_offset_t curbuf;
222:
223: /*
224: * First <residual> buffers get (base+1) physical pages
225: * allocated for them. The rest get (base) physical pages.
226: *
227: * The rest of each buffer occupies virtual space,
228: * but has no physical memory allocated for it.
229: */
230:
231: thisbsize = page_size*(i < residual ? base+1 : base);
232: curbuf = (vm_offset_t)buffers + i * MAXBSIZE;
233: if (thisbsize) {
234: ret = vm_map_enter(buffer_map, &curbuf, thisbsize,
235: (vm_offset_t) 0, FALSE,
236: VM_OBJECT_NULL, (vm_offset_t) 0, FALSE,
237: VM_PROT_DEFAULT, VM_PROT_ALL, VM_INHERIT_DEFAULT);
238: if (ret != KERN_SUCCESS) {
239: panic("Failed to allocate buffer cache pages\n");
240: }
241: ret = vm_map_wire(buffer_map, curbuf, curbuf+thisbsize, VM_PROT_READ | VM_PROT_WRITE, FALSE);
242: if (ret != KERN_SUCCESS)
243: panic("Failed to wire buffer cache pages\n");
244:
245: } else {
246: /* printf("skipping allocating buffer page to buf %d\n",i); */
247: }
248: }
249:
250:
251: #define MEG (1024*1024)
252: {
253: register int nbytes;
254:
255: nbytes = ptoa(bufpages);
256: printf("using %d buffers containing %d.%d%d megabytes of memory\n",
257: nbuf,
258: nbytes/MEG,
259: ((nbytes%MEG)*10)/MEG,
260: ((nbytes%(MEG/10))*100)/MEG);
261:
262: }
263:
264: ret = kmem_suballoc(kernel_map,
265: &mbutl,
266: (vm_size_t) (nmbclusters * MCLBYTES),
267: FALSE,
268: TRUE,
269: &mb_map);
270:
271: if (ret != KERN_SUCCESS)
272: panic("Failed to allocate mb_map\n");
273: /* embutl = ((unsigned char *)mbutl + (nmbclusters * MCLBYTES)); */
274:
275: /*
276: * Set up buffers, so they can be used to read disk labels.
277: */
278: bufinit();
279: }
280:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.