powersave.sh
I was looking for how to manipulate the file system cache in Linux recently and could not find anything. Now I know I dont need to worry about this stuff anymore since I have an SSD ;-) but some of my computers at the office (well all of them) still have hard disks with moving parts.
Please have a look around to learn more about these settings because
as they are in the /proc
file system they are probably
deprecated!.
Powersave script
These settings make the writeback to the disk longer, data will still be written but less frequently.
#!/bin/bash hdparm -S120 /dev/sda echo 60000 >> /proc/sys/vm/dirty_writeback_centisecs echo 40 >> /proc/sys/vm/dirty_ratio echo 1 >> /proc/sys/vm/dirty_background_ratio
Works well on my old HP Laptop anyway ;-)
Freeing Caches
This is documented in the kernel documents here: https://www.kernel.org/doc/Documentation/sysctl/vm.txt. But it is useforl for me to have here.
Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.
To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
echo 3 > /proc/sys/vm/drop_caches
Flushing File System Buffers
As this is a non-destructive operation, and dirty objects are not freeable, the user should run "sync" first in order to make sure all cached objects are freed.
Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.
Helpful Hint: This will be
much more effective if you run sync
first.
To free pagecache:
echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
echo 3 > /proc/sys/vm/drop_caches
As this is a non-destructive operation, and dirty objects are not freeable, the user should run "sync" first in order to make sure all cached objects are freed.
This tunable was added in 2.6.16.
Robbed from: LinuxInsight
One may also check the current status of the swap system:
cat /proc/swaps cat /proc/meminfo vmstat
Putting Drives to Sleep
To put a drive to stand-by mode immediately and have the ability to check that it is in stand-by mode without waking it up
hdparm -y /dev/sda
The alternative method -Y
will put the drive to sleep but,
importatly, will wake the drive when an attempt it made to query the current
state of the drive.
To check the power mode of a drive:
hdparm -C /dev/sda
It is also possible to use smartctl
:
smartctl -i -n standby /dev/sda|grep "^Power mode"