Skip to contentSkip to conversation

xfs_repair: multithread phase 2

PATCH In review Dave Chinner 3 participants 4 messages Jan 4, 2011 – Jan 5, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_repair: multithread phase 2

From: Dave Chinner <[email protected]>

Running some recent repair tests on broken filesystem meant running phase 1 and 2 repeatedly to reproduce an issue at the start of phase
3. Phase 2 was taking approximately 10 minutes to run as it processes each AG serially.

Phase 2 can be trivially parallelised - it is simply scanning the per AG trees to calculate free block counts and free and used inodes counts. This can be done safely in parallel by giving each AG it's own structure to aggregate counts into, then once the AG scan is complete adding them all together.

This patch uses 32-way threading which results in no noticable slowdown on single SATA drives with NCQ, but results in ~10x reduction in runtime on a 12 disk RAID-0 array.

---
 repair/phase2.c |   16 +---
 repair/scan.c   |  303 +++++++++++++++++++++++++++++++-----------------------
 repair/scan.h   |   37 -------
 3 files changed, 176 insertions(+), 180 deletions(-)
repair/phase2.c +2 -14
index e81ebf0..2f22c51 100644
@@ -26,8 +26,7 @@
 #include "progress.h"
 
 void	set_mp(xfs_mount_t *mpp);
-void	scan_ag(xfs_agnumber_t agno);
-void	validate_sb(struct xfs_sb *sb);
+void	scan_ags(struct xfs_mount *mp);
 
 /* workaround craziness in the xlog routines */
 int xlog_recover_do_trans(xlog_t *log, xlog_recover_t *t, int p) { return 0; }
@@ -109,7 +108,6 @@ zero_log(xfs_mount_t *mp)
 void
 phase2(xfs_mount_t *mp)
 {
-	xfs_agnumber_t		i;
 	int			j;
 	ino_tree_node_t		*ino_rec;
 
@@ -138,17 +136,7 @@ phase2(xfs_mount_t *mp)
 
 	set_progress_msg(PROG_FMT_SCAN_AG, (__uint64_t) glob_agcount);
 
-	for (i = 0; i < mp->m_sb.sb_agcount; i++)  {
-		scan_ag(i);
-#ifdef XR_INODE_TRACE
-		print_inode_list(i);
-#endif
-	}
-
-	/*
-	 * Validate that our manual counts match the superblock.
-	 */
-	validate_sb(&mp->m_sb);
+	scan_ags(mp);
 
 	print_final_rpt();
 
repair/scan.c +174 -129

491 lines not on this page · raw message

repair/scan.h +0 -37
index 20567fb..4de1cef 100644
@@ -20,19 +20,6 @@
 
 struct blkmap;
 
-void scan_sbtree(
-	xfs_agblock_t	root,
-	int		nlevels,
-	xfs_agnumber_t	agno,
-	int		suspect,
-	void		(*func)(struct xfs_btree_block	*block,
-				int			level,
-				xfs_agblock_t		bno,
-				xfs_agnumber_t		agno,
-				int			suspect,
-				int			isroot),
-	int		isroot);
-
 int scan_lbtree(
 	xfs_dfsbno_t	root,
 	int		nlevels,
@@ -74,29 +61,5 @@ int scanfunc_bmap(
 	int			check_dups,
 	int			*dirty);
 
-void scanfunc_bno(
-	struct xfs_btree_block	*block,
-	int			level,
-	xfs_agblock_t		bno,
-	xfs_agnumber_t		agno,
-	int			suspect,
-	int			isroot);
-
-void scanfunc_cnt(
-	struct xfs_btree_block	*block,
-	int			level,
-	xfs_agblock_t		bno,
-	xfs_agnumber_t		agno,
-	int			suspect,
-	int			isroot);
-
-void
-scanfunc_ino(
-	struct xfs_btree_block	*block,
-	int			level,
-	xfs_agblock_t		bno,
-	xfs_agnumber_t		agno,
-	int			suspect,
-	int			isroot);
 
 #endif /* _XR_SCAN_H */
Signature · 6 lines
1.7.2.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw
Quoted 3 lines

This patch uses 32-way threading which results in no noticable slowdown on single SATA drives with NCQ, but results in ~10x reduction in runtime on a 12 disk RAID-0 array.

Shouldn't we have at least an option to allow tuning this value, similar to the ag_stride? In fact I wonder why phase 3/4 should use different values for it than phase2.

repair/scan.c scan_sbtree( · line 86

Quoted 10 lines
repair/scan.c +4 -2
@@ -75,8 +80,10 @@ scan_sbtree(
 				xfs_agblock_t		bno,
 				xfs_agnumber_t		agno,
 				int			suspect,
-				int			isroot),
-	int		isroot)
+				int			isroot,
+				struct aghdr_cnts	*agcnts),
+	int		isroot,
+	struct aghdr_cnts *agcnts)

