Android Kernel Optimization
How to add a CPU Governor
The CPU governor itself is just 1 C file, which is located in kernel_source/drivers/cpufreq/, for example: cpufreq_smartass2.c. You are responsible yourself for find the governor (look in an existing kernel repo for your device) But in order to successfully call and compile this file into your kernel you will have to make the following changes:
- Copy your governor file (cpufreq_govname.c) and browse to kernel_source/drivers/cpufreq, now paste it.
- and open Kconfig (this is the interface of the config menu layout) when adding a kernel, you want it to show up in your config. You can do that by adding the choice of governor.
for example, for smartassV2.
next to adding the choice, you also must declare the possibility that the governor gets chosen as default governor.
for example, for smartassV2.
– can’t find the right place to put it? Just search for
“CPU_FREQ_GOV_CONSERVATIVE”, and place the code beneath, same thing counts for
Now that Kconfig is finished you can save and close the file.
- While still in the
/drivers/cpufreqfolder, open Makefile. In Makefile, add the line corresponding to your CPU Governor. for example:
Be ware that you do not call the native C file, but the O file! which is the compiled C file. Save the file.
- Move to:
kernel_source/includes/linux. Now open
cpufreq.hScroll down until you see something like:
(other cpu governors are also listed there)
Now add your entry with the selected CPU Governor, example:
Save the file and close it.
The initial CPU Governor setup is now complete. when you’ve done all steps successfully, you should be able to choose your governor from the menu (
nconfig). Once checked in the menu it will be included to the kernel.
Commit that is nearly the same as above instructions: Add smartassV2 and lulzactive governor commit
You can enhance your kernel by adding new I/O schedulers if needed. Globally, governors and schedulers are the same; they both provide a way how the system should work. However, for the schedulers it is all about the input/output datastream except for the CPU settings. I/O schedulers decide how an upcoming I/O activity will be scheduled. The standard schedulers such as noop or cfq are performing very reasonably.
I/O schedulers can be found in kernel_source/block.
Copy your I/O scheduler file (for example, sio-iosched.c) and browse to kernel_source/block. Paste the scheduler file there.
Now open Kconfig.iosched and add your choice to the Kconfig, for example for SIO:
Then set the default choice option as follows:
Save the file.
Open the Makefile in kernel_source/block/ and simply add the following line for SIO:
Save the file and you are done! The I/O schedulers should now pop up at the menu config.
Similar commit on GitHub: added Simple I/O scheduler.
Low RAM Configuration
Android now supports devices with 512MB of RAM. This documentation is intended to help OEMs optimize and configure Android 4.4 for low-memory devices. Several of these optimizations are generic enough that they can be applied to previous releases as well.
Enable Low Ram Device flag
We are introducing a new API called ActivityManager.isLowRamDevice() for applications to determine if they should turn off specific memory-intensive features that work poorly on low-memory devices.
For 512MB devices, this API is expected to return: "true" It can be enabled by the following system property in the device makefile.
System-wide JIT memory usage is dependent on the number of applications running and the code footprint of those applications. The JIT establishes a maximum translated code cache size and touches the pages within it as needed. JIT costs somewhere between 3M and 6M across a typical running system.
The large apps tend to max out the code cache fairly quickly (which by default has been 1M). On average, JIT cache usage runs somewhere between 100K and 200K bytes per app. Reducing the max size of the cache can help somewhat with memory usage, but if set too low will send the JIT into a thrashing mode. For the really low-memory devices, we recommend the JIT be disabled entirely.
This can be achieved by adding the following line to the product makefile: