Linux system Dalvik heap memory management and recycling introduction

  

Linux system Dalvik virtual machine can do some optimization processing for Android, and the management and recycling of heap memory is an important means to optimize the system. This article will introduce the management and recycling of Dalvik heap memory in Linux system.

Android system starts after

Android system starts, there will be a process to create the first Zygote Dalvik virtual machine, it only maintains a heap. All application processes launched later are forked by the Zygote process and both hold their own Dalvik virtual machine. In the process of creating the application, the Dalvik virtual machine uses the COW policy to copy the address space of the Zygote process.

COW Strategy: At the beginning (when the address space of the Zygote process is not copied), the application process and the Zygote process share the same heap used to allocate objects. When a Zygote process or application process writes to the heap, the kernel performs a real copy operation, causing the Zygote process and the application process to have their own copy, which is called COW. Because copy is very time consuming, you must avoid copying or copying as little as possible.

In order to achieve this, when the first application process is created, the part of the heap memory that has been used is divided into a part, and the unused heap memory is divided into another part. The former is called the Zygote heap, and the latter is called the Active heap. This simply copies the contents of the zygote heap to the application process. In the future, whether it is a Zygote process or an application process, when they need to allocate objects, they are all on the Active heap. This allows the Zygote heap to be written as little as possible, thus reducing the need to perform copy-on-write operations. The objects allocated in the Zygote heap are mainly the classes, resources and objects that the Zygote process preloads during the startup process. This means that these preloaded classes, resources, and objects can be shared long-term in Zygote processes and application processes. This reduces copying effort and reduces memory requirements.

Similar to the JVM, the Dalvik virtual machine also needs to be responsible for managing objects in the heap memory. It also uses the markup cleanup algorithm, but the details are slightly different. Previous12Next page Total 2 pages

Copyright © Windows knowledge All Rights Reserved