Skip to contentSkip to conversation

fix inode stats with lots of metafiles

PATCH In review Christoph Hellwig 4 participants 13 messages Feb 2 – Feb 25 XFS filesystem

lore
Share & tools
lore
#0 lore raw

Hi all,

the second patch fixes the active inode/vnode count on file systems with lots of metafiles, i.e. on SMR hard disks.

The first patch cleans up the counters a bit to prepare for that.

Subject:

 libxfs/xfs_inode_buf.c |    4 ++++
 libxfs/xfs_metafile.c  |    5 +++++
 xfs_icache.c           |    9 ++++++---
 xfs_stats.c            |   17 +++++++++++------
 xfs_stats.h            |   19 ++++++++++---------
 xfs_super.c            |    4 ++--
 6 files changed, 38 insertions(+), 20 deletions(-)
#1 lore raw

PATCH 1/2 xfs: cleanup inode counter stats

Most of the are unused, so mark them as such. Give the remaining ones names that match their use instead of the historic IRIX ones based on vnodes. Note that the names are purely internal to the XFS code, the user interface is based on section names and arrays of counters.

---
 fs/xfs/xfs_icache.c |  6 +++---
 fs/xfs/xfs_stats.c  | 10 +++++-----
 fs/xfs/xfs_stats.h  | 16 ++++++++--------
 fs/xfs/xfs_super.c  |  4 ++--
 4 files changed, 18 insertions(+), 18 deletions(-)
fs/xfs/xfs_icache.c +3 -3
index dbaab4ae709f..f76c6decdaa3 100644
@@ -106,7 +106,7 @@ xfs_inode_alloc(
 	mapping_set_folio_min_order(VFS_I(ip)->i_mapping,
 				    M_IGEO(mp)->min_folio_order);
 
-	XFS_STATS_INC(mp, vn_active);
+	XFS_STATS_INC(mp, xs_inodes_active);
 	ASSERT(atomic_read(&ip->i_pincount) == 0);
 	ASSERT(ip->i_ino == 0);
 
@@ -172,7 +172,7 @@ __xfs_inode_free(
 	/* asserts to verify all state is correct here */
 	ASSERT(atomic_read(&ip->i_pincount) == 0);
 	ASSERT(!ip->i_itemp || list_empty(&ip->i_itemp->ili_item.li_bio_list));
-	XFS_STATS_DEC(ip->i_mount, vn_active);
+	XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
 
 	call_rcu(&VFS_I(ip)->i_rcu, xfs_inode_free_callback);
 }
@@ -2234,7 +2234,7 @@ xfs_inode_mark_reclaimable(
 	struct xfs_mount	*mp = ip->i_mount;
 	bool			need_inactive;
 
-	XFS_STATS_INC(mp, vn_reclaim);
+	XFS_STATS_INC(mp, xs_inode_mark_reclaimable);
 
 	/*
 	 * We should never get here with any of the reclaim flags already set.
fs/xfs/xfs_stats.c +5 -5
index 017db0361cd8..bc4a5d6dc795 100644
@@ -42,7 +42,7 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
 		{ "xstrat",		xfsstats_offset(xs_write_calls)	},
 		{ "rw",			xfsstats_offset(xs_attr_get)	},
 		{ "attr",		xfsstats_offset(xs_iflush_count)},
-		{ "icluster",		xfsstats_offset(vn_active)	},
+		{ "icluster",		xfsstats_offset(xs_inodes_active) },
 		{ "vnodes",		xfsstats_offset(xb_get)		},
 		{ "buf",		xfsstats_offset(xs_abtb_2)	},
 		{ "abtb2",		xfsstats_offset(xs_abtc_2)	},
@@ -100,15 +100,15 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
 void xfs_stats_clearall(struct xfsstats __percpu *stats)
 {
 	int		c;
-	uint32_t	vn_active;
+	uint32_t	xs_inodes_active;
 
 	xfs_notice(NULL, "Clearing xfsstats");
 	for_each_possible_cpu(c) {
 		preempt_disable();
-		/* save vn_active, it's a universal truth! */
-		vn_active = per_cpu_ptr(stats, c)->s.vn_active;
+		/* save xs_inodes_active, it's a universal truth! */
+		xs_inodes_active = per_cpu_ptr(stats, c)->s.xs_inodes_active;
 		memset(per_cpu_ptr(stats, c), 0, sizeof(*stats));
-		per_cpu_ptr(stats, c)->s.vn_active = vn_active;
+		per_cpu_ptr(stats, c)->s.xs_inodes_active = xs_inodes_active;
 		preempt_enable();
 	}
 }
