--- /usr/share/mdadm/checkarray	2011-12-04 02:23:32.000000000 +0400
+++ checkarray	2012-01-07 15:25:04.000000000 +0400
@@ -27,10 +27,14 @@
 	-a|--all & check all assembled arrays (check /proc/mdstat).
 	-s|--status & print redundancy check status of devices.
 	-x|--cancel & queue a request to cancel a running redundancy check.
-	-i|--idle & perform check in a lowest I/O scheduling class (idle).
-	-l|--slow & perform check in a lower-than-standard I/O scheduling class.
-	-f|--fast & perform check in higher-than-standard I/O scheduling class.
-	--realtime & perform check in real-time I/O scheduling class (DANGEROUS!).
+	-i|--idle & perform check in a lowest I/O scheduling class (idle)
+		  & and with high niceness.
+	-l|--slow & perform check in a lower-than-standard I/O scheduling class
+		  & and with moderate niceness, above of the normal.
+	-f|--fast & perform check in higher-than-standard I/O scheduling class
+		  & and with normal niceness.
+	--realtime & perform check in real-time I/O scheduling class (DANGEROUS!)
+		  & and with low niceness (CPU priority above of the normal).
 	-c|--cron & honour AUTOCHECK setting in /etc/default/mdadm.
 	-q|--quiet & suppress informational messages.
 	-Q|--real-quiet & suppress all output messages, including warnings and errors.
@@ -65,16 +69,17 @@
 status=0
 action=check
 ionice=
+renice=
 
 for opt in $@; do
   case "$opt" in
     -a|--all) all=1;;
     -s|--status) action=status;;
     -x|--cancel) action=idle;;
-    -i|--idle) ionice=idle;;
-    -l|--slow) ionice=low;;
-    -f|--fast) ionice=high;;
-    --realtime) ionice=realtime;;
+    -i|--idle) ionice='-c3'; renice='-n 15';;
+    -l|--slow) ionice='-c2 -n7'; renice='-n 5';;
+    -f|--fast) ionice='-c2 -n0'; renice='-n 0';;
+    --realtime) ionice='-c1 -n4'; renice='-n -5';;
     -c|--cron) cron=1;;
     -q|--quiet) quiet=1;;
     -Q|--real-quiet) quiet=2;;
@@ -180,21 +185,15 @@
       echo $action > $SYNC_ACTION_CTL
       [ $quiet -lt 1 ] && echo "$PROGNAME: I: check queued for array $array." >&2
 
-      case "$ionice" in
-        idle) arg='-c3';;
-        low) arg='-c2 -n7';;
-        high) arg='-c2 -n0';;
-        realtime) arg='-c1 -n4';;
-        *) break;;
-      esac
-
       resync_pid= wait=5
       while [ $wait -gt 0 ]; do
         wait=$((wait - 1))
         resync_pid=$(ps -ef | awk -v dev=$array 'BEGIN { pattern = "^\\[" dev "_resync]$" } $8 ~ pattern { print $2 }')
         if [ -n "$resync_pid" ]; then
-          [ $quiet -lt 1 ] && echo "$PROGNAME: I: selecting $ionice I/O scheduling class for resync of $array." >&2
-          ionice -p "$resync_pid" $arg
+          [ $quiet -lt 1 ] && echo "$PROGNAME: I: selecting with ionice $ionice I/O scheduling class for resync of $array." >&2
+          [ -n "$ionice" ] && ionice -p "$resync_pid" $ionice 1>/dev/null
+          [ $quiet -lt 1 ] && echo "$PROGNAME: I: selecting with renice $renice scheduling priority for resync of $array." >&2
+          [ -n "$renice" ] && renice $renice -p "$resync_pid" 1>/dev/null
           break
         fi
         sleep 1
