MCPcopy Create free account
hub / github.com/F-Stack/f-stack / tunable_mbinit

Function tunable_mbinit

freebsd/kern/kern_mbuf.c:136–181  ·  view source on GitHub ↗

* tunable_mbinit() has to be run before any mbuf allocations are done. */

Source from the content-addressed store, hash-verified

134 * tunable_mbinit() has to be run before any mbuf allocations are done.
135 */
136static void
137tunable_mbinit(void *dummy)
138{
139 quad_t realmem;
140
141 /*
142 * The default limit for all mbuf related memory is 1/2 of all
143 * available kernel memory (physical or kmem).
144 * At most it can be 3/4 of available kernel memory.
145 */
146#ifndef FSTACK
147 realmem = qmin((quad_t)physmem * PAGE_SIZE, vm_kmem_size);
148#else
149 realmem = (quad_t)physmem * PAGE_SIZE;
150#endif
151
152 maxmbufmem = realmem / 2;
153 TUNABLE_QUAD_FETCH("kern.ipc.maxmbufmem", &maxmbufmem);
154 if (maxmbufmem > realmem / 4 * 3)
155 maxmbufmem = realmem / 4 * 3;
156
157 TUNABLE_INT_FETCH("kern.ipc.nmbclusters", &nmbclusters);
158 if (nmbclusters == 0)
159 nmbclusters = maxmbufmem / MCLBYTES / 4;
160
161 TUNABLE_INT_FETCH("kern.ipc.nmbjumbop", &nmbjumbop);
162 if (nmbjumbop == 0)
163 nmbjumbop = maxmbufmem / MJUMPAGESIZE / 4;
164
165 TUNABLE_INT_FETCH("kern.ipc.nmbjumbo9", &nmbjumbo9);
166 if (nmbjumbo9 == 0)
167 nmbjumbo9 = maxmbufmem / MJUM9BYTES / 6;
168
169 TUNABLE_INT_FETCH("kern.ipc.nmbjumbo16", &nmbjumbo16);
170 if (nmbjumbo16 == 0)
171 nmbjumbo16 = maxmbufmem / MJUM16BYTES / 6;
172
173 /*
174 * We need at least as many mbufs as we have clusters of
175 * the various types added together.
176 */
177 TUNABLE_INT_FETCH("kern.ipc.nmbufs", &nmbufs);
178 if (nmbufs < nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16)
179 nmbufs = lmax(maxmbufmem / MSIZE / 5,
180 nmbclusters + nmbjumbop + nmbjumbo9 + nmbjumbo16);
181}
182SYSINIT(tunable_mbinit, SI_SUB_KMEM, SI_ORDER_MIDDLE, tunable_mbinit, NULL);
183
184static int

Callers

nothing calls this directly

Calls 2

qminFunction · 0.85
lmaxFunction · 0.85

Tested by

no test coverage detected