[Galaxy Ace S5830 Android Development] tazzz811:
Create 00tweaks and put all the codes inside 00tweaks then put the file to system/etc/init.d

#!/system/bin/sh

#remounting the file systems with noatime and nodiratime flags to save battery and CPU cycles

for k in $(busybox mount | grep relatime | cut -d " " -f3)
do
sync
busybox mount -o remount,noatime,nodiratime $k
done

#if mounting is not successful then manual mounting will do the thing for you
mount -o remount,noatime,nodiratime auto /
mount -o remount,noatime,nodiratime auto /dev
mount -o remount,noatime,nodiratime auto /proc
mount -o remount,noatime,nodiratime auto /sys
mount -o remount,noatime,nodiratime auto /mnt/asec
mount -o remount,noatime,nodiratime auto /system
mount -o remount,noatime,nodiratime auto /data
mount -o remount,noatime,nodiratime auto /cache
mount -o remount,noatime,nodiratime auto /mnt/sdcard
mount -o remount,noatime,nodiratime auto /mnt/secure/asec
mount -o remount,noatime,nodiratime auto /mnt/sdcard/.android_secure

#flags every mounted partition as non rotational and increases it's cache size for more read speed

MTD=`ls -d /sys/block/mtd*`;
LOOP=`ls -d /sys/block/loop*`;
RAM=`ls -d /sys/block/ram*`;
MMC=`ls -d /sys/block/mmc*`;

for j in $MTD $LOOP $RAM
do
echo "0" > $j/queue/rotational;
echo "4096" > $j/queue/read_ahead_kb;

done

echo "4096" > /sys/devices/virtual/bdi/179:0/read_ahead_kb;

for a in $MTD $MMC
do
echo "512" > $a/queue/nr_requests;
done

#internet speed tweaks
echo 0 > /proc/sys/net/ipv4/tcp_timestamps;
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse;
echo 1 > /proc/sys/net/ipv4/tcp_sack;
echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle;
echo 1 > /proc/sys/net/ipv4/tcp_window_scaling;
echo 5 > /proc/sys/net/ipv4/tcp_keepalive_probes;
echo 30 > /proc/sys/net/ipv4/tcp_keepalive_intvl;
echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout;
echo 404480 > /proc/sys/net/core/wmem_max;
echo 404480 > /proc/sys/net/core/rmem_max;
echo 256960 > /proc/sys/net/core/rmem_default;
echo 256960 > /proc/sys/net/core/wmem_default;
echo 4096 16384 404480 > /proc/sys/net/ipv4/tcp_wmem;
echo 4096 87380 404480 > /proc/sys/net/ipv4/tcp_rmem;

#vm management tweaks
echo "0" > /proc/sys/vm/swappiness;
echo "95" > /proc/sys/vm/dirty_ratio;
echo "10" > /proc/sys/vm/vfs_cache_pressure;
echo "20480" > /proc/sys/vm/min_free_kbytes;
echo "1" > /proc/sys/vm/oom_kill_allocating_task;
echo "0" > /proc/sys/vm/laptop_mode;
echo "60000" > /proc/sys/vm/dirty_expire_centisecs;
echo "60" > /proc/sys/vm/dirty_background_ratio;
echo "6000" > /proc/sys/vm/dirty_writeback_centisecs;
echo "3" > /proc/sys/vm/drop_caches;

#kernel tweaks
echo "8" > /proc/sys/vm/page-cluster;
echo "64000" > /proc/sys/kernel/msgmni;
echo "64000" > /proc/sys/kernel/msgmax;
echo "10" > /proc/sys/fs/lease-break-time;
echo 500 512000 64 2048 > /proc/sys/kernel/sem;