fs/xfs/xfs_stats.h +8 -8
index 153d2381d0a8..64bc0cc18126 100644
@@ -100,14 +100,14 @@ struct __xfsstats {
 	uint32_t		xs_iflush_count;
 	uint32_t		xs_icluster_flushcnt;
 	uint32_t		xs_icluster_flushinode;
-	uint32_t		vn_active;	/* # vnodes not on free lists */
-	uint32_t		vn_alloc;	/* # times vn_alloc called */
-	uint32_t		vn_get;		/* # times vn_get called */
-	uint32_t		vn_hold;	/* # times vn_hold called */
-	uint32_t		vn_rele;	/* # times vn_rele called */
-	uint32_t		vn_reclaim;	/* # times vn_reclaim called */
-	uint32_t		vn_remove;	/* # times vn_remove called */
-	uint32_t		vn_free;	/* # times vn_free called */
+	uint32_t		xs_inodes_active;
+	uint32_t		__unused_vn_alloc;
+	uint32_t		__unused_vn_get;
+	uint32_t		__unused_vn_hold;
+	uint32_t		xs_inode_destroy;
+	uint32_t		xs_inode_destroy2; /* same as xs_inode_destroy */
+	uint32_t		xs_inode_mark_reclaimable;
+	uint32_t		__unused_vn_free;
 	uint32_t		xb_get;
 	uint32_t		xb_create;
 	uint32_t		xb_get_locked;
fs/xfs/xfs_super.c +2 -2
index 149b659e1692..3f25a0001a61 100644
@@ -725,8 +725,8 @@ xfs_fs_destroy_inode(
 	trace_xfs_destroy_inode(ip);
 
 	ASSERT(!rwsem_is_locked(&inode->i_rwsem));
-	XFS_STATS_INC(ip->i_mount, vn_rele);
-	XFS_STATS_INC(ip->i_mount, vn_remove);
+	XFS_STATS_INC(ip->i_mount, xs_inode_destroy);
+	XFS_STATS_INC(ip->i_mount, xs_inode_destroy2);
 	xfs_inode_mark_reclaimable(ip);
 }
 
Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH 1/2] xfs: cleanup inode counter stats

Quoted 1 line · Christoph Hellwig

Most of the are unused, so mark them as such. Give the remaining ones

Nit - Typo - "Most of the are <...>" -> "Most of them are <...>"

Quoted 86 lines

names that match their use instead of the historic IRIX ones based on vnodes. Note that the names are purely internal to the XFS code, the user interface is based on section names and arrays of counters.

---
 fs/xfs/xfs_icache.c |  6 +++---
 fs/xfs/xfs_stats.c  | 10 +++++-----
 fs/xfs/xfs_stats.h  | 16 ++++++++--------
 fs/xfs/xfs_super.c  |  4 ++--
 4 files changed, 18 insertions(+), 18 deletions(-)
fs/xfs/xfs_icache.c +3 -3
index dbaab4ae709f..f76c6decdaa3 100644
@@ -106,7 +106,7 @@ xfs_inode_alloc(
 	mapping_set_folio_min_order(VFS_I(ip)->i_mapping,
 				    M_IGEO(mp)->min_folio_order);
 
-	XFS_STATS_INC(mp, vn_active);
+	XFS_STATS_INC(mp, xs_inodes_active);
 	ASSERT(atomic_read(&ip->i_pincount) == 0);
 	ASSERT(ip->i_ino == 0);
 
@@ -172,7 +172,7 @@ __xfs_inode_free(
 	/* asserts to verify all state is correct here */
 	ASSERT(atomic_read(&ip->i_pincount) == 0);
 	ASSERT(!ip->i_itemp || list_empty(&ip->i_itemp->ili_item.li_bio_list));
-	XFS_STATS_DEC(ip->i_mount, vn_active);
+	XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
 
 	call_rcu(&VFS_I(ip)->i_rcu, xfs_inode_free_callback);
 }
@@ -2234,7 +2234,7 @@ xfs_inode_mark_reclaimable(
 	struct xfs_mount	*mp = ip->i_mount;
 	bool			need_inactive;
 
-	XFS_STATS_INC(mp, vn_reclaim);
+	XFS_STATS_INC(mp, xs_inode_mark_reclaimable);
 
 	/*
 	 * We should never get here with any of the reclaim flags already set.
fs/xfs/xfs_stats.c +5 -5
index 017db0361cd8..bc4a5d6dc795 100644
@@ -42,7 +42,7 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
 		{ "xstrat",		xfsstats_offset(xs_write_calls)	},
 		{ "rw",			xfsstats_offset(xs_attr_get)	},
 		{ "attr",		xfsstats_offset(xs_iflush_count)},
-		{ "icluster",		xfsstats_offset(vn_active)	},
+		{ "icluster",		xfsstats_offset(xs_inodes_active) },
 		{ "vnodes",		xfsstats_offset(xb_get)		},
 		{ "buf",		xfsstats_offset(xs_abtb_2)	},
 		{ "abtb2",		xfsstats_offset(xs_abtc_2)	},
@@ -100,15 +100,15 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
 void xfs_stats_clearall(struct xfsstats __percpu *stats)
 {
 	int		c;
-	uint32_t	vn_active;
+	uint32_t	xs_inodes_active;
 
 	xfs_notice(NULL, "Clearing xfsstats");
 	for_each_possible_cpu(c) {
 		preempt_disable();
-		/* save vn_active, it's a universal truth! */
-		vn_active = per_cpu_ptr(stats, c)->s.vn_active;
+		/* save xs_inodes_active, it's a universal truth! */
+		xs_inodes_active = per_cpu_ptr(stats, c)->s.xs_inodes_active;
 		memset(per_cpu_ptr(stats, c), 0, sizeof(*stats));
-		per_cpu_ptr(stats, c)->s.vn_active = vn_active;
+		per_cpu_ptr(stats, c)->s.xs_inodes_active = xs_inodes_active;
 		preempt_enable();
 	}
 }
