aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosef Bacik <jbacik@fb.com>2016-01-11 17:28:38 -0500
committerDavid Sterba <dsterba@suse.com>2016-02-18 05:21:48 -0500
commitfb4b10e5d56639389fbc46dc8a87e81578af0b64 (patch)
tree8f2d932803d21caafbce03d7c9395b7fb699e051
parent388f7b1d6e8ca06762e2454d28d6c3c55ad0fe95 (diff)
Btrfs: change how we update the global block rsv
I'm writing a tool to visualize the enospc system in order to help debug enospc bugs and I found weird data and ran it down to when we update the global block rsv. We add all of the remaining free space to the block rsv, do a trace event, then remove the extra and do another trace event. This makes my visualization look silly and is unintuitive code as well. Fix this stuff to only add the amount we are missing, or free the amount we are missing. This is less clean to read but more explicit in what it is doing, as well as only emitting events for values that make sense. Thanks, Signed-off-by: Josef Bacik <jbacik@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/extent-tree.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index e2287c7c10be..07f47a5d0d6f 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -5373,27 +5373,33 @@ static void update_global_block_rsv(struct btrfs_fs_info *fs_info)
5373 5373
5374 block_rsv->size = min_t(u64, num_bytes, SZ_512M); 5374 block_rsv->size = min_t(u64, num_bytes, SZ_512M);
5375 5375
5376 num_bytes = sinfo->bytes_used + sinfo->bytes_pinned + 5376 if (block_rsv->reserved < block_rsv->size) {
5377 sinfo->bytes_reserved + sinfo->bytes_readonly + 5377 num_bytes = sinfo->bytes_used + sinfo->bytes_pinned +
5378 sinfo->bytes_may_use; 5378 sinfo->bytes_reserved + sinfo->bytes_readonly +
5379 5379 sinfo->bytes_may_use;
5380 if (sinfo->total_bytes > num_bytes) { 5380 if (sinfo->total_bytes > num_bytes) {
5381 num_bytes = sinfo->total_bytes - num_bytes; 5381 num_bytes = sinfo->total_bytes - num_bytes;
5382 block_rsv->reserved += num_bytes; 5382 num_bytes = min(num_bytes,
5383 sinfo->bytes_may_use += num_bytes; 5383 block_rsv->size - block_rsv->reserved);
5384 trace_btrfs_space_reservation(fs_info, "space_info", 5384 block_rsv->reserved += num_bytes;
5385 sinfo->flags, num_bytes, 1); 5385 sinfo->bytes_may_use += num_bytes;
5386 } 5386 trace_btrfs_space_reservation(fs_info, "space_info",
5387 5387 sinfo->flags, num_bytes,
5388 if (block_rsv->reserved >= block_rsv->size) { 5388 1);
5389 }
5390 } else if (block_rsv->reserved > block_rsv->size) {
5389 num_bytes = block_rsv->reserved - block_rsv->size; 5391 num_bytes = block_rsv->reserved - block_rsv->size;
5390 sinfo->bytes_may_use -= num_bytes; 5392 sinfo->bytes_may_use -= num_bytes;
5391 trace_btrfs_space_reservation(fs_info, "space_info", 5393 trace_btrfs_space_reservation(fs_info, "space_info",
5392 sinfo->flags, num_bytes, 0); 5394 sinfo->flags, num_bytes, 0);
5393 block_rsv->reserved = block_rsv->size; 5395 block_rsv->reserved = block_rsv->size;
5394 block_rsv->full = 1;
5395 } 5396 }
5396 5397
5398 if (block_rsv->reserved == block_rsv->size)
5399 block_rsv->full = 1;
5400 else
5401 block_rsv->full = 0;
5402
5397 spin_unlock(&block_rsv->lock); 5403 spin_unlock(&block_rsv->lock);
5398 spin_unlock(&sinfo->lock); 5404 spin_unlock(&sinfo->lock);
5399} 5405}