[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bdflush can't work with ext3



On Sun, Feb 22, 2004 at 10:48:40PM +0530, Deboo wrote:
> I have converted my partitions to ext3 but I learnt the other day while
> trying to use bdflush to make the hdd spin down, that it won't work with
> ext3 partitions ecause ext3 partitions wrrite to disk every 5 seconds, the
> journal get written I mean. Is there no way to make the hdd spin down with
> ext3? If no, then is reiser or any other kind of journalled FS work with
> bdflush? Or is there any other bdflush type utility to do this?
> 

I am guessing you are using laptop mode because otherwise the kernel
flushes its buffers every 30 seconds anyway.
Is it a custom kernel or a debian one. If its a debian one, for the
moment you will need the script from 2.6 which uses the commit mount
option with a small change (it doesn't reset the value).
If its a custom kernel I can send you a patch (I am currently working
on a fix, but its in a testing phase now and it will probably be some
time before it hits the standard kernels.)
I attached a modified laptop-mode script you can use for now.
Just note that although it has options for xfs and reiserfs they won't
work for the moment as they require a patch to add the needed support
(reiserfs doesn't have the support at all at the moment and xfs is
limited to 5 minutes).

> Regards,
> Deboo
> 
> 
> -- 
> To UNSUBSCRIBE, email to debian-user-request@lists.debian.org 
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
> 
>  
>  +++++++++++++++++++++++++++++++++++++++++++
>  This Mail Was Scanned By Mail-seCure System
>  at the Tel-Aviv University CC.
> 
#!/bin/sh

# start or stop laptop_mode, best run by a power management daemon when
# ac gets connected/disconnected from a laptop
#
# install as /sbin/laptop_mode
#
# Contributors to this script:	Kiko Piris
#				Bart Samwel
#				Dax Kelson
# Original Linux 2.4 version by: Jens Axboe

parse_mount_opts () {
	OPT="$1"
	shift
	echo "$*"			| \
	sed 's/.*/,&,/'			| \
	sed 's/,'"$OPT"'=[0-9]*,/,/g'	| \
	sed 's/,,*/,/g'			| \
	sed 's/^,//'			| \
	sed 's/,$//'			| \
	cat -
}

parse_mount_opts_wfstab () {
	L_DEV=$1
	shift
	OPT=$1
	shift
	L_OPTS="$*"

	PARSEDOPTS1="$(parse_mount_opts $OPT $L_OPTS)"
	# Watch for a default commit/transaction in fstab
	FSTAB_OPTS="$(cat /etc/fstab | sed 's/	/ /g' | grep ^\ *"$L_DEV " | awk '{ print $4 }')"
	if [ -z "$(echo "$FSTAB_OPTS" | grep "$OPT=")" ] ; then
		# no commit/transaction option specified in fstab: set it to 0
		echo "$PARSEDOPTS1,$OPT=30"
	else
		# commit/transaction option specified in fstab: extract the value, and use it
		echo -n "$PARSEDOPTS1,$OPT="
		echo "$FSTAB_OPTS"	| \
		sed 's/.*/,&,/'		| \
		sed 's/.*,'"$OPT"'=//'	| \
		sed 's/,.*//'		| \
		cat -
	fi
}

KLEVEL="$(uname -r | cut -c1-3)"
case "$KLEVEL" in
	"2.4"|"2.6")
		true
		;;
	*)
		echo "Unhandled kernel version: $KLEVEL ('uname -r' = '$(uname -r)')"
		exit 1
		;;
esac

# Shall we remount journaled fs. with appropiate commit/transaction interval? (1=yes)
DO_REMOUNTS=1

# age time, in seconds. should be put into a sysconfig file
MAX_AGE=600

# Allowed dirty ratio, in pct. should be put into a sysconfig file as well.
DIRTY_RATIO=40

# kernel default dirty buffer age
DEF_AGE=30
DEF_UPDATE=5
DEF_DIRTY_BACKGROUND_RATIO=10
DEF_DIRTY_RATIO=40

# This is temporary: we have to read this from the kernel somewhere.
HZ=100

# hdparm spindown settings
ACAD_HD=0
BATT_HD=4

