Sysctl.conf 안드로이드

The sysctl.conf is a configuration file for "sysctl" which is an interface for dynamically changing kernel parameters in the Linux OS. The configuration file contains the following elements, vm.min_free_kbytes, vm.dirty_ratio, vm.dirty_backgroud_ratio, vm.vfs_cache_pressure, vm.oom_kill_allocating_task. There are many other elements within the file, but we will be primarily focusing on these specifically (the vm prefix stands for virtual memory). The sysctl.conf file should be located in /etc (/system/etc) by default. To enable it you need your ROM to execute "sysctl -p" somewhere during the boot process (or shortly afterward). We will also be discussing how to enable it if it is not already done so. You can also run sysctl -p manually to enable it any time after the OS is started.

Now, let’s get down to what sysctl.conf does and how it works.

Min Free KBytes (vm.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 pages_min value for each lowmem zone in the system. Each lowmem zone gets a number of reserved free pages based proportionally on its size. Default is 2048kb.

Dirty Ratio (vm.dirty_ratio)
 and Dirty Background Ratio (vm.dirty_background_ratio) control how often the kernel writes data to "disk" (in our case the internal microSD system card, not the removable microSD card). When your apps write data to disk, Linux actually doesn't write the data out to the disk right away, it actually writes the stuff to system memory and the kernel handles when and how the data is actually going to be flushed to the disk. These values represent a percentage, the higher the percentage, the longer it waits to flush, the lower the percentage, the more often flushes will occur. Now remember, we are dealing with solid state storage, not the traditional disk platter and spindle. So we are actually able to delay flushes a little longer with solid state versus a traditional hard drive disk.

VFS Cache Pressure (vm.vfs_cache_pressure) -
Now here is where it gets interesting! File system cache (dentry/inode) is really more important than the block cache above in dirty ratio and dirty background ratio, so we really want the kernel to use up much more of the RAM for file system cache, this will increas the performance of the system without sacrificing performance at the application level. The default value is 100, as a percentage, and what you want to do is lower the value to tell the kernel to favor the file system cache and not drop them aggressively.

Oom Allocating Task
 (vm.oom_kill_allocating_task) (enable or disable, generally in Linux this value is either a "1" or a "0," representing as on or off.) -This enables or disables killing the OOM-triggering task in out-of-memory (oom) situations. If this is set to zero, or disabled, the OOM killer will scan through the entire task list and select a task based on heuristics to kill. This normally selects a rogue memory-hogging task that frees up a large amount of memory when killed. If this is set to non-zero, or enabled, the OOM killer simply kills the task that triggered the out-of-memory condition. This avoids the expensive task list scan, which can take mass amounts of time and "hang" or freeze the system.

This information has been pulled from the following sites:
http://www.imoseyon.com/2011/05/dxd2-tweaks-new-version-man-its-been.html (newest)
imoseyon: Sysctl tweaking for faster, longer lasting Android (deprecated)
imoseyon: sysctl (and minfree) tweaks revisited (deprecated)
/proc/sys/vm | LinuxInsight (deprecated)

sysctl (and minfree) tweaks revisited

(This is a follow up to my first post).

First of all, I believe tweaking minfree is just as important, if not more, than sysctl.  Android tends to behave badly when there's very little free memory.  When you're running your device with say less than 20-30MB of free RAM, a misbehaving app or two could invoke kernel's OOM killer and cause the device to become unstable, then eventually reboot or freeze.

For that reason, I don't like the default value of 25MB minfree.  (minfree, btw, is android's memory management system).  From my experience, I think at least 80MB minfree is required for your device to run fast and stable.  In general I recommend Rubix's minfree setting (20480 blocks x 4 will give you 80MB): 

echo "2048,3072,6144,15360,17920,20480"  > /sys/module/lowmemorykiller/parameters/minfree

I personally run my Droid X with the following: 

echo "256,512,1024,5120,13000,20000" > /sys/module/lowmemorykiller/parameters/minfree

