Skip to content

Commit

Permalink
xfs: per-filesystem stats counter implementation
Browse files Browse the repository at this point in the history
This patch modifies the stats counting macros and the callers
to those macros to properly increment, decrement, and add-to
the xfs stats counts. The counts for global and per-fs stats
are correctly advanced, and cleared by writing a "1" to the
corresponding clear file.

global counts: /sys/fs/xfs/stats/stats
per-fs counts: /sys/fs/xfs/sda*/stats/stats

global clear:  /sys/fs/xfs/stats/stats_clear
per-fs clear:  /sys/fs/xfs/sda*/stats/stats_clear

[dchinner: cleaned up macro variables, removed CONFIG_FS_PROC around
 stats structures and macros. ]

Signed-off-by: Bill O'Donnell <[email protected]>
Reviewed-by: Eric Sandeen <[email protected]>
Signed-off-by: Dave Chinner <[email protected]>
  • Loading branch information
Bill O'Donnell authored and dchinner committed Oct 12, 2015
1 parent 225e463 commit ff6d6af
Show file tree
Hide file tree
Showing 21 changed files with 131 additions and 118 deletions.
8 changes: 4 additions & 4 deletions fs/xfs/libxfs/xfs_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,8 @@ xfs_alloc_ag_vextent(
-((long)(args->len)));
}

XFS_STATS_INC(xs_allocx);
XFS_STATS_ADD(xs_allocb, args->len);
XFS_STATS_INC(args->mp, xs_allocx);
XFS_STATS_ADD(args->mp, xs_allocb, args->len);
return error;
}

Expand Down Expand Up @@ -1808,8 +1808,8 @@ xfs_free_ag_extent(

if (!isfl)
xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, (long)len);
XFS_STATS_INC(xs_freex);
XFS_STATS_ADD(xs_freeb, len);
XFS_STATS_INC(mp, xs_freex);
XFS_STATS_ADD(mp, xs_freeb, len);

trace_xfs_free_extent(mp, agno, bno, len, isfl, haveleft, haveright);

