HAMMER VFS - Attempt to fix a low-memory deadlock
authorMatthew Dillon <dillon@apollo.backplane.com>
Fri, 2 Dec 2011 01:12:12 +0000 (17:12 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Fri, 2 Dec 2011 01:12:12 +0000 (17:12 -0800)
* Avoid trying to allocate a new buffer cache buffer when memory is
  low from inside the blockmap allocation path (where the global
  blockmap lock is held).

Reported-by: tuxillo
sys/vfs/hammer/hammer_blockmap.c

index f97909f..7bb656b 100644 (file)
@@ -601,9 +601,13 @@ again:
         *
         * If we are reserving a whole buffer (or more), the caller will
         * probably use a direct read, so do nothing.
+        *
+        * If we do not have a whole lot of system memory we really can't
+        * afford to block while holding the blkmap_lock!
         */
        if (bytes < HAMMER_BUFSIZE && (next_offset & HAMMER_BUFMASK) == 0) {
-               hammer_bnew(hmp, next_offset, errorp, &buffer3);
+               if (!vm_page_count_min(HAMMER_BUFSIZE / PAGE_SIZE))
+                       hammer_bnew(hmp, next_offset, errorp, &buffer3);
        }
 
        /*