Ashmem Anonymous Shared memory
The Anonymous shared memory (ASHMEM) mechanism of Android is based on the shared memory of the Linux kernel, but the ASHMEM is associated with the cache Shrinker, increasing the registration interface of the memory reclamation algorithm, so that the Linux memory management system will no longer be recycled using the memory area. The ASHMEM is implemented in kernel-driven form and creates/dev/ashmem device files in the file system. If process A and process B require shared memory, process a can open the file by opening and set the name and size of the shared memory with the IOCTL command Ashmem_set_name and Ashmem_set_size. MMAP uses handle to obtain a shared memory area, and process B uses the same handle, which is used by mmap to obtain the same piece of memory. The transfer of handle between processes can be achieved by means of binders.
For a valid recycle, the owner of the memory area is required to notify the Ashmem driver. Through the coordination of the user, the Ashmem driver, and the Linux memory management system, the memory management is more suitable to the embedded mobile device memory less characteristics. The ASHMEM mechanism assists the memory management system to effectively manage memory that is no longer in use, while simultaneously using binder process communication mechanisms to realize memory sharing between processes.
Ashmem not only adapts to Linux developers in the form of/dev/ashmem device files, but also provides access to the Android system runtime and the application framework layer. In the system runtime, the C + + call interface is provided, and the Java calling interface is provided at the application framework layer. In fact, the Java calling interface of the application framework layer is invoked through the JNI method to invoke the C/s + + Call interface of the system runtime, and finally into the Ashmem driver of the kernel space.
LMK mechanism
Android security Model Android security mechanism (memory management)