# use deadline scheduler
echo deadline > /sys/class/block/mmcblk0/queue/scheduler;
echo deadline > /sys/class/block/stl14/queue/scheduler;
echo deadline > /sys/class/block/stl13/queue/scheduler;
echo deadline > /sys/class/block/stl12/queue/scheduler;
echo 8 > /sys/class/block/mmcblk0/queue/iosched/fifo_batch;
echo 8 > /sys/class/block/stl14/queue/iosched/fifo_batch;
echo 8 > /sys/class/block/stl13/queue/iosched/fifo_batch;
echo 8 > /sys/class/block/stl12/queue/iosched/fifo_batch;
echo 400 > /sys/class/block/mmcblk0/queue/iosched/read_expire;
echo 400 > /sys/class/block/stl14/queue/iosched/read_expire;
echo 400 > /sys/class/block/stl13/queue/iosched/read_expire;
echo 400 > /sys/class/block/stl12/queue/iosched/read_expire;
echo 4 > /sys/class/block/mmcblk0/queue/iosched/writes_starved;
echo 4 > /sys/class/block/stl14/queue/iosched/writes_starved;
echo 4 > /sys/class/block/stl13/queue/iosched/writes_starved;
echo 4 > /sys/class/block/stl12/queue/iosched/writes_starved;

#setprop
setprop wifi.supplicant_scan_interval 600;
setprop windowsmgr.max_events_per_sec 260;
setprop ro.lge.proximity.delay 25;
setprop mot.proximity.delay 75;
setprop net.tcp.buffersize.default 4096,87380,256960,4096,16384,256960;
setprop net.tcp.buffersize.wifi 4096,87380,256960,4096,16384,256960;
setprop net.tcp.buffersize.umts 4096,87380,256960,4096,16384,256960;
setprop ro.HOME_APP_ADJ 1;
setprop ro.mot.eri.losalert.delay 1000;
setprop video.accelerate.hw 1;
setprop ro.ril.disable.power.collapse 0;
setprop pm.sleep_mode 1;
setprop media.stagefright.enable-player true;

#lowmemory
FOREGROUND_APP_MEM="2560";
VISIBLE_APP_MEM="4096";
SECONDARY_SERVER_MEM="6144";
HIDDEN_APP_MEM="17408";
CONTENT_PROVIDER_MEM="19456";
EMPTY_APP_MEM="23552";

#governor scaling awake
GOVERNOR_SCALE="ondemand";
GOVERNOR_FREQENCY_MAX="800000";
GOVERNOR_FREQENCY_MIN="245760";
SAMPLING_RATE="50000";
FREQ_STEP="40";
UP_THRESHOLD="90";
DOWN_THRESHOLD="20";

#governor scaling sleep
SLEEP_SCALE="ondemand";
SLEEP_FREQENCY_MAX="480000";
SLEEP_FREQENCY_MIN="245760";
XSAMPLING_RATE="100000";
XFREQ_STEP="15";
XUP_THRESHOLD="90";
XDOWN_THRESHOLD="20";

#locking app
LOCK_APP_IN_MEMORY_ENABLED="0"
LOCK_APP_SU="1"
LOCK_APP_DIALER="0"
LOCK_APP_MMS="0"
LOCK_APP_HANDCENT="0"

# =========
# remove lag when answering phone calls
# =========
MAX_PHONE()
{
pidphone=`pidof com.android.phone`;
if [ $pidphone ];
then
/system/xbin/echo "-17" > /proc/$pidphone/oom_adj;
renice -20 $pidphone;
if [ $MAX_APP -eq "1" ];
then
exit;
else
MAX_APP_STARTER;
MAX_APP=1;
exit;
fi;
else
sleep 3;
MAX_PHONE;
fi;
}

# =========
# remove lag from su (root)
# =========
MAX_SU()
{
pidsu=`pidof com.noshufou.android.su`;
if [ $pidsu ];
then
/system/xbin/echo "-17" > /proc/$pidsu/oom_adj;
renice -20 $pidsu;
exit;
else
sleep 3;
MAX_SU;
fi;
}

# =========
# remove lag from Clock
# =========
MAX_DIALER()
{
piddialer=`pidof kz.mek.DialerOne`;
if [ $piddialer ];
then
/system/xbin/echo "-17" > /proc/$piddialer/oom_adj;
renice -10 $piddialer;
exit;
else
sleep 3;
MAX_DIALER;
fi;
}

# =========
# remove lag from MMS
# =========
MAX_MMS()
{
pidmms=`pidof com.android.mms`;
if [ $pidmms ];
then
/system/xbin/echo "-17" > /proc/$pidmms/oom_adj;
renice -10 $pidmms;
exit;
else
sleep 3;
MAX_MMS;
fi;
}