Both should be fine.  Be sure that the last two numbers are at least 13000 and 20000.

Now back to sysctl.  Personally, I haven't had to manually drop caches at all.  In fact, my phone will probably run fine indefinitely without having to purge (longest i've run it without rebooting was 5 days, but it's really hard not to reboot your phone when you tweak it as much as i do - the kernel will automatically drop caches when it think it needs more memory). But I'm not a heavy user (i don't play games),  your mileage will vary of course, and you may need to purge every once in while.   To purge page, dentry and inode caches, use this command:
sync; echo 3 > /proc/sys/vm/drop_caches
My personal recommendation for most people (no manual flushing should be required):
vm.dirty_ratio = 90
vm.dirty_background_ratio = 55
vm.vfs_cache_pressure = 20
If you are willing to play around with manual or timed flushing I think you can squeeze a little more performance and battery life with:
vm.dirty_ratio = 90
vm.dirty_background_ratio = 70
vm.vfs_cache_pressure = 1
Btw, you can schedule cache purge using Tasker/sl4a, or you can use cron.

Sysctl tweaking for faster, longer lasting Android

If your ROM supports sysctl, you can do lots of cool things.  (Well even if your ROM doesn't you can as long as you're rooted with busybox, but it takes a bit more work).

In this post, let's focus on three settings: vm.dirty_ratio, vm.dirty_backgroud_ratio, and vm.vfs_cache_pressure.

vm.dirty_ratio and vm.dirty_background_ratio control how often kernel writes data to "disk" (well in our case the microSD card).  When your apps write data to disk, Linux actually doesn't write the data out to disk right away, it actually writes the stuff to system memory and the kernel handles when/how the data is actually going to be flushed to disk.

I dunno - how much difference can it actually make?  We're not talking about traditional hard drives with spindles, we're talking about solid state stuff.  I suppose there could be a slight savings in battery life and increase in performance if you delay the data flush as much as you can.

I ended up with:
vm.dirty_ratio = 90
vm.dirty_background_ratio = 70
Now vm.vfs_cache_pressure is much more interesting. File system cache (dentry/inode) is really more important than the block cache above, so we really want the kernel to use up much of the RAM for them.  The default value is 100, and what you want to do is lower that value to tell the kernel to favor the file system cache and not drop them aggressively.

You can also take it a step further and set it to 1 (lowest possible without being dangerous).  With the value of 1 the kernel will drop cache only when it's completely out of memory. 
vm.vfs_cache_pressure = 1
The problem is if you lower the value too much, after a day or two your device may start getting sluggish because the amount of RAM available to the applications continue to shrink to the point where they are starved for memory.  So I came up with a solution to manually drop caches nightly!
echo 3 > /proc/sys/vm/drop_caches 
# tells kernel to drop all file system caches
And what I do to ensure that the caches are dropped nightly is to run the following sl4a scripts via tasker.  Cron would be better but busybox on android doesn't seem to support it yet.

(It also reverts the dirty settings because I don't care if my phone writes to disk aggresively while i'm sleeping and it's being charged.)
su -c 'echo 3 > /proc/sys/vm/drop_caches;\
sysctl -w vm.dirty_background_ratio=3;\
sysctl -w vm.dirty_ratio=15'
And the following script at wakeup time:
su -c 'echo 3 > /proc/sys/vm/drop_caches;\
sysctl -w vm.dirty_background_ratio=70;\
sysctl -w vm.dirty_ratio=90'
Finally, here's what my sysctl.conf file looks like:
# cat /etc/sysctl.conf
# shouldn't matter - no swap is used
vm.swappiness = 0

# try to keep at least 4MB in memory
vm.min_free_kbytes = 4096

# favor block cache
vm.dirty_ratio = 90 
vm.dirty_background_ratio = 70

# extremely favor file cache
vm.vfs_cache_pressure = 1

# reboot when OOM happens
vm.panic_on_oom = 2

# wait 5 sec before rebooting when OOM
kernel.panic = 5



# currently experimenting
kernel.shmmax = 268435456
kernel.shmall = 16777216
I've been running at the above settings for a few days now, and the phone has been faster than ever with zero ill effects.  Your mileage may vary of course.

데비안에서 CD-ROM없이 패키지 설치하기 리눅스

처음으로 데비안 설치 시 apt-get으로 패키지를 설치 하려 하면 CD-ROM을 넣으라고 하는 경우가 있습니다

그럴 경우에는

시스템 - 관리 - 시냅틱 패키지 관리자 에 루트 비밀번호를 치고 들어가

설정 - 저장소 Third-part software 에서 CD-ROM에 관련된 탭을 체크 해제 하시면 됩니다

데비안 sudo 설정 리눅스

루트 터미널 실행후
vi /etc/sudoers (vi가 익숙치 않다면 gedit으로 여는것을 추천)

그후
  root           ALL=(ALL)       ALL             라고 써있는부분을
  자신의 계정        ALL=(ALL)       ALL   으로 수정

대소문자 구별하니 주의하세요.
그 후로 sudo로 권한을 얻을때는 루트 비밀번호가 아니라 계정 비밀번호를 입력하시면 됩니다.

etc. 안드로이드

GPS.conf
(create or edit your /system/etc/gps.conf with a file manager with root access)

For improving GPS lock time and signal.

a) European NTP server (replace for america or asia in your case)

Code:
NTP_SERVER=europe.pool.ntp.org
XTRA_SERVER_1=http://xtra1.gpsonextra.net/xtra.bin
XTRA_SERVER_2=http://xtra2.gpsonextra.net/xtra.bin
XTRA_SERVER_3=http://xtra3.gpsonextra.net/xtra.bin

b) SE supl for A-GPS (better than Nokia's or Google's)