Please make this a

void *priv

to keep scan_sbtree generic.

repair/scan.c _("out-of-order bmap key (file offset) in inode %llu, %s fork, fsbno %llu\n"), · line 491

Quoted 13 lines
repair/scan.c +12 -0
 void
+scanfunc_bno(
+	struct xfs_btree_block	*block,
+	int			level,
+	xfs_agblock_t		bno,
+	xfs_agnumber_t		agno,
+	int			suspect,
+	int			isroot,
+	struct aghdr_cnts	*agcnts)
+{
+	return scanfunc_allocbt(block, level, bno, agno,
+				suspect, isroot, XFS_ABTB_MAGIC, agcnts);
+}

Now that we have private data bassed to the scanfuncs we could use that to communicate if we're doing a bno or cnt scan. Maybe writing it directly into struct aghdr_cnts is too ugly, in that case we can have a scan_priv structure that contains the magic and the aghdr_cnts.

Quoted 3 lines

void
scan_freelist(

This could become static.

Quoted 3 lines

* Scan an AG for obvious corruption.
*
* Note: This code is not reentrant due to the use of global variables.

That's not true any more I think.

repair/scan.c validate_agi( · line 1177

Quoted 6 lines

*/

repair/scan.c +2 -3
-void
-scan_ag(
-	xfs_agnumber_t	agno)
+void *
+scan_ag(void *args)

Can be static.

Quoted 8 lines
repair/scan.c +8 -0
+#define SCAN_THREADS 32
+
+void
+scan_ags(
+	struct xfs_mount	*mp)
+{
+	struct aghdr_cnts agcnts[mp->m_sb.sb_agcount];
+	pthread_t	thr[SCAN_THREADS];

repair/scan.c scan_ag( · line 1335

Quoted 10 lines
repair/scan.c +10 -0
+	__uint64_t	fdblocks = 0;
+	__uint64_t	icount = 0;
+	__uint64_t	ifreecount = 0;
+	int		i, j, err;
+
+	/*
+	 * scan a few AGs in parallel. The scan is IO latency bound,
+	 * so running a few at a time will speed it up significantly.
+	 */
+	for (i = 0; i < mp->m_sb.sb_agcount; i += SCAN_THREADS) {

I think this should use the workqueues from repair/threads.c. Just create a workqueue with 32 threads, and then enqueue all the AGs.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#2 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines

This patch uses 32-way threading which results in no noticable slowdown on single SATA drives with NCQ, but results in ~10x reduction in runtime on a 12 disk RAID-0 array.

Shouldn't we have at least an option to allow tuning this value, similar to the ag_stride? In fact I wonder why phase 3/4 should use different values for it than phase2.

Phase 3/4/5 use agressive prefetch to try to maximise throughput, while phase 2 has no prefetch and uses synchronous reads. Effectively the use of lots of parallelism simply keeps multiple IOs in flight rather than reading them one at a time, hence reducing the effective IO latency.

Quoted 14 lines

repair/scan.c scan_sbtree( · line 86

Quoted 11 lines
repair/scan.c +4 -2
@@ -75,8 +80,10 @@ scan_sbtree(
 				xfs_agblock_t		bno,
 				xfs_agnumber_t		agno,
 				int			suspect,
-				int			isroot),
-	int		isroot)
+				int			isroot,
+				struct aghdr_cnts	*agcnts),
+	int		isroot,
+	struct aghdr_cnts *agcnts)

Please make this a

Quoted 3 lines

void *priv

to keep scan_sbtree generic.

OK.

Quoted 5 lines

repair/scan.c validate_agi( · line 1174

Quoted 3 lines
repair/scan.c +0 -0
  * Scan an AG for obvious corruption.
  *
  * Note: This code is not reentrant due to the use of global variables.

That's not true any more I think.

Good point.

Quoted 13 lines
Quoted 13 lines
repair/scan.c +13 -0
+#define SCAN_THREADS 32
+
+void
+scan_ags(
+	struct xfs_mount	*mp)
+{
+	struct aghdr_cnts agcnts[mp->m_sb.sb_agcount];
+	pthread_t	thr[SCAN_THREADS];
+	__uint64_t	fdblocks = 0;
+	__uint64_t	icount = 0;
+	__uint64_t	ifreecount = 0;
+	int		i, j, err;
+
Quoted 8 lines

repair/scan.c scan_ag( · line 1335

Quoted 5 lines
repair/scan.c +5 -0
+	/*
+	 * scan a few AGs in parallel. The scan is IO latency bound,
+	 * so running a few at a time will speed it up significantly.
+	 */
+	for (i = 0; i < mp->m_sb.sb_agcount; i += SCAN_THREADS) {

I think this should use the workqueues from repair/threads.c. Just create a workqueue with 32 threads, and then enqueue all the AGs.

Ok. I just used an API I'm familiar with and didn't have to think about.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 1/1
#3 lore raw
In reply to Dave Chinner
Quoted 13 lines · Dave Chinner

From: Dave Chinner <[email protected]>

Running some recent repair tests on broken filesystem meant running phase 1 and 2 repeatedly to reproduce an issue at the start of phase
3. Phase 2 was taking approximately 10 minutes to run as it processes each AG serially.

Phase 2 can be trivially parallelised - it is simply scanning the per AG trees to calculate free block counts and free and used inodes counts. This can be done safely in parallel by giving each AG it's own structure to aggregate counts into, then once the AG scan is complete adding them all together.

Quoted 3 lines

This patch uses 32-way threading which results in no noticable slowdown on single SATA drives with NCQ, but results in ~10x reduction in runtime on a 12 disk RAID-0 array.

This is great. And evidently not very hard at all. It should have been done a long time ago...

I had a few of the same comments Christoph had (though I didn't know about the the workqueues). I'll reiterate one, that SCAN_THREADS should be a command line option. 32 is a fine default, but there's no sense in restricting it to that.

A few other things, below, but this looks good to me.

Quoted 6 lines
---
 repair/phase2.c |   16 +---
 repair/scan.c   |  303 +++++++++++++++++++++++++++++++-----------------------
 repair/scan.h   |   37 -------
 3 files changed, 176 insertions(+), 180 deletions(-)

. . .

repair/scan.c

Quoted 4 lines
repair/scan.c +0 -0
index 85017ff..dd62776 100644

. . .

repair/scan.c _("out-of-order bmap key (file offset) in inode %llu, %s fork, fsbno %llu\n"), · line 478

Quoted 3 lines
repair/scan.c +0 -0
@@ -469,6 +477,34 @@ _("out-of-order bmap key (file offset) in inode %llu, %s fork, fsbno %llu\n"),
 }
 

Can this (and scanfunc_cnt() and scanfunc_ino()) be given static scope now?

Quoted 4 lines
repair/scan.c +3 -0
 void
+scanfunc_bno(
+	struct xfs_btree_block	*block,
+	int			level,

repair/scan.c _("out-of-order bmap key (file offset) in inode %llu, %s fork, fsbno %llu\n"), · line 492

Quoted 10 lines
repair/scan.c +10 -0
+	xfs_agblock_t		bno,
+	xfs_agnumber_t		agno,
+	int			suspect,
+	int			isroot,
+	struct aghdr_cnts	*agcnts)
+{
+	return scanfunc_allocbt(block, level, bno, agno,
+				suspect, isroot, XFS_ABTB_MAGIC, agcnts);
+}
+

. . .

repair/scan.c validate_agi( · line 1169

Quoted 2 lines
repair/scan.c +0 -0
@@ -1155,42 +1169,15 @@ validate_agi(
 }

. . .

repair/scan.c validate_agi( · line 1177

Quoted 5 lines
repair/scan.c +2 -3
-void
-scan_ag(
-	xfs_agnumber_t	agno)
+void *
+scan_ag(void *args)

Maybe arg (singular)

repair/scan.c validate_agi( · line 1183

Quoted 6 lines
repair/scan.c +2 -0
 {
+	struct aghdr_cnts *agcnts = args;
+	xfs_agnumber_t	agno = agcnts->agno;
 	xfs_agf_t	*agf;
 	xfs_buf_t	*agfbuf;
 	int		agf_dirty = 0;

. . .

repair/scan.c scan_ag( · line 1313

Quoted 7 lines
repair/scan.c +3 -0
@@ -1331,4 +1308,72 @@ scan_ag(
 		libxfs_putbuf(sbbuf);
 	free(sb);
 	PROG_RPT_INC(prog_rpt_done[agno], 1);
+
+#ifdef XR_INODE_TRACE
+	print_inode_list(i);

I know this is only under XR_INODE_TRACE, but
now that you're multi-threading these, the
output can get interleaved and therefore
somewhat useless. Maybe you could adjust
print_inode_list() so it includes the AG
number with each line output rather than
just prior to printing all of them.

repair/scan.c scan_ag( · line 1318

Quoted 5 lines
repair/scan.c +5 -0
+#endif
+	return NULL;
+}
+
+#define SCAN_THREADS 32

Make this configurable at runtime.

repair/scan.c scan_ag( · line 1324

Quoted 6 lines
repair/scan.c +6 -0
+
+void
+scan_ags(
+	struct xfs_mount	*mp)
+{
+	struct aghdr_cnts agcnts[mp->m_sb.sb_agcount];

There is some mention about the per-thread stack size getting set at the time the program starts in the pthread documentation. I don't expect this will be a problem in practice, but maybe this should be allocated dynamically.

repair/scan.c scan_ag( · line 1336

Quoted 12 lines
repair/scan.c +12 -0
+	pthread_t	thr[SCAN_THREADS];
+	__uint64_t	fdblocks = 0;
+	__uint64_t	icount = 0;
+	__uint64_t	ifreecount = 0;
+	int		i, j, err;
+
+	/*
+	 * scan a few AGs in parallel. The scan is IO latency bound,
+	 * so running a few at a time will speed it up significantly.
+	 */
+	for (i = 0; i < mp->m_sb.sb_agcount; i += SCAN_THREADS) {
+		for (j = 0; j < SCAN_THREADS; j++) {
			xfs_agnumber_t agno = i + j;

repair/scan.c scan_ag( · line 1337

Quoted 1 line
repair/scan.c +1 -0
+			if (i + j >= mp->m_sb.sb_agcount)
			if (agno >= mp->m_sb.sg_agcount)
				(and so on, throughout this section)

repair/scan.c scan_ag( · line 1339

Quoted 2 lines
repair/scan.c +2 -0
+				break;
+			memset(&agcnts[i + j], 0, sizeof(agcnts[i]));

agcnts[i + j]

repair/scan.c scan_ag( · line 1343

Quoted 4 lines
repair/scan.c +4 -0
+			agcnts[i + j].agno = i + j;
+			err = pthread_create(&thr[j], NULL, scan_ag,
+							&agcnts[i + j]);
+			if (err)

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs