L2ARC: Relax locking during write

Previous code held ARC state sublist lock throughout all L2ARC
write process, which included number of allocations and even ZIO
issues.  Being blocked in any of those places the code could also
block ARC eviction, that could cause OOM activation or even dead-
lock if system is low on memory or one is too fragmented.

Fix it by dropping the lock as soon as we see a block eligible
for L2ARC writing and pick it up later using earlier inserted
marker.  While there, also reduce scope of hash lock, moving
ZIO allocation and other operations not requiring header access
out of it.  All operations requiring header access move under
hash lock, since L2_WRITING flag does not prevent header eviction
only transition to arc_l2c_only state with L1 header.

To be able to manipulate sublist lock and marker as needed add few
more multilist functions and modify one.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by:	Alexander Motin <mav@FreeBSD.org>
Sponsored by:	iXsystems, Inc.
Closes #16040
This commit is contained in:
Alexander Motin
2024-04-09 19:23:19 -04:00
committed by GitHub
parent 9e63631dea
commit 997f85b4d3
6 changed files with 136 additions and 104 deletions
+24 -2
View File
@@ -277,9 +277,15 @@ multilist_get_random_index(multilist_t *ml)
return (random_in_range(ml->ml_num_sublists));
}
void
multilist_sublist_lock(multilist_sublist_t *mls)
{
mutex_enter(&mls->mls_lock);
}
/* 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_lock_idx(multilist_t *ml, unsigned int sublist_idx)
{
multilist_sublist_t *mls;
@@ -294,7 +300,7 @@ multilist_sublist_lock(multilist_t *ml, unsigned int sublist_idx)
multilist_sublist_t *
multilist_sublist_lock_obj(multilist_t *ml, void *obj)
{
return (multilist_sublist_lock(ml, ml->ml_index_func(ml, obj)));
return (multilist_sublist_lock_idx(ml, ml->ml_index_func(ml, obj)));
}
void
@@ -327,6 +333,22 @@ multilist_sublist_insert_tail(multilist_sublist_t *mls, void *obj)
list_insert_tail(&mls->mls_list, obj);
}
/* please see comment above multilist_sublist_insert_head */
void
multilist_sublist_insert_after(multilist_sublist_t *mls, void *prev, void *obj)
{
ASSERT(MUTEX_HELD(&mls->mls_lock));
list_insert_after(&mls->mls_list, prev, obj);
}
/* please see comment above multilist_sublist_insert_head */
void
multilist_sublist_insert_before(multilist_sublist_t *mls, void *next, void *obj)
{
ASSERT(MUTEX_HELD(&mls->mls_lock));
list_insert_before(&mls->mls_list, next, obj);
}
/*
* Move the object one element forward in the list.
*