Skip to contentSkip to conversation

android: binder: use VM_ALLOC to get vm area

PATCH In review Ganesh Mahendran 5 participants 9 messages Jan 10, 2018 – Jan 25, 2018 Android drivers

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 android: binder: use VM_ALLOC to get vm area

VM_IOREMAP is used to access hardware through a mechanism called I/O mapped memory. Android binder is a IPC machanism which will not access I/O memory.

And VM_IOREMAP has alignment requiement which may not needed in binder.

    __get_vm_area_node()
    {
    ...
        if (flags & VM_IOREMAP)
            align = 1ul << clamp_t(int, fls_long(size),
               PAGE_SHIFT, IOREMAP_MAX_ORDER);
    ...
    }

This patch will save some kernel vm area, especially for 32bit os.

In 32bit OS, kernel vm area is only 240MB. We may got below error when launching a app:

<3>[ 4482.440053] binder_alloc: binder_alloc_mmap_handler: 15728 8ce67000-8cf65000 get_vm_area failed -12
<3>[ 4483.218817] binder_alloc: binder_alloc_mmap_handler: 15745 8ce67000-8cf65000 get_vm_area failed -12

----
V3: update comments
V2: update comments

---
 drivers/android/binder_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/android/binder_alloc.c +1 -1
index 07b866a..5a426c8 100644
@@ -670,7 +670,7 @@ int binder_alloc_mmap_handler(struct binder_alloc *alloc,
 		goto err_already_mapped;
 	}
 
