[Android General] Paget96:
Everyone who knows a bit of the performance/battery mods wants sometime to learn what is inside and how it's working :)

Here is a guide by [MENTION=5514152]Paget96[/MENTION] (me) ^~^

As we know for every mod we need root, this is needed because we must to access to android shell.

init.d support, that is a folder which launch files from it on every boot. Init.d is included on some ROM's by default, but on some you need yo enable it by default(I will explain later how). ;)

Next thing what you need is for sure busybox. :) And a little bit of free space on the /system partition.

Everyone knows how to root, I don't need to explain how to do that :D right?

User who doesn't have init.d will make it with next steps.

1. Flash superSU by [MENTION=631273]Chainfire[/MENTION] (IMPORTANT)

2. In /system/etc/ make a file with the name "install-recovery-2.sh and push next code in it

#!/system/bin/sh
/system/bin/sysinit

3. Inside system/bin make a file with the name " sysinit" and push next code in it

#!/system/bin/sh

busybox sleep 30

export PATH=/sbin:/system/sbin:/system/bin:/system/xbin
run-parts /system/etc/init.d

4. Open /system/etc and make folder with the name "init.d"

Now you need to set permissions for all of this files.

Open terminal emulator and do next:

su

This will give root access

busybox chmod 755 /system/etc/install-recovery-2.sh
busybox chown 0.2000 /system/etc/install-recovery-2.sh

With this you will set "executable" permissions.

And we need permission for sysinit

busybox chmod 755 /system/bin/sysinit
busybox chown 0.2000 /system/bin/sysinit

And that's it :D

To install busybox use app "busybox installer" by stericson from playstore.

***IMPORTANT*** Don't change too much things, because you will get crap in your hands :)

Tools which are needed is

Text editor, I suggest Turbo Editor

Terminal emulator

ES file explorer

Ok, let's start :)

We will start with virtual memory tweaking...

Open file manager and create one folder where you will build a mod.

Inside it we will create one file for beginning and call it "00sysmod"

