Skip to content

Commit c201d9c

Browse files
author
Darrick J. Wong
committed
xfs: rename xfs_bmap_add_free to xfs_free_extent_later
xfs_bmap_add_free isn't a block mapping function; it schedules deferred freeing operations for a later point in a compound transaction chain. While it's primarily used by bunmapi, its use has expanded beyond that. Move it to xfs_alloc.c and rename the function since it's now general freeing functionality. Bring the slab cache bits in line with the way we handle the other intent items. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Chandan Babu R <[email protected]>
1 parent f3c799c commit c201d9c

File tree

12 files changed

+118
-106
lines changed

12 files changed

+118
-106
lines changed

fs/xfs/libxfs/xfs_ag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ xfs_ag_shrink_space(
850850
if (err2 != -ENOSPC)
851851
goto resv_err;
852852

853-
__xfs_bmap_add_free(*tpp, args.fsbno, delta, NULL, true);
853+
__xfs_free_extent_later(*tpp, args.fsbno, delta, NULL, true);
854854

855855
/*
856856
* Roll the transaction before trying to re-init the per-ag

fs/xfs/libxfs/xfs_alloc.c

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "xfs_ag_resv.h"
2828
#include "xfs_bmap.h"
2929

30-
extern struct kmem_cache *xfs_bmap_free_item_cache;
30+
struct kmem_cache *xfs_extfree_item_cache;
3131

3232
struct workqueue_struct *xfs_alloc_wq;
3333

@@ -2440,7 +2440,7 @@ xfs_agfl_reset(
24402440

24412441
/*
24422442
* Defer an AGFL block free. This is effectively equivalent to
2443-
* xfs_bmap_add_free() with some special handling particular to AGFL blocks.
2443+
* xfs_free_extent_later() with some special handling particular to AGFL blocks.
24442444
*
24452445
* Deferring AGFL frees helps prevent log reservation overruns due to too many
24462446
* allocation operations in a transaction. AGFL frees are prone to this problem
@@ -2459,10 +2459,10 @@ xfs_defer_agfl_block(
24592459
struct xfs_mount *mp = tp->t_mountp;
24602460
struct xfs_extent_free_item *new; /* new element */
24612461

2462-
ASSERT(xfs_bmap_free_item_cache != NULL);
2462+
ASSERT(xfs_extfree_item_cache != NULL);
24632463
ASSERT(oinfo != NULL);
24642464

2465-
new = kmem_cache_alloc(xfs_bmap_free_item_cache,
2465+
new = kmem_cache_alloc(xfs_extfree_item_cache,
24662466
GFP_KERNEL | __GFP_NOFAIL);
24672467
new->xefi_startblock = XFS_AGB_TO_FSB(mp, agno, agbno);
24682468
new->xefi_blockcount = 1;
@@ -2474,6 +2474,52 @@ xfs_defer_agfl_block(
24742474
xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_AGFL_FREE, &new->xefi_list);
24752475
}
24762476

2477+
/*
2478+
* Add the extent to the list of extents to be free at transaction end.
2479+
* The list is maintained sorted (by block number).
2480+
*/
2481+
void
2482+
__xfs_free_extent_later(
2483+
struct xfs_trans *tp,
2484+
xfs_fsblock_t bno,
2485+
xfs_filblks_t len,
2486+
const struct xfs_owner_info *oinfo,
2487+
bool skip_discard)
2488+
{
2489+
struct xfs_extent_free_item *new; /* new element */
2490+
#ifdef DEBUG
2491+
struct xfs_mount *mp = tp->t_mountp;
2492+
xfs_agnumber_t agno;
2493+
xfs_agblock_t agbno;
2494+
2495+
ASSERT(bno != NULLFSBLOCK);
2496+
ASSERT(len > 0);
2497+
ASSERT(len <= MAXEXTLEN);
2498+
ASSERT(!isnullstartblock(bno));
2499+
agno = XFS_FSB_TO_AGNO(mp, bno);
2500+
agbno = XFS_FSB_TO_AGBNO(mp, bno);
2501+
ASSERT(agno < mp->m_sb.sb_agcount);
2502+
ASSERT(agbno < mp->m_sb.sb_agblocks);
2503+
ASSERT(len < mp->m_sb.sb_agblocks);
2504+
ASSERT(agbno + len <= mp->m_sb.sb_agblocks);
2505+
#endif
2506+
ASSERT(xfs_extfree_item_cache != NULL);
2507+
2508+
new = kmem_cache_alloc(xfs_extfree_item_cache,
2509+
GFP_KERNEL | __GFP_NOFAIL);
2510+
new->xefi_startblock = bno;
2511+
new->xefi_blockcount = (xfs_extlen_t)len;
2512+
if (oinfo)
2513+
new->xefi_oinfo = *oinfo;
2514+
else
2515+
new->xefi_oinfo = XFS_RMAP_OINFO_SKIP_UPDATE;
2516+
new->xefi_skip_discard = skip_discard;
2517+
trace_xfs_bmap_free_defer(tp->t_mountp,
2518+
XFS_FSB_TO_AGNO(tp->t_mountp, bno), 0,
2519+
XFS_FSB_TO_AGBNO(tp->t_mountp, bno), len);
2520+
xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_FREE, &new->xefi_list);
2521+
}
2522+
24772523
#ifdef DEBUG
24782524
/*
24792525
* Check if an AGF has a free extent record whose length is equal to
@@ -3499,3 +3545,20 @@ xfs_agfl_walk(
34993545

35003546
return 0;
35013547
}
3548+
3549+
int __init
3550+
xfs_extfree_intent_init_cache(void)
3551+
{
3552+
xfs_extfree_item_cache = kmem_cache_create("xfs_extfree_intent",
3553+
sizeof(struct xfs_extent_free_item),
3554+
0, 0, NULL);
3555+
3556+
return xfs_extfree_item_cache != NULL ? 0 : -ENOMEM;
3557+
}
3558+
3559+
void
3560+
xfs_extfree_intent_destroy_cache(void)
3561+
{
3562+
kmem_cache_destroy(xfs_extfree_item_cache);
3563+
xfs_extfree_item_cache = NULL;
3564+
}

fs/xfs/libxfs/xfs_alloc.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,36 @@ xfs_buf_to_agfl_bno(
248248
return bp->b_addr;
249249
}
250250

251+
void __xfs_free_extent_later(struct xfs_trans *tp, xfs_fsblock_t bno,
252+
xfs_filblks_t len, const struct xfs_owner_info *oinfo,
253+
bool skip_discard);
254+
255+
/*
256+
* List of extents to be free "later".
257+
* The list is kept sorted on xbf_startblock.
258+
*/
259+
struct xfs_extent_free_item {
260+
struct list_head xefi_list;
261+
xfs_fsblock_t xefi_startblock;/* starting fs block number */
262+
xfs_extlen_t xefi_blockcount;/* number of blocks in extent */
263+
bool xefi_skip_discard;
264+
struct xfs_owner_info xefi_oinfo; /* extent owner */
265+
};
266+
267+
static inline void
268+
xfs_free_extent_later(
269+
struct xfs_trans *tp,
270+
xfs_fsblock_t bno,
271+
xfs_filblks_t len,
272+
const struct xfs_owner_info *oinfo)
273+
{
274+
__xfs_free_extent_later(tp, bno, len, oinfo, false);
275+
}
276+
277+
278+
extern struct kmem_cache *xfs_extfree_item_cache;
279+
280+
int __init xfs_extfree_intent_init_cache(void);
281+
void xfs_extfree_intent_destroy_cache(void);
282+
251283
#endif /* __XFS_ALLOC_H__ */

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include "xfs_iomap.h"
3939

