003 File Manager
Current Path:
/usr/src/sys/contrib/openzfs/module/zfs
usr
/
src
/
sys
/
contrib
/
openzfs
/
module
/
zfs
/
📁
..
📄
Makefile.in
(4.57 KB)
📄
THIRDPARTYLICENSE.cityhash
(1.03 KB)
📄
THIRDPARTYLICENSE.cityhash.descrip
(39 B)
📄
abd.c
(31.72 KB)
📄
aggsum.c
(8.46 KB)
📄
arc.c
(330.91 KB)
📄
blkptr.c
(4.26 KB)
📄
bplist.c
(2.38 KB)
📄
bpobj.c
(27.82 KB)
📄
bptree.c
(8.2 KB)
📄
bqueue.c
(4.7 KB)
📄
btree.c
(65.19 KB)
📄
dataset_kstats.c
(6.32 KB)
📄
dbuf.c
(141.84 KB)
📄
dbuf_stats.c
(6.05 KB)
📄
ddt.c
(28.01 KB)
📄
ddt_zap.c
(4.38 KB)
📄
dmu.c
(60.44 KB)
📄
dmu_diff.c
(6.25 KB)
📄
dmu_object.c
(14.73 KB)
📄
dmu_objset.c
(79.38 KB)
📄
dmu_recv.c
(98.69 KB)
📄
dmu_redact.c
(37.09 KB)
📄
dmu_send.c
(95.51 KB)
📄
dmu_traverse.c
(21.98 KB)
📄
dmu_tx.c
(40.13 KB)
📄
dmu_zfetch.c
(13.56 KB)
📄
dnode.c
(71.32 KB)
📄
dnode_sync.c
(24.93 KB)
📄
dsl_bookmark.c
(51.22 KB)
📄
dsl_crypt.c
(78.06 KB)
📄
dsl_dataset.c
(141.61 KB)
📄
dsl_deadlist.c
(27.94 KB)
📄
dsl_deleg.c
(19.92 KB)
📄
dsl_destroy.c
(36.73 KB)
📄
dsl_dir.c
(65.45 KB)
📄
dsl_pool.c
(42.92 KB)
📄
dsl_prop.c
(32.88 KB)
📄
dsl_scan.c
(134.47 KB)
📄
dsl_synctask.c
(7.94 KB)
📄
dsl_userhold.c
(18.26 KB)
📄
edonr_zfs.c
(3.21 KB)
📄
fm.c
(39.75 KB)
📄
gzip.c
(2.57 KB)
📄
hkdf.c
(4.5 KB)
📄
lz4.c
(26.46 KB)
📄
lzjb.c
(3.85 KB)
📄
metaslab.c
(190.62 KB)
📄
mmp.c
(24.93 KB)
📄
multilist.c
(12.21 KB)
📄
objlist.c
(2.58 KB)
📄
pathname.c
(2.52 KB)
📄
range_tree.c
(24.9 KB)
📄
refcount.c
(7.82 KB)
📄
rrwlock.c
(10.82 KB)
📄
sa.c
(59.23 KB)
📄
sha256.c
(2.89 KB)
📄
skein_zfs.c
(2.92 KB)
📄
spa.c
(272.81 KB)
📄
spa_boot.c
(1.28 KB)
📄
spa_checkpoint.c
(21.54 KB)
📄
spa_config.c
(16.97 KB)
📄
spa_errlog.c
(11.35 KB)
📄
spa_history.c
(17.75 KB)
📄
spa_log_spacemap.c
(47.13 KB)
📄
spa_misc.c
(75.4 KB)
📄
spa_stats.c
(27.08 KB)
📄
space_map.c
(31.45 KB)
📄
space_reftree.c
(4.21 KB)
📄
txg.c
(27.49 KB)
📄
uberblock.c
(2.17 KB)
📄
unique.c
(2.53 KB)
📄
vdev.c
(143.91 KB)
📄
vdev_cache.c
(11.71 KB)
📄
vdev_draid.c
(96.86 KB)
📄
vdev_draid_rand.c
(1.16 KB)
📄
vdev_indirect.c
(60.83 KB)
📄
vdev_indirect_births.c
(5.88 KB)
📄
vdev_indirect_mapping.c
(18.06 KB)
📄
vdev_initialize.c
(22.38 KB)
📄
vdev_label.c
(57.52 KB)
📄
vdev_mirror.c
(26.76 KB)
📄
vdev_missing.c
(3.74 KB)
📄
vdev_queue.c
(37.61 KB)
📄
vdev_raidz.c
(76.09 KB)
📄
vdev_raidz_math.c
(17.18 KB)
📄
vdev_raidz_math_aarch64_neon.c
(112.13 KB)
📄
vdev_raidz_math_aarch64_neon_common.h
(23.64 KB)
📄
vdev_raidz_math_aarch64_neonx2.c
(5.39 KB)
📄
vdev_raidz_math_avx2.c
(10.64 KB)
📄
vdev_raidz_math_avx512bw.c
(10.93 KB)
📄
vdev_raidz_math_avx512f.c
(17.9 KB)
📄
vdev_raidz_math_impl.h
(34.78 KB)
📄
vdev_raidz_math_powerpc_altivec.c
(213.46 KB)
📄
vdev_raidz_math_powerpc_altivec_common.h
(22.62 KB)
📄
vdev_raidz_math_scalar.c
(9.54 KB)
📄
vdev_raidz_math_sse2.c
(25.84 KB)
📄
vdev_raidz_math_ssse3.c
(118 KB)
📄
vdev_rebuild.c
(34.65 KB)
📄
vdev_removal.c
(72.08 KB)
📄
vdev_root.c
(4.28 KB)
📄
vdev_trim.c
(50.92 KB)
📄
zap.c
(35.35 KB)
📄
zap_leaf.c
(22.75 KB)
📄
zap_micro.c
(42.18 KB)
📄
zcp.c
(42.29 KB)
📄
zcp_get.c
(21.01 KB)
📄
zcp_global.c
(1.9 KB)
📄
zcp_iter.c
(18.21 KB)
📄
zcp_set.c
(2.37 KB)
📄
zcp_synctask.c
(13.69 KB)
📄
zfeature.c
(17.6 KB)
📄
zfs_byteswap.c
(5.64 KB)
📄
zfs_fm.c
(40.58 KB)
📄
zfs_fuid.c
(19.69 KB)
📄
zfs_ioctl.c
(195.48 KB)
📄
zfs_log.c
(20.6 KB)
📄
zfs_onexit.c
(5.09 KB)
📄
zfs_quota.c
(12.93 KB)
📄
zfs_ratelimit.c
(2.35 KB)
📄
zfs_replay.c
(26.11 KB)
📄
zfs_rlock.c
(20.38 KB)
📄
zfs_sa.c
(13.09 KB)
📄
zfs_vnops.c
(22 KB)
📄
zil.c
(111.32 KB)
📄
zio.c
(144.72 KB)
📄
zio_checksum.c
(17.28 KB)
📄
zio_compress.c
(5.92 KB)
📄
zio_inject.c
(25.79 KB)
📄
zle.c
(2.52 KB)
📄
zrlock.c
(4.45 KB)
📄
zthr.c
(16.41 KB)
📄
zvol.c
(42.96 KB)
Editing: multilist.c
/* * CDDL HEADER START * * This file and its contents are supplied under the terms of the * Common Development and Distribution License ("CDDL"), version 1.0. * You may only use this file in accordance with the terms of version * 1.0 of the CDDL. * * A full copy of the text of the CDDL should have accompanied this * source. A copy of the CDDL is also available via the Internet at * http://www.illumos.org/license/CDDL. * * CDDL HEADER END */ /* * Copyright (c) 2013, 2017 by Delphix. All rights reserved. */ #include <sys/zfs_context.h> #include <sys/multilist.h> #include <sys/trace_zfs.h> /* needed for spa_get_random() */ #include <sys/spa.h> /* * This overrides the number of sublists in each multilist_t, which defaults * to the number of CPUs in the system (see multilist_create()). */ int zfs_multilist_num_sublists = 0; /* * Given the object contained on the list, return a pointer to the * object's multilist_node_t structure it contains. */ #ifdef ZFS_DEBUG static multilist_node_t * multilist_d2l(multilist_t *ml, void *obj) { return ((multilist_node_t *)((char *)obj + ml->ml_offset)); } #endif /* * Initialize a new mutlilist using the parameters specified. * * - 'size' denotes the size of the structure containing the * multilist_node_t. * - 'offset' denotes the byte offset of the mutlilist_node_t within * the structure that contains it. * - 'num' specifies the number of internal sublists to create. * - 'index_func' is used to determine which sublist to insert into * when the multilist_insert() function is called; as well as which * sublist to remove from when multilist_remove() is called. The * requirements this function must meet, are the following: * * - It must always return the same value when called on the same * object (to ensure the object is removed from the list it was * inserted into). * * - It must return a value in the range [0, number of sublists). * The multilist_get_num_sublists() function may be used to * determine the number of sublists in the multilist. * * Also, in order to reduce internal contention between the sublists * during insertion and removal, this function should choose evenly * between all available sublists when inserting. This isn't a hard * requirement, but a general rule of thumb in order to garner the * best multi-threaded performance out of the data structure. */ static multilist_t * multilist_create_impl(size_t size, size_t offset, unsigned int num, multilist_sublist_index_func_t *index_func) { ASSERT3U(size, >, 0); ASSERT3U(size, >=, offset + sizeof (multilist_node_t)); ASSERT3U(num, >, 0); ASSERT3P(index_func, !=, NULL); multilist_t *ml = kmem_alloc(sizeof (*ml), KM_SLEEP); ml->ml_offset = offset; ml->ml_num_sublists = num; ml->ml_index_func = index_func; ml->ml_sublists = kmem_zalloc(sizeof (multilist_sublist_t) * ml->ml_num_sublists, KM_SLEEP); ASSERT3P(ml->ml_sublists, !=, NULL); for (int i = 0; i < ml->ml_num_sublists; i++) { multilist_sublist_t *mls = &ml->ml_sublists[i]; mutex_init(&mls->mls_lock, NULL, MUTEX_NOLOCKDEP, NULL); list_create(&mls->mls_list, size, offset); } return (ml); } /* * Allocate a new multilist, using the default number of sublists (the number * of CPUs, or at least 4, or the tunable zfs_multilist_num_sublists). Note * that the multilists do not expand if more CPUs are hot-added. In that case, * we will have less fanout than boot_ncpus, but we don't want to always * reserve the RAM necessary to create the extra slots for additional CPUs up * front, and dynamically adding them is a complex task. */ multilist_t * multilist_create(size_t size, size_t offset, multilist_sublist_index_func_t *index_func) { int num_sublists; if (zfs_multilist_num_sublists > 0) { num_sublists = zfs_multilist_num_sublists; } else { num_sublists = MAX(boot_ncpus, 4); } return (multilist_create_impl(size, offset, num_sublists, index_func)); } /* * Destroy the given multilist object, and free up any memory it holds. */ void multilist_destroy(multilist_t *ml) { ASSERT(multilist_is_empty(ml)); for (int i = 0; i < ml->ml_num_sublists; i++) { multilist_sublist_t *mls = &ml->ml_sublists[i]; ASSERT(list_is_empty(&mls->mls_list)); list_destroy(&mls->mls_list); mutex_destroy(&mls->mls_lock); } ASSERT3P(ml->ml_sublists, !=, NULL); kmem_free(ml->ml_sublists, sizeof (multilist_sublist_t) * ml->ml_num_sublists); ml->ml_num_sublists = 0; ml->ml_offset = 0; kmem_free(ml, sizeof (multilist_t)); } /* * Insert the given object into the multilist. * * This function will insert the object specified into the sublist * determined using the function given at multilist creation time. * * The sublist locks are automatically acquired if not already held, to * ensure consistency when inserting and removing from multiple threads. */ void multilist_insert(multilist_t *ml, void *obj) { unsigned int sublist_idx = ml->ml_index_func(ml, obj); multilist_sublist_t *mls; boolean_t need_lock; DTRACE_PROBE3(multilist__insert, multilist_t *, ml, unsigned int, sublist_idx, void *, obj); ASSERT3U(sublist_idx, <, ml->ml_num_sublists); mls = &ml->ml_sublists[sublist_idx]; /* * Note: Callers may already hold the sublist lock by calling * multilist_sublist_lock(). Here we rely on MUTEX_HELD() * returning TRUE if and only if the current thread holds the * lock. While it's a little ugly to make the lock recursive in * this way, it works and allows the calling code to be much * simpler -- otherwise it would have to pass around a flag * indicating that it already has the lock. */ need_lock = !MUTEX_HELD(&mls->mls_lock); if (need_lock) mutex_enter(&mls->mls_lock); ASSERT(!multilist_link_active(multilist_d2l(ml, obj))); multilist_sublist_insert_head(mls, obj); if (need_lock) mutex_exit(&mls->mls_lock); } /* * Remove the given object from the multilist. * * This function will remove the object specified from the sublist * determined using the function given at multilist creation time. * * The necessary sublist locks are automatically acquired, to ensure * consistency when inserting and removing from multiple threads. */ void multilist_remove(multilist_t *ml, void *obj) { unsigned int sublist_idx = ml->ml_index_func(ml, obj); multilist_sublist_t *mls; boolean_t need_lock; DTRACE_PROBE3(multilist__remove, multilist_t *, ml, unsigned int, sublist_idx, void *, obj); ASSERT3U(sublist_idx, <, ml->ml_num_sublists); mls = &ml->ml_sublists[sublist_idx]; /* See comment in multilist_insert(). */ need_lock = !MUTEX_HELD(&mls->mls_lock); if (need_lock) mutex_enter(&mls->mls_lock); ASSERT(multilist_link_active(multilist_d2l(ml, obj))); multilist_sublist_remove(mls, obj); if (need_lock) mutex_exit(&mls->mls_lock); } /* * Check to see if this multilist object is empty. * * This will return TRUE if it finds all of the sublists of this * multilist to be empty, and FALSE otherwise. Each sublist lock will be * automatically acquired as necessary. * * If concurrent insertions and removals are occurring, the semantics * of this function become a little fuzzy. Instead of locking all * sublists for the entire call time of the function, each sublist is * only locked as it is individually checked for emptiness. Thus, it's * possible for this function to return TRUE with non-empty sublists at * the time the function returns. This would be due to another thread * inserting into a given sublist, after that specific sublist was check * and deemed empty, but before all sublists have been checked. */ int multilist_is_empty(multilist_t *ml) { for (int i = 0; i < ml->ml_num_sublists; i++) { multilist_sublist_t *mls = &ml->ml_sublists[i]; /* See comment in multilist_insert(). */ boolean_t need_lock = !MUTEX_HELD(&mls->mls_lock); if (need_lock) mutex_enter(&mls->mls_lock); if (!list_is_empty(&mls->mls_list)) { if (need_lock) mutex_exit(&mls->mls_lock); return (FALSE); } if (need_lock) mutex_exit(&mls->mls_lock); } return (TRUE); } /* Return the number of sublists composing this multilist */ unsigned int multilist_get_num_sublists(multilist_t *ml) { return (ml->ml_num_sublists); } /* Return a randomly selected, valid sublist index for this multilist */ unsigned int multilist_get_random_index(multilist_t *ml) { return (spa_get_random(ml->ml_num_sublists)); } /* Lock and return the sublist specified at the given index */ multilist_sublist_t * multilist_sublist_lock(multilist_t *ml, unsigned int sublist_idx) { multilist_sublist_t *mls; ASSERT3U(sublist_idx, <, ml->ml_num_sublists); mls = &ml->ml_sublists[sublist_idx]; mutex_enter(&mls->mls_lock); return (mls); } /* Lock and return the sublist that would be used to store the specified obj */ multilist_sublist_t * multilist_sublist_lock_obj(multilist_t *ml, void *obj) { return (multilist_sublist_lock(ml, ml->ml_index_func(ml, obj))); } void multilist_sublist_unlock(multilist_sublist_t *mls) { mutex_exit(&mls->mls_lock); } /* * We're allowing any object to be inserted into this specific sublist, * but this can lead to trouble if multilist_remove() is called to * remove this object. Specifically, if calling ml_index_func on this * object returns an index for sublist different than what is passed as * a parameter here, any call to multilist_remove() with this newly * inserted object is undefined! (the call to multilist_remove() will * remove the object from a list that it isn't contained in) */ void multilist_sublist_insert_head(multilist_sublist_t *mls, void *obj) { ASSERT(MUTEX_HELD(&mls->mls_lock)); list_insert_head(&mls->mls_list, obj); } /* please see comment above multilist_sublist_insert_head */ void multilist_sublist_insert_tail(multilist_sublist_t *mls, void *obj) { ASSERT(MUTEX_HELD(&mls->mls_lock)); list_insert_tail(&mls->mls_list, obj); } /* * Move the object one element forward in the list. * * This function will move the given object forward in the list (towards * the head) by one object. So, in essence, it will swap its position in * the list with its "prev" pointer. If the given object is already at the * head of the list, it cannot be moved forward any more than it already * is, so no action is taken. * * NOTE: This function **must not** remove any object from the list other * than the object given as the parameter. This is relied upon in * arc_evict_state_impl(). */ void multilist_sublist_move_forward(multilist_sublist_t *mls, void *obj) { void *prev = list_prev(&mls->mls_list, obj); ASSERT(MUTEX_HELD(&mls->mls_lock)); ASSERT(!list_is_empty(&mls->mls_list)); /* 'obj' must be at the head of the list, nothing to do */ if (prev == NULL) return; list_remove(&mls->mls_list, obj); list_insert_before(&mls->mls_list, prev, obj); } void multilist_sublist_remove(multilist_sublist_t *mls, void *obj) { ASSERT(MUTEX_HELD(&mls->mls_lock)); list_remove(&mls->mls_list, obj); } int multilist_sublist_is_empty(multilist_sublist_t *mls) { ASSERT(MUTEX_HELD(&mls->mls_lock)); return (list_is_empty(&mls->mls_list)); } int multilist_sublist_is_empty_idx(multilist_t *ml, unsigned int sublist_idx) { multilist_sublist_t *mls; int empty; ASSERT3U(sublist_idx, <, ml->ml_num_sublists); mls = &ml->ml_sublists[sublist_idx]; ASSERT(!MUTEX_HELD(&mls->mls_lock)); mutex_enter(&mls->mls_lock); empty = list_is_empty(&mls->mls_list); mutex_exit(&mls->mls_lock); return (empty); } void * multilist_sublist_head(multilist_sublist_t *mls) { ASSERT(MUTEX_HELD(&mls->mls_lock)); return (list_head(&mls->mls_list)); } void * multilist_sublist_tail(multilist_sublist_t *mls) { ASSERT(MUTEX_HELD(&mls->mls_lock)); return (list_tail(&mls->mls_list)); } void * multilist_sublist_next(multilist_sublist_t *mls, void *obj) { ASSERT(MUTEX_HELD(&mls->mls_lock)); return (list_next(&mls->mls_list, obj)); } void * multilist_sublist_prev(multilist_sublist_t *mls, void *obj) { ASSERT(MUTEX_HELD(&mls->mls_lock)); return (list_prev(&mls->mls_list, obj)); } void multilist_link_init(multilist_node_t *link) { list_link_init(link); } int multilist_link_active(multilist_node_t *link) { return (list_link_active(link)); } /* BEGIN CSTYLED */ ZFS_MODULE_PARAM(zfs, zfs_, multilist_num_sublists, INT, ZMOD_RW, "Number of sublists used in each multilist"); /* END CSTYLED */
Upload File
Create Folder