Skip to contentSkip to conversation

iostat messed up with md on 2.6.16.x

PATCH Pallai Roland 2 participants 2 messages May 24, 2006 – May 25, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi,

I upgraded my kernel from 2.6.15.6 to 2.6.16.16 and now the 'iostat -x
1' permanently shows 100% utilisation on each disk that member of an md array. I asked my friend who using 3 boxes with 2.6.16.2 2.6.16.9 2.6.16.11 and raid1, he's reported the same too. it works for anyone? I don't think that it's exactly a md problem, but only appears with the md, so I wrote here

I did a basic debugging on evening and I think the problem is the
double calling of disk->in_flight-- in block/ll_rw_blk.c - I dont know why, but here's a sample line from /proc/diskstats after a raid array assembled:

    8    0 sda 52 1134 8256 568 3 7 24 16 4294967295 433820 4294534144
                                          ^^^^^^^^^^ in_flight = -1

I wrote an ugly workaround and now the iostat working well [see
attach#1], but if it's a real bug, someone should find the root cause of it, please

ps: the 'proactive disk replacement' patch for raid5 has been ported to
2.6.16 and tested by some of my friends and now it's working for us, lots of bugs fixed since my last post, if you want to give a try, I attached that too (and sorry for the big post if you're not intrested in)

--
dap

raid tombok alatt az in_flight -1 -be csap at amikor elstartol a cucc, ehol a fix cyrax 2.6.16.2 2.6.16.9 2.6.16.11
dap 2.6.16.16

block/ll_rw_blk.c renamed from block/ll_rw_blk.c.orig +8 -2
@@ -2746,7 +2746,10 @@
 
 	if (req->rq_disk) {
 		disk_round_stats(req->rq_disk);
-		req->rq_disk->in_flight--;
+		if (req->rq_disk->in_flight > 0)
+		    req->rq_disk->in_flight--;
+		else
+		    printk("attempt_merge: assert(req->rq_disk->in_flight) failed\n");
 	}
 
 	req->ioprio = ioprio_best(req->ioprio, next->ioprio);
@@ -3408,7 +3411,10 @@
 		__disk_stat_inc(disk, ios[rw]);
 		__disk_stat_add(disk, ticks[rw], duration);
 		disk_round_stats(disk);
-		disk->in_flight--;
+		if (disk->in_flight > 0)
+		    disk->in_flight--;
+		else
+		    printk("end_that_request_last: assert(disk->in_flight) failed\n");
 	}
 	if (req->end_io)
 		req->end_io(req, error);

Changelog:
8
- ...

This is a feature patch that implements 'proactive raid5 disk
replacement' (http://www.arctic.org/~dean/raid-wishlist.html),
that could help a lot on large raid5 arrays built from cheap sata drives when the IO traffic such large that daily media scan on the disks isn't possible.
An atypical breakdown situation is when a drive gets kicked from the
array due to a bad block, I replace it but the resync fails cause another 2-3 disks has hidden badblocks too. In this situation I've to save the disks with dd and rebuild bad blocks with a userspace tool (by hand), meanwhile the site is down for hours. This patch tries to provide a solution for this problem, the two main feature is:
1. Don't kick a drive on read error cause it is possible that 99.99% is
useable and will help (to serve and to save data) if another drive shows bad sectors in same array - Neil's new (experimental) sector rewrite feature included, the first thing is always a try to rewrite the bad sector
2. Let to mirror a partially failed drive to a spare _online_ and
replace the source of the mirror with the spare when it's done. Bad blocks isn't a problem unless same stripe is damaged on two disks what's a rare case. In this way is possible to fix an array with partially failed drives without data loss and without downtime. In other words, you never have to degrade the array due to a disk change, you can do that in optimal state.

Per-device bad block cache is implemented to speed up arrays with
partially failed drives (replies are often slow from those), also helps to determine badly damaged drives based on number of bad blocks, and can take an action if steps over an user defined threshold (see /proc/sys/dev/raid/badblock_tolerance). Rewrite of a bad block will delete the entry from the cache.
performance is affected just a little bit if there's no or some
registered bad blocks, but over a million that could be a problem currently..

Some words about error handling: first big change is now you can use an
external error handler, what means that a user-space script will be called by the kernel to handle the situation. The common method in this script is to call 'mdadm' and choosing return values (see below). This is good -for example- if you have 1 spare drive for 2 arrays, a script can handle it nicely.. If the script has failed to run (or does not exists), there's a default algorithm, the main guidelines of that:
- a "disk fail" means that it's oversteps the 'badblock threshold' or failed on write
- if a drive fails in an optimal array and there's no spare the disk will be kicked from the array
- if the drive fails in degraded array the drive _won't_ be kicked. processes gets read/write error if data is needed from the damaged sectors. if you want the old behavior use an external error handler
- if drive fails and there's a spare then the proactive mirroring begins to the spare. the failing drive won't be kicked until the mirror has not been done

