[go: up one dir, main page]

|
|
Log in / Subscribe / Register

The Android ION memory allocator

The Android ION memory allocator

Posted Jul 5, 2016 13:24 UTC (Tue) by excors (subscriber, #95769)
In reply to: The Android ION memory allocator by simonwan
Parent article: The Android ION memory allocator

The only necessary permission should be read access to /dev/ion, and if you didn't have that permission you wouldn't even be able to open the device.

Error -19 is -ENODEV, and I think ion_alloc can only return that if there are no heaps that match the heap_id_mask in your allocation request, so you should check you're setting that correctly. /sys/kernel/debug/ion/heaps/ should list the heaps available on your device (though you probably need to read the kernel headers to find the enum definitions for them).

Also check that you're calling the right version of the kernel API - lots of details have changed since this article was written (e.g. the heap mask is now a separate field in ion_allocation_data, not part of flags), so you should use libion or read the kernel source from your particular device.


to post comments

The Android ION memory allocator

Posted Jul 6, 2016 0:59 UTC (Wed) by simonwan (guest, #109625) [Link] (1 responses)

Hi excors,

Thank you for the reply. I tested the program on Android and I checked the /ion/heaps while I get the results as "adsp, audio, kmalloc, mm, qsecom, system" but I don't know where I could find the enum definitions, could you please give me some advice?

Sincerely,
Simon

The Android ION memory allocator

Posted Jul 6, 2016 17:39 UTC (Wed) by excors (subscriber, #95769) [Link]

That looks like a Qualcomm device, so I think you want the ion_heap_ids from msm_ion.h

(The definitions might vary on different versions and different devices - ideally you should find the kernel source for your specific device. Probably most similar-generation Qualcomm devices will be compatible, though.)

If you're using libion, call ion_alloc with heap_mask set to e.g. (1 << ION_SYSTEM_HEAP_ID) to use the system heap. (If you're not using libion, look at its implementation to see how to call the ioctls directly.)

If you want to share the ion buffer with non-CPU bits of hardware (e.g. the GPU or camera), you might need to use one of the other heaps, but the restrictions are not documented anywhere so you'll have to guess.

On non-Qualcomm devices, you might need to set heap_mask to e.g. (1 << ION_HEAP_TYPE_SYSTEM) instead, because some other vendors use those HEAP_TYPE enums as the heap IDs instead of inventing a whole new set of IDs - there are no common standards here. The heap configuration is either hard-coded into the kernel source or loaded from Device Tree, so you'll have to look there if you want to find out the details for other devices.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds