/proc and /sys tricks

Really the sysfs and /proc filesystems are worlds of magic and fantasy. Each day I discover a new trick using this filesystems. So, I decided to post a short summary of my favorites ones. Enjoy and feel free to add your tricks in comments, maybe we can a /proc and /sys knownledge database in a post 🙂

1. Scanning for LUNs in attached FC (or any other SCSI compliance host).

echo "- - -" > /sys/class/scsi_host/hostX/scan

2. CPU hotplug.

# Set cpuX offline
echo "0" > /sys/devices/system/cpu/cpuX/online
# Set cpuX online
echo "0" > /sys/devices/system/cpu/cpuX/online

3. Enable dmesg timestamp.

echo Y >/sys/modules/prinkt/parameters/time

4. Restore a removed file when is still in use.
Let’s suppose that you have a file in fd YYY, opened by process XXX, and you need to recover that file after remove it.

cat /proc/XXX/fd/YY > /tmp/myfile_restored

5. Get the IO operations for a process:

cat /proc/XXX/io

The syscr and the syscw are the accumulated read and write IO operations that process do where running.

6. Increase size of IO scheduler queue:
Let’s suppose that you wanto to change the IO queue size on drive XXX.

echo "10000" >/sys/block/XXX/queue/nr_request

7. Get the current IO scheduler enabed to a specific device:
Let’s suppose that you want to known the IO scheduler for device XXX.

cat /sys/block/XXX/queue/scheduler

8. Get the threads of pdflush process which are running:

cat /proc/sys/vm/nr_pdflush_threads

9. Set the percentage threshold for memory to start to flushd data to disk:

echo XX > /proc/sys/vm/dirty_background_ratio

10. Set the sleep time for pdflush checking (in centisecs):

echo XXX > /proc/sys/vm/dirty_writeback_centisecs

11. Set the time to live for a data in buffer, when raises, data will commit to disk (in centisecs):

echo XXX > /proc/sys/vm/dirty_expire_centisecs

12. Prevent a process to be killed by OOM killer.
Let’s suppos that we have to prevent OMM to kill the process with PID XXX

echo "-17" > /proc/XXX/oom_adj

Note that you cannot forbid OMM killer to kill any process, this change only gives more resistence to be killed to the process, If everthing else fails, the process will be died anyway.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s