FORUMS
Remove All Ads from XDA

 View Poll Results: Was this guide helpful to you?

Yes
 
98 Vote(s)
96.08%
No
 
4 Vote(s)
3.92%

[GUIDE][Kernel] Comprehensive Guide to Kernels. [UPDATE:21.12.16]

707 posts
Thanks Meter: 539
 
By Kyuubi10, Senior Member on 29th May 2015, 01:36 AM
Post Reply Email Thread
If I answer the question of "what is a kernel" it wouldn't tell you much, besides there are enough other threads on XDA and other websites to answer this question.
The best question is "Why to use a custom Kernel?", which answers not only what it is, but also what it can do.

I like the way its explained here:
http://www.makeuseof.com/tag/conside...ndroid-kernel/

The next most important thing you need besides the custom kernel is an app to manage it.
Yes, you can change the code directly, but for most non-nerds an app tends to be best, providing a nice GUI to facilitate tuning.
And since I am aiming for this guide to be N00b proof, I am gonna provide as much information as possible.

There aren't many apps which give you control over all features of the kernel and, personally, I hate having to download multiple apps to control every feature of the kernel.
So these are my top 3 recommendations:
  1. The original app from the kernel's dev. You know, the one made specifically for use with that Kernel?
  2. Device Control [root] by Alexander Martinz (Not gonna explain why, just go and test it for yourself or at least look at the play store page)
  3. Kernel Adiutor by Willi Ye (It has a nice material GUI, + Extra features such as tweaking low memory killer, sysctl & sysfs)
What I most found lacking in other kernel guides was a well organised and comprehensive list of things custom kernels can offer. And since there is so much a Kernel could offer I'm going to try to provide it in categories with a couple examples so you get a good idea.

If I there is anything not accounted for, you are welcome to reply to this post and I will be checking every day to expand with any new info.

So without any further ado:

