]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/unix_startup.c
018ea1583e65e13a03fb3b50f8b95230715eddfb
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1992,7 NeXT Computer, Inc.
25 * Unix data structure initialization.
29 #include <mach/mach_types.h>
31 #include <vm/vm_kern.h>
32 #include <mach/vm_prot.h>
34 #include <sys/param.h>
35 #include <sys/buf_internal.h>
36 #include <sys/clist.h>
38 #include <sys/systm.h>
40 #include <sys/vnode.h>
41 #include <sys/sysctl.h>
42 #include <dev/ppc/cons.h>
44 extern vm_map_t mb_map
;
46 extern u_long tcp_sendspace
;
47 extern u_long tcp_recvspace
;
49 void bsd_bufferinit(void);
50 extern void md_prepare_for_shutdown(int, int, char *);
52 int bsd_mbuf_cluster_reserve(void);
55 * Declare these as initialized data so we can patch them.
59 int max_nbuf_headers
= NBUF
;
60 int niobuf
= NBUF
/ 2;
61 int nbuf_hashelements
= NBUF
;
64 int max_nbuf_headers
= 0;
66 int nbuf_hashelements
= 0;
70 SYSCTL_INT (_kern
, OID_AUTO
, nbuf
, CTLFLAG_RD
, &nbuf
, 0, "");
71 SYSCTL_INT (_kern
, OID_AUTO
, maxnbuf
, CTLFLAG_RW
, &max_nbuf_headers
, 0, "");
73 __private_extern__
int customnbuf
= 0;
74 int srv
= 0; /* Flag indicates a server boot when set */
78 vm_map_t bufferhdr_map
;
81 extern void bsd_startupearly(void);
84 bsd_startupearly(void)
86 vm_offset_t firstaddr
;
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;
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;
104 nbuf_hashelements
= max_nbuf_headers
;
107 niobuf
= max_nbuf_headers
;
113 size
= (max_nbuf_headers
+ niobuf
) * sizeof(struct buf
);
114 size
= round_page(size
);
116 ret
= kmem_suballoc(kernel_map
,
123 if (ret
!= KERN_SUCCESS
)
124 panic("Failed to create bufferhdr_map");
126 ret
= kernel_memory_allocate(bufferhdr_map
,
130 KMA_HERE
| KMA_KOBJECT
);
132 if (ret
!= KERN_SUCCESS
)
133 panic("Failed to allocate bufferhdr_map");
135 buf
= (struct buf
*) firstaddr
;
141 nmbclusters
= bsd_mbuf_cluster_reserve() / MCLBYTES
;
143 if ((scale
= nmbclusters
/ NMBCLUSTERS
) > 1) {
144 tcp_sendspace
*= scale
;
145 tcp_recvspace
*= scale
;
147 if (tcp_sendspace
> (32 * 1024))
148 tcp_sendspace
= 32 * 1024;
149 if (tcp_recvspace
> (32 * 1024))
150 tcp_recvspace
= 32 * 1024;
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;
161 desiredvnodes
= (sane_size
/65536) + 1024;
162 if (desiredvnodes
> 263168)
163 desiredvnodes
= 263168;
171 cons
.t_dev
= makedev(12, 0);
175 ret
= kmem_suballoc(kernel_map
,
176 (vm_offset_t
*) & mbutl
,
177 (vm_size_t
) (nmbclusters
* MCLBYTES
),
182 if (ret
!= KERN_SUCCESS
)
183 panic("Failed to allocate mb_map\n");
186 * Set up buffers, so they can be used to read disk labels.
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.
199 bsd_mbuf_cluster_reserve(void)
201 if (sane_size
> (64 * 1024 * 1024) || ncl
) {
203 if ((nmbclusters
= ncl
) == 0) {
204 if ((nmbclusters
= ((sane_size
/ 16)/MCLBYTES
)) > 32768)
209 return (nmbclusters
* MCLBYTES
);