btrfs: increase the metadata allowance for the free_space_cache
Currently, there is no way for the free space cache to recover from being serviced by purely bitmaps because the extent threshold is set to 0 in recalculate_thresholds() when we surpass the metadata allowance. This adds a recovery mechanism by keeping large extents out of the bitmaps and increases the metadata upper bound to 64KB. The recovery mechanism bypasses this upper bound, thus making it a soft upper bound. But, with the bypass being 1MB or greater, it shouldn't add unbounded overhead. Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Dennis Zhou <dennis@kernel.org> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
committed by
David Sterba
parent
dbc2a8c927
commit
5d90c5c757
@@ -24,7 +24,8 @@
|
|||||||
#include "discard.h"
|
#include "discard.h"
|
||||||
|
|
||||||
#define BITS_PER_BITMAP (PAGE_SIZE * 8UL)
|
#define BITS_PER_BITMAP (PAGE_SIZE * 8UL)
|
||||||
#define MAX_CACHE_BYTES_PER_GIG SZ_32K
|
#define MAX_CACHE_BYTES_PER_GIG SZ_64K
|
||||||
|
#define FORCE_EXTENT_THRESHOLD SZ_1M
|
||||||
|
|
||||||
struct btrfs_trim_range {
|
struct btrfs_trim_range {
|
||||||
u64 start;
|
u64 start;
|
||||||
@@ -1694,26 +1695,17 @@ static void recalculate_thresholds(struct btrfs_free_space_ctl *ctl)
|
|||||||
ASSERT(ctl->total_bitmaps <= max_bitmaps);
|
ASSERT(ctl->total_bitmaps <= max_bitmaps);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The goal is to keep the total amount of memory used per 1gb of space
|
* We are trying to keep the total amount of memory used per 1GiB of
|
||||||
* at or below 32k, so we need to adjust how much memory we allow to be
|
* space to be MAX_CACHE_BYTES_PER_GIG. However, with a reclamation
|
||||||
* used by extent based free space tracking
|
* mechanism of pulling extents >= FORCE_EXTENT_THRESHOLD out of
|
||||||
|
* bitmaps, we may end up using more memory than this.
|
||||||
*/
|
*/
|
||||||
if (size < SZ_1G)
|
if (size < SZ_1G)
|
||||||
max_bytes = MAX_CACHE_BYTES_PER_GIG;
|
max_bytes = MAX_CACHE_BYTES_PER_GIG;
|
||||||
else
|
else
|
||||||
max_bytes = MAX_CACHE_BYTES_PER_GIG * div_u64(size, SZ_1G);
|
max_bytes = MAX_CACHE_BYTES_PER_GIG * div_u64(size, SZ_1G);
|
||||||
|
|
||||||
/*
|
bitmap_bytes = ctl->total_bitmaps * ctl->unit;
|
||||||
* we want to account for 1 more bitmap than what we have so we can make
|
|
||||||
* sure we don't go over our overall goal of MAX_CACHE_BYTES_PER_GIG as
|
|
||||||
* we add more bitmaps.
|
|
||||||
*/
|
|
||||||
bitmap_bytes = (ctl->total_bitmaps + 1) * ctl->unit;
|
|
||||||
|
|
||||||
if (bitmap_bytes >= max_bytes) {
|
|
||||||
ctl->extents_thresh = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* we want the extent entry threshold to always be at most 1/2 the max
|
* we want the extent entry threshold to always be at most 1/2 the max
|
||||||
@@ -2099,6 +2091,10 @@ static bool use_bitmap(struct btrfs_free_space_ctl *ctl,
|
|||||||
forced = true;
|
forced = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* This is a way to reclaim large regions from the bitmaps. */
|
||||||
|
if (!forced && info->bytes >= FORCE_EXTENT_THRESHOLD)
|
||||||
|
return false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we are below the extents threshold then we can add this as an
|
* If we are below the extents threshold then we can add this as an
|
||||||
* extent, and don't have to deal with the bitmap
|
* extent, and don't have to deal with the bitmap
|
||||||
|
|||||||
Reference in New Issue
Block a user