# =========
# remove lag from HANDCENT
# =========
MAX_HANDCENT()
{
pidhandcent=`pidof com.handcent.nextsms`;
if [ $pidhandcent ];
then
/system/xbin/echo "-17" > /proc/$pidhandcent/oom_adj;
renice -10 $pidhandcent;
exit;
else
sleep 3;
MAX_HANDCENT;
fi;
}

# =========
# Background process to optimize process
# =========
MAX_APP_STARTER()
{
if [ $LOCK_APP_IN_MEMORY_ENABLED -eq "1" ];
then
if [ $LOCK_APP_SU -eq "1" ];
then
(while [ 1 ];
do
sleep 5;
MAX_SU;
done &);
fi;
if [ $LOCK_APP_MMS -eq "1" ];
then
(while [ 1 ];
do
sleep 3;
MAX_MMS;
done &);
fi;
if [ $LOCK_APP_HANDCENT -eq "1" ];
then
(while [ 1 ];
do
sleep 3;
MAX_HANDCENT;
done &);
fi;
if [ $LOCK_APP_DIALER -eq "1" ];
then
(while [ 1 ];
do
sleep 3;
MAX_DIALER;
done &);
fi;
exit;
else
(while [ 1 ];
do
sleep 3;
MAX_APP_STARTER;
done &);
fi;
}

if [ $LOCK_APP_IN_MEMORY_ENABLED -eq "1" ];
then
(while [ 1 ];
do
sleep 3;
MAX_PHONE;
done &);
fi;

GOV_MODE()
{
echo "1" >/proc/sys/vm/overcommit_memory;
echo "4" > /proc/sys/vm/min_free_order_shift;
echo $FOREGROUND_APP_MEM,$VISIBLE_APP_MEM,$SECONDARY_SERVER_MEM,$HIDDEN_APP_MEM,$CONTENT_PROVIDER_MEM,$EMPTY_APP_MEM > /sys/module/lowmemorykiller/parameters/minfree;

echo $GOVERNOR_SCALE > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor;
echo $GOVERNOR_FREQENCY_MAX > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo $GOVERNOR_FREQENCY_MIN > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq;
echo $SAMPLING_RATE > /sys/devices/system/cpu/cpu0/cpufreq/$GOVERNOR_SCALE/sampling_rate;
echo $FREQ_STEP > /sys/devices/system/cpu/cpu0/cpufreq/$GOVERNOR_SCALE/freq_step;
echo $UP_THRESHOLD > /sys/devices/system/cpu/cpu0/cpufreq/$GOVERNOR_SCALE/up_threshold;
echo $DOWN_THRESHOLD > /sys/devices/system/cpu/cpu0/cpufreq/$GOVERNOR_SCALE/down_threshold;
}

SLEEP_MODE()
{
echo "1" >/proc/sys/vm/overcommit_memory;
echo "4" > /proc/sys/vm/min_free_order_shift;
echo $FOREGROUND_APP_MEM,$VISIBLE_APP_MEM,$SECONDARY_SERVER_MEM,$HIDDEN_APP_MEM,$CONTENT_PROVIDER_MEM,$EMPTY_APP_MEM > /sys/module/lowmemorykiller/parameters/minfree;

echo $SLEEP_SCALE > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor;
echo $SLEEP_FREQENCY_MAX > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq;
echo $SLEEP_FREQENCY_MIN > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq;
echo $XSAMPLING_RATE > /sys/devices/system/cpu/cpu0/cpufreq/$SLEEP_SCALE/sampling_rate;
echo $XFREQ_STEP > /sys/devices/system/cpu/cpu0/cpufreq/$SLEEP_SCALE/freq_step;
echo $XUP_THRESHOLD > /sys/devices/system/cpu/cpu0/cpufreq/$SLEEP_SCALE/up_threshold;
echo $XDOWN_THRESHOLD > /sys/devices/system/cpu/cpu0/cpufreq/$SLEEP_SCALE/down_threshold;
}

# =========
# Background process to check screen state
# =========
(while [ 1 ];
do
STATE=`cat /sys/power/wait_for_fb_wake`;
GOV_MODE;
sleep 3;
STATE=`cat /sys/power/wait_for_fb_sleep`;
SLEEP_MODE;
sleep 3;
done &);