if [ ! -e /proc/sys/vm/laptop_mode ]; then
	echo "Kernel is not patched with laptop_mode patch."
	exit 1
fi

if [ ! -w /proc/sys/vm/laptop_mode ]; then
	echo "You do not have enough privileges to enable laptop_mode."
	exit 1
fi

case "$1" in
	start)
		# XFS counts in jiffies, the others in centisecs.
		AGE=$((100*$MAX_AGE))
		XFS_AGE=$(($HZ*$MAX_AGE))
		echo -n "Starting laptop_mode"
		echo "1" > /proc/sys/vm/laptop_mode
		case "$KLEVEL" in
			"2.4")
				echo "30 500 0 0 $AGE $AGE 60 20 0"	> /proc/sys/vm/bdflush
				;;
			"2.6")
				echo "$AGE"				> /proc/sys/vm/dirty_writeback_centisecs
				echo "$AGE"				> /proc/sys/vm/dirty_expire_centisecs
				echo "$DIRTY_RATIO"			> /proc/sys/vm/dirty_ratio
				echo "$DIRTY_RATIO"			> /proc/sys/vm/dirty_background_ratio
				;;
		esac
		if [ -d /proc/sys/vm/pagebuf ] ; then
			# This only needs to be set, not reset -- it is only used when
			# laptop mode is enabled.
			echo $XFS_AGE > /proc/sys/vm/pagebuf/lm_flush_age
		fi
		if [ $DO_REMOUNTS -eq 1 ]; then
			cat /etc/mtab | \
				while read DEV MP FST OPTS DUMP PASS ; do
					case "$FST" in 
						"ext3")
							PARSEDOPTS="$(parse_mount_opts commit $OPTS)"
							mount $DEV -t $FST $MP -o remount,$PARSEDOPTS,commit=$MAX_AGE
							;;
						"reiserfs")
							PARSEDOPTS="$(parse_mount_opts transaction $OPTS)"
							mount $DEV -t $FST $MP -o remount,$PARSEDOPTS,transaction=$MAX_AGE
							;;
						# No need to do anything for xfs
					esac
				done
		fi

		/sbin/hdparm -S $BATT_HD /dev/hda > /dev/null 2>&1
		/sbin/hdparm -B 1 /dev/hda > /dev/null 2>&1

		echo "."
		;;
	stop)
		U_AGE=$((100*$DEF_UPDATE))
		B_AGE=$((100*$DEF_AGE))
		echo -n "Stopping laptop_mode"
		echo "0" > /proc/sys/vm/laptop_mode
		case "$KLEVEL" in
			"2.4")
				echo "30 500 0 0 $U_AGE $B_AGE 60 20 0"	> /proc/sys/vm/bdflush
				;;
			"2.6")
				echo "$U_AGE"				> /proc/sys/vm/dirty_writeback_centisecs
				echo "$B_AGE"				> /proc/sys/vm/dirty_expire_centisecs
				echo "$DEF_DIRTY_RATIO"			> /proc/sys/vm/dirty_ratio
				echo "$DEF_DIRTY_BACKGROUND_RATIO"	> /proc/sys/vm/dirty_background_ratio
				;;
		esac
		if [ $DO_REMOUNTS -eq 1 ]; then
			cat /etc/mtab | \
				while read DEV MP FST OPTS DUMP PASS ; do
					case "$FST" in
						"ext3")
							PARSEDOPTS="$(parse_mount_opts_wfstab $DEV commit $OPTS)"
							mount $DEV -t $FST $MP -o remount,$PARSEDOPTS
							;;
						"reiserfs")
							PARSEDOPTS="$(parse_mount_opts_wfstab $DEV transaction $OPTS)"
							mount $DEV -t $FST $MP -o remount,$PARSEDOPTS
							;;
						# No need to do anything for xfs
					esac
				done
		fi

		/sbin/hdparm -S $ACAD_HD /dev/hda  > /dev/null 2>&1
		/sbin/hdparm -B 255 /dev/hda > /dev/null 2>&1

		echo "."
		;;
	*)
		echo "Usage: $0 {start|stop}"
		;;

esac

exit 0

Reply to: