Android Memory Management

Source: Internet
Author: User

first of all, the Android memory management mechanism is quite complex, want to speak clearly more difficult, and secondly for the vast majority of users, only care about memory is not enough, as for how memory management of this technical details, not the user need to consider, write such a topic has no meaning? After all, we use mobile phones, not to study mobile phones. The final concern is that the topic will not be too technical, the vast majority of users will not see or lack of the corresponding background. But there is an incentive to write about a topic that has always beenMIUIThe team is also learning from the user in the process of interacting with the user, and some of your suggestions or ideas will always enlighten us, and this topic I believe you can also give enlightenment. Although memory management is a very technical topic, but we can still look at these issues from the user's perspective, how memory management affects our use of mobile phones, as users, we can do something. I will try to make such a topic less technical, but there will be some technical terminology and implementation of the relevant discussion, if interested, let's take a look.

we start with a post from the User: "Legendary artifact that keeps your MS moments free of memory"The Alter minfree option is mentioned in this post, and in this article we'll talk about what this is and how it works."

(1) Android is a multitasking system, which means that you can run multiple programs at the same time, which should be familiar to everyone. In general, there is a certain amount of time overhead to start running a program, so in order to run faster, Android does not kill it immediately when you exit a program so that it can be started quickly the next time you run the program. As the system retains more and more programs, the memory will certainly appear insufficient, and this time Android system began to wield the butcher's kill program. Here is a very obvious question, who to kill?

(2) The executioner of the Android system killing program is called "Lowmemory Killer", it is implemented in the Linux kernel. Here it implements a mechanism by which the importance of the program decides who to kill. In layman's terms, who does not work, first kill who. Android divides the importance of the program into the following categories, descending sequentially in order of importance:

Name Oom_adj Explain
Foregroud_app 0 Foreground program, which can be understood as the program you are using
Visible_app 1 User-Visible Programs
Secondary_server 2 Background services, such as QQ will run in the background services
Home_app 4 Home, that's the main interface.
Hidden_app 7 Programs that are hidden
Content_provider 14 Content providers,
Empty_app
15
No service, no content provided

each of these programs will have a Oom_adj value, the smaller the value, the more important the program, the less likely to be killed.

(3) In addition to the above-mentioned procedural importance classification, the Android system also maintains another table, this table is a correspondence relationship, take N1 as an example:
Oom_adj Memory Alert value (in 4 K units)
0 1536
1 2048
2 4096
7 5120
14 5632
15 6144
This table defines a correspondence, each of which corresponds to a value of importance, and when the available memory of the system is below a certain alert, it kills all programs that are greater than the value of the value corresponding to that alert. For example, when the available memory is less than 6144 * 4K = 24MB, start killing all Empty_app, when the available memory is less than 5632 * 4K = 22MB, start killing all
of Content_provider and Empty_app.


(4) Alter Minfree What is changed, the above table is composed of two files:
/sys/module/lowmemorykiller/parameters/adj and/sys/module/lowmemorykiller/parameters/minfree.

Alter MINFREEE is to modify/sys/module/lowmemorykiller/parameters/minfree this file, for example, if the last item is changed to 32 * 1024, then when the available memory is less than 128MB is , he began to kill all the Empty_app.

Android Memory Management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.