[Galaxy S Plus I9001 Android Development] Christopher83:
Special features and sysfs settings (Part 2):

Timer slack controller and dynamic management of the minimal timer slack value

The timer slack controller is a feature developed by Kirill Shutemov and it allows to set the minimal timer slack value for every process contained within a control group (cgroup).

A timer slack allows the kernel to manage processes wakeup requests at some future time.

Thanks to this feature, the kernel can set a specific timer slack for the involved processes, minimizing the number of wakeups and allowing a lower system's power consumption.

For further info: Timer slack for slacker developers

I also implemented a new feature in addition to the above one that allows the dynamic management of the minimal timer slack value.

So, it's possible to use different minimal timer slack value when the system is active and when has been suspended.

How to customize the dynamic timer slack controller feature:

Three new cgroup parameters are exposed inside each processes hierarchy contained in /dev/cpuctl path:

- timer_slack.min_slack_ns is the timer slack used when the system is active for the current processes hierarchy

- timer_slack.min_slack_suspend_ns is the timer slack used when the system is suspended for the current processes hierarchy

- timer_slack.effective_slack_suspend_ns is the timer slack currently used

At the moment, the values chosen and used by K^Kernel are the following:

- core processes (/dev/cpuctl), 0 ns when the system is active, 50000 ns when the system is suspended

- foreground apps/processes (/dev/cpuctl/apps), 0 ns when the system is active, 250000 ns when the system is suspended

- background non interactive apps/processes (/dev/cpuctl/apps/bg_non_interactive), 100000000 ns when the system is active, 250000000 ns when the system is suspended

1) By directly editing one of the file written above inside /dev/cpuctl and inside each hierarchy subfolder, by setting the preferred value (note that set value will be lost after a reboot/shutdown)

2) By using Terminal Emulator (note that set value will be lost after a reboot/shutdown)

- Open Terminal Emulator

- Run these commands to set the minimal timer slack for generic and core apps/processes

su
echo 0 > /dev/cpuctl/timer_slack.min_slack_ns
echo 50000 > /dev/cpuctl/timer_slack.min_slack_suspend_ns

- Run these commands to set the minimal timer slack for apps/processes in foreground

su
echo 0 > /dev/cpuctl/apps/timer_slack.min_slack_ns
echo 100000 > /dev/cpuctl/apps/timer_slack.min_slack_suspend_ns

- Run these commands to set the minimal timer slack for apps/processes in background and non interactive

su
echo 100000000 > /dev/cpuctl/apps/bg_non_interactive/timer_slack.min_slack_ns
echo 250000000 > /dev/cpuctl/apps/bg_non_interactive/timer_slack.min_slack_suspend_ns

LowMemoryKiller management of not killable processes

This feature allows to define processes and system processes white-lists filled with the preferred process names and to not be killed by lowmemorykiller, unless it is absolutely necessary.

This feature exposes four new lowmemorykiller parameters:

- donotkill_proc, is the flag to enable / disable this feature for the processes chosen by the user

- donotkill_sysproc, is the flag to enable / disable this feature for the system processes chosen by the user

- donotkill_proc_names, is the list of process names (comma separated) chosen by the user to be preserved from killing

- donotkill_sysproc_names, is the list of user system process names (comma separated) chosen by the user to be preserved from killing

When the lowmemorykiller needs to free ram, it will first kill the processes not included inside the two process name lists chosen by the user.

If there are no more standard killable processes, then it will be necessary to kill one of the processes included inside one of the two white-lists, to prevent system hangs, slowdowns, etc.

How to customize the white lists of processes to preserve from killing:

On K^Kernel the feature is enabled by default and the provided processes white lists are the following:

- donotkill_proc_names = "com.cyanogenmod.trebuchet,com.anddoes.launcher,com.teslacoilsw.launcher,org.adwfreak.launcher,gtp.nextlauncher,android.inputmethod.latin,com.touchtype.swiftkey"

this means that Trebuchet Launcher, Apex Launcher, Nova Launcher, ADW Launcher, Next Launcher, stock keyboard and SwiftKey keyboard will be preserved from killing

- donotkill_sysproc_names = "android.process.acore,com.android.phone,com.bel.android.dspmanager"

this means that the system process, the phone process and DSP Manager will be preserved from killing

1) By using a customized init.d script (the custom value will be always restored after a reboot, if you don't format the system partition)

- Download the script named 80dnkp

- If the file has been saved with .txt extension (stock browser), rename it by removing the .txt extension

- Edit the file by setting your preferred status and processes list

- Copy the new file inside /etc/init.d

- Give the rwxr-xr-x permissions to the file (read, write, execution for owner, read and execution for group users, read and execution for others)

- Reboot

2) By directly editing the files inside /sys/module/lowmemorykiller/parameters (note that set values will be lost after a reboot/shutdown)

3) By using Terminal Emulator (note that set values will be lost after a reboot/shutdown)

- Open Terminal Emulator

- Run these commands if you want to enable the feature

# To enable this feature for the processes chosen by the user
echo 1 > /sys/module/lowmemorykiller/parameters/donotkill_proc
# To enable this feature for the system processes chosen by the user
echo 1 > /sys/module/lowmemorykiller/parameters/donotkill_sysproc

- Run these commands if you want to disable the feature

# To disable this feature for the processes chosen by the user
echo 0 > /sys/module/lowmemorykiller/parameters/donotkill_proc
# To disable this feature for the system processes chosen by the user
echo 0 > /sys/module/lowmemorykiller/parameters/donotkill_sysproc

- Run this command if you want to add, for example, Trebuchet Launcher (CM default launcher) and the default keyboard to the processes white list

echo "com.cyanogenmod.trebuchet,android.inputmethod.latin" > /sys/module/lowmemorykiller/parameters/donotkill_proc_names

- Run this command if you want to add, for example, the system process, the phone process and DSP Manager to the system processes white list

echo "android.process.acore,com.android.phone,com.bel.android.dspmanager" > /sys/module/lowmemorykiller/parameters/donotkill_sysproc_names

Work in progress...