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

Function buf_init

freebsd/contrib/openzfs/module/zfs/arc.c:1263–1316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1261}
1262
1263static void
1264buf_init(void)
1265{
1266 uint64_t *ct = NULL;
1267 uint64_t hsize = 1ULL << 12;
1268 int i, j;
1269
1270 /*
1271 * The hash table is big enough to fill all of physical memory
1272 * with an average block size of zfs_arc_average_blocksize (default 8K).
1273 * By default, the table will take up
1274 * totalmem * sizeof(void*) / 8K (1MB per GB with 8-byte pointers).
1275 */
1276 while (hsize * zfs_arc_average_blocksize < arc_all_memory())
1277 hsize <<= 1;
1278retry:
1279 buf_hash_table.ht_mask = hsize - 1;
1280#if defined(_KERNEL)
1281 /*
1282 * Large allocations which do not require contiguous pages
1283 * should be using vmem_alloc() in the linux kernel
1284 */
1285 buf_hash_table.ht_table =
1286 vmem_zalloc(hsize * sizeof (void*), KM_SLEEP);
1287#else
1288 buf_hash_table.ht_table =
1289 kmem_zalloc(hsize * sizeof (void*), KM_NOSLEEP);
1290#endif
1291 if (buf_hash_table.ht_table == NULL) {
1292 ASSERT(hsize > (1ULL << 8));
1293 hsize >>= 1;
1294 goto retry;
1295 }
1296
1297 hdr_full_cache = kmem_cache_create("arc_buf_hdr_t_full", HDR_FULL_SIZE,
1298 0, hdr_full_cons, hdr_full_dest, NULL, NULL, NULL, 0);
1299 hdr_full_crypt_cache = kmem_cache_create("arc_buf_hdr_t_full_crypt",
1300 HDR_FULL_CRYPT_SIZE, 0, hdr_full_crypt_cons, hdr_full_crypt_dest,
1301 NULL, NULL, NULL, 0);
1302 hdr_l2only_cache = kmem_cache_create("arc_buf_hdr_t_l2only",
1303 HDR_L2ONLY_SIZE, 0, hdr_l2only_cons, hdr_l2only_dest, NULL,
1304 NULL, NULL, 0);
1305 buf_cache = kmem_cache_create("arc_buf_t", sizeof (arc_buf_t),
1306 0, buf_cons, buf_dest, NULL, NULL, NULL, 0);
1307
1308 for (i = 0; i < 256; i++)
1309 for (ct = zfs_crc64_table + i, *ct = i, j = 8; j > 0; j--)
1310 *ct = (*ct >> 1) ^ (-(*ct & 1) & ZFS_CRC64_POLY);
1311
1312 for (i = 0; i < BUF_LOCKS; i++) {
1313 mutex_init(&buf_hash_table.ht_locks[i].ht_lock,
1314 NULL, MUTEX_DEFAULT, NULL);
1315 }
1316}
1317
1318#define ARC_MINTIME (hz>>4) /* 62 ms */
1319

Callers 1

arc_initFunction · 0.85

Calls 3

kmem_cache_createFunction · 0.85
arc_all_memoryFunction · 0.50
mutex_initFunction · 0.50

Tested by

no test coverage detected