pmem/ashmem file descriptor by IPC/Binder

594 views
Skip to first unread message

timyao

unread,
Jan 25, 2010, 9:12:07 PM1/25/10
to android-platform
Hi,
I have a question about the file descriptor created by pmem or ashmem.
It's said the file descriptor can be transfered to other processes by
IPC/binder so the memory can be shared. But I wonder how the file
descriptor can be used by another process if it's not the case when a
child process inherits fd sets from its parent.

Looking at the code of init_workspace() (in system\core\init
\property_service.c),system_properties memory region is created by
init process and I understand that's how those system property
functions (\bionic\libc\bionic \system_properties.c) work since all
processes are child of init. But how about other cases like the frame
buffer heap created by opencore for video rendering? They are not in
same process so how does it work?

Hope anybody can guide me on this. Thanks.

Dianne Hackborn

unread,
Jan 26, 2010, 12:52:27 PM1/26/10
to android-...@googlegroups.com
MemoryDealer and associated classes are an example of a way to implement shared memory:


--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.




--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

timyao

unread,
Jan 26, 2010, 6:43:30 PM1/26/10
to android-platform
Thanks Dianne for your points. I have read some other post about
binder usage in Android from you and that is very valuable.

It looks MemoryDealer is something on the top of what I'm really
interested.

I'm thinking about using pmem for other projects as a common physical
memory allocator. There is general need to allocate physical
contiguous memory if the hardware graphic engine does not support
scatter gathering and understand any virtual address from user space.
Pmem is one of the drivers raised my interest.

I have been looking at PPM and CME. PPM (http://lwn.net/Articles/
355462/) can convert an allocated memory to Sys V shared memory so
other process can use it in a standard way. CMEM (from TI's LinuxTool
kit) can return physical address to user land and another process just
mmap again in it's own process space to share it. And I don't
understand how Android handle the same problem.

My guess is internally inside the binder, it uses sockets to transfer
FD opened in one process and make a copy in another process, like
mentioned here:
http://www.myelin.co.nz/post/2003/12/2/


On Jan 26, 9:52 am, Dianne Hackborn <hack...@android.com> wrote:
> MemoryDealer and associated classes are an example of a way to implement
> shared memory:
>

> http://android.git.kernel.org/?p=platform/frameworks/base.git;a=tree;...


>
>
>
>
>
> On Mon, Jan 25, 2010 at 6:12 PM, timyao <tim...@gmail.com> wrote:
> > Hi,
> > I have a question about the file descriptor created by pmem or ashmem.
> > It's said the file descriptor can be transfered to other processes by
> > IPC/binder so the memory can be shared. But I wonder how the file
> > descriptor can be used by another process if it's not the case when a
> > child process inherits fd sets from its parent.
>
> > Looking at the code of init_workspace() (in system\core\init
> > \property_service.c),system_properties memory region is created by
> > init process and I understand that's how those system property
> > functions (\bionic\libc\bionic \system_properties.c) work since all
> > processes are child of init. But how about other cases like the frame
> > buffer heap created by opencore for video rendering? They are not in
> > same process so how does it work?
>
> > Hope anybody can guide me on this. Thanks.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-platform" group.
> > To post to this group, send email to android-...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > android-platfo...@googlegroups.com<android-platform%2Bunsubscrib e...@googlegroups.com>


> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-platform?hl=en.
>
> --
> Dianne Hackborn
> Android framework engineer

> hack...@android.com


>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails. All such
> questions should be posted on public forums, where I and others can see and
> answer them.

On Jan 26, 9:52 am, Dianne Hackborn <hack...@android.com> wrote:
> MemoryDealer and associated classes are an example of a way to implement
> shared memory:
>

> http://android.git.kernel.org/?p=platform/frameworks/base.git;a=tree;...


>
>
>
>
>
> On Mon, Jan 25, 2010 at 6:12 PM, timyao <tim...@gmail.com> wrote:
> > Hi,
> > I have a question about the file descriptor created by pmem or ashmem.
> > It's said the file descriptor can be transfered to other processes by
> > IPC/binder so the memory can be shared. But I wonder how the file
> > descriptor can be used by another process if it's not the case when a
> > child process inherits fd sets from its parent.
>
> > Looking at the code of init_workspace() (in system\core\init
> > \property_service.c),system_properties memory region is created by
> > init process and I understand that's how those system property
> > functions (\bionic\libc\bionic \system_properties.c) work since all
> > processes are child of init. But how about other cases like the frame
> > buffer heap created by opencore for video rendering? They are not in
> > same process so how does it work?
>
> > Hope anybody can guide me on this. Thanks.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-platform" group.
> > To post to this group, send email to android-...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > android-platfo...@googlegroups.com<android-platform%2Bunsubscrib e...@googlegroups.com>


