btrfs: fix reclaim counter leak of space_info objects
authorFilipe Manana <fdmanana@suse.com>
Tue, 7 Apr 2020 10:38:49 +0000 (11:38 +0100)
committerDavid Sterba <dsterba@suse.com>
Wed, 8 Apr 2020 17:11:19 +0000 (19:11 +0200)
commitd611add48b717ae34f59e0f474bfa7a7d840c4c4
treec0f923bb98b5b7f04e00cba98ea58ad75409902a
parent7af597433d435b56b7c5c8260dad6f979153957b
btrfs: fix reclaim counter leak of space_info objects

Whenever we add a ticket to a space_info object we increment the object's
reclaim_size counter witht the ticket's bytes, and we decrement it with
the corresponding amount only when we are able to grant the requested
space to the ticket. When we are not able to grant the space to a ticket,
or when the ticket is removed due to a signal (e.g. an application has
received sigterm from the terminal) we never decrement the counter with
the corresponding bytes from the ticket. This leak can result in the
space reclaim code to later do much more work than necessary. So fix it
by decrementing the counter when those two cases happen as well.

Fixes: db161806dc5615 ("btrfs: account ticket size at add/delete time")
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-group.c
fs/btrfs/space-info.c