]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Use list_remove_head() where possible.
authorAlexander Motin <mav@FreeBSD.org>
Fri, 9 Jun 2023 17:12:52 +0000 (13:12 -0400)
committerGitHub <noreply@github.com>
Fri, 9 Jun 2023 17:12:52 +0000 (10:12 -0700)
... instead of list_head() + list_remove().  On FreeBSD the list
functions are not inlined, so in addition to more compact code
this also saves another function call.

Reviewed-by: Brian Atkinson <batkinson@lanl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Alexander Motin <mav@FreeBSD.org>
Sponsored by: iXsystems, Inc.
Closes #14955

20 files changed:
cmd/zed/agents/zfs_agents.c
cmd/zed/agents/zfs_mod.c
module/os/freebsd/zfs/zfs_acl.c
module/os/linux/zfs/zfs_acl.c
module/zfs/arc.c
module/zfs/bplist.c
module/zfs/dmu_objset.c
module/zfs/dmu_tx.c
module/zfs/dsl_dataset.c
module/zfs/dsl_dir.c
module/zfs/dsl_scan.c
module/zfs/fm.c
module/zfs/refcount.c
module/zfs/spa.c
module/zfs/spa_misc.c
module/zfs/vdev_indirect.c
module/zfs/zfs_fm.c
module/zfs/zfs_fuid.c
module/zfs/zfs_onexit.c
module/zfs/zvol.c

index a2daa77a61fe2a6d569a8d65cf22500e04aa6f34..8fabb8d081a545fb65f2a47725a669d9d8d49e56 100644 (file)
@@ -369,9 +369,7 @@ zfs_agent_consumer_thread(void *arg)
                        return (NULL);
                }
 
