Skip dbuf_evict_one() from dbuf_evict_notify() for reclaim thread

Avoid calling dbuf_evict_one() from memory reclaim contexts (e.g. Linux
kswapd, FreeBSD pagedaemon). This prevents deadlock caused by reclaim
threads waiting for the dbuf hash lock in the call sequence:
dbuf_evict_one -> dbuf_destroy -> arc_buf_destroy

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com>
Signed-off-by: Kaitlin Hoang <kthoang@amazon.com>
Closes #17561
This commit is contained in:
khoang98
2025-08-01 19:47:41 -04:00
committed by Tony Hutter
parent 46bc182a5d
commit 3a8e23d0f8
6 changed files with 46 additions and 1 deletions
+9
View File
@@ -100,6 +100,15 @@ spl_panic(const char *file, const char *func, int line, const char *fmt, ...)
va_end(ap);
}
/*
* Check if the current thread is a memory reclaim thread.
* Returns true if curproc is pageproc (FreeBSD's page daemon).
*/
int
current_is_reclaim_thread(void)
{
return (curproc == pageproc);
}
SYSINIT(opensolaris_utsname_init, SI_SUB_TUNABLES, SI_ORDER_ANY,
opensolaris_utsname_init, NULL);
+12
View File
@@ -27,6 +27,7 @@
#include <sys/kmem.h>
#include <sys/tsd.h>
#include <sys/string.h>
#include <sys/misc.h>
/*
* Thread interfaces
@@ -196,3 +197,14 @@ issig(void)
}
EXPORT_SYMBOL(issig);
/*
* Check if the current thread is a memory reclaim thread.
* Returns true if current thread is kswapd.
*/
int
current_is_reclaim_thread(void)
{
return (current_is_kswapd());
}
EXPORT_SYMBOL(current_is_reclaim_thread);
+9 -1
View File
@@ -841,8 +841,16 @@ dbuf_evict_notify(uint64_t size)
* and grabbing the lock results in massive lock contention.
*/
if (size > dbuf_cache_target_bytes()) {
if (size > dbuf_cache_hiwater_bytes())
/*
* Avoid calling dbuf_evict_one() from memory reclaim context
* (e.g. Linux kswapd, FreeBSD pagedaemon) to prevent deadlocks.
* Memory reclaim threads can get stuck waiting for the dbuf
* hash lock.
*/
if (size > dbuf_cache_hiwater_bytes() &&
!current_is_reclaim_thread()) {
dbuf_evict_one();
}
cv_signal(&dbuf_evict_cv);
}
}