Since commit b02441999efcc6152b87cd58e7970bb7843f76cf, we don't wait all
ordered extents, but I run into some enospc errors when doing large file
create and delete test, it's because shrink_delalloc() does not write
enough delalloc bytes and wait them finished:
    From: Miao Xie <>
    Date: Mon, 4 Nov 2013 23:13:25 +0800
    Subject: [PATCH] Btrfs: don't wait for the completion of all the ordered 

    It is very likely that there are lots of ordered extents in the filesytem,
    if we wait for the completion of all of them when we want to reclaim some
    space for the metadata space reservation, we would be blocked for a long
    time. The performance would drop down suddenly for a long time.

But since Josef introduced "Btrfs: introduce ticketed enospc infrastructure",
shrink_delalloc() starts to be run asynchronously, then If we want to reclaim
metadata space, we can try harder, after all, false enospc error is not

Signed-off-by: Wang Xiaoguang <>
 fs/btrfs/extent-tree.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 46c2a37..f7c420b 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4721,7 +4721,7 @@ static void shrink_delalloc(struct btrfs_root *root, u64 
to_reclaim, u64 orig,
                if (trans)
                if (wait_ordered)
-                       btrfs_wait_ordered_roots(root->fs_info, items,
+                       btrfs_wait_ordered_roots(root->fs_info, -1,
                                                 0, (u64)-1);
@@ -4775,6 +4775,14 @@ skip_async:
                delalloc_bytes = percpu_counter_sum_positive(
+               if (loops == 2) {
+                       /*
+                        * Try to write all current delalloc bytes and wait all
+                        * ordered extents to have a last try.
+                        */
+                       to_reclaim = delalloc_bytes;
+                       items = -1;
+               }

To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to
More majordomo info at

Reply via email to