From: Chris Mason <clm@fb.com>
Date: Thu, 22 Oct 2015 02:00:38 +0000 (-0700)
Subject: Merge branch 'allocator-fixes' into for-linus-4.4
X-Git-Tag: MMI-PSA29.97-13-9~8852^2~48
X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a9e6d153563d2ed69c6cd7fb4fa5ce4ca7c712eb;p=GitHub%2FMotorolaMobilityLLC%2Fkernel-slsi.git

Merge branch 'allocator-fixes' into for-linus-4.4

Signed-off-by: Chris Mason <clm@fb.com>
---

a9e6d153563d2ed69c6cd7fb4fa5ce4ca7c712eb
diff --cc fs/btrfs/extent-tree.c
index 46609607789b,475764502d42..92fdbc6b89e7
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@@ -3363,9 -3431,19 +3436,19 @@@ again
  	ret = btrfs_prealloc_file_range_trans(inode, trans, 0, 0, num_pages,
  					      num_pages, num_pages,
  					      &alloc_hint);
+ 	/*
+ 	 * Our cache requires contiguous chunks so that we don't modify a bunch
+ 	 * of metadata or split extents when writing the cache out, which means
+ 	 * we can enospc if we are heavily fragmented in addition to just normal
+ 	 * out of space conditions.  So if we hit this just skip setting up any
+ 	 * other block groups for this transaction, maybe we'll unpin enough
+ 	 * space the next time around.
+ 	 */
  	if (!ret)
  		dcs = BTRFS_DC_SETUP;
+ 	else if (ret == -ENOSPC)
+ 		set_bit(BTRFS_TRANS_CACHE_ENOSPC, &trans->transaction->flags);
 -	btrfs_free_reserved_data_space(inode, num_pages);
 +	btrfs_free_reserved_data_space(inode, 0, num_pages);
  
  out_put:
  	iput(inode);