]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Avoid memory allocations in the ARC eviction thread
authorMark Johnston <markjdb@gmail.com>
Fri, 21 Jan 2022 18:28:13 +0000 (13:28 -0500)
committerMark Johnston <markj@FreeBSD.org>
Mon, 21 Feb 2022 14:59:23 +0000 (09:59 -0500)
commit005452c350f5f2f3e16267557f3365a198336868
treec8f8c51a727821325369ac641824eca6bddcc5f7
parentf8fa2f0e7577c5f1cd4239cf73f5e11dcefe61d0
Avoid memory allocations in the ARC eviction thread

When the eviction thread goes to shrink an ARC state, it allocates a set
of marker buffers used to hold its place in the state's sublists.

This can be problematic in low memory conditions, since
1) the allocation can be substantial, as we allocate NCPU markers;
2) on at least FreeBSD, page reclamation can block in
   arc_wait_for_eviction()

In particular, in stress tests it's possible to hit a deadlock on
FreeBSD when the number of free pages is very low, wherein the system is
waiting for the page daemon to reclaim memory, the page daemon is
waiting for the ARC eviction thread to finish, and the ARC eviction
thread is blocked waiting for more memory.

Try to reduce the likelihood of such deadlocks by pre-allocating markers
for the eviction thread at ARC initialization time.  When evicting
buffers from an ARC state, check to see if the current thread is the ARC
eviction thread, and use the pre-allocated markers for that purpose
rather than dynamically allocating them.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: George Amanakis <gamanakis@gmail.com>
Signed-off-by: Mark Johnston <markj@FreeBSD.org>
Closes #12985
(cherry picked from commit 6e2a59181e286a397d260fa9f140b58688d60c58)
sys/contrib/openzfs/include/sys/zthr.h
sys/contrib/openzfs/module/zfs/arc.c
sys/contrib/openzfs/module/zfs/zthr.c