Expand Down
6 changes: 3 additions & 3 deletions fs/xfs/libxfs/xfs_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ xfs_attr_get(
uint lock_mode;
int error;

XFS_STATS_INC(xs_attr_get);
XFS_STATS_INC(ip->i_mount, xs_attr_get);

if (XFS_FORCED_SHUTDOWN(ip->i_mount))
return -EIO;
Expand Down Expand Up @@ -209,7 +209,7 @@ xfs_attr_set(
int rsvd = (flags & ATTR_ROOT) != 0;
int error, err2, committed, local;

XFS_STATS_INC(xs_attr_set);
XFS_STATS_INC(mp, xs_attr_set);

if (XFS_FORCED_SHUTDOWN(dp->i_mount))
return -EIO;
Expand Down Expand Up @@ -412,7 +412,7 @@ xfs_attr_remove(
xfs_fsblock_t firstblock;
int error;

XFS_STATS_INC(xs_attr_remove);
XFS_STATS_INC(mp, xs_attr_remove);

if (XFS_FORCED_SHUTDOWN(dp->i_mount))
return -EIO;
Expand Down
20 changes: 10 additions & 10 deletions fs/xfs/libxfs/xfs_bmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ xfs_bmap_search_extents(
xfs_ifork_t *ifp; /* inode fork pointer */
xfs_bmbt_rec_host_t *ep; /* extent record pointer */

XFS_STATS_INC(xs_look_exlist);
XFS_STATS_INC(ip->i_mount, xs_look_exlist);
ifp = XFS_IFORK_PTR(ip, fork);

ep = xfs_bmap_search_multi_extents(ifp, bno, eofp, lastxp, gotp, prevp);
Expand Down Expand Up @@ -1732,7 +1732,7 @@ xfs_bmap_add_extent_delay_real(
ASSERT(!bma->cur ||
(bma->cur->bc_private.b.flags & XFS_BTCUR_BPRV_WASDEL));

XFS_STATS_INC(xs_add_exlist);
XFS_STATS_INC(mp, xs_add_exlist);

#define LEFT r[0]
#define RIGHT r[1]
Expand Down Expand Up @@ -2286,7 +2286,7 @@ xfs_bmap_add_extent_unwritten_real(
ASSERT(*idx <= ifp->if_bytes / sizeof(struct xfs_bmbt_rec));
ASSERT(!isnullstartblock(new->br_startblock));

XFS_STATS_INC(xs_add_exlist);
XFS_STATS_INC(mp, xs_add_exlist);

#define LEFT r[0]
#define RIGHT r[1]
Expand Down Expand Up @@ -2946,7 +2946,7 @@ xfs_bmap_add_extent_hole_real(
ASSERT(!bma->cur ||
!(bma->cur->bc_private.b.flags & XFS_BTCUR_BPRV_WASDEL));

XFS_STATS_INC(xs_add_exlist);
XFS_STATS_INC(mp, xs_add_exlist);

state = 0;
if (whichfork == XFS_ATTR_FORK)
Expand Down Expand Up @@ -4036,7 +4036,7 @@ xfs_bmapi_read(
if (XFS_FORCED_SHUTDOWN(mp))
return -EIO;

XFS_STATS_INC(xs_blk_mapr);
XFS_STATS_INC(mp, xs_blk_mapr);

ifp = XFS_IFORK_PTR(ip, whichfork);

Expand Down Expand Up @@ -4221,7 +4221,7 @@ xfs_bmapi_delay(
if (XFS_FORCED_SHUTDOWN(mp))
return -EIO;

XFS_STATS_INC(xs_blk_mapw);
XFS_STATS_INC(mp, xs_blk_mapw);

if (!(ifp->if_flags & XFS_IFEXTENTS)) {
error = xfs_iread_extents(NULL, ip, XFS_DATA_FORK);
Expand Down Expand Up @@ -4525,7 +4525,7 @@ xfs_bmapi_write(

ifp = XFS_IFORK_PTR(ip, whichfork);

XFS_STATS_INC(xs_blk_mapw);
XFS_STATS_INC(mp, xs_blk_mapw);

if (*firstblock == NULLFSBLOCK) {
if (XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_BTREE)
Expand Down Expand Up @@ -4718,12 +4718,12 @@ xfs_bmap_del_extent(
xfs_filblks_t temp2; /* for indirect length calculations */
int state = 0;

XFS_STATS_INC(xs_del_exlist);
mp = ip->i_mount;
XFS_STATS_INC(mp, xs_del_exlist);

if (whichfork == XFS_ATTR_FORK)
state |= BMAP_ATTRFORK;

mp = ip->i_mount;
ifp = XFS_IFORK_PTR(ip, whichfork);
ASSERT((*idx >= 0) && (*idx < ifp->if_bytes /
(uint)sizeof(xfs_bmbt_rec_t)));
Expand Down Expand Up @@ -5070,7 +5070,7 @@ xfs_bunmapi(
*done = 1;
return 0;
}
XFS_STATS_INC(xs_blk_unmap);
XFS_STATS_INC(mp, xs_blk_unmap);
isrt = (whichfork == XFS_DATA_FORK) && XFS_IS_REALTIME_INODE(ip);
start = bno;
bno = start + len - 1;
Expand Down
39 changes: 23 additions & 16 deletions fs/xfs/libxfs/xfs_btree.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,38 @@ union xfs_btree_rec {
/*
* Generic stats interface
*/
#define __XFS_BTREE_STATS_INC(type, stat) \
XFS_STATS_INC(xs_ ## type ## _2_ ## stat)
#define XFS_BTREE_STATS_INC(cur, stat) \
#define __XFS_BTREE_STATS_INC(mp, type, stat) \
XFS_STATS_INC(mp, xs_ ## type ## _2_ ## stat)
#define XFS_BTREE_STATS_INC(cur, stat) \
do { \
struct xfs_mount *__mp = cur->bc_mp; \
switch (cur->bc_btnum) { \
case XFS_BTNUM_BNO: __XFS_BTREE_STATS_INC(abtb, stat); break; \
case XFS_BTNUM_CNT: __XFS_BTREE_STATS_INC(abtc, stat); break; \
case XFS_BTNUM_BMAP: __XFS_BTREE_STATS_INC(bmbt, stat); break; \
case XFS_BTNUM_INO: __XFS_BTREE_STATS_INC(ibt, stat); break; \
case XFS_BTNUM_FINO: __XFS_BTREE_STATS_INC(fibt, stat); break; \
case XFS_BTNUM_BNO: __XFS_BTREE_STATS_INC(__mp, abtb, stat); break; \
case XFS_BTNUM_CNT: __XFS_BTREE_STATS_INC(__mp, abtc, stat); break; \
case XFS_BTNUM_BMAP: __XFS_BTREE_STATS_INC(__mp, bmbt, stat); break; \
case XFS_BTNUM_INO: __XFS_BTREE_STATS_INC(__mp, ibt, stat); break; \
case XFS_BTNUM_FINO: __XFS_BTREE_STATS_INC(__mp, fibt, stat); break; \
case XFS_BTNUM_MAX: ASSERT(0); /* fucking gcc */ ; break; \
} \
} while (0)

#define __XFS_BTREE_STATS_ADD(type, stat, val) \
XFS_STATS_ADD(xs_ ## type ## _2_ ## stat, val)
#define __XFS_BTREE_STATS_ADD(mp, type, stat, val) \
XFS_STATS_ADD(mp, xs_ ## type ## _2_ ## stat, val)
#define XFS_BTREE_STATS_ADD(cur, stat, val) \
do { \
struct xfs_mount *__mp = cur->bc_mp; \
switch (cur->bc_btnum) { \
case XFS_BTNUM_BNO: __XFS_BTREE_STATS_ADD(abtb, stat, val); break; \
case XFS_BTNUM_CNT: __XFS_BTREE_STATS_ADD(abtc, stat, val); break; \
case XFS_BTNUM_BMAP: __XFS_BTREE_STATS_ADD(bmbt, stat, val); break; \
case XFS_BTNUM_INO: __XFS_BTREE_STATS_ADD(ibt, stat, val); break; \
case XFS_BTNUM_FINO: __XFS_BTREE_STATS_ADD(fibt, stat, val); break; \
case XFS_BTNUM_MAX: ASSERT(0); /* fucking gcc */ ; break; \
case XFS_BTNUM_BNO: \
__XFS_BTREE_STATS_ADD(__mp, abtb, stat, val); break; \
case XFS_BTNUM_CNT: \
__XFS_BTREE_STATS_ADD(__mp, abtc, stat, val); break; \
case XFS_BTNUM_BMAP: \
__XFS_BTREE_STATS_ADD(__mp, bmbt, stat, val); break; \
case XFS_BTNUM_INO: \
__XFS_BTREE_STATS_ADD(__mp, ibt, stat, val); break; \
case XFS_BTNUM_FINO: \
__XFS_BTREE_STATS_ADD(__mp, fibt, stat, val); break; \
case XFS_BTNUM_MAX: ASSERT(0); /* fucking gcc */ ; break; \
} \
} while (0)

Expand Down
6 changes: 3 additions & 3 deletions fs/xfs/libxfs/xfs_dir2.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ xfs_dir_createname(
rval = xfs_dir_ino_validate(tp->t_mountp, inum);
if (rval)
return rval;
XFS_STATS_INC(xs_dir_create);
XFS_STATS_INC(dp->i_mount, xs_dir_create);
}

args = kmem_zalloc(sizeof(*args), KM_SLEEP | KM_NOFS);
Expand Down Expand Up @@ -365,7 +365,7 @@ xfs_dir_lookup(
int lock_mode;

ASSERT(S_ISDIR(dp->i_d.di_mode));
XFS_STATS_INC(xs_dir_lookup);
XFS_STATS_INC(dp->i_mount, xs_dir_lookup);

/*
* We need to use KM_NOFS here so that lockdep will not throw false
Expand Down Expand Up @@ -444,7 +444,7 @@ xfs_dir_removename(
int v; /* type-checking value */

ASSERT(S_ISDIR(dp->i_d.di_mode));
XFS_STATS_INC(xs_dir_remove);
XFS_STATS_INC(dp->i_mount, xs_dir_remove);

args = kmem_zalloc(sizeof(*args), KM_SLEEP | KM_NOFS);
if (!args)
Expand Down
2 changes: 1 addition & 1 deletion fs/xfs/xfs_attr_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ xfs_attr_list_int(
xfs_inode_t *dp = context->dp;
uint lock_mode;

XFS_STATS_INC(xs_attr_list);
XFS_STATS_INC(dp->i_mount, xs_attr_list);

if (XFS_FORCED_SHUTDOWN(dp->i_mount))
return -EIO;
Expand Down
18 changes: 9 additions & 9 deletions fs/xfs/xfs_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ _xfs_buf_alloc(
atomic_set(&bp->b_pin_count, 0);
init_waitqueue_head(&bp->b_waiters);

XFS_STATS_INC(xb_create);
XFS_STATS_INC(target->bt_mount, xb_create);
trace_xfs_buf_init(bp, _RET_IP_);

return bp;
Expand Down Expand Up @@ -357,12 +357,12 @@ xfs_buf_allocate_memory(
"possible memory allocation deadlock in %s (mode:0x%x)",
__func__, gfp_mask);

XFS_STATS_INC(xb_page_retries);
XFS_STATS_INC(bp->b_target->bt_mount, xb_page_retries);
congestion_wait(BLK_RW_ASYNC, HZ/50);
goto retry;
}

XFS_STATS_INC(xb_page_found);
XFS_STATS_INC(bp->b_target->bt_mount, xb_page_found);

nbytes = min_t(size_t, size, PAGE_SIZE - offset);
size -= nbytes;
Expand Down Expand Up @@ -516,7 +516,7 @@ _xfs_buf_find(
new_bp->b_pag = pag;
spin_unlock(&pag->pag_buf_lock);
} else {
XFS_STATS_INC(xb_miss_locked);
XFS_STATS_INC(btp->bt_mount, xb_miss_locked);
spin_unlock(&pag->pag_buf_lock);
xfs_perag_put(pag);
}
Expand All @@ -529,11 +529,11 @@ _xfs_buf_find(
if (!xfs_buf_trylock(bp)) {
if (flags & XBF_TRYLOCK) {
xfs_buf_rele(bp);
XFS_STATS_INC(xb_busy_locked);
XFS_STATS_INC(btp->bt_mount, xb_busy_locked);
return NULL;
}
xfs_buf_lock(bp);
XFS_STATS_INC(xb_get_locked_waited);
XFS_STATS_INC(btp->bt_mount, xb_get_locked_waited);
}

/*
Expand All @@ -549,7 +549,7 @@ _xfs_buf_find(
}

trace_xfs_buf_find(bp, flags, _RET_IP_);
XFS_STATS_INC(xb_get_locked);
XFS_STATS_INC(btp->bt_mount, xb_get_locked);
return bp;
}

Expand Down Expand Up @@ -603,7 +603,7 @@ xfs_buf_get_map(
}
}

XFS_STATS_INC(xb_get);
XFS_STATS_INC(target->bt_mount, xb_get);
trace_xfs_buf_get(bp, flags, _RET_IP_);
return bp;
}
Expand Down Expand Up @@ -643,7 +643,7 @@ xfs_buf_read_map(
trace_xfs_buf_read(bp, flags, _RET_IP_);

if (!XFS_BUF_ISDONE(bp)) {
XFS_STATS_INC(xb_get_read);
XFS_STATS_INC(target->bt_mount, xb_get_read);
bp->b_ops = ops;
_xfs_buf_read(bp, flags);
} else if (flags & XBF_ASYNC) {
Expand Down
2 changes: 1 addition & 1 deletion fs/xfs/xfs_dir2_readdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ xfs_readdir(
return -EIO;

ASSERT(S_ISDIR(dp->i_d.di_mode));
XFS_STATS_INC(xs_dir_getdents);
XFS_STATS_INC(dp->i_mount, xs_dir_getdents);

args.dp = dp;
args.geo = dp->i_mount->m_dir_geo;
Expand Down
14 changes: 7 additions & 7 deletions fs/xfs/xfs_dquot.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ xfs_qm_dqdestroy(
ASSERT(list_empty(&dqp->q_lru));

mutex_destroy(&dqp->q_qlock);
kmem_zone_free(xfs_qm_dqzone, dqp);

XFS_STATS_DEC(xs_qm_dquot);
XFS_STATS_DEC(dqp->q_mount, xs_qm_dquot);
kmem_zone_free(xfs_qm_dqzone, dqp);
}

/*
Expand Down Expand Up @@ -605,7 +605,7 @@ xfs_qm_dqread(
break;
}

XFS_STATS_INC(xs_qm_dquot);
XFS_STATS_INC(mp, xs_qm_dquot);

trace_xfs_dqread(dqp);

Expand Down Expand Up @@ -747,12 +747,12 @@ xfs_qm_dqget(
mutex_unlock(&qi->qi_tree_lock);

trace_xfs_dqget_hit(dqp);
XFS_STATS_INC(xs_qm_dqcachehits);
XFS_STATS_INC(mp, xs_qm_dqcachehits);
*O_dqpp = dqp;
return 0;
}
mutex_unlock(&qi->qi_tree_lock);
XFS_STATS_INC(xs_qm_dqcachemisses);
XFS_STATS_INC(mp, xs_qm_dqcachemisses);

/*
* Dquot cache miss. We don't want to keep the inode lock across
Expand Down Expand Up @@ -806,7 +806,7 @@ xfs_qm_dqget(
mutex_unlock(&qi->qi_tree_lock);
trace_xfs_dqget_dup(dqp);
xfs_qm_dqdestroy(dqp);
XFS_STATS_INC(xs_qm_dquot_dups);
XFS_STATS_INC(mp, xs_qm_dquot_dups);
goto restart;
}

Expand Down Expand Up @@ -846,7 +846,7 @@ xfs_qm_dqput(
trace_xfs_dqput_free(dqp);

if (list_lru_add(&qi->qi_lru, &dqp->q_lru))
XFS_STATS_INC(xs_qm_dquot_unused);
XFS_STATS_INC(dqp->q_mount, xs_qm_dquot_unused);
}
xfs_dqunlock(dqp);
}
Expand Down
Loading

0 comments on commit ff6d6af

Please sign in to comment.