Use list_remove_head() where possible.

... 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
This commit is contained in:
Alexander Motin 2023-06-09 13:12:52 -04:00 committed by GitHub
parent 55b1842f92
commit b3ad3f48d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 34 additions and 76 deletions

View File

@ -369,9 +369,7 @@ zfs_agent_consumer_thread(void *arg)
return (NULL); return (NULL);
} }
if ((event = (list_head(&agent_events))) != NULL) { if ((event = list_remove_head(&agent_events)) != NULL) {
list_remove(&agent_events, event);
(void) pthread_mutex_unlock(&agent_lock); (void) pthread_mutex_unlock(&agent_lock);
/* dispatch to all event subscribers */ /* dispatch to all event subscribers */
@ -434,8 +432,7 @@ zfs_agent_fini(void)
(void) pthread_join(g_agents_tid, NULL); (void) pthread_join(g_agents_tid, NULL);
/* drain any pending events */ /* drain any pending events */
while ((event = (list_head(&agent_events))) != NULL) { while ((event = list_remove_head(&agent_events)) != NULL) {
list_remove(&agent_events, event);
nvlist_free(event->ae_nvl); nvlist_free(event->ae_nvl);
free(event); free(event);
} }

View File

@ -1288,17 +1288,14 @@ zfs_slm_fini(void)
tpool_destroy(g_tpool); tpool_destroy(g_tpool);
} }
while ((pool = (list_head(&g_pool_list))) != NULL) { while ((pool = list_remove_head(&g_pool_list)) != NULL) {
list_remove(&g_pool_list, pool);
zpool_close(pool->uap_zhp); zpool_close(pool->uap_zhp);
free(pool); free(pool);
} }
list_destroy(&g_pool_list); list_destroy(&g_pool_list);
while ((device = (list_head(&g_device_list))) != NULL) { while ((device = list_remove_head(&g_device_list)) != NULL)
list_remove(&g_device_list, device);
free(device); free(device);
}
list_destroy(&g_device_list); list_destroy(&g_device_list);
libzfs_fini(g_zfshdl); libzfs_fini(g_zfshdl);

View File

@ -495,10 +495,8 @@ zfs_acl_release_nodes(zfs_acl_t *aclp)
{ {
zfs_acl_node_t *aclnode; zfs_acl_node_t *aclnode;
while ((aclnode = list_head(&aclp->z_acl))) { while ((aclnode = list_remove_head(&aclp->z_acl)))
list_remove(&aclp->z_acl, aclnode);
zfs_acl_node_free(aclnode); zfs_acl_node_free(aclnode);
}
aclp->z_acl_count = 0; aclp->z_acl_count = 0;
aclp->z_acl_bytes = 0; aclp->z_acl_bytes = 0;
} }

View File

@ -493,10 +493,8 @@ zfs_acl_release_nodes(zfs_acl_t *aclp)
{ {
zfs_acl_node_t *aclnode; zfs_acl_node_t *aclnode;
while ((aclnode = list_head(&aclp->z_acl))) { while ((aclnode = list_remove_head(&aclp->z_acl)))
list_remove(&aclp->z_acl, aclnode);
zfs_acl_node_free(aclnode); zfs_acl_node_free(aclnode);
}
aclp->z_acl_count = 0; aclp->z_acl_count = 0;
aclp->z_acl_bytes = 0; aclp->z_acl_bytes = 0;
} }

View File

