| 784 | } |
| 785 | |
| 786 | void |
| 787 | dbuf_init(void) |
| 788 | { |
| 789 | uint64_t hsize = 1ULL << 16; |
| 790 | dbuf_hash_table_t *h = &dbuf_hash_table; |
| 791 | int i; |
| 792 | |
| 793 | /* |
| 794 | * The hash table is big enough to fill all of physical memory |
| 795 | * with an average block size of zfs_arc_average_blocksize (default 8K). |
| 796 | * By default, the table will take up |
| 797 | * totalmem * sizeof(void*) / 8K (1MB per GB with 8-byte pointers). |
| 798 | */ |
| 799 | while (hsize * zfs_arc_average_blocksize < physmem * PAGESIZE) |
| 800 | hsize <<= 1; |
| 801 | |
| 802 | retry: |
| 803 | h->hash_table_mask = hsize - 1; |
| 804 | #if defined(_KERNEL) |
| 805 | /* |
| 806 | * Large allocations which do not require contiguous pages |
| 807 | * should be using vmem_alloc() in the linux kernel |
| 808 | */ |
| 809 | h->hash_table = vmem_zalloc(hsize * sizeof (void *), KM_SLEEP); |
| 810 | #else |
| 811 | h->hash_table = kmem_zalloc(hsize * sizeof (void *), KM_NOSLEEP); |
| 812 | #endif |
| 813 | if (h->hash_table == NULL) { |
| 814 | /* XXX - we should really return an error instead of assert */ |
| 815 | ASSERT(hsize > (1ULL << 10)); |
| 816 | hsize >>= 1; |
| 817 | goto retry; |
| 818 | } |
| 819 | |
| 820 | dbuf_kmem_cache = kmem_cache_create("dmu_buf_impl_t", |
| 821 | sizeof (dmu_buf_impl_t), |
| 822 | 0, dbuf_cons, dbuf_dest, NULL, NULL, NULL, 0); |
| 823 | |
| 824 | for (i = 0; i < DBUF_MUTEXES; i++) |
| 825 | mutex_init(&h->hash_mutexes[i], NULL, MUTEX_DEFAULT, NULL); |
| 826 | |
| 827 | dbuf_stats_init(h); |
| 828 | |
| 829 | /* |
| 830 | * All entries are queued via taskq_dispatch_ent(), so min/maxalloc |
| 831 | * configuration is not required. |
| 832 | */ |
| 833 | dbu_evict_taskq = taskq_create("dbu_evict", 1, defclsyspri, 0, 0, 0); |
| 834 | |
| 835 | for (dbuf_cached_state_t dcs = 0; dcs < DB_CACHE_MAX; dcs++) { |
| 836 | dbuf_caches[dcs].cache = |
| 837 | multilist_create(sizeof (dmu_buf_impl_t), |
| 838 | offsetof(dmu_buf_impl_t, db_cache_link), |
| 839 | dbuf_cache_multilist_index_func); |
| 840 | zfs_refcount_create(&dbuf_caches[dcs].size); |
| 841 | } |
| 842 | |
| 843 | dbuf_evict_thread_exit = B_FALSE; |
no test coverage detected