-               if ((event = (list_head(&agent_events))) != NULL) {
-                       list_remove(&agent_events, event);
-
+               if ((event = list_remove_head(&agent_events)) != NULL) {
                        (void) pthread_mutex_unlock(&agent_lock);
 
                        /* dispatch to all event subscribers */
@@ -434,8 +432,7 @@ zfs_agent_fini(void)
        (void) pthread_join(g_agents_tid, NULL);
 
        /* drain any pending events */
-       while ((event = (list_head(&agent_events))) != NULL) {
-               list_remove(&agent_events, event);
+       while ((event = list_remove_head(&agent_events)) != NULL) {
                nvlist_free(event->ae_nvl);
                free(event);
        }
index 1c82bd4f0010698e1a9c6998e7c6f7bfca104f70..b07a02712295bb2f0a708eddadba5921cc6719f8 100644 (file)
@@ -1288,17 +1288,14 @@ zfs_slm_fini(void)
                tpool_destroy(g_tpool);
        }
 
-       while ((pool = (list_head(&g_pool_list))) != NULL) {
-               list_remove(&g_pool_list, pool);
+       while ((pool = list_remove_head(&g_pool_list)) != NULL) {
                zpool_close(pool->uap_zhp);
                free(pool);
        }
        list_destroy(&g_pool_list);
 
-       while ((device = (list_head(&g_device_list))) != NULL) {
-               list_remove(&g_device_list, device);
+       while ((device = list_remove_head(&g_device_list)) != NULL)
                free(device);
-       }
        list_destroy(&g_device_list);
 
        libzfs_fini(g_zfshdl);
index a077076927a1bcb146b0bf8c655752145afcbcb0..20466aeaaa05b82229f69e96b23348f018ec9204 100644 (file)
@@ -495,10 +495,8 @@ zfs_acl_release_nodes(zfs_acl_t *aclp)
 {
        zfs_acl_node_t *aclnode;
 
-       while ((aclnode = list_head(&aclp->z_acl))) {
-               list_remove(&aclp->z_acl, aclnode);
+       while ((aclnode = list_remove_head(&aclp->z_acl)))
                zfs_acl_node_free(aclnode);
-       }
        aclp->z_acl_count = 0;
        aclp->z_acl_bytes = 0;
 }
index ff26f47f2e043e4c52c67e7986d947e147eedd92..a1fd3c9856cca1f8d96855991a7211aa8213145b 100644 (file)
@@ -493,10 +493,8 @@ zfs_acl_release_nodes(zfs_acl_t *aclp)
 {
        zfs_acl_node_t *aclnode;
 
-       while ((aclnode = list_head(&aclp->z_acl))) {
-               list_remove(&aclp->z_acl, aclnode);
+       while ((aclnode = list_remove_head(&aclp->z_acl)))
                zfs_acl_node_free(aclnode);
-       }
        aclp->z_acl_count = 0;
        aclp->z_acl_bytes = 0;
 }
index 6f68c29fc7f5fc5faf48162215da6f33568e2acf..dcd4620fcd2010ddf870447d914bceb7922686ea 100644 (file)
@@ -7866,8 +7866,7 @@ arc_fini(void)
        taskq_destroy(arc_prune_taskq);
 
        mutex_enter(&arc_prune_mtx);
-       while ((p = list_head(&arc_prune_list)) != NULL) {
-               list_remove(&arc_prune_list, p);
+       while ((p = list_remove_head(&arc_prune_list)) != NULL) {
                zfs_refcount_remove(&p->p_refcnt, &arc_prune_list);
                zfs_refcount_destroy(&p->p_refcnt);
                kmem_free(p, sizeof (*p));
@@ -8324,20 +8323,14 @@ out:
 static void
 l2arc_do_free_on_write(void)
 {
-       list_t *buflist;
-       l2arc_data_free_t *df, *df_prev;
+       l2arc_data_free_t *df;
 
        mutex_enter(&l2arc_free_on_write_mtx);
-       buflist = l2arc_free_on_write;
-
-       for (df = list_tail(buflist); df; df = df_prev) {
-               df_prev = list_prev(buflist, df);
+       while ((df = list_remove_head(l2arc_free_on_write)) != NULL) {
                ASSERT3P(df->l2df_abd, !=, NULL);
                abd_free(df->l2df_abd);
-               list_remove(buflist, df);
                kmem_free(df, sizeof (l2arc_data_free_t));
        }
-
        mutex_exit(&l2arc_free_on_write_mtx);
 }
 
index 1c1f7892bb7df93c493950d2f827977287f40401..da7360f8ce109b0ca03e63b1261953f910bb7eb4 100644 (file)
@@ -65,9 +65,8 @@ bplist_iterate(bplist_t *bpl, bplist_itor_t *func, void *arg, dmu_tx_t *tx)
        bplist_entry_t *bpe;
 
        mutex_enter(&bpl->bpl_lock);
-       while ((bpe = list_head(&bpl->bpl_list))) {
+       while ((bpe = list_remove_head(&bpl->bpl_list))) {
                bplist_iterate_last_removed = bpe;
-               list_remove(&bpl->bpl_list, bpe);
                mutex_exit(&bpl->bpl_lock);
                func(arg, &bpe->bpe_blk, tx);
                kmem_free(bpe, sizeof (*bpe));
@@ -82,10 +81,7 @@ bplist_clear(bplist_t *bpl)
        bplist_entry_t *bpe;
 
        mutex_enter(&bpl->bpl_lock);
-       while ((bpe = list_head(&bpl->bpl_list))) {
-               bplist_iterate_last_removed = bpe;
-               list_remove(&bpl->bpl_list, bpe);
+       while ((bpe = list_remove_head(&bpl->bpl_list)))
                kmem_free(bpe, sizeof (*bpe));
-       }
        mutex_exit(&bpl->bpl_lock);
 }
index c19ebf424953ee7e236b1223e88b99a74de27a20..778b18817eeff6889ebc89f1b52190e86d44dd9f 100644 (file)
@@ -1755,9 +1755,8 @@ dmu_objset_sync(objset_t *os, zio_t *pio, dmu_tx_t *tx)
        taskq_wait(dmu_objset_pool(os)->dp_sync_taskq);
 
        list = &DMU_META_DNODE(os)->dn_dirty_records[txgoff];
-       while ((dr = list_head(list)) != NULL) {
+       while ((dr = list_remove_head(list)) != NULL) {
                ASSERT0(dr->dr_dbuf->db_level);
-               list_remove(list, dr);
                zio_nowait(dr->dr_zio);
        }
 
index c4e274bd4c428de2ed663c7902cf5b032b7adb44..0eb8c17e331ab35c92230c96d37ea6f8e0a4df71 100644 (file)
@@ -1396,8 +1396,7 @@ dmu_tx_do_callbacks(list_t *cb_list, int error)
 {
        dmu_tx_callback_t *dcb;
 
-       while ((dcb = list_tail(cb_list)) != NULL) {
-               list_remove(cb_list, dcb);
+       while ((dcb = list_remove_tail(cb_list)) != NULL) {
                dcb->dcb_func(dcb->dcb_data, error);
                kmem_free(dcb, sizeof (dmu_tx_callback_t));
        }
index 14e7ced4007c842dc6b4dd02516d0875f4c104ca..d6db617292234ef77d18ad37b6b6dc4cb9745a13 100644 (file)
@@ -3782,8 +3782,7 @@ snaplist_destroy(list_t *l, const void *tag)
        if (l == NULL || !list_link_active(&l->list_head))
                return;
 
-       while ((snap = list_tail(l)) != NULL) {
-               list_remove(l, snap);
+       while ((snap = list_remove_tail(l)) != NULL) {
                dsl_dataset_rele(snap->ds, tag);
                kmem_free(snap, sizeof (*snap));
        }
index eac9828a204aca50a54fe756bdc7a7d265436ab4..bbe6a03d620f60f511743df035a4922ec59a2a65 100644 (file)
@@ -1490,7 +1490,7 @@ dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx)
        if (tr_cookie == NULL)
                return;
 
-       while ((tr = list_head(tr_list)) != NULL) {
+       while ((tr = list_remove_head(tr_list)) != NULL) {
                if (tr->tr_ds) {
                        mutex_enter(&tr->tr_ds->dd_lock);
                        ASSERT3U(tr->tr_ds->dd_tempreserved[txgidx], >=,
@@ -1500,7 +1500,6 @@ dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx)
                } else {
                        arc_tempreserve_clear(tr->tr_size);
                }
-               list_remove(tr_list, tr);
                kmem_free(tr, sizeof (struct tempreserve));
        }
 
index 9ee719a5eef66d40bcd888da1dfa7b04ae3156df..1dd44171c10e581147c70073ed6491221f9e6bd5 100644 (file)
@@ -3437,10 +3437,8 @@ scan_io_queues_run_one(void *arg)
         * If we were suspended in the middle of processing,
         * requeue any unfinished sios and exit.
         */
-       while ((sio = list_head(&sio_list)) != NULL) {
-               list_remove(&sio_list, sio);
+       while ((sio = list_remove_head(&sio_list)) != NULL)
                scan_io_queue_insert_impl(queue, sio);
-       }
 
        queue->q_zio = NULL;
        mutex_exit(q_lock);
index 76956572f8bd6a279b2481f163e5192d22f1a1f6..77d87b694a43cf4113b7076b7f759f94173d6b07 100644 (file)
@@ -148,8 +148,7 @@ zfs_zevent_drain(zevent_t *ev)
        list_remove(&zevent_list, ev);
 
        /* Remove references to this event in all private file data */
-       while ((ze = list_head(&ev->ev_ze_list)) != NULL) {
-               list_remove(&ev->ev_ze_list, ze);
+       while ((ze = list_remove_head(&ev->ev_ze_list)) != NULL) {
                ze->ze_zevent = NULL;
                ze->ze_dropped++;
        }
index c9a504f67451da5d376ea85f930a9c9fa4349ca6..601d27f8c47a5663316d2265289444d963c6e7e5 100644 (file)
@@ -88,14 +88,11 @@ zfs_refcount_destroy_many(zfs_refcount_t *rc, uint64_t number)
        reference_t *ref;
 
        ASSERT3U(rc->rc_count, ==, number);
-       while ((ref = list_head(&rc->rc_list))) {
-               list_remove(&rc->rc_list, ref);
+       while ((ref = list_remove_head(&rc->rc_list)))
                kmem_cache_free(reference_cache, ref);
-       }
        list_destroy(&rc->rc_list);
 
-       while ((ref = list_head(&rc->rc_removed))) {
-               list_remove(&rc->rc_removed, ref);
+       while ((ref = list_remove_head(&rc->rc_removed))) {
                kmem_cache_free(reference_history_cache, ref->ref_removed);
                kmem_cache_free(reference_cache, ref);
        }
index 27bbb8f09259d6e1336da521993470b6b55a5633..88ee4ea9f458842b108fd9c176402257df193891 100644 (file)
@@ -1609,16 +1609,16 @@ spa_unload_log_sm_metadata(spa_t *spa)
 {
        void *cookie = NULL;
        spa_log_sm_t *sls;
+       log_summary_entry_t *e;
+
        while ((sls = avl_destroy_nodes(&spa->spa_sm_logs_by_txg,
            &cookie)) != NULL) {
                VERIFY0(sls->sls_mscount);
                kmem_free(sls, sizeof (spa_log_sm_t));
        }
 
-       for (log_summary_entry_t *e = list_head(&spa->spa_log_summary);
-           e != NULL; e = list_head(&spa->spa_log_summary)) {
+       while ((e = list_remove_head(&spa->spa_log_summary)) != NULL) {
                VERIFY0(e->lse_mscount);
-               list_remove(&spa->spa_log_summary, e);
                kmem_free(e, sizeof (log_summary_entry_t));
        }
 
index 89e1ce7165db72c1a5c1c32a32c35755a707cedf..014c539eb683d62c0c062ccc1e0895aca1035610 100644 (file)
@@ -814,8 +814,7 @@ spa_remove(spa_t *spa)
        if (spa->spa_root)
                spa_strfree(spa->spa_root);
 
-       while ((dp = list_head(&spa->spa_config_list)) != NULL) {
-               list_remove(&spa->spa_config_list, dp);
+       while ((dp = list_remove_head(&spa->spa_config_list)) != NULL) {
                if (dp->scd_path != NULL)
                        spa_strfree(dp->scd_path);
                kmem_free(dp, sizeof (spa_config_dirent_t));
index a16ad2f4e7cf89d23b150df3f9ecd95f29a5e039..89667585345dbd1107ff588b7b3124a965d85e6c 100644 (file)
@@ -293,17 +293,16 @@ vdev_indirect_map_free(zio_t *zio)
        indirect_vsd_t *iv = zio->io_vsd;
 
        indirect_split_t *is;
-       while ((is = list_head(&iv->iv_splits)) != NULL) {
+       while ((is = list_remove_head(&iv->iv_splits)) != NULL) {
                for (int c = 0; c < is->is_children; c++) {
                        indirect_child_t *ic = &is->is_child[c];
                        if (ic->ic_data != NULL)
                                abd_free(ic->ic_data);
                }
-               list_remove(&iv->iv_splits, is);
 
                indirect_child_t *ic;
-               while ((ic = list_head(&is->is_unique_child)) != NULL)
-                       list_remove(&is->is_unique_child, ic);
+               while ((ic = list_remove_head(&is->is_unique_child)) != NULL)
+                       ;
 
                list_destroy(&is->is_unique_child);
 
@@ -1659,8 +1658,8 @@ out:
        for (indirect_split_t *is = list_head(&iv->iv_splits);
            is != NULL; is = list_next(&iv->iv_splits, is)) {
                indirect_child_t *ic;
-               while ((ic = list_head(&is->is_unique_child)) != NULL)
-                       list_remove(&is->is_unique_child, ic);
+               while ((ic = list_remove_head(&is->is_unique_child)) != NULL)
+                       ;
 
                is->is_unique_children = 0;
        }
index bdd0e96c327a904fc1a26c11ec6b9c00200769f2..c42ef048dd742fbc2b29fb2b6e8cd4c832dc03d6 100644 (file)
@@ -1522,9 +1522,8 @@ zfs_ereport_fini(void)
 {
        recent_events_node_t *entry;
 
-       while ((entry = list_head(&recent_events_list)) != NULL) {
+       while ((entry = list_remove_head(&recent_events_list)) != NULL) {
                avl_remove(&recent_events_tree, entry);
-               list_remove(&recent_events_list, entry);
                kmem_free(entry, sizeof (*entry));
        }
        avl_destroy(&recent_events_tree);
index 44aaae9c12644aa60e6053f718df9700696c211e..add4241dcc99344e6e9151915c56bdda55b507fc 100644 (file)
@@ -699,19 +699,15 @@ zfs_fuid_info_free(zfs_fuid_info_t *fuidp)
        zfs_fuid_t *zfuid;
        zfs_fuid_domain_t *zdomain;
 
-       while ((zfuid = list_head(&fuidp->z_fuids)) != NULL) {
-               list_remove(&fuidp->z_fuids, zfuid);
+       while ((zfuid = list_remove_head(&fuidp->z_fuids)) != NULL)
                kmem_free(zfuid, sizeof (zfs_fuid_t));
-       }
 
        if (fuidp->z_domain_table != NULL)
                kmem_free(fuidp->z_domain_table,
                    (sizeof (char *)) * fuidp->z_domain_cnt);
 
-       while ((zdomain = list_head(&fuidp->z_domains)) != NULL) {
-               list_remove(&fuidp->z_domains, zdomain);
+       while ((zdomain = list_remove_head(&fuidp->z_domains)) != NULL)
                kmem_free(zdomain, sizeof (zfs_fuid_domain_t));
-       }
 
        kmem_free(fuidp, sizeof (zfs_fuid_info_t));
 }
index 63acf7ab2e4d28b9094f81b6e9666e3093c2b6ea..7bf804b6779018a41cf944b622624bb237db5c6e 100644 (file)
@@ -87,8 +87,7 @@ zfs_onexit_destroy(zfs_onexit_t *zo)
        zfs_onexit_action_node_t *ap;
 
        mutex_enter(&zo->zo_lock);
-       while ((ap = list_head(&zo->zo_actions)) != NULL) {
-               list_remove(&zo->zo_actions, ap);
+       while ((ap = list_remove_head(&zo->zo_actions)) != NULL) {
                mutex_exit(&zo->zo_lock);
                ap->za_func(ap->za_data);
                kmem_free(ap, sizeof (zfs_onexit_action_node_t));
index 06bc75c634a68bbdc58d26047ce771ce807fb41d..cd4e6f0c75589a91e299270a2f9780450e0c189d 100644 (file)
@@ -1203,8 +1203,7 @@ zvol_create_minors_recursive(const char *name)
         * Prefetch is completed, we can do zvol_os_create_minor
         * sequentially.
         */
-       while ((job = list_head(&minors_list)) != NULL) {
-               list_remove(&minors_list, job);
+       while ((job = list_remove_head(&minors_list)) != NULL) {
                if (!job->error)
                        (void) zvol_os_create_minor(job->name);
                kmem_strfree(job->name);
@@ -1311,10 +1310,8 @@ zvol_remove_minors_impl(const char *name)
        rw_exit(&zvol_state_lock);
 
        /* Drop zvol_state_lock before calling zvol_free() */
-       while ((zv = list_head(&free_list)) != NULL) {
-               list_remove(&free_list, zv);
+       while ((zv = list_remove_head(&free_list)) != NULL)
                zvol_os_free(zv);
-       }
 }
 
 /* Remove minor for this specific volume only */