@ -7866,8 +7866,7 @@ arc_fini(void)
taskq_destroy(arc_prune_taskq); taskq_destroy(arc_prune_taskq);
mutex_enter(&arc_prune_mtx); mutex_enter(&arc_prune_mtx);
while ((p = list_head(&arc_prune_list)) != NULL) { while ((p = list_remove_head(&arc_prune_list)) != NULL) {
list_remove(&arc_prune_list, p);
zfs_refcount_remove(&p->p_refcnt, &arc_prune_list); zfs_refcount_remove(&p->p_refcnt, &arc_prune_list);
zfs_refcount_destroy(&p->p_refcnt); zfs_refcount_destroy(&p->p_refcnt);
kmem_free(p, sizeof (*p)); kmem_free(p, sizeof (*p));
@ -8324,20 +8323,14 @@ out:
static void static void
l2arc_do_free_on_write(void) l2arc_do_free_on_write(void)
{ {
list_t *buflist; l2arc_data_free_t *df;
l2arc_data_free_t *df, *df_prev;
mutex_enter(&l2arc_free_on_write_mtx); mutex_enter(&l2arc_free_on_write_mtx);
buflist = l2arc_free_on_write; while ((df = list_remove_head(l2arc_free_on_write)) != NULL) {
for (df = list_tail(buflist); df; df = df_prev) {
df_prev = list_prev(buflist, df);
ASSERT3P(df->l2df_abd, !=, NULL); ASSERT3P(df->l2df_abd, !=, NULL);
abd_free(df->l2df_abd); abd_free(df->l2df_abd);
list_remove(buflist, df);
kmem_free(df, sizeof (l2arc_data_free_t)); kmem_free(df, sizeof (l2arc_data_free_t));
} }
mutex_exit(&l2arc_free_on_write_mtx); mutex_exit(&l2arc_free_on_write_mtx);
} }

View File

@ -65,9 +65,8 @@ bplist_iterate(bplist_t *bpl, bplist_itor_t *func, void *arg, dmu_tx_t *tx)
bplist_entry_t *bpe; bplist_entry_t *bpe;
mutex_enter(&bpl->bpl_lock); 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; bplist_iterate_last_removed = bpe;
list_remove(&bpl->bpl_list, bpe);
mutex_exit(&bpl->bpl_lock); mutex_exit(&bpl->bpl_lock);
func(arg, &bpe->bpe_blk, tx); func(arg, &bpe->bpe_blk, tx);
kmem_free(bpe, sizeof (*bpe)); kmem_free(bpe, sizeof (*bpe));
@ -82,10 +81,7 @@ bplist_clear(bplist_t *bpl)
bplist_entry_t *bpe; bplist_entry_t *bpe;
mutex_enter(&bpl->bpl_lock); 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);
kmem_free(bpe, sizeof (*bpe)); kmem_free(bpe, sizeof (*bpe));
}
mutex_exit(&bpl->bpl_lock); mutex_exit(&bpl->bpl_lock);
} }

View 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); taskq_wait(dmu_objset_pool(os)->dp_sync_taskq);
list = &DMU_META_DNODE(os)->dn_dirty_records[txgoff]; 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); ASSERT0(dr->dr_dbuf->db_level);
list_remove(list, dr);
zio_nowait(dr->dr_zio); zio_nowait(dr->dr_zio);
} }

View File