fs/xfs/xfs_stats.h +0 -2
index 153d2381d0a8..64bc0cc18126 100644
@@ -100,14 +100,14 @@ struct __xfsstats {
 	uint32_t		xs_iflush_count;
 	uint32_t		xs_icluster_flushcnt;
 	uint32_t		xs_icluster_flushinode;
-	uint32_t		vn_active;	/* # vnodes not on free lists */
-	uint32_t		vn_alloc;	/* # times vn_alloc called */

fs/xfs/xfs_stats.h struct __xfsstats { · line 106

Quoted 10 lines
fs/xfs/xfs_stats.h +4 -6
-	uint32_t		vn_get;		/* # times vn_get called */
-	uint32_t		vn_hold;	/* # times vn_hold called */
-	uint32_t		vn_rele;	/* # times vn_rele called */
-	uint32_t		vn_reclaim;	/* # times vn_reclaim called */
-	uint32_t		vn_remove;	/* # times vn_remove called */
-	uint32_t		vn_free;	/* # times vn_free called */
+	uint32_t		xs_inodes_active;
+	uint32_t		__unused_vn_alloc;
+	uint32_t		__unused_vn_get;
+	uint32_t		__unused_vn_hold;

Any reason to keep the unused field?

Quoted 12 lines
fs/xfs/xfs_stats.h +4 -0
+	uint32_t		xs_inode_destroy;
+	uint32_t		xs_inode_destroy2; /* same as xs_inode_destroy */
+	uint32_t		xs_inode_mark_reclaimable;
+	uint32_t		__unused_vn_free;
 	uint32_t		xb_get;
 	uint32_t		xb_create;
 	uint32_t		xb_get_locked;
fs/xfs/xfs_super.c +0 -0
index 149b659e1692..3f25a0001a61 100644

fs/xfs/xfs_super.c xfs_fs_destroy_inode( · line 729

Quoted 7 lines
fs/xfs/xfs_super.c +2 -2
@@ -725,8 +725,8 @@ xfs_fs_destroy_inode(
 	trace_xfs_destroy_inode(ip);
 
 	ASSERT(!rwsem_is_locked(&inode->i_rwsem));
-	XFS_STATS_INC(ip->i_mount, vn_rele);
-	XFS_STATS_INC(ip->i_mount, vn_remove);
+	XFS_STATS_INC(ip->i_mount, xs_inode_destroy);
+	XFS_STATS_INC(ip->i_mount, xs_inode_destroy2);

So this patch basically renames some of the fields from the older legacy conventions (concept of vn/virtual-inodes) to new linux-XFS conventions. Based on this understanding, this change looks okay to me.

Quoted 3 lines
fs/xfs/xfs_super.c +0 -0
 	xfs_inode_mark_reclaimable(ip);
 }
 
#3 lore raw

Re: [PATCH 1/2] xfs: cleanup inode counter stats

Quoted 4 lines · Nirjhar Roy (IBM)
Quoted 1 line · Christoph Hellwig

Most of the are unused, so mark them as such. Give the remaining ones

Nit - Typo - "Most of the are <...>" -> "Most of them are <...>"

Yes, thanks.

Quoted 5 lines

fs/xfs/xfs_stats.h struct __xfsstats { · line 106

Quoted 4 lines
fs/xfs/xfs_stats.h +4 -0
+	uint32_t		xs_inodes_active;
+	uint32_t		__unused_vn_alloc;
+	uint32_t		__unused_vn_get;
+	uint32_t		__unused_vn_hold;

Any reason to keep the unused field?

If we drop the unused fields the sysfs output would change.

Reviewed-by on v1 1/2
#4 lore raw

Re: [PATCH 1/2] xfs: cleanup inode counter stats

In reply to Christoph Hellwig
Quoted 6 lines · Christoph Hellwig

Most of the are unused, so mark them as such. Give the remaining ones names that match their use instead of the historic IRIX ones based on vnodes. Note that the names are purely internal to the XFS code, the user interface is based on section names and arrays of counters.

With the s/of the/of them/ typo that Nirjhar mentioned fixed, this looks fine to me. I've long thought those fields were unused, so I'm glad they're finally getting cleaned out.

(and yes I agree that the struct layout stuff means we should just leave the fields and maybe reuse the space some day; and not otherwise change the struct layout)

--D

Quoted 117 lines
---
 fs/xfs/xfs_icache.c |  6 +++---
 fs/xfs/xfs_stats.c  | 10 +++++-----
 fs/xfs/xfs_stats.h  | 16 ++++++++--------
 fs/xfs/xfs_super.c  |  4 ++--
 4 files changed, 18 insertions(+), 18 deletions(-)
fs/xfs/xfs_icache.c +3 -3
index dbaab4ae709f..f76c6decdaa3 100644
@@ -106,7 +106,7 @@ xfs_inode_alloc(
 	mapping_set_folio_min_order(VFS_I(ip)->i_mapping,
 				    M_IGEO(mp)->min_folio_order);
 
-	XFS_STATS_INC(mp, vn_active);
+	XFS_STATS_INC(mp, xs_inodes_active);
 	ASSERT(atomic_read(&ip->i_pincount) == 0);
 	ASSERT(ip->i_ino == 0);
 
@@ -172,7 +172,7 @@ __xfs_inode_free(
 	/* asserts to verify all state is correct here */
 	ASSERT(atomic_read(&ip->i_pincount) == 0);
 	ASSERT(!ip->i_itemp || list_empty(&ip->i_itemp->ili_item.li_bio_list));
-	XFS_STATS_DEC(ip->i_mount, vn_active);
+	XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
 
 	call_rcu(&VFS_I(ip)->i_rcu, xfs_inode_free_callback);
 }
@@ -2234,7 +2234,7 @@ xfs_inode_mark_reclaimable(
 	struct xfs_mount	*mp = ip->i_mount;
 	bool			need_inactive;
 
-	XFS_STATS_INC(mp, vn_reclaim);
+	XFS_STATS_INC(mp, xs_inode_mark_reclaimable);
 
 	/*
 	 * We should never get here with any of the reclaim flags already set.
fs/xfs/xfs_stats.c +5 -5
index 017db0361cd8..bc4a5d6dc795 100644
@@ -42,7 +42,7 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
 		{ "xstrat",		xfsstats_offset(xs_write_calls)	},
 		{ "rw",			xfsstats_offset(xs_attr_get)	},
 		{ "attr",		xfsstats_offset(xs_iflush_count)},
-		{ "icluster",		xfsstats_offset(vn_active)	},
+		{ "icluster",		xfsstats_offset(xs_inodes_active) },
 		{ "vnodes",		xfsstats_offset(xb_get)		},
 		{ "buf",		xfsstats_offset(xs_abtb_2)	},
 		{ "abtb2",		xfsstats_offset(xs_abtc_2)	},
@@ -100,15 +100,15 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
 void xfs_stats_clearall(struct xfsstats __percpu *stats)
 {
 	int		c;
-	uint32_t	vn_active;
+	uint32_t	xs_inodes_active;
 
 	xfs_notice(NULL, "Clearing xfsstats");
 	for_each_possible_cpu(c) {
 		preempt_disable();
-		/* save vn_active, it's a universal truth! */
-		vn_active = per_cpu_ptr(stats, c)->s.vn_active;
+		/* save xs_inodes_active, it's a universal truth! */
+		xs_inodes_active = per_cpu_ptr(stats, c)->s.xs_inodes_active;
 		memset(per_cpu_ptr(stats, c), 0, sizeof(*stats));
-		per_cpu_ptr(stats, c)->s.vn_active = vn_active;
+		per_cpu_ptr(stats, c)->s.xs_inodes_active = xs_inodes_active;
 		preempt_enable();
 	}
 }
fs/xfs/xfs_stats.h +8 -8
index 153d2381d0a8..64bc0cc18126 100644
@@ -100,14 +100,14 @@ struct __xfsstats {
 	uint32_t		xs_iflush_count;
 	uint32_t		xs_icluster_flushcnt;
 	uint32_t		xs_icluster_flushinode;
-	uint32_t		vn_active;	/* # vnodes not on free lists */
-	uint32_t		vn_alloc;	/* # times vn_alloc called */
-	uint32_t		vn_get;		/* # times vn_get called */
-	uint32_t		vn_hold;	/* # times vn_hold called */
-	uint32_t		vn_rele;	/* # times vn_rele called */
-	uint32_t		vn_reclaim;	/* # times vn_reclaim called */
-	uint32_t		vn_remove;	/* # times vn_remove called */
-	uint32_t		vn_free;	/* # times vn_free called */
+	uint32_t		xs_inodes_active;
+	uint32_t		__unused_vn_alloc;
+	uint32_t		__unused_vn_get;
+	uint32_t		__unused_vn_hold;
+	uint32_t		xs_inode_destroy;
+	uint32_t		xs_inode_destroy2; /* same as xs_inode_destroy */
+	uint32_t		xs_inode_mark_reclaimable;
+	uint32_t		__unused_vn_free;
 	uint32_t		xb_get;
 	uint32_t		xb_create;
 	uint32_t		xb_get_locked;
fs/xfs/xfs_super.c +2 -2
index 149b659e1692..3f25a0001a61 100644
@@ -725,8 +725,8 @@ xfs_fs_destroy_inode(
 	trace_xfs_destroy_inode(ip);
 
 	ASSERT(!rwsem_is_locked(&inode->i_rwsem));
-	XFS_STATS_INC(ip->i_mount, vn_rele);
-	XFS_STATS_INC(ip->i_mount, vn_remove);
+	XFS_STATS_INC(ip->i_mount, xs_inode_destroy);
+	XFS_STATS_INC(ip->i_mount, xs_inode_destroy2);
 	xfs_inode_mark_reclaimable(ip);
 }
 
Signature · 1 line
2.47.3
#5 lore raw

PATCH 2/2 xfs: remove metafile inodes from the active inode stat

In reply to Christoph Hellwig

The active inode (or active vnode until recently) stat can get much larger than expected on file systems with a lot of metafile inodes like zoned file systems on SMR hard disks with 10.000s of rtg rmap inodes.

Remove all metafile inodes from the active counter to make it more useful to track actual workloads and add a separate counter for active metafile inodes.

This fixes xfs/177 on SMR hard drives.

---
 fs/xfs/libxfs/xfs_inode_buf.c |  4 ++++
 fs/xfs/libxfs/xfs_metafile.c  |  5 +++++
 fs/xfs/xfs_icache.c           |  5 ++++-
 fs/xfs/xfs_stats.c            | 11 ++++++++---
 fs/xfs/xfs_stats.h            |  3 ++-
 5 files changed, 23 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_inode_buf.c +4 -0
index dcc9566ef5fe..91a499ced4e8 100644
@@ -268,6 +268,10 @@ xfs_inode_from_disk(
 	}
 	if (xfs_is_reflink_inode(ip))
 		xfs_ifork_init_cow(ip);
+	if (xfs_is_metadir_inode(ip)) {
+		XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
+		XFS_STATS_INC(ip->i_mount, xs_inodes_meta);
+	}
 	return 0;
 
 out_destroy_data_fork:
fs/xfs/libxfs/xfs_metafile.c +5 -0
index cf239f862212..71f004e9dc64 100644
@@ -61,6 +61,9 @@ xfs_metafile_set_iflag(
 	ip->i_diflags2 |= XFS_DIFLAG2_METADATA;
 	ip->i_metatype = metafile_type;
 	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+
+	XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
+	XFS_STATS_INC(ip->i_mount, xs_inodes_meta);
 }
 
 /* Clear the metadata directory inode flag. */
@@ -74,6 +77,8 @@ xfs_metafile_clear_iflag(
 
 	ip->i_diflags2 &= ~XFS_DIFLAG2_METADATA;
 	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+	XFS_STATS_INC(ip->i_mount, xs_inodes_active);
+	XFS_STATS_DEC(ip->i_mount, xs_inodes_meta);
 }
 
 /*
fs/xfs/xfs_icache.c +4 -1
index f76c6decdaa3..f2d4294efd37 100644
@@ -172,7 +172,10 @@ __xfs_inode_free(
 	/* asserts to verify all state is correct here */
 	ASSERT(atomic_read(&ip->i_pincount) == 0);
 	ASSERT(!ip->i_itemp || list_empty(&ip->i_itemp->ili_item.li_bio_list));
-	XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
+	if (xfs_is_metadir_inode(ip))
+		XFS_STATS_DEC(ip->i_mount, xs_inodes_meta);
+	else
+		XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
 
 	call_rcu(&VFS_I(ip)->i_rcu, xfs_inode_free_callback);
 }
fs/xfs/xfs_stats.c +8 -3
index bc4a5d6dc795..c13d600732c9 100644
@@ -59,7 +59,8 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
 		{ "rtrefcntbt",		xfsstats_offset(xs_qm_dqreclaims)},
 		/* we print both series of quota information together */
 		{ "qm",			xfsstats_offset(xs_gc_read_calls)},
-		{ "zoned",		xfsstats_offset(__pad1)},
+		{ "zoned",		xfsstats_offset(xs_inodes_meta)},
+		{ "metafile",		xfsstats_offset(xs_xstrat_bytes)},
 	};
 
 	/* Loop over all stats groups */
@@ -99,16 +100,20 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
 
 void xfs_stats_clearall(struct xfsstats __percpu *stats)
 {
+	uint32_t	xs_inodes_active, xs_inodes_meta;
 	int		c;
-	uint32_t	xs_inodes_active;
 
 	xfs_notice(NULL, "Clearing xfsstats");
 	for_each_possible_cpu(c) {
 		preempt_disable();
-		/* save xs_inodes_active, it's a universal truth! */
+		/*
+		 * Save the active / meta inode counters, as they are stateful.
+		 */
 		xs_inodes_active = per_cpu_ptr(stats, c)->s.xs_inodes_active;
+		xs_inodes_meta = per_cpu_ptr(stats, c)->s.xs_inodes_meta;
 		memset(per_cpu_ptr(stats, c), 0, sizeof(*stats));
 		per_cpu_ptr(stats, c)->s.xs_inodes_active = xs_inodes_active;
+		per_cpu_ptr(stats, c)->s.xs_inodes_meta = xs_inodes_meta;
 		preempt_enable();
 	}
 }
fs/xfs/xfs_stats.h +2 -1
index 64bc0cc18126..57c32b86c358 100644
@@ -142,7 +142,8 @@ struct __xfsstats {
 	uint32_t		xs_gc_read_calls;
 	uint32_t		xs_gc_write_calls;
 	uint32_t		xs_gc_zone_reset_calls;
-	uint32_t		__pad1;
+/* Metafile counters */
+	uint32_t		xs_inodes_meta;
 /* Extra precision counters */
 	uint64_t		xs_xstrat_bytes;
 	uint64_t		xs_write_bytes;
Signature · 1 line
2.47.3
#6 lore raw

Re: [PATCH 2/2] xfs: remove metafile inodes from the active inode stat

Quoted 3 lines · Christoph Hellwig

The active inode (or active vnode until recently) stat can get much larger than expected on file systems with a lot of metafile inodes like zoned file systems on SMR hard disks with 10.000s of rtg rmap inodes.

And this was causing (or could have caused) some sort of counter overflows or something?

Quoted 6 lines

Remove all metafile inodes from the active counter to make it more useful to track actual workloads and add a separate counter for active metafile inodes.

This fixes xfs/177 on SMR hard drives.

I can see that xfs/177 has a couple of sub-test cases (like Round 1,2, ...) - do you remember if 1 particular round was causing problems or were there issues with all/most of them?

Quoted 15 lines
---
 fs/xfs/libxfs/xfs_inode_buf.c |  4 ++++
 fs/xfs/libxfs/xfs_metafile.c  |  5 +++++
 fs/xfs/xfs_icache.c           |  5 ++++-
 fs/xfs/xfs_stats.c            | 11 ++++++++---
 fs/xfs/xfs_stats.h            |  3 ++-
 5 files changed, 23 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_inode_buf.c +0 -0
index dcc9566ef5fe..91a499ced4e8 100644

fs/xfs/libxfs/xfs_inode_buf.c xfs_inode_from_disk( · line 273

Quoted 6 lines
fs/xfs/libxfs/xfs_inode_buf.c +3 -0
@@ -268,6 +268,10 @@ xfs_inode_from_disk(
 	}
 	if (xfs_is_reflink_inode(ip))
 		xfs_ifork_init_cow(ip);
+	if (xfs_is_metadir_inode(ip)) {
+		XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
+		XFS_STATS_INC(ip->i_mount, xs_inodes_meta);

So is it like then there is a state(or at some function) where xs_inodes_active counter was bumped up even though "ip" was a metadir inode and here in the above line it is corrected(i.e, decremented by 1) and xs_inodes_meta is incremented - shouldn't the appropriate counter have been directly bumped up whenever it was created? Something similar to what is being done in __xfs_inode_free()? For example, in xfs_inode_alloc() I can see a XFS_STATS_INC(mp, vn_active) - shouldn't we bump the appropriate counter(xs_inode_{active or meta} there directly? Can you please let me know if my understanding is correct or am I missing something?

Quoted 85 lines
fs/xfs/libxfs/xfs_inode_buf.c +1 -0
+	}
 	return 0;
 
 out_destroy_data_fork:
fs/xfs/libxfs/xfs_metafile.c +5 -0
index cf239f862212..71f004e9dc64 100644
@@ -61,6 +61,9 @@ xfs_metafile_set_iflag(
 	ip->i_diflags2 |= XFS_DIFLAG2_METADATA;
 	ip->i_metatype = metafile_type;
 	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+
+	XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
+	XFS_STATS_INC(ip->i_mount, xs_inodes_meta);
 }
 
 /* Clear the metadata directory inode flag. */
@@ -74,6 +77,8 @@ xfs_metafile_clear_iflag(
 
 	ip->i_diflags2 &= ~XFS_DIFLAG2_METADATA;
 	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+	XFS_STATS_INC(ip->i_mount, xs_inodes_active);
+	XFS_STATS_DEC(ip->i_mount, xs_inodes_meta);
 }
 
 /*
fs/xfs/xfs_icache.c +4 -1
index f76c6decdaa3..f2d4294efd37 100644
@@ -172,7 +172,10 @@ __xfs_inode_free(
 	/* asserts to verify all state is correct here */
 	ASSERT(atomic_read(&ip->i_pincount) == 0);
 	ASSERT(!ip->i_itemp || list_empty(&ip->i_itemp->ili_item.li_bio_list));
-	XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
+	if (xfs_is_metadir_inode(ip))
+		XFS_STATS_DEC(ip->i_mount, xs_inodes_meta);
+	else
+		XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
 
 	call_rcu(&VFS_I(ip)->i_rcu, xfs_inode_free_callback);
 }
fs/xfs/xfs_stats.c +8 -3
index bc4a5d6dc795..c13d600732c9 100644
@@ -59,7 +59,8 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
 		{ "rtrefcntbt",		xfsstats_offset(xs_qm_dqreclaims)},
 		/* we print both series of quota information together */
 		{ "qm",			xfsstats_offset(xs_gc_read_calls)},
-		{ "zoned",		xfsstats_offset(__pad1)},
+		{ "zoned",		xfsstats_offset(xs_inodes_meta)},
+		{ "metafile",		xfsstats_offset(xs_xstrat_bytes)},
 	};
 
 	/* Loop over all stats groups */
@@ -99,16 +100,20 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
 
 void xfs_stats_clearall(struct xfsstats __percpu *stats)
 {
+	uint32_t	xs_inodes_active, xs_inodes_meta;
 	int		c;
-	uint32_t	xs_inodes_active;
 
 	xfs_notice(NULL, "Clearing xfsstats");
 	for_each_possible_cpu(c) {
 		preempt_disable();
-		/* save xs_inodes_active, it's a universal truth! */
+		/*
+		 * Save the active / meta inode counters, as they are stateful.
+		 */
 		xs_inodes_active = per_cpu_ptr(stats, c)->s.xs_inodes_active;
+		xs_inodes_meta = per_cpu_ptr(stats, c)->s.xs_inodes_meta;
 		memset(per_cpu_ptr(stats, c), 0, sizeof(*stats));
 		per_cpu_ptr(stats, c)->s.xs_inodes_active = xs_inodes_active;
+		per_cpu_ptr(stats, c)->s.xs_inodes_meta = xs_inodes_meta;
 		preempt_enable();
 	}
 }
fs/xfs/xfs_stats.h +0 -0
index 64bc0cc18126..57c32b86c358 100644

fs/xfs/xfs_stats.h struct __xfsstats { · line 146

Quoted 6 lines
fs/xfs/xfs_stats.h +2 -1
@@ -142,7 +142,8 @@ struct __xfsstats {
 	uint32_t		xs_gc_read_calls;
 	uint32_t		xs_gc_write_calls;
 	uint32_t		xs_gc_zone_reset_calls;
-	uint32_t		__pad1;
+/* Metafile counters */
+	uint32_t		xs_inodes_meta;

uint64_t would be an overkill, isn't it?

This patch looks okay to me - I have some questions posted above. I have mostly looked into whether the appropriate checks for meta/normal inodes have been made, whether the counter updations are done correctly etc and from those perspectives - this intent of this patch looks okay to me. --NR

Quoted 3 lines
fs/xfs/xfs_stats.h +0 -0
 /* Extra precision counters */
 	uint64_t		xs_xstrat_bytes;
 	uint64_t		xs_write_bytes;
#7 lore raw

Re: [PATCH 2/2] xfs: remove metafile inodes from the active inode stat

Quoted 5 lines · Nirjhar Roy (IBM)
Quoted 3 lines · Christoph Hellwig

The active inode (or active vnode until recently) stat can get much larger than expected on file systems with a lot of metafile inodes like zoned file systems on SMR hard disks with 10.000s of rtg rmap inodes.

And this was causing (or could have caused) some sort of counter overflows or something?

Not really an overflow. But if you have a lot of metadir inodes it messes up the stats with extra counts that are not user visible.

Quoted 3 lines
Quoted 1 line

This fixes xfs/177 on SMR hard drives.

I can see that xfs/177 has a couple of sub-test cases (like Round 1,2, ...) - do you remember if 1 particular round was causing problems or were there issues with all/most of them?

Comparing the cached values to the expected ones.

Quoted 5 lines

So is it like then there is a state(or at some function) where xs_inodes_active counter was bumped up even though "ip" was a metadir inode and here in the above line it is corrected (i.e, decremented by 1) and xs_inodes_meta is incremented - shouldn't the appropriate counter have been directly bumped up whenever it was created?

xfs_inode_alloc doesn't know if the inode is going to be a meta inode, as it hasn't been read from disk yet for the common case. For the less common inode allocation case we'd know it, but passing it down would be a bit annoying.

Quoted 3 lines

fs/xfs/xfs_stats.h struct __xfsstats { · line 146

Quoted 2 lines
fs/xfs/xfs_stats.h +2 -0
+/* Metafile counters */
+	uint32_t		xs_inodes_meta;

uint64_t would be an overkill, isn't it?

Yes. Sticking to the same type as the active inodes here.

#8 lore raw

Re: [PATCH 2/2] xfs: remove metafile inodes from the active inode stat

Quoted 8 lines · Christoph Hellwig
Quoted 5 lines · Nirjhar Roy (IBM)
Quoted 3 lines · Christoph Hellwig

The active inode (or active vnode until recently) stat can get much larger than expected on file systems with a lot of metafile inodes like zoned file systems on SMR hard disks with 10.000s of rtg rmap inodes.

And this was causing (or could have caused) some sort of counter overflows or something?

Not really an overflow. But if you have a lot of metadir inodes it messes up the stats with extra counts that are not user visible.

Okay.

Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

This fixes xfs/177 on SMR hard drives.

I can see that xfs/177 has a couple of sub-test cases (like Round 1,2, ...) - do you remember if 1 particular round was causing problems or were there issues with all/most of them?

Comparing the cached values to the expected ones.

Noted.

Quoted 10 lines
Quoted 6 lines

So is it like then there is a state(or at some function) where xs_inodes_active counter was bumped up even though "ip" was a metadir inode and here in the above line it is corrected (i.e, decremented by 1) and xs_inodes_meta is incremented - shouldn't the appropriate counter have been directly bumped up whenever it was created?

xfs_inode_alloc doesn't know if the inode is going to be a meta inode, as it hasn't been read from disk yet for the common case. For the less common inode allocation case we'd know it, but passing it down would be a bit annoying.

Okay, now I get it. Thank you. So we increment the stats for regular inode (since this is more common) and later adjust if our assumption is wrong, i.e, the inode turns out to be a metadir inode. Right?

Quoted 5 lines
Quoted 4 lines

fs/xfs/xfs_stats.h struct __xfsstats { · line 146

Quoted 3 lines
fs/xfs/xfs_stats.h +2 -0
+/* Metafile counters */
+	uint32_t		xs_inodes_meta;

uint64_t would be an overkill, isn't it?

Yes. Sticking to the same type as the active inodes here.

Okay, makes sense.

--NR

Quoted 1 line
Signature · 3 lines
Nirjhar Roy
Linux Kernel Developer
IBM, Bangalore
#9 lore raw

Re: [PATCH 2/2] xfs: remove metafile inodes from the active inode stat

Quoted 3 lines · Nirjhar Roy (IBM)

Okay, now I get it. Thank you. So we increment the stats for regular inode (since this is more common) and later adjust if our assumption is wrong, i.e, the inode turns out to be a metadir inode. Right?

Yes, although it would not really call it an assumption, but just the fast path.

Reviewed-by on v1 2/2
#10 lore raw

Re: [PATCH 2/2] xfs: remove metafile inodes from the active inode stat

In reply to Christoph Hellwig
Quoted 11 lines · Christoph Hellwig

The active inode (or active vnode until recently) stat can get much larger than expected on file systems with a lot of metafile inodes like zoned file systems on SMR hard disks with 10.000s of rtg rmap inodes.

Remove all metafile inodes from the active counter to make it more useful to track actual workloads and add a separate counter for active metafile inodes.

This fixes xfs/177 on SMR hard drives.

Looks ok to me, though I wonder slightly about the atomicity of the percpu counter inc/decrements. But it's been that way for a long time so

--D

Quoted 117 lines
---
 fs/xfs/libxfs/xfs_inode_buf.c |  4 ++++
 fs/xfs/libxfs/xfs_metafile.c  |  5 +++++
 fs/xfs/xfs_icache.c           |  5 ++++-
 fs/xfs/xfs_stats.c            | 11 ++++++++---
 fs/xfs/xfs_stats.h            |  3 ++-
 5 files changed, 23 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_inode_buf.c +4 -0
index dcc9566ef5fe..91a499ced4e8 100644
@@ -268,6 +268,10 @@ xfs_inode_from_disk(
 	}
 	if (xfs_is_reflink_inode(ip))
 		xfs_ifork_init_cow(ip);
+	if (xfs_is_metadir_inode(ip)) {
+		XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
+		XFS_STATS_INC(ip->i_mount, xs_inodes_meta);
+	}
 	return 0;
 
 out_destroy_data_fork:
fs/xfs/libxfs/xfs_metafile.c +5 -0
index cf239f862212..71f004e9dc64 100644
@@ -61,6 +61,9 @@ xfs_metafile_set_iflag(
 	ip->i_diflags2 |= XFS_DIFLAG2_METADATA;
 	ip->i_metatype = metafile_type;
 	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+
+	XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
+	XFS_STATS_INC(ip->i_mount, xs_inodes_meta);
 }
 
 /* Clear the metadata directory inode flag. */
@@ -74,6 +77,8 @@ xfs_metafile_clear_iflag(
 
 	ip->i_diflags2 &= ~XFS_DIFLAG2_METADATA;
 	xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+	XFS_STATS_INC(ip->i_mount, xs_inodes_active);
+	XFS_STATS_DEC(ip->i_mount, xs_inodes_meta);
 }
 
 /*
fs/xfs/xfs_icache.c +4 -1
index f76c6decdaa3..f2d4294efd37 100644
@@ -172,7 +172,10 @@ __xfs_inode_free(
 	/* asserts to verify all state is correct here */
 	ASSERT(atomic_read(&ip->i_pincount) == 0);
 	ASSERT(!ip->i_itemp || list_empty(&ip->i_itemp->ili_item.li_bio_list));
-	XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
+	if (xfs_is_metadir_inode(ip))
+		XFS_STATS_DEC(ip->i_mount, xs_inodes_meta);
+	else
+		XFS_STATS_DEC(ip->i_mount, xs_inodes_active);
 
 	call_rcu(&VFS_I(ip)->i_rcu, xfs_inode_free_callback);
 }
fs/xfs/xfs_stats.c +8 -3
index bc4a5d6dc795..c13d600732c9 100644
@@ -59,7 +59,8 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
 		{ "rtrefcntbt",		xfsstats_offset(xs_qm_dqreclaims)},
 		/* we print both series of quota information together */
 		{ "qm",			xfsstats_offset(xs_gc_read_calls)},
-		{ "zoned",		xfsstats_offset(__pad1)},
+		{ "zoned",		xfsstats_offset(xs_inodes_meta)},
+		{ "metafile",		xfsstats_offset(xs_xstrat_bytes)},
 	};
 
 	/* Loop over all stats groups */
@@ -99,16 +100,20 @@ int xfs_stats_format(struct xfsstats __percpu *stats, char *buf)
 
 void xfs_stats_clearall(struct xfsstats __percpu *stats)
 {
+	uint32_t	xs_inodes_active, xs_inodes_meta;
 	int		c;
-	uint32_t	xs_inodes_active;
 
 	xfs_notice(NULL, "Clearing xfsstats");
 	for_each_possible_cpu(c) {
 		preempt_disable();
-		/* save xs_inodes_active, it's a universal truth! */
+		/*
+		 * Save the active / meta inode counters, as they are stateful.
+		 */
 		xs_inodes_active = per_cpu_ptr(stats, c)->s.xs_inodes_active;
+		xs_inodes_meta = per_cpu_ptr(stats, c)->s.xs_inodes_meta;
 		memset(per_cpu_ptr(stats, c), 0, sizeof(*stats));
 		per_cpu_ptr(stats, c)->s.xs_inodes_active = xs_inodes_active;
+		per_cpu_ptr(stats, c)->s.xs_inodes_meta = xs_inodes_meta;
 		preempt_enable();
 	}
 }
fs/xfs/xfs_stats.h +2 -1
index 64bc0cc18126..57c32b86c358 100644
@@ -142,7 +142,8 @@ struct __xfsstats {
 	uint32_t		xs_gc_read_calls;
 	uint32_t		xs_gc_write_calls;
 	uint32_t		xs_gc_zone_reset_calls;
-	uint32_t		__pad1;
+/* Metafile counters */
+	uint32_t		xs_inodes_meta;
 /* Extra precision counters */
 	uint64_t		xs_xstrat_bytes;
 	uint64_t		xs_write_bytes;
Signature · 1 line
2.47.3
#11 lore raw

Re: [PATCH 2/2] xfs: remove metafile inodes from the active inode stat

Quoted 5 lines · Darrick J. Wong
Quoted 1 line

Looks ok to me, though I wonder slightly about the atomicity of the percpu counter inc/decrements. But it's been that way for a long time so

It's not atomic, but the percpu summing is by definition never fully atomic anyway. So it might add a bit more of error margin than the pure summing, but it removes the much larger error margin of having the metadir inodes accounted in the first place.

maintainer Applied
#12 lore raw
In reply to Christoph Hellwig
Quoted 14 lines · Christoph Hellwig

the second patch fixes the active inode/vnode count on file systems with lots of metafiles, i.e. on SMR hard disks.

The first patch cleans up the counters a bit to prepare for that.

Subject:

 libxfs/xfs_inode_buf.c |    4 ++++
 libxfs/xfs_metafile.c  |    5 +++++
 xfs_icache.c           |    9 ++++++---
 xfs_stats.c            |   17 +++++++++++------
 xfs_stats.h            |   19 ++++++++++---------
 xfs_super.c            |    4 ++--
 6 files changed, 38 insertions(+), 20 deletions(-)
Quoted 1 line

[...]

Applied to for-next, thanks!

[1/2] xfs: cleanup inode counter stats

      commit: 810e363df769b096bfc9546b1c43fae803492cde
[2/2] xfs: remove metafile inodes from the active inode stat
      commit: 428980f6202be859428afd9887cb122028de00d5

Best regards,

Signature · 1 line
Carlos Maiolino <[email protected]>