Feature List
General Settings:
These are things which do not fall within any of the other categories to follow. They are things which are usually classed separately in the App used to control the kernel. Examples include but are not limited to Fast Charge, Gesture (Knock on, Swipe2Wake), Color Calibration, Vibration Strength.
Advanced Settings:
These are similar to the general settings, but as the name suggests they are a bit more advanced and require a bit more knowledge/research to use effectively.
This includes Entropy (if you have no idea what this is look for Seeder App. The description of the App explains this very well.), Voltage Control (Ever heard of UnderVolting?), TCP Congestion Control (As a Networking Student I had no trouble understanding the technical documents about this, but knowing many who will be reading aren't knowledgeable of technical jargon I have included a nice link.)
http://androidmodguide.blogspot.co.u...lgorithms.html

As I know that there will probably be things I'm missing here, if you find anything which I have not explained, a quick google might be very helpful. Otherwise you are welcome to post a reply to this thread (even including the results of your Google if you need someone to explain it to you in a simple way.)

UPDATE 21/12/16: After getting my new HTC 10 I begun doing some research to understand the big.LITTLE configuration. It turns out that there are in fact some tweakable tunables for this. I won't be providing any recommended settings, since currently I am using a modded PnP which dynamically manages Kernel tunables for me, and as far as I know this is a feature unique to HTC.
But for those interested in finding out more here is a guide you could look through, if you want to learn more. The tunables are at the very end.
https://android.googlesource.com/ker.../sched-hmp.txt

CPU Settings:
This is what you're most likely here for, this is the home of Over (and Under) Clocking.
But it also provides other very useful settings which might not look so simple at first. Here you can select a CPU governor (No guys, I will not list and explain what each one is, there are just too many and too many with stupid names. Instead I will leave you guys with a link to another guide specific about CPU Govs.)
http://androidmodguide.blogspot.co.uk/p/blog-page.html

While we're still talking about CPU Governors, there is a further option that you have if your app supports it. You can tune the specific tunables for each specific Governor, to get the best result possible and most suited to you. Whether you want more performance or battery savings from that specific governor.

Here you can also find toggles for HotPlugging or its counter part CPUquiet (Available only for NVIDIA CPUs I believe.) Hotplugging is simply the technology which decides when and which cores to turn off. CPUquiet is similar but rather than turning off the cores it simply makes the idle. The advantage is debated but the possibility is still there.
GPU Settings:
This one doesn't have many features (That I know of), it allows you to Over/UnderClock your GPU and also change its Governor.
Memory Settings:
(EDIT: I have included a Memory settings after doing a bit more of research about it, since its slightly more complicated compared to the other settings. Although most of these settings are available in both custom or stock kernels they can be tweaked to experience performance and battery improvements. So I'll try to cover as much as I can.)

Here you can tweak anything related to RAM and Cache. For tweaking these settings I suggest using the app Kernel Adiutor which I recommended earlier.
Things which you can find in all kernels are Low Memory Killer (Out of memory killer function on Android.) There is no need for me to explain it, what it does is self explanatory, to better understand the tunables I will provide this link:
http://forum.xda-developers.com/showthread.php?t=622666

You can also find tunables for Virtual Memory (Caching parameters), which is part of "sysctl" in the kernel. Tweaking this improves cache management, helping improve load times of cached apps, battery saving by emptying cache less often etc...
Here is a link which will give you a description for each parameter: https://www.kernel.org/doc/Documentation/sysctl/vm.txt

But there are also things which are not active or part of all kernels. zRAM is part of stock, and some custom kernels disable it. While KSM (Kernel Samepage Merging) can be added by some customs.

zRAM is just compressed RAM space. So you can store more in RAM by compressing the data you can fit more data inside your RAM.
Now obviously it is slower than actual normal RAM (since you have to encrypt and decrypt the data), but apparently it still is faster than using swap (which is in your internal memory rather than RAM). The principle works based on that Android prefers to keep data stored as much as possible in RAM to keep recently used apps running quickly. The more you use an app the more priority it has, therefore will stay in normal RAM, things you use sometimes but not very often are kept in zRAM (regardless of how full your actual RAM is), but since you don't use this very often you don't notice the performance hiccup of decrypting that data.
Then last case scenario things you barely use are kept in swap.
For you IT enthusiasts you should have realised already that "z" is the technology prefix for Compression. So it shouldn't come as a surprise that zRAM is compressed RAM.

KSM (Kernel Samepage Merging), this is simple, but it requires knowledge of some terminology. I will try to explain as simple as possible.
It allows the system to merge/share identical memory pages in RAM from different Applications/Processes. Thus it frees up RAM memory.
The only drawback to this is that it's up to your CPU to perform this task, therefore while it will increase performance it will also use up battery. But this is negligibly small (In my experience).
Therefore my recommendation is that if your Kernel offers this keep it turned on.
File System Settings:
The most desired setting available here is I/O schedulers. Again, I will not specify each scheduler since there are enough guides on the interbebs to give you all the info you need. On the other hand, I will leave you with my favourite of those guides.
http://androidmodguide.blogspot.co.u...chedulers.html

The next most interesting settings is Read Ahead Buffer, this simply lets you choose how much data to load the buffer cache with. According to most benchmarks/tests the best value for this is 3 mb aka 3072 kb. This link gives you a better idea of it: https://broodplank.net/?p=788
Thermal Driver:
Here you can find toggles to manage overheating of the CPU and GPU. An example of which is MSM-Thermal and Core Control. I'm not gonna go into detail about these, since they are pretty self explanatory, and in my experience they both had descriptions beneath the toggles.
The most important thing to keep note of here is that only one should be on at any given time. If you turn 2 or more of these on together it may give you some issues. (It did with me.)
Tips & Recommendations
This is where as usual the writer gets to voice his opinion
Don't hate if you don't agree, just reply with your own opinion!!
I believe that any good custom Kernel should consistently provide some common settings.
We could say the minimum required to be considered a good custom Kernel.

Here is my list of basics:
  • General Settings:
    • Knock On (AKA double tap to wake)
    • Fast Charge
  • Advanced Settings:
    • Entropy
    • TCP Congestion Control
  • CPU Settings, all of it.
  • File System Settings, all of it.

Also my recommendation and tips for ideal CPU tuning and I/O schedulers.

FIrstly, CPU governors can be tuned to improve performance or battery saving. I found a good guide which explains the tunables:
http://forum.xda-developers.com/gala...les-o-t1369817

My recommendations will not take into account all the possible governors, but obviously if you take into account my recommendations and swap my choice of governor for an improved version of the same, or a similar one, then it should be even better.
While regarding the I/O schedulers, they are extremely under documented in comparison to CPU governors. And I have not managed to find a guide on how to best tune the tunables for the schedulers, so I will not cover this. If any one reading has any idea about this, please feel free to share your knowledge with us lowly humans!!
Actual testing reports and comparisons among schedulers are extremely difficult to find. So I will only recommend ones which I have found enough articles for or ones which I have tested myself.

Now for my list of recommendations:
  • Ideal CPU Governor
    • For general use, with a battery saving focus I would recommend the Conservative governor. And if you need a bit more of performance then it can be tuned to provide such.
    • For performance I would use Wheatley. If unavailable, then Elemental X or Interactive will be fine.

    N/B: I added wheatley as an update after using it for a couple months, it has a double focus on both performance and battery saving. It follows the idea of "race to idle", that since idle saves the most battery then dealing with processes quicker means more time spent in idle. Therefore it will scale up to higher frequencies than ondemand and interactive, and it will try to deal with all processes in as quick a time as possible.
    But it also focuses on battery, and if a process queue is taking long it will resort to scaling down the frequency to save battery while still getting work done.
    In my experience I have not felt it glitch, and its very stable. It has improved my battery life (not as much as conservative), but it also has allowed me to use my device at full power.
    But as with anything, there's always a downfall, which for wheatley is that it is a rare governor to find in most kernels. Currently I only have it on skydragon kernel. Most other kernels do not feature this governor.


    EDIT 29/02/2016: I have learned of a new way to tune the parameters for Interactive governor, for optimum efficiency, when wheatley governor is unavailable. Since Interactive is always available - it is one of the stock governors.
    In short it is tuning the parameters to use and spend more time in efficient frequency steps, in order to save battery while keeping the performance as high as possible. Using the fastest frequency steps before a huge jump in voltage consumption.
    The links which helped me do it are the following:
    http://forum.xda-developers.com/show....php?t=2769899
    https://vjnaik.wordpress.com/2015/06...-rooted-phone/


  • Ideal I/O Scheduler
    • For general use of your phone or tablet I would recommend using ZEN. It can provide good performance and better than average multitasking while having an average battery consumption. Being considerably better than ROW while at only slightly more battery intensive.
      Obviously ROW is second choice, but if both of the above are unavailable, then B] FIOPS[/B] is a good replacement, ensuring an above average visual experience, good battery saving, at the expense of multitasking capabilities.
      If battery isn't an issue, or you stream a lot of videos, then BFQ appears to provide similar experience to FIOPS plus excellent multitasking, at the expense of battery.
    • For Gaming, this was hard to find since there weren't any specific articles focusing on this, but from the descriptions and certain comments it appears that SIO provides a good experience. Others mentioned BFQ since it reduces lag.
      For gaming you should absolutely avoid ROW and FIOPS since both have reported to increase lag during gaming.
    • For best battery saving the recommendation is definitely FIOPS. While it isn't the most battery saving scheduler (Noop is), it will provide the most battery saving while also efficiently giving you a great user experience.
    • For general multitasking the best one is BFQ. It will provide the best transfer rates (aka copy paste and install kind of thing), best for streaming & watching HD videos, and great for keeping loads of apps open at the same time.

    N/B: I added ZEN to the list after using it for a couple months. At the time I first released this guide I could not find a kernel which offered this scheduler to test it. But after a while it started becoming more popular, and now it is easily accessible through most major kernels.
    In my experience with it it has improved my multitasking slightly, while also reducing lag on general use. Battery increase unnoticeable.


  • Virtual Memory tuning
    This one is a bit more complicated, and I have heard a whole bunch of stuff... Which is why I decided to test it myself and then come back to give you guys a report for it. The effects of VM tuning are not obvious at first glance and but affects the overall feel of the device. (Whether it feels like new, or sluggish etc...)
    The main tunables you need to worry about are: Dirty Ratio, Dirty Background Ratio, Overcommit Ratio and Swappiness.
    The guide I added above under "Memory Settings" will explain what each of these are.

    • Dirty Ratio & Dirty Background Ratio - Most people say that these need to be high, so that more stuff is stored in Cache. This will make your phone quick. Because cache is quick. But in reality this is only good advice if all you need to load on your phone is the system UI. Because as soon as you start loading different apps this cache fills quickly, and whenever you want to open an app/file/webpage that is not in cache, your CPU is tasked with both emptying whatever is filling up cache memory and load your new app into cache. Thus making multitasking a nightmare within the first day. A simple reboot of the phone is not enough, nor is clearing RAM (Note: Cache is not RAM).
      Often the only solution to speed up your device is to Wipe Cache and Dalvik Cache from recovery every day. And for people with 150+ Apps installed which need to be optimized on boot, this means a lot of time is wasted.
      My personal recommendation is to keep Dirty Ratio at around 40, which is double the stock value. Thus you have enough room before your phone freezes to free up cache. While Dirty Background Ration at 10, so that in the background without freezing the app you're currently in the kernel is constantly clearing cache. Allowing enough space for whatever you need to load.

    • Overcommit Ratio - While increasing allows more multitasking, I recommend leaving this at 0. It keeps RAM from completely filling up, thus avoiding "app xxx not responding" issues.

    • Swappiness - You have three kinds of fast memory on your phone, from quickest to slowest: Cache, RAM, Swap.
      Swap is the last resort for your phone's memory. It is usually used when your RAM is nearly full. Swap is used for app data which is not currently being used, but part of the group of apps you use the most. (This is related to the Low memory killer, so for more information check that link. )
      Since app data stored in Swap is stuff you don't use often it doesn't affect your phone greatly. But the more data kept in RAM, rather than Swap, the better.
      Therefore after loads of try and testing I found that 40 is the perfect sweet spot. Allowing higher performance while keeping some data rather than completely deleting it when RAM is full.


This is my Guide to Kernels, if you find that it has helped you and would like to thank me remember to press thanks.
If you have any questions please do ask them, I'll answer the best I can.
If you would like to add more, dispute any of the things I said, give extra info on any specific thing which you believe deserves a more thorough breakdown, then go ahead, fell free to comment below.

Thank you for reading this Guide.


The Following 92 Users Say Thank You to Kyuubi10 For This Useful Post: [ View ] Gift Kyuubi10 Ad-Free
 
 
2nd October 2015, 12:25 AM |#2  
Saber's Avatar
Recognized Contributor
Flag Down under
Thanks Meter: 8,217
 
Donate to Me
More
Nice guide and thanks for linking to my website

gsstudios
The Following 6 Users Say Thank You to Saber For This Useful Post: [ View ] Gift Saber Ad-Free
8th October 2015, 05:18 PM |#3  
Kyuubi10's Avatar
OP Senior Member
Thanks Meter: 539
 
More
Quote:
Originally Posted by gsstudios

Nice guide and thanks for linking to my website

gsstudios

It was a pleasure, you have one of the most well informed and well organised guides to the stuff I could find.
Most others are just all over the place.

Keep blogging!
9th October 2015, 12:16 AM |#4  
luke!'s Avatar
Senior Member
Thanks Meter: 205
 
More
Very useful guide

Just a question: would it be possible gathering info about the "power suspend mode" that is often found in Kernel Adiutor?
What are the differences among the available options?
Thanks again for your guide
10th October 2015, 06:53 PM |#5  
Kyuubi10's Avatar
OP Senior Member
Thanks Meter: 539
 
More
Quote:
Originally Posted by luke!

Very useful guide

Just a question: would it be possible gathering info about the "power suspend mode" that is often found in Kernel Adiutor?

What are the differences among the available options?
Thanks again for your guide

It took me ages to research, because initially when I did I found nothing. Whenever I searched this I would only find stuff about wakelocks. The wakelock system is more important to developers than actual users, so it was of no use to me.
But after a bit of research I THINK I found the original source code for this feature...I will put a couple links at the bottom for the enthusiasts to see.
(N.B. I will keep researching as I get more time to see if I can find more info on this, because it puzzles me also.)

Before I explain anything you must understand what the suspend state is, usually it is called sleep.
I usually cba to explain anything...since I am awful at explaining stuff in written form...I usually like to explain verbally. So I will leave you with a couple links:

Power suspend in Linux - http://unix.stackexchange.com/questi...pend-hybrid-do

Power suspend in Android - http://bamboopuppy.com/android-suspe...rief-overview/

How it interacts with the hardware - https://source.android.com/devices/s...pend-mode.html

Now for this kernel feature... I seems from what I have read that it is not activating or deactivating suspend mode....instead it is simply deciding on what "metric" to use.
Generally you could say that suspend state would be achieved on request by the kernel. But what if you want to automate the process so that it uses less requests, and thus goes to sleep quicker and more efficiently?
You make it so it bases on something else's output in order to initiate the count down.

This could be screen on/off (LCD panel), idle time (autosleep function), hybrid (autosleep & LCD panel whichever comes first), or userspace (defined by user.)

In all honesty, how it all works in detail I have no idea. But that is the basic idea.

I also have no idea why it keeps locking to userspace, as if it was default.
It seems that this function is not fully functional yet, or maybe it needs some fixing.

The gerrit page for the source code says that this project was abandoned by the main devs.
Gerrit page - https://gerrit.omnirom.org/#/c/9137/2

In summary, from other things I have read they say that Hybrid is the best one for battery life. But for me it never stays on Hybrid, it keeps resetting to userspace. Therefore I am unable to give you any further information about this.

I hope I helped.
The Following 3 Users Say Thank You to Kyuubi10 For This Useful Post: [ View ] Gift Kyuubi10 Ad-Free
19th December 2015, 04:58 PM |#6  
Thank you, thank you, thank you, for putting this up so organized, the only problem on xda is proper guides, I can understand how much time and energy you have put into finding and putting up this guide, and the best part you have given links to the original author and not just copied their hard work and spread their knowledge combined. Well Done mate. That's a real example of how member of xda should be. this will help a lot of people. will share links to this thread.

Edit: added your thread link in my signature, hope you don't mind. I thought it would be better this way for people to see.
The Following 2 Users Say Thank You to billysam For This Useful Post: [ View ] Gift billysam Ad-Free
29th February 2016, 05:38 PM |#7  
Kyuubi10's Avatar
OP Senior Member
Thanks Meter: 539
 
More
Quote:
Originally Posted by luke!

Very useful guide

Just a question: would it be possible gathering info about the "power suspend mode" that is often found in Kernel Adiutor?

What are the differences among the available options?
Thanks again for your guide

I have some new info about this, I don't remember specifics of where I got this, but it was in a thread about custom kernels.
A lost of people were asking why the setting was stuck.
And if I remember correctly it seems that this feature is a left-over stub from a failed project, which now has been superseded by Doze on Marshmallow.
It works exactly as I described, with the exception of Userspace, which rather than being defined by user it is defined by app. e.g. when app x says it's time to sleep phone will sleep. The other options are automated, and hybrid is the default option and we as users have no way to change it. It's been this way for a while, idk why Adiutor still has the option available.

Also finally understood fully why wakelocks kept popping up when I searched for this...it's because apps can set wakelocks to prevent the "power suspend" from happening, or even to wake the phone from a "power suspend" in order to not stop the app from running. This would be things like facebook, or other messenger apps which want to have a constant running service.
This created huge battery drains in KK and Lollipop, but now in Marshmallow Doze is a bit tougher to get around. Simple wakelocks won't do anymore.


Quote:
Originally Posted by billysam

Thank you, thank you, thank you, for putting this up so organized, the only problem on xda is proper guides, I can understand how much time and energy you have put into finding and putting up this guide, and the best part you have given links to the original author and not just copied their hard work and spread their knowledge combined. Well Done mate. That's a real example of how member of xda should be. this will help a lot of people. will share links to this thread.

Edit: added your thread link in my signature, hope you don't mind. I thought it would be better this way for people to see.

It's honestly been a pleasure.
I have been learning even more and soon I will re-update this thread with a lot of new info I have found.
I'm glad you liked this Guide, it did take me time and it's good that it has been recognized. You've made my day

This brings to mind the fact that I have been thinking on a new guide to newcomers into rooting and XDA, just explaining all that which is possible in a short but well organized guide .

Feel free to copy the link and share however you would like, it is honestly a huge help!
The Following 2 Users Say Thank You to Kyuubi10 For This Useful Post: [ View ] Gift Kyuubi10 Ad-Free
24th May 2016, 07:29 PM |#8  
rwxr-xr-xis's Avatar
Senior Member
Thanks Meter: 155
 
More
Thank you for making this guide, it helped me to understand my device further more
26th May 2016, 04:50 PM |#9  
zhaozihanzzh's Avatar
Senior Member
Flag Zibo City,Shandong province in China
Thanks Meter: 199
 
More
Thanks!

Android小楼阁-QQ群 439637151
来自搭载Android 2.3 GingerBread的华为Y220-T10
14th June 2016, 03:30 PM |#10  
Junior Member
Flag Jakarta
Thanks Meter: 1
 
More
hello dude can i get your screenshot your setting on your kernel adiutor for daily, power save, and Gaming
4th July 2016, 01:39 PM |#11  
Kyuubi10's Avatar
OP Senior Member
Thanks Meter: 539
 
More
Quote:
Originally Posted by .c.t.r.

hello dude can i get your screenshot your setting on your kernel adiutor for daily, power save, and Gaming

Unfortunately I don't keep presents.
I change on the fly as needed.

It just works better for testing rather than having specific presets to use, because I am constantly changing the actual values I use, also as apps get updated and their RAM usage increase or decrease, the values are always very fluid for me. I just keep changing until I find a comfortable value.

If there is anything specific you would like to know ask, and I'll advise you accordingly.
Post Reply Subscribe to Thread

Tags
comprehensive, guide, kernel (android os), noob proof

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes