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

Function bufinit

freebsd/kern/vfs_bio.c:1153–1294  ·  view source on GitHub ↗

Initialize the buffer subsystem. Called before use of any buffers. */

Source from the content-addressed store, hash-verified

1151
1152/* Initialize the buffer subsystem. Called before use of any buffers. */
1153void
1154bufinit(void)
1155{
1156 struct buf *bp;
1157 int i;
1158
1159 KASSERT(maxbcachebuf >= MAXBSIZE,
1160 ("maxbcachebuf (%d) must be >= MAXBSIZE (%d)\n", maxbcachebuf,
1161 MAXBSIZE));
1162 bq_init(&bqempty, QUEUE_EMPTY, -1, "bufq empty lock");
1163 mtx_init(&rbreqlock, "runningbufspace lock", NULL, MTX_DEF);
1164 mtx_init(&bdlock, "buffer daemon lock", NULL, MTX_DEF);
1165 mtx_init(&bdirtylock, "dirty buf lock", NULL, MTX_DEF);
1166
1167 unmapped_buf = (caddr_t)kva_alloc(maxphys);
1168
1169 /* finally, initialize each buffer header and stick on empty q */
1170 for (i = 0; i < nbuf; i++) {
1171 bp = nbufp(i);
1172 bzero(bp, sizeof(*bp) + sizeof(vm_page_t) * atop(maxbcachebuf));
1173 bp->b_flags = B_INVAL;
1174 bp->b_rcred = NOCRED;
1175 bp->b_wcred = NOCRED;
1176 bp->b_qindex = QUEUE_NONE;
1177 bp->b_domain = -1;
1178 bp->b_subqueue = mp_maxid + 1;
1179 bp->b_xflags = 0;
1180 bp->b_data = bp->b_kvabase = unmapped_buf;
1181 LIST_INIT(&bp->b_dep);
1182 BUF_LOCKINIT(bp);
1183 bq_insert(&bqempty, bp, false);
1184 }
1185
1186 /*
1187 * maxbufspace is the absolute maximum amount of buffer space we are
1188 * allowed to reserve in KVM and in real terms. The absolute maximum
1189 * is nominally used by metadata. hibufspace is the nominal maximum
1190 * used by most other requests. The differential is required to
1191 * ensure that metadata deadlocks don't occur.
1192 *
1193 * maxbufspace is based on BKVASIZE. Allocating buffers larger then
1194 * this may result in KVM fragmentation which is not handled optimally
1195 * by the system. XXX This is less true with vmem. We could use
1196 * PAGE_SIZE.
1197 */
1198 maxbufspace = (long)nbuf * BKVASIZE;
1199 hibufspace = lmax(3 * maxbufspace / 4, maxbufspace - maxbcachebuf * 10);
1200 lobufspace = (hibufspace / 20) * 19; /* 95% */
1201 bufspacethresh = lobufspace + (hibufspace - lobufspace) / 2;
1202
1203 /*
1204 * Note: The 16 MiB upper limit for hirunningspace was chosen
1205 * arbitrarily and may need further tuning. It corresponds to
1206 * 128 outstanding write IO requests (if IO size is 128 KiB),
1207 * which fits with many RAID controllers' tagged queuing limits.
1208 * The lower 1 MiB limit is the historical upper limit for
1209 * hirunningspace.
1210 */

Callers 5

cpu_startupFunction · 0.85
cpu_startupFunction · 0.85
cpu_startupFunction · 0.85
cpu_startupFunction · 0.85
cpu_startupFunction · 0.85

Calls 12

bq_initFunction · 0.85
mtx_initFunction · 0.85
kva_allocFunction · 0.85
nbufpFunction · 0.85
bzeroFunction · 0.85
bq_insertFunction · 0.85
lmaxFunction · 0.85
lminFunction · 0.85
vmem_set_reclaimFunction · 0.85
uma_zcache_createFunction · 0.85
bd_initFunction · 0.85
counter_u64_allocFunction · 0.85

Tested by

no test coverage detected