Code:
SUPL_HOST=supl.sonyericsson.com
SUPL_PORT=7275


Other tweaks or guidelines

1. Patch your hosts file for blocking Ads 
(please think before doing this; many developers are supported through this way)

Code:
You can use AdFree application for this or changing manually your hosts file.
Here are some databases:
http://www.mvps.org/winhelp2002/hosts.txt
http://pgl.yoyo.org/adservers/serverlist.php?showintro=0;hostformat=hosts

2. Use CyanogenMOD's APN list file - it's one of the most complete.

Code:
It's located in /system/etc/apns-conf.xml

3. Use UOT kitchen for basic theming on your device.

Code:
http://uot.dakra.lt/

4. Use Google's dns servers

Code:
Create an empty file, name it resolv.conf and put there these 2 lines:
nameserver 8.8.8.8
nameserver 8.8.4.4

Save to /system/etc/.

5. Update Superuser and su binary to latest version (3.0 beta)

Code:
http://goo-inside.me/superuser/

6. Disable sync feature in sqlite
(author: ownhere - needs a source for your device so you can compile the /system/lib/libsqlite.so)

Code:
Patch file here: http://forum.xda-developers.com/showthread.php?t=903507

7. Do not use task killers.


Alright, I think this is it for now.
If you have any other tweaks or better values, you can PM me and I'll include them.


init.d 안드로이드

Init.d
(needs ROM with init.d access and busybox, open empty file, insert header #!/system/bin/sh and put these there, save in /system/etc/init.d and name it something like 77tweaks)

1. strict minfree handler tweak

Code:
echo "2048,3072,6144,15360,17920,20480" > /sys/module/lowmemorykiller/parameters/minfree

2. internet speed tweaks

Code:
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;

3. vm management tweaks 

Code:
echo "4096" > /proc/sys/vm/min_free_kbytes
echo "0" > /proc/sys/vm/oom_kill_allocating_task;
echo "0" > /proc/sys/vm/panic_on_oom;
echo "0" > /proc/sys/vm/laptop_mode;
echo "0" > /proc/sys/vm/swappiness
echo "50" > /proc/sys/vm/vfs_cache_pressure
echo "90" > /proc/sys/vm/dirty_ratio
echo "70" > /proc/sys/vm/dirty_background_ratio

4. misc kernel tweaks

Code:
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;

5. battery tweaks

Code:
echo "500" > /proc/sys/vm/dirty_expire_centisecs
echo "1000" > /proc/sys/vm/dirty_writeback_centisecs

6. EXT4 tweaks (greatly increase I/O)
(needs /system, /cache, /data partitions formatted to EXT4)

a) removes journalism

