Android ION

One of the features google added to linux kernel is a general purpose allocator /dev/ion. The new allocator allows us to allocate memory from different heaps and devices, virtual and physical

User space usage

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>

#include "/home/developer/kernel3.4/goldfish/include/linux/ion.h"

void main()
	int *p;
	struct ion_fd_data fd_data;
	struct ion_allocation_data ionAllocData;
	ionAllocData.align = 0;
	ionAllocData.flags = ION_HEAP_TYPE_SYSTEM;

	int fd=open("/dev/ion",O_RDWR);
	ioctl(fd,ION_IOC_ALLOC, &ionAllocData);
	fd_data.handle = ionAllocData.handle;
	printf("hello all %d\n",p[0]);

Kernel usage

extern struct ion_device *idev;

void allocfromion()
    int *buf;
    struct ion_handle *data;

    client = ion_client_create(idev, -1, "user");
    data = ion_alloc(client,0x1000,0,ION_HEAP_SYSTEM_MASK);
    buf = ion_map_kernel(client,data);


Tagged , ,

1 thought on “Android ION

  1. […] abusando do sistema de gerenciamento de memória do Android – o alocador de memória Android ION. O ION foi introduzido com o Android 4.0 no final de 2011 e simplesmente fornece aos aplicativos a […]

Comments are closed.