Skip to content

Commit e23aaf4

Browse files
osandovDarrick J. Wong
authored andcommitted
xfs: invert the realtime summary cache
In commit 355e353 ("xfs: cache minimum realtime summary level"), I added a cache of the minimum level of the realtime summary that has any free extents. However, it turns out that the _maximum_ level is more useful for upcoming optimizations, and basically equivalent for the existing usage. So, let's change the meaning of the cache to be the maximum level + 1, or 0 if there are no free extents. For example, if the cache contains: {0, 4} then there are no free extents starting in realtime bitmap block 0, and there are no free extents larger than or equal to 2^4 blocks starting in realtime bitmap block 1. The cache is a loose upper bound, so there may or may not be free extents smaller than 2^4 blocks in realtime bitmap block 1. Signed-off-by: Omar Sandoval <osandov@fb.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent e2cf427 commit e23aaf4

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

fs/xfs/libxfs/xfs_rtbitmap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,10 @@ xfs_rtmodify_summary_int(
495495
xfs_suminfo_t val = xfs_suminfo_add(args, infoword, delta);
496496

497497
if (mp->m_rsum_cache) {
498-
if (val == 0 && log == mp->m_rsum_cache[bbno])
499-
mp->m_rsum_cache[bbno]++;
500-
if (val != 0 && log < mp->m_rsum_cache[bbno])
498+
if (val == 0 && log + 1 == mp->m_rsum_cache[bbno])
501499
mp->m_rsum_cache[bbno] = log;
500+
if (val != 0 && log >= mp->m_rsum_cache[bbno])
501+
mp->m_rsum_cache[bbno] = log + 1;
502502
}
503503
xfs_trans_log_rtsummary(args, infoword);
504504
if (sum)

fs/xfs/xfs_mount.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ typedef struct xfs_mount {
101101

102102
/*
103103
* Optional cache of rt summary level per bitmap block with the
104-
* invariant that m_rsum_cache[bbno] <= the minimum i for which
105-
* rsum[i][bbno] != 0. Reads and writes are serialized by the rsumip
106-
* inode lock.
104+
* invariant that m_rsum_cache[bbno] > the maximum i for which
105+
* rsum[i][bbno] != 0, or 0 if rsum[i][bbno] == 0 for all i.
106+
* Reads and writes are serialized by the rsumip inode lock.
107107
*/
108108
uint8_t *m_rsum_cache;
109109
struct xfs_mru_cache *m_filestream; /* per-mount filestream data */

fs/xfs/xfs_rtalloc.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,19 @@ xfs_rtany_summary(
5454
int log; /* loop counter, log2 of ext. size */
5555
xfs_suminfo_t sum; /* summary data */
5656

57-
/* There are no extents at levels < m_rsum_cache[bbno]. */
58-
if (mp->m_rsum_cache && low < mp->m_rsum_cache[bbno])
59-
low = mp->m_rsum_cache[bbno];
57+
/* There are no extents at levels >= m_rsum_cache[bbno]. */
58+
if (mp->m_rsum_cache) {
59+
high = min(high, mp->m_rsum_cache[bbno] - 1);
60+
if (low > high) {
61+
*stat = 0;
62+
return 0;
63+
}
64+
}
6065

6166
/*
6267
* Loop over logs of extent sizes.
6368
*/
64-
for (log = low; log <= high; log++) {
69+
for (log = high; log >= low; log--) {
6570
/*
6671
* Get one summary datum.
6772
*/
@@ -82,9 +87,9 @@ xfs_rtany_summary(
8287
*/
8388
*stat = 0;
8489
out:
85-
/* There were no extents at levels < log. */
86-
if (mp->m_rsum_cache && log > mp->m_rsum_cache[bbno])
87-
mp->m_rsum_cache[bbno] = log;
90+
/* There were no extents at levels > log. */
91+
if (mp->m_rsum_cache && log + 1 < mp->m_rsum_cache[bbno])
92+
mp->m_rsum_cache[bbno] = log + 1;
8893
return 0;
8994
}
9095

@@ -887,12 +892,14 @@ xfs_alloc_rsum_cache(
887892
xfs_extlen_t rbmblocks) /* number of rt bitmap blocks */
888893
{
889894
/*
890-
* The rsum cache is initialized to all zeroes, which is trivially a
891-
* lower bound on the minimum level with any free extents. We can
892-
* continue without the cache if it couldn't be allocated.
895+
* The rsum cache is initialized to the maximum value, which is
896+
* trivially an upper bound on the maximum level with any free extents.
897+
* We can continue without the cache if it couldn't be allocated.
893898
*/
894-
mp->m_rsum_cache = kvzalloc(rbmblocks, GFP_KERNEL);
895-
if (!mp->m_rsum_cache)
899+
mp->m_rsum_cache = kvmalloc(rbmblocks, GFP_KERNEL);
900+
if (mp->m_rsum_cache)
901+
memset(mp->m_rsum_cache, -1, rbmblocks);
902+
else
896903
xfs_warn(mp, "could not allocate realtime summary cache");
897904
}
898905

0 commit comments

Comments
 (0)