4040
struct kmem_cache *xfs_bmap_intent_cache;
41-
struct kmem_cache *xfs_bmap_free_item_cache;
4241

4342
/*
4443
* Miscellaneous helper functions
@@ -522,56 +521,6 @@ xfs_bmap_validate_ret(
522521
#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
523522
#endif /* DEBUG */
524523

525-
/*
526-
* bmap free list manipulation functions
527-
*/
528-
529-
/*
530-
* Add the extent to the list of extents to be free at transaction end.
531-
* The list is maintained sorted (by block number).
532-
*/
533-
void
534-
__xfs_bmap_add_free(
535-
struct xfs_trans *tp,
536-
xfs_fsblock_t bno,
537-
xfs_filblks_t len,
538-
const struct xfs_owner_info *oinfo,
539-
bool skip_discard)
540-
{
541-
struct xfs_extent_free_item *new; /* new element */
542-
#ifdef DEBUG
543-
struct xfs_mount *mp = tp->t_mountp;
544-
xfs_agnumber_t agno;
545-
xfs_agblock_t agbno;
546-
547-
ASSERT(bno != NULLFSBLOCK);
548-
ASSERT(len > 0);
549-
ASSERT(len <= MAXEXTLEN);
550-
ASSERT(!isnullstartblock(bno));
551-
agno = XFS_FSB_TO_AGNO(mp, bno);
552-
agbno = XFS_FSB_TO_AGBNO(mp, bno);
553-
ASSERT(agno < mp->m_sb.sb_agcount);
554-
ASSERT(agbno < mp->m_sb.sb_agblocks);
555-
ASSERT(len < mp->m_sb.sb_agblocks);
556-
ASSERT(agbno + len <= mp->m_sb.sb_agblocks);
557-
#endif
558-
ASSERT(xfs_bmap_free_item_cache != NULL);
559-
560-
new = kmem_cache_alloc(xfs_bmap_free_item_cache,
561-
GFP_KERNEL | __GFP_NOFAIL);
562-
new->xefi_startblock = bno;
563-
new->xefi_blockcount = (xfs_extlen_t)len;
564-
if (oinfo)
565-
new->xefi_oinfo = *oinfo;
566-
else
567-
new->xefi_oinfo = XFS_RMAP_OINFO_SKIP_UPDATE;
568-
new->xefi_skip_discard = skip_discard;
569-
trace_xfs_bmap_free_defer(tp->t_mountp,
570-
XFS_FSB_TO_AGNO(tp->t_mountp, bno), 0,
571-
XFS_FSB_TO_AGBNO(tp->t_mountp, bno), len);
572-
xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_FREE, &new->xefi_list);
573-
}
574-
575524
/*
576525
* Inode fork format manipulation functions
577526
*/
@@ -626,7 +575,7 @@ xfs_bmap_btree_to_extents(
626575
if ((error = xfs_btree_check_block(cur, cblock, 0, cbp)))
627576
return error;
628577
xfs_rmap_ino_bmbt_owner(&oinfo, ip->i_ino, whichfork);
629-
xfs_bmap_add_free(cur->bc_tp, cbno, 1, &oinfo);
578+
xfs_free_extent_later(cur->bc_tp, cbno, 1, &oinfo);
630579
ip->i_nblocks--;
631580
xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, -1L);
632581
xfs_trans_binval(tp, cbp);
@@ -5297,7 +5246,7 @@ xfs_bmap_del_extent_real(
52975246
if (xfs_is_reflink_inode(ip) && whichfork == XFS_DATA_FORK) {
52985247
xfs_refcount_decrease_extent(tp, del);
52995248
} else {
5300-
__xfs_bmap_add_free(tp, del->br_startblock,
5249+
__xfs_free_extent_later(tp, del->br_startblock,
53015250
del->br_blockcount, NULL,
53025251
(bflags & XFS_BMAPI_NODISCARD) ||
53035252
del->br_state == XFS_EXT_UNWRITTEN);

fs/xfs/libxfs/xfs_bmap.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ struct xfs_inode;
1313
struct xfs_mount;
1414
struct xfs_trans;
1515

16-
extern struct kmem_cache *xfs_bmap_free_item_cache;
17-
1816
/*
1917
* Argument structure for xfs_bmap_alloc.
2018
*/
@@ -44,19 +42,6 @@ struct xfs_bmalloca {
4442
int flags;
4543
};
4644

47-
/*
48-
* List of extents to be free "later".
49-
* The list is kept sorted on xbf_startblock.
50-
*/
51-
struct xfs_extent_free_item
52-
{
53-
xfs_fsblock_t xefi_startblock;/* starting fs block number */
54-
xfs_extlen_t xefi_blockcount;/* number of blocks in extent */
55-
bool xefi_skip_discard;
56-
struct list_head xefi_list;
57-
struct xfs_owner_info xefi_oinfo; /* extent owner */
58-
};
59-
6045
#define XFS_BMAP_MAX_NMAP 4
6146

6247
/*
@@ -189,9 +174,6 @@ unsigned int xfs_bmap_compute_attr_offset(struct xfs_mount *mp);
189174
int xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd);
190175
void xfs_bmap_local_to_extents_empty(struct xfs_trans *tp,
191176
struct xfs_inode *ip, int whichfork);
192-
void __xfs_bmap_add_free(struct xfs_trans *tp, xfs_fsblock_t bno,
193-
xfs_filblks_t len, const struct xfs_owner_info *oinfo,
194-
bool skip_discard);
195177
void xfs_bmap_compute_maxlevels(struct xfs_mount *mp, int whichfork);
196178
int xfs_bmap_first_unused(struct xfs_trans *tp, struct xfs_inode *ip,
197179
xfs_extlen_t len, xfs_fileoff_t *unused, int whichfork);
@@ -239,16 +221,6 @@ int xfs_bmap_add_extent_unwritten_real(struct xfs_trans *tp,
239221
struct xfs_iext_cursor *icur, struct xfs_btree_cur **curp,
240222
struct xfs_bmbt_irec *new, int *logflagsp);
241223

242-
static inline void
243-
xfs_bmap_add_free(
244-
struct xfs_trans *tp,
245-
xfs_fsblock_t bno,
246-
xfs_filblks_t len,
247-
const struct xfs_owner_info *oinfo)
248-
{
249-
__xfs_bmap_add_free(tp, bno, len, oinfo, false);
250-
}
251-
252224
enum xfs_bmap_intent_type {
253225
XFS_BMAP_MAP = 1,
254226
XFS_BMAP_UNMAP,

fs/xfs/libxfs/xfs_bmap_btree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ xfs_bmbt_free_block(
288288
struct xfs_owner_info oinfo;
289289

290290
xfs_rmap_ino_bmbt_owner(&oinfo, ip->i_ino, cur->bc_ino.whichfork);
291-
xfs_bmap_add_free(cur->bc_tp, fsbno, 1, &oinfo);
291+
xfs_free_extent_later(cur->bc_tp, fsbno, 1, &oinfo);
292292
ip->i_nblocks--;
293293

294294
xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);

fs/xfs/libxfs/xfs_defer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "xfs_rmap.h"
2222
#include "xfs_refcount.h"
2323
#include "xfs_bmap.h"
24+
#include "xfs_alloc.h"
2425

2526
static struct kmem_cache *xfs_defer_pending_cache;
2627

@@ -848,6 +849,9 @@ xfs_defer_init_item_caches(void)
848849
if (error)
849850
goto err;
850851
error = xfs_bmap_intent_init_cache();
852+
if (error)
853+
goto err;
854+
error = xfs_extfree_intent_init_cache();
851855
if (error)
852856
goto err;
853857

@@ -861,6 +865,7 @@ xfs_defer_init_item_caches(void)
861865
void
862866
xfs_defer_destroy_item_caches(void)
863867
{
868+
xfs_extfree_intent_destroy_cache();
864869
xfs_bmap_intent_destroy_cache();
865870
xfs_refcount_intent_destroy_cache();
866871
xfs_rmap_intent_destroy_cache();

fs/xfs/libxfs/xfs_ialloc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,7 @@ xfs_difree_inode_chunk(
18271827

18281828
if (!xfs_inobt_issparse(rec->ir_holemask)) {
18291829
/* not sparse, calculate extent info directly */
1830-
xfs_bmap_add_free(tp, XFS_AGB_TO_FSB(mp, agno, sagbno),
1830+
xfs_free_extent_later(tp, XFS_AGB_TO_FSB(mp, agno, sagbno),
18311831
M_IGEO(mp)->ialloc_blks,
18321832
&XFS_RMAP_OINFO_INODES);
18331833
return;
@@ -1872,7 +1872,7 @@ xfs_difree_inode_chunk(
18721872

18731873
ASSERT(agbno % mp->m_sb.sb_spino_align == 0);
18741874
ASSERT(contigblk % mp->m_sb.sb_spino_align == 0);
1875-
xfs_bmap_add_free(tp, XFS_AGB_TO_FSB(mp, agno, agbno),
1875+
xfs_free_extent_later(tp, XFS_AGB_TO_FSB(mp, agno, agbno),
18761876
contigblk, &XFS_RMAP_OINFO_INODES);
18771877

18781878
/* reset range to current bit and carry on... */

fs/xfs/libxfs/xfs_refcount.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ xfs_refcount_adjust_extents(
976976
fsbno = XFS_AGB_TO_FSB(cur->bc_mp,
977977
cur->bc_ag.pag->pag_agno,
978978
tmp.rc_startblock);
979-
xfs_bmap_add_free(cur->bc_tp, fsbno,
979+
xfs_free_extent_later(cur->bc_tp, fsbno,
980980
tmp.rc_blockcount, oinfo);
981981
}
982982

@@ -1021,7 +1021,7 @@ xfs_refcount_adjust_extents(
10211021
fsbno = XFS_AGB_TO_FSB(cur->bc_mp,
10221022
cur->bc_ag.pag->pag_agno,
10231023
ext.rc_startblock);
1024-
xfs_bmap_add_free(cur->bc_tp, fsbno, ext.rc_blockcount,
1024+
xfs_free_extent_later(cur->bc_tp, fsbno, ext.rc_blockcount,
10251025
oinfo);
10261026
}
10271027

@@ -1744,7 +1744,7 @@ xfs_refcount_recover_cow_leftovers(
17441744
rr->rr_rrec.rc_blockcount);
17451745

17461746
/* Free the block. */
1747-
xfs_bmap_add_free(tp, fsb, rr->rr_rrec.rc_blockcount, NULL);
1747+
xfs_free_extent_later(tp, fsb, rr->rr_rrec.rc_blockcount, NULL);
17481748

17491749
error = xfs_trans_commit(tp);
17501750
if (error)

fs/xfs/xfs_extfree_item.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ xfs_extent_free_finish_item(
482482
free->xefi_startblock,
483483
free->xefi_blockcount,
484484
&free->xefi_oinfo, free->xefi_skip_discard);
485-
kmem_cache_free(xfs_bmap_free_item_cache, free);
485+
kmem_cache_free(xfs_extfree_item_cache, free);
486486
return error;
487487
}
488488

@@ -502,7 +502,7 @@ xfs_extent_free_cancel_item(
502502
struct xfs_extent_free_item *free;
503503

504504
free = container_of(item, struct xfs_extent_free_item, xefi_list);
505-
kmem_cache_free(xfs_bmap_free_item_cache, free);
505+
kmem_cache_free(xfs_extfree_item_cache, free);
506506
}
507507

508508
const struct xfs_defer_op_type xfs_extent_free_defer_type = {
@@ -564,7 +564,7 @@ xfs_agfl_free_finish_item(
564564
extp->ext_len = free->xefi_blockcount;
565565
efdp->efd_next_extent++;
566566

567-
kmem_cache_free(xfs_bmap_free_item_cache, free);
567+
kmem_cache_free(xfs_extfree_item_cache, free);
568568
return error;
569569
}
570570

0 commit comments

Comments
 (0)