Code:
tune2fs -o journal_data_writeback /block/path/to/system
tune2fs -O ^has_journal /block/path/to/system
tune2fs -o journal_data_writeback /block/path/to/cache
tune2fs -O ^has_journal /block/path/to/cache
tune2fs -o journal_data_writeback /block/path/to/data
tune2fs -O ^has_journal /block/path/to/data

b) perfect mount options

Code:
busybox mount -o remount,noatime,noauto_da_alloc,nosuid,nodev,nodiratime,barrier=0,nobh /system
busybox mount -o remount,noatime,noauto_da_alloc,nosuid,nodev,nodiratime,barrier=0,nobh /data
busybox mount -o remount,noatime,noauto_da_alloc,nosuid,nodev,nodiratime,barrier=0,nobh /cache

7. Flags blocks as non-rotational and increases cache size

Code:
LOOP=`ls -d /sys/block/loop*`;
RAM=`ls -d /sys/block/ram*`;
MMC=`ls -d /sys/block/mmc*`;
for j in $LOOP $RAM
do
echo "0" > $j/queue/rotational;
echo "2048" > $j/queue/read_ahead_kb;
done

8. microSD card speed tweak 

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

9. Defrags database files

Code:
for i in \`find /data -iname "*.db"`do \sqlite3 $i 'VACUUM;'; done

9. Remove logger

Code:
rm /dev/log/main

10. Ondemand governor tweaks

Code:
SAMPLING_RATE=$(busybox expr `cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_transition_latency` \* 750 / 1000)
echo 95 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
echo $SAMPLING_RATE > /sys/devices/system/cpu/cpu0/cpufreq/ondemand/sampling_rate

11. Auto change governor and I/O Scheduler

a) I/O Scheduler (Best: MTD devices - VR; EMMC devices - SIO) - needs kernel with these

Code:
echo "vr" > /sys/block/mmcblk0/queue/scheduler
or
echo "sio" > /sys/block/mmcblk0/queue/scheduler

b) Governor (Best: Minmax > SavagedZen > Smoothass > Smartass > Interactive) - needs kernel with these

Code:
echo "governor-name-here" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

12. Auto-zipalign on boot
(needs zipalign bin)

13. Loopy Smoothness tweak

14. Move dalvik-cache to cache partition (if it's big enough) to free up data partition space

Code:
CACHESIZE=$(df -k /cache | tail -n1 | tr -s ' ' | cut -d ' ' -f2)
if [ $CACHESIZE -gt 80000 ]
then
echo "Large cache detected, moving dalvik-cache to /cache"
if [ ! -d /cache/dalvik-cache ]
then
busybox rm -rf /cache/dalvik-cache /data/dalvik-cache
mkdir /cache/dalvik-cache /data/dalvik-cache
fi
busybox chown 1000:1000 /cache/dalvik-cache
busybox chmod 0771 /cache/dalvik-cache
# bind mount dalvik-cache so we can still boot without the sdcard
busybox mount -o bind /cache/dalvik-cache /data/dalvik-cache
busybox chown 1000:1000 /data/dalvik-cache
busybox chmod 0771 /data/dalvik-cache
else
echo "Small cache detected, dalvik-cache will remain on /data"
fi

15. Disable normalize sleeper

Code:
mount -t debugfs none /sys/kernel/debug
echo NO_NORMALIZED_SLEEPER > /sys/kernel/debug/sched_features

16. OOM groupings and priorities tweaks - SuperCharger


1 2