zfsonlinux/zfs — pull request #669 by gentoofan (2012-04-16 11:23:16+00:00)
Title: Fix deadlock when using zvols as swap

Previously, it was possible for the direct reclaim path to be invoked
when a write to a zvol was made. When a zvol is used as a swap device,
this often causes swap requests to depend on additional swap requests,
which deadlocks. We address this by disabling the direct reclaim path
when writing to zvols.

Ideally, this would only apply when writing to a zvol that is used as
swap. That approach would require correctness checking to verify that we
do not encounter a situation where we are holding locks that would be
needed should a direct reclaim occur, triggering a write to another
zvol. It is also not clear how swap on a zvol would be detected,
especially in the case where the kernel loopback device is involved.

This partially addresses issue #341. This change prevents the system from deadlocking instantaneously when swap becomes necessary. However, I have found it necessary to increase the value of vm.min_free_kbytes on my system from 65536 to 131072 when running a few instances of `python -c "print 2**10**10"` to allocate more memory than the system physically has. Otherwise, no writes to swap will occur and the system will slowly freeze.