瀏覽代碼

Btrfs: try to allocate from cluster even at LOOP_NO_EMPTY_SIZE

If we reach LOOP_NO_EMPTY_SIZE, we won't even try to use a cluster that
others might have set up.  Odds are that there won't be one, but if
someone else succeeded in setting it up, we might as well use it, even
if we don't try to set up a cluster again.

Signed-off-by: Alexandre Oliva <oliva@lsd.ic.unicamp.br>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Alexandre Oliva 13 年之前
父節點
當前提交
062c05c46b
共有 1 個文件被更改,包括 18 次插入8 次删除
  1. 18 8
      fs/btrfs/extent-tree.c

+ 18 - 8
fs/btrfs/extent-tree.c

@@ -5285,15 +5285,10 @@ alloc:
 		spin_unlock(&block_group->free_space_ctl->tree_lock);
 		spin_unlock(&block_group->free_space_ctl->tree_lock);
 
 
 		/*
 		/*
-		 * Ok we want to try and use the cluster allocator, so lets look
-		 * there, unless we are on LOOP_NO_EMPTY_SIZE, since we will
-		 * have tried the cluster allocator plenty of times at this
-		 * point and not have found anything, so we are likely way too
-		 * fragmented for the clustering stuff to find anything, so lets
-		 * just skip it and let the allocator find whatever block it can
-		 * find
+		 * Ok we want to try and use the cluster allocator, so
+		 * lets look there
 		 */
 		 */
-		if (last_ptr && loop < LOOP_NO_EMPTY_SIZE) {
+		if (last_ptr) {
 			/*
 			/*
 			 * the refill lock keeps out other
 			 * the refill lock keeps out other
 			 * people trying to start a new cluster
 			 * people trying to start a new cluster
@@ -5342,6 +5337,20 @@ alloc:
 			}
 			}
 			spin_unlock(&last_ptr->lock);
 			spin_unlock(&last_ptr->lock);
 refill_cluster:
 refill_cluster:
+			/* If we are on LOOP_NO_EMPTY_SIZE, we can't
+			 * set up a new clusters, so lets just skip it
+			 * and let the allocator find whatever block
+			 * it can find.  If we reach this point, we
+			 * will have tried the cluster allocator
+			 * plenty of times and not have found
+			 * anything, so we are likely way too
+			 * fragmented for the clustering stuff to find
+			 * anything.  */
+			if (loop >= LOOP_NO_EMPTY_SIZE) {
+				spin_unlock(&last_ptr->refill_lock);
+				goto unclustered_alloc;
+			}
+
 			/*
 			/*
 			 * this cluster didn't work out, free it and
 			 * this cluster didn't work out, free it and
 			 * start over
 			 * start over
@@ -5389,6 +5398,7 @@ refill_cluster:
 			goto loop;
 			goto loop;
 		}
 		}
 
 
+unclustered_alloc:
 		offset = btrfs_find_space_for_alloc(block_group, search_start,
 		offset = btrfs_find_space_for_alloc(block_group, search_start,
 						    num_bytes, empty_size);
 						    num_bytes, empty_size);
 		/*
 		/*