You should put your external error handler script at location "/sbin/mdevent"; it gets the following arguments:
1st: name of the md array (eg.: "md0")
2nd: kind of the fail event as string, currently always "drivefail" 3rd: name of the drive (maybe major/minor nr would be better, currently
you can translate to that by /proc/partitions)

Let's see how can you handle some situations from the script:
array is optimal, a disk fails:
you want to.. fail that drive and add a spare for normal rebuilding
mdadm -f /dev/$2 /dev/$3
mdadm -a /dev/$2 /dev/my_spare1
exit 0
..start proactive mirroring of that disk
mdadm -a /dev/$2 /dev/my_spare1
exit 0
..keep it on and reset the badblock cache
exit 1
..just keep it in sync
exit 0
..let the default action
exit 2
Notice that if the proactive mirroring is done the spare won't replace the source drive automatically, you should do it by hand or by a scheduled task. You've got a last chance to re-think it.

Well, better if you know, It's an ugly hack, I'm not a kernel guru,
but I love the idea and now I can't live without it on my own servers (so this is works for me). I hope somebody will implement this feature once in a much nicer adaptation, I'm trying to maintain this patch till then..

(raid6 could be another solution for this problem, but that's the big fat evil in my eyes ;)

use:

1. patch the kernel, this one is against 2.6.14
2. type:

# make the drives
mdadm -B -n1 -l faulty -c4 /dev/md/1 /dev/rd/0
mdadm -B -n1 -l faulty -c4 /dev/md/2 /dev/rd/1
mdadm -B -n1 -l faulty -c4 /dev/md/3 /dev/rd/2
# make the array
mdadm -C -n3 -l5 /dev/md/0 /dev/md/1 /dev/md/2 /dev/md/3
# .. wait for sync ..
# grow bad blocks as ma*tor does :)
mdadm --grow -l faulty -p rp454 /dev/md/1
mdadm --grow -l faulty -p rp738 /dev/md/2
# add a spare
mdadm -a /dev/md/0 /dev/rd/4

# -> fail a drive, sync begins <-
# the md/1 will not be marked as failed, this is the point, but # if you want to, you can issue this command again mdadm -f /dev/md/0 /dev/md/1

# kernel:
# resync from md1 to spare ram4
# added spare for active resync

# .. wonder the read errors from md[12] and the sync goes on!
# feel free to stress the md at this time, mkfs, dd, badblocks, etc

# kernel:
# raid5_spare_active: 3 in_sync 3->0
# /proc/mdstat:
# md0 : active raid5 ram4[0] md3[2] md2[1] md1[0]
# -> ram4 and md1 has same id, this means the spare is a complete
# mirror, if you stop the array you can assembly it with ram4
# instead of md1, the superblock is same on them

# check the mirror (stop write stress if any)
mdadm --grow -l faulty -p none /dev/md/1
cmp /dev/md/1 /dev/rd/4
# hot-replace the mirrored -partially failed- device with the active
#  spare (yes, mark it as failed again, but if there's a syncing- or
#  synced 'active spare' the -f really fails the device or replace
#  it with the synced spare)
mdadm -f /dev/md/0 /dev/md/1

# kernel:
# replace md1 with in_sync active spare ram4

# and voila!
# /proc/mdstat:
#  md0 : active raid5 ram4[0] md3[2] md2[1]
include/linux/sysctl.h renamed from include/linux/sysctl.h.orig +3 -1
@@ -807,7 +807,9 @@
 /* /proc/sys/dev/raid */
 enum {
 	DEV_RAID_SPEED_LIMIT_MIN=1,
-	DEV_RAID_SPEED_LIMIT_MAX=2
+	DEV_RAID_SPEED_LIMIT_MAX=2,
+	DEV_RAID_BADBLOCK_TOLERANCE=3,
+        DEV_RAID_MAX_REWRITES=4
 };
 
 /* /proc/sys/dev/parport/default */
include/linux/raid/md_k.h renamed from include/linux/raid/md_k.h.orig +5 -0
@@ -173,6 +173,11 @@
 	char				uuid[16];
 
 	struct mdk_thread_s		*thread;	/* management thread */
+	struct eeh_data {
+		int			failed_num;	/* drive #, pass to raid5_add_disk()
+							    from handle_stripe() */
+	} eeh_data;
+
 	struct mdk_thread_s		*sync_thread;	/* doing resync or reconstruct */
 	sector_t			curr_resync;	/* blocks scheduled */
 	unsigned long			resync_mark;	/* a recent timestamp */
include/linux/raid/raid5.h renamed from include/linux/raid/raid5.h.orig +12 -0
@@ -156,6 +156,7 @@
 #define	R5_Overlap	7	/* There is a pending overlapping request on this block */
 #define	R5_ReadError	8	/* seen a read error here recently */
 #define	R5_ReWrite	9	/* have tried to over-write the readerror */
+#define	R5_HardReadErr	10	/* rewrite failed, put into badblocks list */
 
 /*
  * Write method
@@ -200,8 +201,17 @@
  */
  
 
+struct badblock {
+	struct badblock		*hash_next, **hash_pprev; /* hash pointers */
+	sector_t		sector; /* stripe # */
+	int			n;	/* # of faults */
+};
+
 struct disk_info {
 	mdk_rdev_t	*rdev;
+	struct badblock **badblock_hashtbl; /* list of known badblocks */
+	char		cache_name[20];
+	kmem_cache_t	*slab_cache; /* badblock db */
 };
 
 struct raid5_private_data {
@@ -238,6 +248,8 @@
 	int			inactive_blocked;	/* release of inactive stripes blocked,
 							 * waiting for 25% to be free
 							 */        
+	int			mirrorit; /* source for active spare resync */
+
 	spinlock_t		device_lock;
 	struct disk_info	disks[0];
 };
drivers/md/md.c renamed from drivers/md/md.c.orig +24 -0
@@ -84,6 +84,11 @@
  * or /sys/block/mdX/md/sync_speed_{min,max}
  */
 
+/* the drive'll be marked failed over this threshold. measure is block. */
+int sysctl_badblock_tolerance = 10000;
+int sysctl_max_rewrites = 10;
+
+
 static int sysctl_speed_limit_min = 1000;
 static int sysctl_speed_limit_max = 200000;
 static inline int speed_min(mddev_t *mddev)
@@ -117,6 +122,22 @@
 		.mode		= 0644,
 		.proc_handler	= &proc_dointvec,
 	},
