Tuesday 14 July 2020

What is Ashmem?

ashmem (Anonymous shared memory subsystem) is a concept which is similar to POSIX SHM (Shared Memory). The difference is, ashmem claims that it overcomes the problem of memory leaks. ashmem is not available for Android applications, but they are used by the low-level system software/processes. The components of System Server like SurfaceFlinger, AudioFlinger, etc use ashmem for IPC. ashmem is fast. Another example where ashmem is used is, the Virtual Machine. When .oat code is provided to the VM using ashmem. When a process wants to communicate with another process, the process creates a shared memory region, and then shares the file descriptor of that memory region with the other process with which it wants to communicate. This file descriptor is sent to other process via Binder. The system processes rely ashmem through IMemory interface, which is not available or not exposed to the app developers.

ashmem also does memory management, by shrinking or expanding the memory area as needed. When the system needs more memory, it shrinks its area and releases memory for the system. If a shared memory area is marked as pinned, then that area can't be released at any circumstance. ashmem uses reference counting to destroy memory regions, when the processes referring to them have exited.

Basically, ashmem is a way used by the system level processes, not by application processes for IPC.

Ashmem supports a number of ioctl calls such as ASHMEM_SET_NAME, ASHMEM_GET_NAME, ASHMEM_SET_SIZE, ASHMEM_GET_SIZE, ASHMEM_SET_PROT_MASK, ASHMEM_GET_PROT_MASK, ASHMEM_PIN, ASHMEM_UNPIN, ASHMEM_GET_PIN_STATUS, ASHMEM_PURGE_ALL_CACHES

Kernal can discard unused shared block of memory when under pressure. Its implementation can be found at mm/ashmem.c with include at include/linux/ashmem.h

No comments:

Post a Comment

What is Image Stabilization? OIS and EIS explained.

Hi Guys, Today I'm going to talk about image stabilization, what are OIS and EIS? How these works and What are the advantages of having ...