@ -1396,8 +1396,7 @@ dmu_tx_do_callbacks(list_t *cb_list, int error)
{ {
dmu_tx_callback_t *dcb; dmu_tx_callback_t *dcb;
while ((dcb = list_tail(cb_list)) != NULL) { while ((dcb = list_remove_tail(cb_list)) != NULL) {
list_remove(cb_list, dcb);
dcb->dcb_func(dcb->dcb_data, error); dcb->dcb_func(dcb->dcb_data, error);
kmem_free(dcb, sizeof (dmu_tx_callback_t)); kmem_free(dcb, sizeof (dmu_tx_callback_t));
} }

View File

@ -3782,8 +3782,7 @@ snaplist_destroy(list_t *l, const void *tag)
if (l == NULL || !list_link_active(&l->list_head)) if (l == NULL || !list_link_active(&l->list_head))
return; return;
while ((snap = list_tail(l)) != NULL) { while ((snap = list_remove_tail(l)) != NULL) {
list_remove(l, snap);
dsl_dataset_rele(snap->ds, tag); dsl_dataset_rele(snap->ds, tag);
kmem_free(snap, sizeof (*snap)); kmem_free(snap, sizeof (*snap));
} }

View File

@ -1490,7 +1490,7 @@ dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx)
if (tr_cookie == NULL) if (tr_cookie == NULL)
return; return;
while ((tr = list_head(tr_list)) != NULL) { while ((tr = list_remove_head(tr_list)) != NULL) {
if (tr->tr_ds) { if (tr->tr_ds) {
mutex_enter(&tr->tr_ds->dd_lock); mutex_enter(&tr->tr_ds->dd_lock);
ASSERT3U(tr->tr_ds->dd_tempreserved[txgidx], >=, ASSERT3U(tr->tr_ds->dd_tempreserved[txgidx], >=,
@ -1500,7 +1500,6 @@ dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx)
} else { } else {
arc_tempreserve_clear(tr->tr_size); arc_tempreserve_clear(tr->tr_size);
} }
list_remove(tr_list, tr);
kmem_free(tr, sizeof (struct tempreserve)); kmem_free(tr, sizeof (struct tempreserve));
} }

View File

@ -3437,10 +3437,8 @@ scan_io_queues_run_one(void *arg)
* If we were suspended in the middle of processing, * If we were suspended in the middle of processing,
* requeue any unfinished sios and exit. * requeue any unfinished sios and exit.
*/ */
while ((sio = list_head(&sio_list)) != NULL) { while ((sio = list_remove_head(&sio_list)) != NULL)
list_remove(&sio_list, sio);
scan_io_queue_insert_impl(queue, sio); scan_io_queue_insert_impl(queue, sio);
}
queue->q_zio = NULL; queue->q_zio = NULL;
mutex_exit(q_lock); mutex_exit(q_lock);

View File

@ -148,8 +148,7 @@ zfs_zevent_drain(zevent_t *ev)
list_remove(&zevent_list, ev); list_remove(&zevent_list, ev);
/* Remove references to this event in all private file data */ /* Remove references to this event in all private file data */
while ((ze = list_head(&ev->ev_ze_list)) != NULL) { while ((ze = list_remove_head(&ev->ev_ze_list)) != NULL) {
list_remove(&ev->ev_ze_list, ze);
ze->ze_zevent = NULL; ze->ze_zevent = NULL;
ze->ze_dropped++; ze->ze_dropped++;
} }

View File

@ -88,14 +88,11 @@ zfs_refcount_destroy_many(zfs_refcount_t *rc, uint64_t number)
reference_t *ref; reference_t *ref;
ASSERT3U(rc->rc_count, ==, number); ASSERT3U(rc->rc_count, ==, number);
while ((ref = list_head(&rc->rc_list))) { while ((ref = list_remove_head(&rc->rc_list)))
list_remove(&rc->rc_list, ref);
kmem_cache_free(reference_cache, ref); kmem_cache_free(reference_cache, ref);
}
list_destroy(&rc->rc_list); list_destroy(&rc->rc_list);
while ((ref = list_head(&rc->rc_removed))) { while ((ref = list_remove_head(&rc->rc_removed))) {
list_remove(&rc->rc_removed, ref);
kmem_cache_free(reference_history_cache, ref->ref_removed); kmem_cache_free(reference_history_cache, ref->ref_removed);
kmem_cache_free(reference_cache, ref); kmem_cache_free(reference_cache, ref);
} }

View File

@ -1609,16 +1609,16 @@ spa_unload_log_sm_metadata(spa_t *spa)
{ {
void *cookie = NULL; void *cookie = NULL;
spa_log_sm_t *sls; spa_log_sm_t *sls;
log_summary_entry_t *e;
while ((sls = avl_destroy_nodes(&spa->spa_sm_logs_by_txg, while ((sls = avl_destroy_nodes(&spa->spa_sm_logs_by_txg,
&cookie)) != NULL) { &cookie)) != NULL) {
VERIFY0(sls->sls_mscount); VERIFY0(sls->sls_mscount);
kmem_free(sls, sizeof (spa_log_sm_t)); kmem_free(sls, sizeof (spa_log_sm_t));
} }
for (log_summary_entry_t *e = list_head(&spa->spa_log_summary); while ((e = list_remove_head(&spa->spa_log_summary)) != NULL) {
e != NULL; e = list_head(&spa->spa_log_summary)) {
VERIFY0(e->lse_mscount); VERIFY0(e->lse_mscount);
list_remove(&spa->spa_log_summary, e);
kmem_free(e, sizeof (log_summary_entry_t)); kmem_free(e, sizeof (log_summary_entry_t));
} }

View File

@ -814,8 +814,7 @@ spa_remove(spa_t *spa)
if (spa->spa_root) if (spa->spa_root)
spa_strfree(spa->spa_root); spa_strfree(spa->spa_root);
while ((dp = list_head(&spa->spa_config_list)) != NULL) { while ((dp = list_remove_head(&spa->spa_config_list)) != NULL) {
list_remove(&spa->spa_config_list, dp);
if (dp->scd_path != NULL) if (dp->scd_path != NULL)
spa_strfree(dp->scd_path); spa_strfree(dp->scd_path);
kmem_free(dp, sizeof (spa_config_dirent_t)); kmem_free(dp, sizeof (spa_config_dirent_t));

View File

@ -293,17 +293,16 @@ vdev_indirect_map_free(zio_t *zio)
indirect_vsd_t *iv = zio->io_vsd; indirect_vsd_t *iv = zio->io_vsd;
indirect_split_t *is; 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++) { for (int c = 0; c < is->is_children; c++) {
indirect_child_t *ic = &is->is_child[c]; indirect_child_t *ic = &is->is_child[c];
if (ic->ic_data != NULL) if (ic->ic_data != NULL)
abd_free(ic->ic_data); abd_free(ic->ic_data);
} }
list_remove(&iv->iv_splits, is);
indirect_child_t *ic; indirect_child_t *ic;
while ((ic = list_head(&is->is_unique_child)) != NULL) while ((ic = list_remove_head(&is->is_unique_child)) != NULL)
list_remove(&is->is_unique_child, ic); ;
list_destroy(&is->is_unique_child); list_destroy(&is->is_unique_child);
@ -1659,8 +1658,8 @@ out:
for (indirect_split_t *is = list_head(&iv->iv_splits); for (indirect_split_t *is = list_head(&iv->iv_splits);
is != NULL; is = list_next(&iv->iv_splits, is)) { is != NULL; is = list_next(&iv->iv_splits, is)) {
indirect_child_t *ic; indirect_child_t *ic;
while ((ic = list_head(&is->is_unique_child)) != NULL) while ((ic = list_remove_head(&is->is_unique_child)) != NULL)
list_remove(&is->is_unique_child, ic); ;
is->is_unique_children = 0; is->is_unique_children = 0;
} }

View File

@ -1522,9 +1522,8 @@ zfs_ereport_fini(void)
{ {
recent_events_node_t *entry; 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); avl_remove(&recent_events_tree, entry);
list_remove(&recent_events_list, entry);
kmem_free(entry, sizeof (*entry)); kmem_free(entry, sizeof (*entry));
} }
avl_destroy(&recent_events_tree); avl_destroy(&recent_events_tree);

View File

@ -699,19 +699,15 @@ zfs_fuid_info_free(zfs_fuid_info_t *fuidp)
zfs_fuid_t *zfuid; zfs_fuid_t *zfuid;
zfs_fuid_domain_t *zdomain; zfs_fuid_domain_t *zdomain;
while ((zfuid = list_head(&fuidp->z_fuids)) != NULL) { while ((zfuid = list_remove_head(&fuidp->z_fuids)) != NULL)
list_remove(&fuidp->z_fuids, zfuid);
kmem_free(zfuid, sizeof (zfs_fuid_t)); kmem_free(zfuid, sizeof (zfs_fuid_t));
}
if (fuidp->z_domain_table != NULL) if (fuidp->z_domain_table != NULL)
kmem_free(fuidp->z_domain_table, kmem_free(fuidp->z_domain_table,
(sizeof (char *)) * fuidp->z_domain_cnt); (sizeof (char *)) * fuidp->z_domain_cnt);
while ((zdomain = list_head(&fuidp->z_domains)) != NULL) { while ((zdomain = list_remove_head(&fuidp->z_domains)) != NULL)
list_remove(&fuidp->z_domains, zdomain);
kmem_free(zdomain, sizeof (zfs_fuid_domain_t)); kmem_free(zdomain, sizeof (zfs_fuid_domain_t));
}
kmem_free(fuidp, sizeof (zfs_fuid_info_t)); kmem_free(fuidp, sizeof (zfs_fuid_info_t));
} }

View File

@ -87,8 +87,7 @@ zfs_onexit_destroy(zfs_onexit_t *zo)
zfs_onexit_action_node_t *ap; zfs_onexit_action_node_t *ap;
mutex_enter(&zo->zo_lock); mutex_enter(&zo->zo_lock);
while ((ap = list_head(&zo->zo_actions)) != NULL) { while ((ap = list_remove_head(&zo->zo_actions)) != NULL) {
list_remove(&zo->zo_actions, ap);
mutex_exit(&zo->zo_lock); mutex_exit(&zo->zo_lock);
ap->za_func(ap->za_data); ap->za_func(ap->za_data);
kmem_free(ap, sizeof (zfs_onexit_action_node_t)); kmem_free(ap, sizeof (zfs_onexit_action_node_t));

View File

@ -1203,8 +1203,7 @@ zvol_create_minors_recursive(const char *name)
* Prefetch is completed, we can do zvol_os_create_minor * Prefetch is completed, we can do zvol_os_create_minor
* sequentially. * sequentially.
*/ */
while ((job = list_head(&minors_list)) != NULL) { while ((job = list_remove_head(&minors_list)) != NULL) {
list_remove(&minors_list, job);
if (!job->error) if (!job->error)
(void) zvol_os_create_minor(job->name); (void) zvol_os_create_minor(job->name);
kmem_strfree(job->name); kmem_strfree(job->name);
@ -1311,11 +1310,9 @@ zvol_remove_minors_impl(const char *name)
rw_exit(&zvol_state_lock); rw_exit(&zvol_state_lock);
/* Drop zvol_state_lock before calling zvol_free() */ /* Drop zvol_state_lock before calling zvol_free() */
while ((zv = list_head(&free_list)) != NULL) { while ((zv = list_remove_head(&free_list)) != NULL)
list_remove(&free_list, zv);
zvol_os_free(zv); zvol_os_free(zv);
} }
}
/* Remove minor for this specific volume only */ /* Remove minor for this specific volume only */
static void static void