by shaun on Sun Nov 15, 2009 8:23 am
I'd like to suggest the possibility that the CPU spiking every three seconds may be caused by the hard drive journalling system. What follows is a method of reducing hard drive activity - but it's quite complex. Also your distribution is not the same as mine so the Hardy stuff at the bottom would probably apply. This is a lot to do to fix this problem so you might not do it!
Constant hard drive noise and accessing.
The operating system here is PC-OS-Open64wstation based on Xubuntu/Ubuntu 9.04 jaunty jackalope.
This problem is a feature of Linux itself. It's annoying Vista-like drive accessing can be heard if you have a noisy hard drive like a WD Raptor. This feature will wear out hard drives soon especially if they are Solid State Drives (SSD). It may also cause CPU spiking. The solution here was tested on the above OS and gave periods of silence of about 44 seconds, which seems satisfactory to me.
The solution presented here comes from the Ubuntu forums (copied from there) and is well over my head (so don't ask). It does work but different commands would be necessary for PC/OS based on a different release of Ubuntu. Items in brackets that start or end in 'Ed.' are comments from myself as the editor.
"By default, Ubuntu (actually, Linux in general), has two important features that cause the disk to write every few seconds. The first is the default journal commit time of the ext3 filesystem and the second is the rate at which the kernel wakes up to write dirty pages to disk.
By default, both of these settings are set to 5 seconds which is one of the primary reasons that Ubuntu systems seem to never have idle disks. This guide will show you how to raise those settings to a higher value in order to reduce disk activity.
Disclaimer
This guide shows you how to change default Ubuntu settings that are specifically in place to reduce the amount of work lost in the case of unexpected system shutdown. If you don't feel your system is 100% stable, do not use this guide. If you live in an area with frequent power outages, do not use this guide.
Implementation
We are going to change the default 5 second settings to 60 seconds. Anywhere were we are using the 60 seconds number, I will highlight in blue (not done here...Ed.) so that if you wish to adjust this value, you know exactly what to change. I'm using 60 seconds because it means that in the event of an unexpected power outage, you will lose at most around 60 seconds of work. If you are using a laptop or have an UPS for your machine, you can set this number higher if you wish.
To do this, we will backup 2 files, change the settings and then reboot to test. All these commands should be run from a new terminal where the current directory is your home directory.
The first file we will change is /etc/fstab so that it only commits the journal every 60 seconds. First, backup /etc/fstab (dda stands for Decrease Disk Activity):
Code: (Ed.. This means copy and paste the following line into ROXTerm using the Edit > Paste menu)
sudo cp /etc/fstab /etc/fstab.dda.bak
Then, tinivole was nice enough to provide an awk command to automatically change all the ext3 partitions to have a commit time of 60 seconds. We will run the command and output to a temporary file so that we can verify that the output is correct:
Code:
awk '{if ($3 == "ext3") print $1" "$2"\t"$3"\t"$4",commit=60 "$5"\t"$6; else print}' /etc/fstab > fstab.tmp
Now, we will verify that the changes are correct:
Code:
diff /etc/fstab fstab.tmp
You should see output that looks similar to this:
6c6
< UUID=d12eeb71-f5a8-4062-95da-d0513c37ced2 / ext3 defaults,errors=remount-ro 0 1
---
> UUID=d12eeb71-f5a8-4062-95da-d0513c37ced2 / ext3 defaults,errors=remount-ro,commit=60 0 1
Notice the ,commit=60. You may have more output than that but, any line in the output that begins with ">" should have it and it's very important that it looks like this. If you have any doubt whatsoever, post the output of that command in this thread (except in this case... Ed.) and wait until myself or someone else says that the output is ok before proceeding.
If the output looks ok, then we can replace /etc/fstab with our temporary file and then remove it:
Code:
sudo cp fstab.tmp /etc/fstab
rm fstab.tmp
That's it for ext3 changes and we will move on to kernel tunable changes. First we will make a backup of /etc/sysctl.conf and create a file for editing:
Code:
sudo cp /etc/sysctl.conf /etc/sysctl.conf.dda.bak
cp /etc/sysctl.conf sysctl.tmp
Now open sysctl.tmp with your editor of choice and, at the bottom of the file, add:
(Ed... Now that's a good one! 'sudo nano -w' would be my choice here, and give the password. This is a sort of text editor. The 'sudo' is to make us 'root' and the '-w' is to avoid return characters or something, and there is a space between the word nano and the -w. The controls are given at the bottom of the window, and you should make the ROXTerm window a little bigger first. The controls required will be ^R for Read File and this refers to the buttons 'Ctrl & r', and ^O and this refers to the buttons 'Ctrl & o' for Write Out, and also ^X which refers to the buttons 'Ctrl & x' for Exit. Thus:
sudo nano -w
give the password
press Ctrl and the 'R' key and enter sysctl.tmp
You would now continue by adding these lines to the bottom of the file, hitting return/enter at the end of each line.)
Code:
vm.dirty_ratio = 40
vm.dirty_background_ratio = 1
vm.dirty_writeback_centisecs = 6000
(Ed... Having done so you now need to save the file thus:
press Ctrl and the 'O' key and enter sysctl.tmp
It will say that the file already exists and do you want to over write it and I think you press the 'Y' key for yes here.
It says how many lines it's written out to confirm that the file was saved.
press Ctrl and the 'X' key to exit from nano back into the normal terminal window.)
In this case, we are specifying centiseconds so, rather than 60 seconds, we use 6000 centiseconds here. The top two options simply wait slightly longer to request disk writes and then write as much as possible.
Once those changes have been made, we can copy our temporary file back and remove it:
Code:
sudo cp sysctl.tmp /etc/sysctl.conf
rm sysctl.tmp
(Ed... The next part may or may not apply depending on your version of PC/OS. I didn't do this part and for me it was unnecessary. The next step for me was to restart the PC to see if it worked and it does improve the situation. Tests are given lower down and when these were run the correct answers were given, in my case.)
Update:
For Hardy, the final step is to disable the part of pm-utils that will reset our values. To do this we simply make the script that resets these values not executable:
Code:
sudo chmod -x /usr/lib/pm-utils/power.d/laptop-tools
This final step is not needed for versions of Ubuntu before Hardy.
That's it for system changes.
Testing
The easiest way to test is to simply reboot your system and, once you have logged in and the system is fully up, watch your hard drive lights. You should notice them flickering far less often. As a more thorough test, you can run the following commands:
Code:
cat /proc/mounts | grep commit
You should see your commit=60 changes with that command. To test the other file we changed, issue the following three commands:
Code:
cat /proc/sys/vm/dirty_ratio
cat /proc/sys/vm/dirty_background_ratio
cat /proc/sys/vm/dirty_writeback_centisecs
The output should be, "40", "1" and "6000" respectively (it may actually be 5999 and not 6000. This is normal)."
* The only other issue is that now in the Home folder you will see two files. In my case one was called 'out_WBx2qr' and the other was called 'out_zTmTNF'. Double clicking these revealed that both were empty, so both were deleted.