Sunday, December 21, 2008

Linux Hard Disk Issue - Excessive Load_Cycle_Count

Prologue: My 2 year old laptop's harddisk had died a few weeks ago, and I replaced it with a Seagate Momentus 5400.3 160GB SATA Drive. I have been running only Linux for a long time on my laptop. (Running Ubuntu Intrepid at present)

While trying to ascertain the cause of this premature death, I came to notice the abnormally high Load_Cycle_Count. This can be checked using smartmontools by issuing the command

sudo smartctl -n standby -a /dev/sda
where /dev/sda has to be replaced with the appropriate disk name. The option -n ensures that if the disk is already in standby, smartctl doesn't wake it up. A little bit of Googling returned quite a lot of stuffs about this issue. Laptop Harddisks, in order to improve power efficiency while on battery, have quite aggressive power management features by default. Now this is not really bad. When the disk is not accessed for sometime it spins down itself. So far so good, the disk stops spinning unnecessarily thereby cutting down power consumption. However no sooner than the disk stops spinning, something causes it to spin up again. This not only defeats the whole purpose of spindown, but also causes unnecessary wear and tear of the disk components. Most modern HDDs have a mechanism which parks the head (loads it up a ramp) when the disk spins down. The head is unloaded back over the platter, once the disk spins up again. However each load and unload cycle causes wear of the loading and unloading mechanism. Seagate HDDs (most others as well) have specifications of maximum of 60,000 load unload cycles. This is quite high. But what I found in my case was, the Load_Cycle_Count was increasing at the rate of about 5-6 per min. That meant the head was parking and unparking every 10sec on avarage. This was quite alarming.
To stop such insane behavior, I set the Advanced Power Management to 254 using hdparm. A value of 254 meant least aggressive power management. By default Ubuntu sets it at 128. This did stop the Load_Cycle_Count from increasing increasing insanely. But the disk now stopped spinning down, and its temperature was shooting up. Within a hour it went up above 60degC (room temp was around 20degC). Now that is even more alarming than the increasing load cycle count. The rated maximum operating temperature for my drive is 60degC. Operating at high temperature severely shortens the life of the disk. At a power management value of 180, the temperature settled at around 55degC. This was better, but not quite good, the disk was 35degC above ambient temperature. During peak summer, the ambient temperature at Kolkata hovers around 40degC. So my disk will get fried up in the summer if I use my laptop in a room without airconditioning.
So preventing the disk from spinning down is not a solution. It has to be ensured that once the disk spins down, it stays like that as long as possible, without spinning up.
I needed to find out who was accessing the disk so frequently. iotop is a nice utility for this. wpa-supplicant was at the top of the list. I am using a wireless connection, and wpa-supplicant frequently logs something. Next was gconf-d, followed by gnome-do and console-kit-daemon. As soon as the disk spins down, one of this will try to do a read/write causing the disk to spin up again. On top of that, every time the disk is accessed, kjournald will write the filesystem journals, update the atime, ctime and mtime of file inodes. All these together keep the disk always busy and wakes it up as soon as it tries to catch a nap.

However there is a utility called laptop-mode-tools which performs some tweaks and tries to keep the hard disk in standby mode as long as possible.
To enable it, first install laptop-mode-tools.

sudo apt-get install laptop-mode-tools
Then it has to be enabled in /etc/default/acpi-support by changing the line
ENABLE_LAPTOP_MODE=false
to
ENABLE_LAPTOP_MODE=true
I changed the configuration file a bit, so as to optimize things as far as possible.
The configuration is there at /etc/laptop-mode/laptop-mode.conf
###### Config file for laptop-mode-tools
## Verbose output on
VERBOSE_OUTPUT=1
## Laptop mode enabled always
ENABLE_LAPTOP_MODE_ON_BATTERY=1
ENABLE_LAPTOP_MODE_ON_AC=1
ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED=1

# When to enable data loss sensitive features
# -------------------------------------------
#
# When data loss sensitive features are disabled, laptop mode tools acts as if
# laptop mode were disabled, for those features only.
#
# Data loss sensitive features include:
# - laptop_mode (i.e., delayed writes)
# - hard drive write cache
#
# All of the options that follow can be set to 0 in order to prevent laptop
# mode tools from using them to stop data loss sensitive features. Use this
# when you have a battery that reports the wrong information, that confuses
# laptop mode tools.
#
# Disabling data loss sensitive features is ACPI-ONLY.
# Disable all data loss sensitive features when the battery level (in % of the
# battery capacity) reaches this value.
#
MINIMUM_BATTERY_CHARGE_PERCENT=3
# Disable data loss sensitive features when the battery reports its state
# as "critical".
#
DISABLE_LAPTOP_MODE_ON_CRITICAL_BATTERY_LEVEL=1