#!/system/bin/sh
busybox chmod 644 /proc/sys/vm/*
busybox sysctl -e -w vm.dirty_background_ratio=3
busybox sysctl -e -w vm.dirty_ratio=15
busybox sysctl -e -w vm.swappiness=40
busybox sysctl -e -w vm.dirty_expire_centisecs=500
busybox sysctl -e -w vm.dirty_writeback_centisecs=3000
busybox sysctl -e -w vm.min_free_kbytes=4096
busybox sysctl -e -w vm.overcommit_memory=1
busybox sysctl -e -w vm.overcommit_ratio=75
busybox sysctl -e -w vm.page-cluster=0
busybox sysctl -e -w vm.panic_on_oom=0

Copy this inside file, save it and copy to init.d folder :)

After that set permissions to 755

busybox chmod 755 /system/etc/init.d/00sysmod

Let's explain every line:

First line is a header of every script.

Next line will change permissions (in this case read, write, read, read) of a files which are inside /proc/sys/vm/*. * means every file.

Everything below it are vm parameters.

vm.dirty_background_ratio

Contains, as a percentage of total available memory that contains free pages

and reclaimable pages, the number of pages at which the background kernel

flusher threads will start writing out dirty data.

The total avaiable memory is not equal to total system memory.

dirty_ratio

Contains, as a percentage of total available memory that contains free pages

and reclaimable pages, the number of pages at which a process which is

generating disk writes will itself start writing out dirty data.

The total avaiable memory is not equal to total system memory.

swappiness

This control is used to define how aggressive the kernel will swap

memory pages. Higher values will increase agressiveness, lower values

decrease the amount of swap. A value of 0 instructs the kernel not to

initiate swap until the amount of free and file-backed pages is less

than the high water mark in a zone.

The default value is 60.

dirty_expire_centisecs

This tunable is used to define when dirty data is old enough to be eligible

for writeout by the kernel flusher threads. It is expressed in 100'ths

of a second. Data which has been dirty in-memory for longer than this

interval will be written out next time a flusher thread wakes up.

dirty_writeback_centisecs

The kernel flusher threads will periodically wake up and write `old' data

out to disk. This tunable expresses the interval between those wakeups, in

100'ths of a second.

Setting this to zero disables periodic writeback altogether.

min_free_kbytes

This is used to force the Linux VM to keep a minimum number

of kilobytes free. The VM uses this number to compute a

watermark[WMARK_MIN] value for each lowmem zone in the system.

Each lowmem zone gets a number of reserved free pages based

proportionally on its size.

Some minimal amount of memory is needed to satisfy PF_MEMALLOC

allocations; if you set this to lower than 1024KB, your system will

become subtly broken, and prone to deadlock under high loads.

Setting this too high will OOM your machine instantly.

overcommit_memory

This value contains a flag that enables memory overcommitment.

When this flag is 0, the kernel attempts to estimate the amount

of free memory left when userspace requests more memory.

When this flag is 1, the kernel pretends there is always enough

memory until it actually runs out.

When this flag is 2, the kernel uses a "never overcommit"

policy that attempts to prevent any overcommit of memory.

Note that user_reserve_kbytes affects this policy.

DON'T CHANGE THIS VALUE, YOU WILL GET CRAP IN A HANDS, THIS IS JUST FOR INFO

overcommit_ratio

With this parameter you will set how much space will allocations use in physical RAM. (Percentage)

page-cluster

page-cluster controls the number of pages up to which consecutive pages

are read in from swap in a single attempt. This is the swap counterpart

to page cache readahead.

The mentioned consecutivity is not in terms of virtual/physical addresses,

but consecutive on swap space - that means they were swapped out together.

It is a logarithmic value - setting it to zero means "1 page", setting

it to 1 means "2 pages", setting it to 2 means "4 pages", etc.

Zero disables swap readahead completely.

panic_on_oom

This enables or disables panic on out-of-memory feature.

If this is set to 0, the kernel will kill some rogue process,

called oom_killer. Usually, oom_killer can kill rogue processes and

system will survive.

If this is set to 1, the kernel panics when out-of-memory happens.

If this is set to 2, the kernel panics compulsorily even on the

above-mentioned. Even oom happens under memory cgroup, the whole

system panics

In this part we will tweak kernel parameters

Open file manager as before and create a file with the name " 00kerneltweak"

Here we will use if statement, just for a little practise ^~^

if [ -e /proc/sys/kernel/shmmni ]; then
busybox echo "2048" > /proc/sys/kernel/shmmni
fi
if [ -e /proc/sys/kernel/shmall ]; then
busybox echo "1572864" > /proc/sys/kernel/shmall
fi
if [ -e /proc/sys/kernel/shmmax ]; then
busybox echo "33554432" > /proc/sys/kernel/shmmax
fi
if [ -e /proc/sys/kernel/msgmni ]; then
busybox echo "512" > /proc/sys/kernel/msgmni
fi
if [ -e /proc/sys/kernel/msgmnb ]; then
busybox echo "16384" > /proc/sys/kernel/msgmnb
fi
if [ -e /proc/sys/kernel/msgmax ]; then
busybox echo "8192" > /proc/sys/kernel/msgmax
fi

Copy this inside file, save it and copy to init.d folder :)

After that set permissions to 755

busybox chmod 755 /system/etc/init.d/00kerneltweak

Same as we learned before if file exist then do next :)

Let's explain this parameters:

shmall

The total amount of shared memory (in pages) which can be allocated on the system

shmmax

The maximum size of a shared memory segment (in pages)

shmmni

The maximum number of shared memory segments available on the system

msgmni

The number of IPC message queue resources allowed (by default, 16).

msgmnb

Defines the maximum size in bytes of a single message queue. The default value is 65536 bytes.

msgmax

The maxim... :D