Skip to content

Commit 9fa47bd

Browse files
author
Darrick J. Wong
committed
xfs: use separate btree cursor cache for each btree type
Now that we have the infrastructure to track the max possible height of each btree type, we can create a separate slab cache for cursors of each type of btree. For smaller indices like the free space btrees, this means that we can pack more cursors into a slab page, improving slab utilization. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Dave Chinner <[email protected]>
1 parent 0ed5f73 commit 9fa47bd

13 files changed

+185
-29
lines changed

fs/xfs/libxfs/xfs_alloc_btree.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "xfs_trans.h"
2121
#include "xfs_ag.h"
2222

23+
static kmem_zone_t *xfs_allocbt_cur_cache;
2324

2425
STATIC struct xfs_btree_cur *
2526
xfs_allocbt_dup_cursor(
@@ -477,7 +478,8 @@ xfs_allocbt_init_common(
477478

478479
ASSERT(btnum == XFS_BTNUM_BNO || btnum == XFS_BTNUM_CNT);
479480

480-
cur = xfs_btree_alloc_cursor(mp, tp, btnum, mp->m_alloc_maxlevels);
481+
cur = xfs_btree_alloc_cursor(mp, tp, btnum, mp->m_alloc_maxlevels,
482+
xfs_allocbt_cur_cache);
481483
cur->bc_ag.abt.active = false;
482484

483485
if (btnum == XFS_BTNUM_CNT) {
@@ -617,3 +619,22 @@ xfs_allocbt_calc_size(
617619
{
618620
return xfs_btree_calc_size(mp->m_alloc_mnr, len);
619621
}
622+
623+
int __init
624+
xfs_allocbt_init_cur_cache(void)
625+
{
626+
xfs_allocbt_cur_cache = kmem_cache_create("xfs_bnobt_cur",
627+
xfs_btree_cur_sizeof(xfs_allocbt_maxlevels_ondisk()),
628+
0, 0, NULL);
629+
630+
if (!xfs_allocbt_cur_cache)
631+
return -ENOMEM;
632+
return 0;
633+
}
634+
635+
void
636+
xfs_allocbt_destroy_cur_cache(void)
637+
{
638+
kmem_cache_destroy(xfs_allocbt_cur_cache);
639+
xfs_allocbt_cur_cache = NULL;
640+
}

fs/xfs/libxfs/xfs_alloc_btree.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,7 @@ void xfs_allocbt_commit_staged_btree(struct xfs_btree_cur *cur,
6262

6363
unsigned int xfs_allocbt_maxlevels_ondisk(void);
6464

65+
int __init xfs_allocbt_init_cur_cache(void);
66+
void xfs_allocbt_destroy_cur_cache(void);
67+
6568
#endif /* __XFS_ALLOC_BTREE_H__ */

fs/xfs/libxfs/xfs_bmap_btree.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "xfs_trace.h"
2323
#include "xfs_rmap.h"
2424

25+
static kmem_zone_t *xfs_bmbt_cur_cache;
26+
2527
/*
2628
* Convert on-disk form of btree root to in-memory form.
2729
*/
@@ -553,7 +555,7 @@ xfs_bmbt_init_cursor(
553555
ASSERT(whichfork != XFS_COW_FORK);
554556

555557
cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_BMAP,
556-
mp->m_bm_maxlevels[whichfork]);
558+
mp->m_bm_maxlevels[whichfork], xfs_bmbt_cur_cache);
557559
cur->bc_nlevels = be16_to_cpu(ifp->if_broot->bb_level) + 1;
558560
cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_bmbt_2);
559561

@@ -675,3 +677,22 @@ xfs_bmbt_calc_size(
675677
{
676678
return xfs_btree_calc_size(mp->m_bmap_dmnr, len);
677679
}
680+
681+
int __init
682+
xfs_bmbt_init_cur_cache(void)
683+
{
684+
xfs_bmbt_cur_cache = kmem_cache_create("xfs_bmbt_cur",
685+
xfs_btree_cur_sizeof(xfs_bmbt_maxlevels_ondisk()),
686+
0, 0, NULL);
687+
688+
if (!xfs_bmbt_cur_cache)
689+
return -ENOMEM;
690+
return 0;
691+
}
692+
693+
void
694+
xfs_bmbt_destroy_cur_cache(void)
695+
{
696+
kmem_cache_destroy(xfs_bmbt_cur_cache);
697+
xfs_bmbt_cur_cache = NULL;
698+
}

fs/xfs/libxfs/xfs_bmap_btree.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,7 @@ extern unsigned long long xfs_bmbt_calc_size(struct xfs_mount *mp,
112112

113113
unsigned int xfs_bmbt_maxlevels_ondisk(void);
114114

115+
int __init xfs_bmbt_init_cur_cache(void);
116+
void xfs_bmbt_destroy_cur_cache(void);
117+
115118
#endif /* __XFS_BMAP_BTREE_H__ */

fs/xfs/libxfs/xfs_btree.c

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
#include "xfs_log.h"
2323
#include "xfs_btree_staging.h"
2424
#include "xfs_ag.h"
25-
26-
/*
27-
* Cursor allocation zone.
28-
*/
29-
kmem_zone_t *xfs_btree_cur_zone;
25+
#include "xfs_alloc_btree.h"
26+
#include "xfs_ialloc_btree.h"
27+
#include "xfs_bmap_btree.h"
28+
#include "xfs_rmap_btree.h"
29+
#include "xfs_refcount_btree.h"
3030

3131
/*
3232
* Btree magic numbers.
@@ -379,7 +379,7 @@ xfs_btree_del_cursor(
379379
kmem_free(cur->bc_ops);
380380
if (!(cur->bc_flags & XFS_BTREE_LONG_PTRS) && cur->bc_ag.pag)
381381
xfs_perag_put(cur->bc_ag.pag);
382-
kmem_cache_free(xfs_btree_cur_zone, cur);
382+
kmem_cache_free(cur->bc_cache, cur);
383383
}
384384

385385
/*
@@ -4962,3 +4962,42 @@ xfs_btree_has_more_records(
49624962
else
49634963
return block->bb_u.s.bb_rightsib != cpu_to_be32(NULLAGBLOCK);
49644964
}
4965+
4966+
/* Set up all the btree cursor caches. */
4967+
int __init
4968+
xfs_btree_init_cur_caches(void)
4969+
{
4970+
int error;
4971+
4972+
error = xfs_allocbt_init_cur_cache();
4973+
if (error)
4974+
return error;
4975+
error = xfs_inobt_init_cur_cache();
4976+
if (error)
4977+
goto err;
4978+
error = xfs_bmbt_init_cur_cache();
4979+
if (error)
4980+
goto err;
4981+
error = xfs_rmapbt_init_cur_cache();
4982+
if (error)
4983+
goto err;
4984+
error = xfs_refcountbt_init_cur_cache();
4985+
if (error)
4986+
goto err;
4987+
4988+
return 0;
4989+
err:
4990+
xfs_btree_destroy_cur_caches();
4991+
return error;
4992+
}
4993+
4994+
/* Destroy all the btree cursor caches, if they've been allocated. */
4995+
void
4996+
xfs_btree_destroy_cur_caches(void)
4997+
{
4998+
xfs_allocbt_destroy_cur_cache();
4999+
xfs_inobt_destroy_cur_cache();
5000+
xfs_bmbt_destroy_cur_cache();
5001+
xfs_rmapbt_destroy_cur_cache();
5002+
xfs_refcountbt_destroy_cur_cache();
5003+
}

fs/xfs/libxfs/xfs_btree.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ struct xfs_trans;
1313
struct xfs_ifork;
1414
struct xfs_perag;
1515

16-
extern kmem_zone_t *xfs_btree_cur_zone;
17-
1816
/*
1917
* Generic key, ptr and record wrapper structures.
2018
*
@@ -92,12 +90,6 @@ uint32_t xfs_btree_magic(int crc, xfs_btnum_t btnum);
9290
#define XFS_BTREE_STATS_ADD(cur, stat, val) \
9391
XFS_STATS_ADD_OFF((cur)->bc_mp, (cur)->bc_statoff + __XBTS_ ## stat, val)
9492

95-
/*
96-
* The btree cursor zone hands out cursors that can handle up to this many
97-
* levels. This is the known maximum for all btree types.
98-
*/
99-
#define XFS_BTREE_CUR_CACHE_MAXLEVELS (9)
100-
10193
struct xfs_btree_ops {
10294
/* size of the key and record structures */
10395
size_t key_len;
@@ -238,6 +230,7 @@ struct xfs_btree_cur
238230
struct xfs_trans *bc_tp; /* transaction we're in, if any */
239231
struct xfs_mount *bc_mp; /* file system mount struct */
240232
const struct xfs_btree_ops *bc_ops;
233+
kmem_zone_t *bc_cache; /* cursor cache */
241234
unsigned int bc_flags; /* btree features - below */
242235
xfs_btnum_t bc_btnum; /* identifies which btree type */
243236
union xfs_btree_irec bc_rec; /* current insert/search record value */
@@ -592,19 +585,22 @@ xfs_btree_alloc_cursor(
592585
struct xfs_mount *mp,
593586
struct xfs_trans *tp,
594587
xfs_btnum_t btnum,
595-
uint8_t maxlevels)
588+
uint8_t maxlevels,
589+
kmem_zone_t *cache)
596590
{
597591
struct xfs_btree_cur *cur;
598592

599-
ASSERT(maxlevels <= XFS_BTREE_CUR_CACHE_MAXLEVELS);
600-
601-
cur = kmem_cache_zalloc(xfs_btree_cur_zone, GFP_NOFS | __GFP_NOFAIL);
593+
cur = kmem_cache_zalloc(cache, GFP_NOFS | __GFP_NOFAIL);
602594
cur->bc_tp = tp;
603595
cur->bc_mp = mp;
604596
cur->bc_btnum = btnum;
605597
cur->bc_maxlevels = maxlevels;
598+
cur->bc_cache = cache;
606599

607600
return cur;
608601
}
609602

603+
int __init xfs_btree_init_cur_caches(void);
604+
void xfs_btree_destroy_cur_caches(void);
605+
610606
#endif /* __XFS_BTREE_H__ */

fs/xfs/libxfs/xfs_ialloc_btree.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "xfs_rmap.h"
2323
#include "xfs_ag.h"
2424

25+
static kmem_zone_t *xfs_inobt_cur_cache;
26+
2527
STATIC int
2628
xfs_inobt_get_minrecs(
2729
struct xfs_btree_cur *cur,
@@ -433,7 +435,7 @@ xfs_inobt_init_common(
433435
struct xfs_btree_cur *cur;
434436

435437
cur = xfs_btree_alloc_cursor(mp, tp, btnum,
436-
M_IGEO(mp)->inobt_maxlevels);
438+
M_IGEO(mp)->inobt_maxlevels, xfs_inobt_cur_cache);
437439
if (btnum == XFS_BTNUM_INO) {
438440
cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_ibt_2);
439441
cur->bc_ops = &xfs_inobt_ops;
@@ -812,3 +814,22 @@ xfs_iallocbt_calc_size(
812814
{
813815
return xfs_btree_calc_size(M_IGEO(mp)->inobt_mnr, len);
814816
}
817+
818+
int __init
819+
xfs_inobt_init_cur_cache(void)
820+
{
821+
xfs_inobt_cur_cache = kmem_cache_create("xfs_inobt_cur",
822+
xfs_btree_cur_sizeof(xfs_inobt_maxlevels_ondisk()),
823+
0, 0, NULL);
824+
825+
if (!xfs_inobt_cur_cache)
826+
return -ENOMEM;
827+
return 0;
828+
}
829+
830+
void
831+
xfs_inobt_destroy_cur_cache(void)
832+
{
833+
kmem_cache_destroy(xfs_inobt_cur_cache);
834+
xfs_inobt_cur_cache = NULL;
835+
}

fs/xfs/libxfs/xfs_ialloc_btree.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,7 @@ void xfs_inobt_commit_staged_btree(struct xfs_btree_cur *cur,
7777

7878
unsigned int xfs_iallocbt_maxlevels_ondisk(void);
7979

80+
int __init xfs_inobt_init_cur_cache(void);
81+
void xfs_inobt_destroy_cur_cache(void);
82+
8083
#endif /* __XFS_IALLOC_BTREE_H__ */

fs/xfs/libxfs/xfs_refcount_btree.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "xfs_rmap.h"
2222
#include "xfs_ag.h"
2323

24+
static kmem_zone_t *xfs_refcountbt_cur_cache;
25+
2426
static struct xfs_btree_cur *
2527
xfs_refcountbt_dup_cursor(
2628
struct xfs_btree_cur *cur)
@@ -323,7 +325,7 @@ xfs_refcountbt_init_common(
323325
ASSERT(pag->pag_agno < mp->m_sb.sb_agcount);
324326

325327
cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_REFC,
326-
mp->m_refc_maxlevels);
328+
mp->m_refc_maxlevels, xfs_refcountbt_cur_cache);
327329
cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_refcbt_2);
328330

329331
cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
@@ -514,3 +516,22 @@ xfs_refcountbt_calc_reserves(
514516

515517
return error;
516518
}
519+
520+
int __init
521+
xfs_refcountbt_init_cur_cache(void)
522+
{
523+
xfs_refcountbt_cur_cache = kmem_cache_create("xfs_refcbt_cur",
524+
xfs_btree_cur_sizeof(xfs_refcountbt_maxlevels_ondisk()),
525+
0, 0, NULL);
526+
527+
if (!xfs_refcountbt_cur_cache)
528+
return -ENOMEM;
529+
return 0;
530+
}
531+
532+
void
533+
xfs_refcountbt_destroy_cur_cache(void)
534+
{
535+
kmem_cache_destroy(xfs_refcountbt_cur_cache);
536+
xfs_refcountbt_cur_cache = NULL;
537+
}

fs/xfs/libxfs/xfs_refcount_btree.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,7 @@ void xfs_refcountbt_commit_staged_btree(struct xfs_btree_cur *cur,
6767

6868
unsigned int xfs_refcountbt_maxlevels_ondisk(void);
6969

70+
int __init xfs_refcountbt_init_cur_cache(void);
71+
void xfs_refcountbt_destroy_cur_cache(void);
72+
7073
#endif /* __XFS_REFCOUNT_BTREE_H__ */

0 commit comments

Comments
 (0)