# The drives that laptop mode controls.
# Separate them by a space, e.g. HD="/dev/hda /dev/hdb". The default is a
# wildcard, which will get you all your IDE and SCSI/SATA drives.
#
HD="/dev/[hs]d[abcdefgh]"
# The partitions (or mount points) that laptop mode controls.
# Separate the values by spaces. Use "auto" to indicate all partitions on drives
# listed in HD. You can add things to "auto", e.g. "auto /dev/hdc3". You can
# also specify mount points, e.g. "/mnt/data".
#
PARTITIONS="auto /dev/mapper/*"
ASSUME_SCSI_IS_SATA=1

# Maximum time, in seconds, of work that you are prepared to lose when your
# system crashes or power runs out. This is the maximum time that Laptop Mode
# will keep unsaved data waiting in memory before spinning up your hard drive.
#
LM_BATT_MAX_LOST_WORK_SECONDS=900
LM_AC_MAX_LOST_WORK_SECONDS=600


#
# Should laptop mode tools control readahead?
#
CONTROL_READAHEAD=1
# 10MB readahead in laptop mode
LM_READAHEAD=10240
NOLM_READAHEAD=128

# Disks will be mounted with noatime in laptop mode, atime updates to file inodes will be 
# stopped.
CONTROL_NOATIME=1
# Don't use relatime instead of noatime
USE_RELATIME=0

# set hdd timeout
CONTROL_HD_IDLE_TIMEOUT=1
LM_AC_HD_IDLE_TIMEOUT_SECONDS=60
LM_BATT_HD_IDLE_TIMEOUT_SECONDS=30
NOLM_HD_IDLE_TIMEOUT_SECONDS=7200

# set HDD power management
CONTROL_HD_POWERMGMT=1
BATT_HD_POWERMGMT=1
LM_AC_HD_POWERMGMT=127
NOLM_AC_HD_POWERMGMT=254


# enable write cache
CONTROL_HD_WRITECACHE=1

NOLM_AC_HD_WRITECACHE=1
NOLM_BATT_HD_WRITECACHE=0
LM_HD_WRITECACHE=1

CONTROL_MOUNT_OPTIONS=1


#
# Dirty synchronous ratio.  At this percentage of dirty pages the process
# which calls write() does its own writeback.
# At 80percent of dirty pages disk write is performed. This holds up things in memory and
# prevents frequent disk writes
LM_DIRTY_RATIO=80
NOLM_DIRTY_RATIO=40


#
# Allowed dirty background ratio, in percent.  Once DIRTY_RATIO has been
# exceeded, the kernel will wake pdflush which will then reduce the amount
# of dirty memory to dirty_background_ratio.
# Once writeout has commenced write as much as possible to disk, without keeping back anything.
# So this has been set to 1 percent
LM_DIRTY_BACKGROUND_RATIO=1
NOLM_DIRTY_BACKGROUND_RATIO=10


#
# kernel default settings -- don't touch these unless you know what you're 
# doing.
#
DEF_UPDATE=5
DEF_XFS_AGE_BUFFER=15
DEF_XFS_SYNC_INTERVAL=30
DEF_XFS_BUFD_INTERVAL=1
DEF_MAX_AGE=30


#
# This must be adjusted manually to the value of HZ in the running kernel
# on 2.4, until the XFS people change their 2.4 external interfaces to work in
# centisecs. This can be automated, but it's a work in progress that still
# needs some fixes. On 2.6 kernels, XFS uses USER_HZ instead of HZ for
# external interfaces, and that is currently always set to 100. So you don't
# need to change this on 2.6.
#
XFS_HZ=100


#
# Seconds laptop mode has to to wait after the disk goes idle before doing
# a sync.
#
LM_SECONDS_BEFORE_SYNC=2

After enabling laptop-mode, the hdd is being able to sleep peacefully for quite sometime in between spinups. Also the operating temperature is rarely exceeding 50degC now. The load cycle count is still increasing but at a much slower rate. Hopefully this HDD is going to last longer than the previous one.

Saturday, December 6, 2008

Evolution Of A Linux User