+	{
+		.ctl_name	= DEV_RAID_BADBLOCK_TOLERANCE,
+		.procname	= "badblock_tolerance",
+		.data		= &sysctl_badblock_tolerance,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= &proc_dointvec,
+	},
+	{
+		.ctl_name	= DEV_RAID_MAX_REWRITES,
+		.procname	= "max_rewrites",
+		.data		= &sysctl_max_rewrites,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= &proc_dointvec,
+	},
 	{ .ctl_name = 0 }
 };
 
@@ -5042,6 +5063,9 @@
 EXPORT_SYMBOL(md_wakeup_thread);
 EXPORT_SYMBOL(md_print_devices);
 EXPORT_SYMBOL(md_check_recovery);
+EXPORT_SYMBOL(kick_rdev_from_array);	// fixme
+EXPORT_SYMBOL(sysctl_badblock_tolerance);
+EXPORT_SYMBOL(sysctl_max_rewrites);
 MODULE_LICENSE("GPL");
 MODULE_ALIAS("md");
 MODULE_ALIAS_BLOCKDEV_MAJOR(MD_MAJOR);
drivers/md/raid5.c renamed from drivers/md/raid5.c.orig +662 -44

937 lines not on this page · raw message

#1 lore raw
Quoted 15 lines · On Wednesday May 24, [email protected] wrote:

Hi,

I upgraded my kernel from 2.6.15.6 to 2.6.16.16 and now the 'iostat -x
1' permanently shows 100% utilisation on each disk that member of an md array. I asked my friend who using 3 boxes with 2.6.16.2 2.6.16.9 2.6.16.11 and raid1, he's reported the same too. it works for anyone? I don't think that it's exactly a md problem, but only appears with the md, so I wrote here

I did a basic debugging on evening and I think the problem is the
double calling of disk->in_flight-- in block/ll_rw_blk.c - I dont know why, but here's a sample line from /proc/diskstats after a raid array assembled:

Quoted 6 lines
    8    0 sda 52 1134 8256 568 3 7 24 16 4294967295 433820 4294534144
                                          ^^^^^^^^^^ in_flight = -1

I wrote an ugly workaround and now the iostat working well [see
attach#1], but if it's a real bug, someone should find the root cause of it, please

http://lkml.org/lkml/2006/5/23/42

might help...

NeilBrown