> > .
> > For more options, visit this group at
> >http://groups.google.com/group/android-platform?hl=en.
>
> --
> Dianne Hackborn
> Android framework engineer

> hack...@android.com

Dianne Hackborn

unread,
Jan 26, 2010, 8:58:59 PM1/26/10
to android-...@googlegroups.com
I just pointed to this code as an example of code that does something like what you ask.  You don't need to use those classes, you can use the implementation as a guide for yourself.

This code does not use sockets at all; the binder driver has a mechanism for transferring fds across IPC calls that is independent of sockets.

To unsubscribe from this group, send email to android-platfo...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.




--
Dianne Hackborn
Android framework engineer

timyao

unread,
Jan 27, 2010, 1:52:01 PM1/27/10
to android-platform
Can you point to me where is the code to transfer fds across IPC? Is
it inside binder or it's something in the kernel?

-Tim

> > > > android-platfo...@googlegroups.com<android-platform%2Bunsubscrib e...@googlegroups.com><android-platform%2Bunsubscrib

> > > > android-platfo...@googlegroups.com<android-platform%2Bunsubscrib e...@googlegroups.com><android-platform%2Bunsubscrib


> > e...@googlegroups.com>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/android-platform?hl=en.
>
> > > --
> > > Dianne Hackborn
> > > Android framework engineer
> > > hack...@android.com
>
> > > Note: please don't send private questions to me, as I don't have time to
> > > provide private support, and so won't reply to such e-mails.  All such
> > > questions should be posted on public forums, where I and others can see
> > and
> > > answer them.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "android-platform" group.
> > To post to this group, send email to android-...@googlegroups.com.
> > To unsubscribe from this group, send email to

Dianne Hackborn

unread,
Jan 27, 2010, 3:17:11 PM1/27/10
to android-...@googlegroups.com
Sorry I can't off-hand.  The user-space binder code puts the FD in the transaction data and the driver takes care of transferring it.  (Fwiw, there should be no reason at all to go into this code -- if you want to use the binder to transfer FDs, use the standard Parcel APIs like the memory deal code does.  If you don't want to use the binder, this code won't help you in any way.)

To unsubscribe from this group, send email to android-platfo...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.




--
Dianne Hackborn
Android framework engineer
hac...@android.com

Colin Burgess

unread,
Jan 27, 2010, 3:19:46 PM1/27/10
to android-...@googlegroups.com

timyao

unread,
Jan 28, 2010, 6:31:36 PM1/28/10
to android-platform
Yes! task_fd_install() with BINDER_TYPE_FD type of transaction. Now I
understand how it works. Many thanks.

On Jan 27, 12:19 pm, Colin Burgess <colin.burg...@gmail.com> wrote:
> It's in the kernel
>

> http://android.git.kernel.org/?p=kernel/common.git;a=blob;f=drivers/m...

> colin.burg...@gmail.com

timyao

unread,
Jan 28, 2010, 6:43:46 PM1/28/10
to android-platform
I'm just curious how binder works for fd transfer. And I'm trying to
write our own physical memory allocator (to add HW acceleration for Qt
etc. ) and have the memory sharing problem too so I thought I can
learn something from Android. The graphic core can only handle
contiguous physical memory on my platform. Now it seems pmem is
tightly coupled with binder and it's not strait forward just to use it
as an independent kernel driver. Maybe I can extract some code from
binder.c and put it inside the pmem driver and use it:)

Dianne Hackborn

unread,
Jan 29, 2010, 5:47:01 AM1/29/10
to android-...@googlegroups.com
As far as I know pmem is not tightly coupled to the binder at all, it is just a regular fd transfer.

But you need to move this to android-kernel to have a discussion at that level; I can't help you.

To unsubscribe from this group, send email to android-platfo...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.




--
Dianne Hackborn
Android framework engineer
Reply all
Reply to author
Forward
0 new messages