-	area = get_vm_area(vma->vm_end - vma->vm_start, VM_IOREMAP);
+	area = get_vm_area(vma->vm_end - vma->vm_start, VM_ALLOC);
 	if (area == NULL) {
 		ret = -ENOMEM;
 		failure_string = "get_vm_area";
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 23 lines · Ganesh Mahendran

VM_IOREMAP is used to access hardware through a mechanism called I/O mapped memory. Android binder is a IPC machanism which will not access I/O memory.

And VM_IOREMAP has alignment requiement which may not needed in binder.

    __get_vm_area_node()
    {
    ...
        if (flags & VM_IOREMAP)
            align = 1ul << clamp_t(int, fls_long(size),
               PAGE_SHIFT, IOREMAP_MAX_ORDER);
    ...
    }

This patch will save some kernel vm area, especially for 32bit os.

In 32bit OS, kernel vm area is only 240MB. We may got below error when launching a app:

<3>[ 4482.440053] binder_alloc: binder_alloc_mmap_handler: 15728 8ce67000-8cf65000 get_vm_area failed -12
<3>[ 4483.218817] binder_alloc: binder_alloc_mmap_handler: 15745 8ce67000-8cf65000 get_vm_area failed -12
Quoted 7 lines

----
V3: update comments
V2: update comments

---
 drivers/android/binder_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Martijn and Todd, any objections to this patch?

thanks,

greg k-h

#2 lore raw
Quoted 32 lines · Greg KH
Quoted 23 lines · Ganesh Mahendran

VM_IOREMAP is used to access hardware through a mechanism called I/O mapped memory. Android binder is a IPC machanism which will not access I/O memory.

And VM_IOREMAP has alignment requiement which may not needed in binder.

    __get_vm_area_node()
    {
    ...
        if (flags & VM_IOREMAP)
            align = 1ul << clamp_t(int, fls_long(size),
               PAGE_SHIFT, IOREMAP_MAX_ORDER);
    ...
    }

This patch will save some kernel vm area, especially for 32bit os.

In 32bit OS, kernel vm area is only 240MB. We may got below error when launching a app:

<3>[ 4482.440053] binder_alloc: binder_alloc_mmap_handler: 15728 8ce67000-8cf65000 get_vm_area failed -12
<3>[ 4483.218817] binder_alloc: binder_alloc_mmap_handler: 15745 8ce67000-8cf65000 get_vm_area failed -12
Quoted 7 lines

----
V3: update comments
V2: update comments

---
 drivers/android/binder_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 1 line

Martijn and Todd, any objections to this patch?

Looks fine to me. Arve, do you remember the rationale for using VM_IOREMAP?

Quoted 4 lines

thanks,

greg k-h

maintainer
#3 lore raw
Quoted 33 lines · Todd Kjos
Quoted 32 lines · Greg KH
Quoted 30 lines · Ganesh Mahendran

VM_IOREMAP is used to access hardware through a mechanism called I/O mapped memory. Android binder is a IPC machanism which will not access I/O memory.

And VM_IOREMAP has alignment requiement which may not needed in binder.

    __get_vm_area_node()
    {
    ...
        if (flags & VM_IOREMAP)
            align = 1ul << clamp_t(int, fls_long(size),
               PAGE_SHIFT, IOREMAP_MAX_ORDER);
    ...
    }

This patch will save some kernel vm area, especially for 32bit os.

In 32bit OS, kernel vm area is only 240MB. We may got below error when launching a app:

<3>[ 4482.440053] binder_alloc: binder_alloc_mmap_handler: 15728 8ce67000-8cf65000 get_vm_area failed -12
<3>[ 4483.218817] binder_alloc: binder_alloc_mmap_handler: 15745 8ce67000-8cf65000 get_vm_area failed -12

----
V3: update comments
V2: update comments

---
 drivers/android/binder_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 4 lines
Quoted 1 line

Martijn and Todd, any objections to this patch?

Looks fine to me. Arve, do you remember the rationale for using VM_IOREMAP?

I don't remember for sure, but I think it used alloc_vm_area at some point, and that uses VM_IOREMAP.

Signature · 1 line
Arve Hjønnevåg
#4 lore raw

Hi, Arve:

2018-01-23 2:55 GMT+08:00 Arve Hjønnevåg <[email protected]>:

Quoted 34 lines · Todd Kjos
Quoted 33 lines · Greg KH
Quoted 32 lines · Ganesh Mahendran
Quoted 30 lines

VM_IOREMAP is used to access hardware through a mechanism called I/O mapped memory. Android binder is a IPC machanism which will not access I/O memory.

And VM_IOREMAP has alignment requiement which may not needed in binder.

    __get_vm_area_node()
    {
    ...
        if (flags & VM_IOREMAP)
            align = 1ul << clamp_t(int, fls_long(size),
               PAGE_SHIFT, IOREMAP_MAX_ORDER);
    ...
    }

This patch will save some kernel vm area, especially for 32bit os.

In 32bit OS, kernel vm area is only 240MB. We may got below error when launching a app:

<3>[ 4482.440053] binder_alloc: binder_alloc_mmap_handler: 15728 8ce67000-8cf65000 get_vm_area failed -12
<3>[ 4483.218817] binder_alloc: binder_alloc_mmap_handler: 15745 8ce67000-8cf65000 get_vm_area failed -12

----
V3: update comments
V2: update comments

---
 drivers/android/binder_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Martijn and Todd, any objections to this patch?

Looks fine to me. Arve, do you remember the rationale for using VM_IOREMAP?

I don't remember for sure, but I think it used alloc_vm_area at some point, and that uses VM_IOREMAP.

Yes, in alloc_vm_area(), it uses VM_IOREMAP flag.

In binder, the ~1MB vm area is cut into binder_buffer which is not even page aligned.
So for binder IPC, there is no need to align vm area(512KB now). For 64 bit OS, the vm area is very big, but for 32 bit OS, default vm area is only 240.
The vm area will soon be exhausted, then no app can be launched.

Thanks.

Quoted 3 lines

--
Arve Hjønnevåg

#5 lore raw
In reply to Todd Kjos

Hi, Todd:

2018-01-23 1:02 GMT+08:00 Todd Kjos <[email protected]>:

Quoted 33 lines · Greg KH
Quoted 32 lines · Ganesh Mahendran
Quoted 30 lines

VM_IOREMAP is used to access hardware through a mechanism called I/O mapped memory. Android binder is a IPC machanism which will not access I/O memory.

And VM_IOREMAP has alignment requiement which may not needed in binder.

    __get_vm_area_node()
    {
    ...
        if (flags & VM_IOREMAP)
            align = 1ul << clamp_t(int, fls_long(size),
               PAGE_SHIFT, IOREMAP_MAX_ORDER);
    ...
    }

This patch will save some kernel vm area, especially for 32bit os.

In 32bit OS, kernel vm area is only 240MB. We may got below error when launching a app:

<3>[ 4482.440053] binder_alloc: binder_alloc_mmap_handler: 15728 8ce67000-8cf65000 get_vm_area failed -12
<3>[ 4483.218817] binder_alloc: binder_alloc_mmap_handler: 15745 8ce67000-8cf65000 get_vm_area failed -12

----
V3: update comments
V2: update comments

---
 drivers/android/binder_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 3 lines
Quoted 1 line

Martijn and Todd, any objections to this patch?

Looks fine to me. Arve, do you remember the rationale for using VM_IOREMAP?

Thanks for your review.

Quoted 5 lines
Quoted 5 lines

thanks,

greg k-h

#7 lore raw

Hi, Martijn

2018-01-24 22:33 GMT+08:00 Martijn Coenen <[email protected]>:

Quoted 4 lines · Greg KH
Quoted 1 line

Martijn and Todd, any objections to this patch?

Looks good to me.

Thanks for your review.

Should I cherry-pick this change to aosp kernel 3.10/3.18/4.4/4.9 now?

Thanks.

Quoted 5 lines
Quoted 5 lines

thanks,

greg k-h

maintainer
#8 lore raw
Quoted 11 lines · Ganesh Mahendran

Hi, Martijn

2018-01-24 22:33 GMT+08:00 Martijn Coenen <[email protected]>:

Quoted 4 lines · Greg KH
Quoted 1 line

Martijn and Todd, any objections to this patch?

Looks good to me.

Thanks for your review.

Should I cherry-pick this change to aosp kernel 3.10/3.18/4.4/4.9 now?

If you need it "right now", sure. Otherwise if you can wait 2 weeks, it will automatically show up in the 3.18/4.4/4.9/4.14 android-common branches as part of the stable kernel updates.

It's your choice, but either way to get it into 3.10, you will need to submit it to AOSP.

thanks,

greg k-h