bengreen.eu Circle Device

 

Quick Reference

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

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.

Quick Links: Techie Stuff | General | Personal | Quick Reference