This article does not talk about details, about methods, about ideas.
See a lot of people in the system optimization completely lost in the head, disorderly mess bump, really can not help but want to say a few words, but not directly, or write down to make a note.
What is the Android system?
This seems like a simple question, but do you really know how Android works? Understanding the nature of the Android system is the premise of system development.
A system (or OS, to be more precise) is essentially a software system that allocates and uses hardware resources properly. From this point of view, the Android system consists of two main parts, Linux and ART, and the rest can be seen as software running on top of it. ART provides the application running environment and can be seen as a relatively independent part of the system, which can usually be optimized for specific purpose. When we talk about system optimization, we’re talking about optimizing Android based on Linux.
The essence of performance optimization
As mentioned earlier, the system is the allocation and use of hardware resources. This means that the hardware has essentially capped the system’s performance, and the goal of performance optimization is to maximize the use of hardware resources. Along this line of thought, we can give several directions for performance optimization:
- Hardware enhancements: This is a bit of a stretch, since today’s embedded devices are highly integrated and cannot be replaced with hardware. The enhancement here mainly refers to the overclocking of CPU, GPU, Memory and other important hardware units. The frequencies calibrated by the hardware are all conservative frequencies. As long as the heat dissipation is well handled, it can usually work stably at higher frequencies. The main issue with overclocking is stability, and it is not recommended to modify the frequency until a complete stress test has been completed.
- Hardware resource allocation optimization: Hardware resources are fixed, so our optimization direction is how to efficiently use the hardware resources. Both Linux and Android are moving towards generic platforms, but when it comes to developing specific products, there are specific priorities. The direction of optimization is to tilt hardware resources to key functions. Some of the techniques involved are: cgroups, priority tuning, CPU frequency range tuning, CPU core binding, etc.
- Scheduling policy optimization: Linux is a universal system, its scheduling policy is necessarily balanced, we can adjust the scheduling policy according to the specific product form. The techniques involved here are: CPU scheduling strategy, I/O scheduling strategy, memory recycling strategy, THERMAL strategy, file system tuning, etc.
- Software performance optimization: We have to admit the fact that there is little consideration for performance in software development. Most software has room for optimization. Of course, we won’t optimize all the software, we need to find the key software. In addition to code optimization, you can also use hardware acceleration units such as GPU and NPU to optimize software.
- System resource optimization at the application level: Sometimes, hardware resource optimization on the system is not enough to meet our needs. Because the application layer knows best which processes are important while the system is running. The application layer can coordinate the use of system resources by keeping important processes and releasing unimportant processes. The key here is balance, ensuring that the processes that users care about the most have enough resources.
Performance optimization method
In fact, there is no standard method and step for system performance optimization, and the general direction is the five above. The optimization can be done in all directions or only in one direction. As long as the final performance indicators meet the requirements, the optimization work is completed. The key point here is:
- How to determine if the optimization meets the performance criteria.
- How to find the optimization point.
Determining the two key points above is the tool, which is the core of performance optimization. The reason so many people go crazy with performance tuning is because they don’t know what the core is. We need tools (whether they are in-system, homegrown, or third-party) to measure system performance and determine optimization goals. We also need tools to find optimizations, and guesswork alone is not a good idea. Android itself comes with great performance debugging tools, and there are a number of open source tools on Linux that are easy to use. How to determine the optimization method based on the tool data, this is the test of the ability of the engineer. But if you don’t use the tools, even if you solve the performance problem, I will despise you.
Finally, it needs to be emphasized that hardware resources are fixed, and system performance optimization needs to do is to balance the use of resources. There is no single way to optimize performance, and there are no shortcuts. Use tools to find where performance consumption is high. A little bit of optimization, one cycle per MS, is what performance optimization needs to do.