A message taken from Kulua mailing list.
From - Tue Dec 14 13:22:38 1999
Received: from kuhub.cc.ku.edu by lark.cc.ku.edu (8.8.7/1.1.8.2/12Jan95-0207PM)
id PAA0000031643; Mon, 13 Dec 1999 15:07:29 -0600 (CST)
Received: from DIRECTORY-DAEMON by KUHUB.CC.KU.EDU (PMDF V5.2-32 #39821)
id <01JJGH1JNK6800TMXQ@KUHUB.CC.KU.EDU>; Mon,
13 Dec 1999 15:07:27 CST (UTC -06:00)
Received: from violet.jayhawks.net
("port 1826"@violet.jayhawks.net [24.124.24.226])
by KUHUB.CC.KU.EDU (PMDF V5.2-32 #39821)
with ESMTP id <01JJGH1G9GT400TIKN@KUHUB.CC.KU.EDU>; Mon,
13 Dec 1999 15:07:23 -0600 (UTC -06:00)
Received: (from listserv@localhost) by violet.jayhawks.net (8.9.3/8.9.3)
id PAA19912; Mon, 13 Dec 1999 15:06:33 -0600
Resent-date: Mon, 13 Dec 1999 15:06:33 -0600
Date: Mon, 13 Dec 1999 15:06:20 -0600 (CST)
Resent-from: kulua-l@kulua.org
From: Jeffrey Watts 
Subject: Evolution Of A Linux User [LONG]
Resent-sender: kulua-l-request@kulua.org
To: KULUA List 
Reply-to: kulua-l@kulua.org
Resent-message-id: <7T62ND.A.52E.M_VV4@violet.jayhawks.net>
Message-id: 
MIME-version: 1.0
Content-type: TEXT/PLAIN; charset=US-ASCII
Precedence: list
X-Loop: kulua-l@kulua.org
X-Authentication-warning: violet.jayhawks.net: listserv set sender to
kulua-l-request@kulua.org using -f
X-Mailing-List:  archive/latest/8103

---------- Forwarded message ----------
Subject: Evolution Of A Linux User

Evolution Of A Linux User
November 28, 1999

During the past year, the scientists in Humorix's Vast Research Lab Of
Doom have studied the behavior and attitude of the typical Windows and
Linux user. They have found that the average Linux user goes through ten
stages of development from a "Microserf" to an "Enlightened Linux User".
An eleventh stage, "Getting A Life", has also been observed, but only on
extremely rare occasions.

The 11 stages of evolution are summarized below.  Note, however, that this
life cycle is not universal.  Many pundits, Microsoft stock holders, and
PHBs never advance beyond Stage 0 ("Microserf"). Moreover, many extreme
Slashdot addicts are stuck between Stages 6 and 7 ("Linux Zealot") and
never evolve to Stage 9 ("Enlightened Linux User").  And, unfortunately,
far too many people are unable to leave Stage 8 ("Back to Reality") and
achieve Geek Self-Actualization due to problems outside of their control.

STAGE 0. MICROSERF

You are the number one member of the Bill Gates fan club.  Your life
revolves around x86 computers running the latest version of Microsoft
solutions: Windows, Office, Internet Explorer, Visual Basic, and even Bob.
You have nothing but hate for those eccentric Mac weenies with their
click-n-drool interfaces and those stone-age Unix oldtimers with their
archaic command lines.

You frequently send angry letters to your elected representative about
Microsoft's "freedom to innovative".  You think lawyers are evil (unless
they are defending innovative companies like Microsoft). You own an
autographed copy of a book that was ghostwritten by Bill Gates.  Your
blood boils when somebody forwards you a so-called Microsoft "joke" by
email.

In short, you are a Microserf.

STAGE 1. FEAR, UNCERTAINTY, DOUBT... ABOUT MICROSOFT

Your world-view begins to sour as you encounter a growing number of
annoyances with Microsoft products.  The number of Blue Screens increases,
however you ascribe the problem (at first) to conflicts with poorly
written drivers that came with your peripherals.  Icons keep jumping
around the desktop unpredicatably.  You spend 30 minutes one day idly
searching for an obscure configuration option in the Control Panel.

Slowly but surely, you begin to have doubts about the quality of Microsoft
software.  Then, the Microsoft Network, to which you have dutifully
subscribed since 1995, begins to double bill your credit card.  You
attempt to rectify the problem, but are stymied by the burgeoning
bureaucracy of Microsoft's Customer Support Department.  Fear sets in...
will you get your money back?

Meanwhile, something called "Linux" appears on the fringe of your radar.
You immediately dismiss the idea of a viable and quality Microsoft
alternative (Linux is Unix-based and therefore must suck, you conclude).
Nevertheless, you wish something could be done for some of the annoyances
in Windows.  But you do nothing about it.

STAGE 2. FEAR, UNCERTAINTY, DOUBT... ABOUT LINUX

You keep hearing about this Linux thing, and Open Source, and Apache, and
FreeBSD as well.  One of your friends installs Linux and says, "It's cool,
dude!" You discover that the selection of Windows books at your local
bookstore has remained constant while the Linux and Unix books are
multiplying like rabbits. You argue, "Well, this just means Linux sucks...
if there was such a large demand for it, there wouldn't be many books on
shelves."

Nevertheless, as time wears on and Windows becomes more fragile, the
temptation to give Linux a try becomes more and more irresistable. While
at your local SuperMegaOfficeSupplyStore, you pick up a boxed version of
Red Hat on impulse.

With much hubris, you completely ignore the documentation and attempt to
install the OS by the seat of your pants.  The installation is a failure;
Linux simply cannot work with the WinModem, WinSoundCard,
WinIDEController, WinPrinter, WinMonitor, and WinDRAM that came with your
"Windows 98 Ready" machine from CompUSSR.  You don't realize this however,
since you didn't read the FAQs and HOWTOs.  You immediately blame the
problems on Linux and give up.  You ditch your Red Hat copy by selling it
on eBay.

After the installation fiasco, you leave fearful, uncertain, and doubtful
about this "alternative" operating system.  Windows may have its problems,
but Microsoft will fix them in the next upgrade, you reckon.

STAGE 3. BORN-AGAIN MICROSERF

"Linux sucks" is your new attitude towards life.  Windows, all things
considered, ain't so bad.  You resolve to become a better Microsoft
customer by participating in the Microsoft Developer Network and the Site
Builder Network.  You buy a bunch of "study guides" to pass the MCSE
examination.

You launch a Windows advocacy site on some dinky free webpage provider,
utilizing the latest innovations in VBScript, ActiveX, and other
IE-specific features.  Instead of lurking, you now actively participate
in Linux and Macintosh bashing on various Usenet groups.  Upon discovering
Slashdot for the first time, you assume the role of the Bastard Anonymous
Coward From Hell by posting countless flamebait posts about how cool
Microsoft is and how much "Linsux" (as you call it) is a crappy OS.

You proudly wear an "All Hail Chairman Bill" T-shirt and display numerous
pro-Microsoft bumper stickers ("Honk if you hate anti-trust laws") on your
car.  You never leave home without your Windows CE-based palmtop computer.
You make a pilgrimage to Redmond to marvel at the glory that is the
Microsoft Campus.

STAGE 4. DISGRUNTLED USER

Your Microserf ways come to an abrupt end when everything goes wrong. You
lose a vital work-related document to a Windows crash.  You lose your job
as an indirect result.  You find that applying for jobs is difficult...
everyone wants your resume in the latest version of Word, but you have an
older version that has an incompatible file format.

You waste more and more time tinkering with Windows and other Microsoft
programs to keep them in working order.  You encounter serious problems
with Windows, but your calls to technical support only yield the dreaded
response, "re-install the OS".

After much grief you finally land another job at a software company, only
to find out a month later that Microsoft has announced a competing product
to be "integrated" with the next version of Windows.  You soon lose your
job.

You can't take it much longer.  You are now an official Disgruntled User,
and are ready for a way to escape from the depths of Microsoft Hell.  You
are ready for anything at all... even a primitive, archaic,
hard-to-install, grief-laden alternative like Linux.

STAGE 5. A RELIGIOUS EXPERIENCE

You resolve to install Linux now, for real.  Your friends say "It's about
time", and tell you to RTFM this time.  After losing yourself in the
documentation for several days, you figure out why your previous encounter
with Linux was a disaster: you need real hardware, not WinCrap.

With a new computer at your desk, and a Red Hat CD-ROM in hand, you embark
on a voyage of discovery to the land of Linux.  Your life is changed
forever; words cannot describe the rush you feel when you first log in as
"root" after the successful installation.  You stare blankly at the screen
in awe; you are unable to utter a word, unable to think of anything else
except "HOLY SHIT THIS IS SO DAMN COOL!!!!"

You spend hours, and then days, exploring the depths of the Linux system:
a filesystem layout that actually makes sense (no "My Documents" crap),
a command line so powerful it makes MS-DOS look like the Stone Age
technology that it is... and best of all, no Blue Screen!

"Why have I wasted my life with Microsoft?  I'm never going back!" you
exclaim wildly.  You have thrown off the yoke of Redmond Oppression.

STAGE 6. LINUX CONVERT

You still keep a copy of Windows around, but you find yourself booting
into Linux more and more.  The meager amount of diskspace you set aside
for your first Linux install dwindles; you decide to buy a second hard
drive exclusively for Linux.

You re-install everything, including the kitchen sink (Emacs).  Once you
finally get PPP working (it was a nasty challenge, but you're so enamored
with Linux that you hardly notice), you go on a Freshmeat Binge:
downloading and installing every piece of Free Software you come across.

STAGE 7. LINUX ZEALOT

Your enthusiasm for Linux is unbounded.  You do anything and everything
to advocate Linux and spite your old master, Microsoft.  Usenet, Slashdot,
and LinuxToday are your hangouts.  You have a strong opinion about the
GNU GPL and you're not afraid to share it.

Linux World Domination is your new life's ambition; you put career,
wealth, and dating on the back burner.  You participate in flamefests
against those braindead Windows lusers (stuck in Stage 3) that inhabit
Usenet and ZDNet.  You purchase all kinds of tacky made-in-Taiwan Linux
merchandise (T-shirt, mouse pads, stuffed penguins, etc.) to show your
support.

You rearrange books in a bookstore so that the Linux tomes are displayed
more prominently.  You get in trouble with your boss because you spend
all your time surfing Slashdot at work.  You  petition your local
government to migrate their computer systems to free software.  You move
to another residence just so you can say you live on Apache Street.

Instead of a novel, you read the Linux kernel source for pleasure.   You
establish your own regional Linux User Group in the hope that you can
invite a guest speaker in the future and get their autograph.  You learn
Perl with the goal of automating common tasks, but you spend more time
tinkering with "just one more perl script" than actually getting stuff
done.

STAGE 8. BACK TO REALITY

Your zealotry subsides as you are forced to re-enter the Real World. Your
boss demands that you submit documents in the latest Word format, nothing
else will do.  Some of your favorite websites become harder to use because
they keep incorporating features enhanced for Windows and IE.  The new
peripherals you bought from BigEvilProprietaryCo don't work with Linux
and probably never will.

Your ISP is acquired by another company, a very Microsoft-friendly
company, to be exact.  They "upgrade" the system; however, the only change
you can notice is that Linux and PPP no longer work without extensive
hacking.  Then, citing "customer-driven demand", your ISP makes more
"enhancements", and Linux no longer works at all.  Calling their tech
support is an exercise in futility, they simply say, "Linux?  What is
that?  Whatever it is we don't support it, and never will.  Go use Windows
like everybody else."

Reality sets in: you are forced to use Windows more and more.   Your blood
pressure rises, you have more headaches, you waste hours and hours due to
Windows "issues", but you have no choice.

STAGE 9. ENLIGHTENED LINUX USER

Then you have an inspiration: you do have a choice, you can hack your own
drivers for your hardware, you can find another ISP, you can get another
job.  Everything comes into focus, you have become a Linux Guru.

You kludge together drivers for your "Windows-compatible" hardware.  You
finally (after much searching) locate a local ISP that's actually run by
competent geeks, not MCSEs and PHBs. You find a new, better job at a
Linux-friendly company.

In your spare time, you work on various Open Source projects. You build
up a reputation and receive "The Letter" to participate in the IPO of a
Linux business.  You join the bandwagon and create your own Linux portal
website.

You're at the pinnacle of evolution for a Linux user.  With much joy, you
become 100% Microsoft free.  You ditch your Windows partition and burn
all of the Windows disks and manuals that you own.

STAGE 10. GET A LIFE

You become bored with Linux, and computers in general.  You're still a
hardcore geek, of course, but you wonder if there isn't something better
you could be doing.  You've been told to "get a life" countless times
during your existence on Earth, but now you wonder if maybe you should
have heeded that advice.

Unexpectedly, a media conglomerate (i.e. Andover, Ziff-Davis,
Internet.com, etc.) offers to buy your Linux portal website and domain
name for an obscene price that contains a significant number of digits.
Without hesistation you accept; this windfall, combined with your earnings
from Linux stocks, is enough to retire on.

And that's exactly what you do.  You move off to a small tropical island,
and get a life.



-------------------------------------------------------------------------- 
* Please read the FAQ:   http://kulua.org/index.phtml?body=Info/FAQ.phtml
* To unsubscribe:  Send an email to  with the 
following in the body: "unsubscribe "