From 198d3cda3228184f6d8b0955b0a07c3dc4aba542 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Thu, 28 Jul 2022 11:28:06 -0700 Subject: [PATCH] Add scoutfs_alloc_meta_low_since() Add scoutfs_alloc_meta_low_since() to test if the metadata avail or freed resources have been used by a given amount since a previous snapshot. Signed-off-by: Zach Brown --- kmod/src/alloc.c | 21 +++++++++++++++++++++ kmod/src/alloc.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/kmod/src/alloc.c b/kmod/src/alloc.c index 76bff395..0284150e 100644 --- a/kmod/src/alloc.c +++ b/kmod/src/alloc.c @@ -1351,6 +1351,27 @@ void scoutfs_alloc_meta_remaining(struct scoutfs_alloc *alloc, u32 *avail_total, } while (read_seqretry(&alloc->seqlock, seq)); } +/* + * Returns true if the caller's consumption of nr from either avail or + * freed would end up exceeding their budget relative to the starting + * remaining snapshot they took. + */ +bool scoutfs_alloc_meta_low_since(struct scoutfs_alloc *alloc, u32 avail_start, u32 freed_start, + u32 budget, u32 nr) +{ + u32 avail_use; + u32 freed_use; + u32 avail; + u32 freed; + + scoutfs_alloc_meta_remaining(alloc, &avail, &freed); + + avail_use = avail_start - avail; + freed_use = freed_start - freed; + + return ((avail_use + nr) > budget) || ((freed_use + nr) > budget); +} + bool scoutfs_alloc_test_flag(struct super_block *sb, struct scoutfs_alloc *alloc, u32 flag) { diff --git a/kmod/src/alloc.h b/kmod/src/alloc.h index b3a7e3c6..5e0d4ff3 100644 --- a/kmod/src/alloc.h +++ b/kmod/src/alloc.h @@ -159,6 +159,8 @@ int scoutfs_alloc_splice_list(struct super_block *sb, bool scoutfs_alloc_meta_low(struct super_block *sb, struct scoutfs_alloc *alloc, u32 nr); void scoutfs_alloc_meta_remaining(struct scoutfs_alloc *alloc, u32 *avail_total, u32 *freed_space); +bool scoutfs_alloc_meta_low_since(struct scoutfs_alloc *alloc, u32 avail_start, u32 freed_start, + u32 budget, u32 nr); bool scoutfs_alloc_test_flag(struct super_block *sb, struct scoutfs_alloc *alloc, u32 flag);