Skip to content

binder: faster page installations

Carlos Llamas lkml 7 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest9 patches 0 repliesNew
  2. v69 patches 5 repliesSuperseded
  3. v59 patches 7 repliesSuperseded
Earlier versions · 4
VersionPostedPatchesRepliesStatus
v49 patches7 repliesSuperseded
v38 patches7 repliesSuperseded
v28 patches14 repliesSuperseded
v18 patches3 repliesSuperseded

Changes in v7 from the cover letter

* cast page->private to struct binder_shrinker_mdata before kfree()

Patches in v7 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9Revert "binder: switch alloc->mutex to spinlock_t"drivers/android/binder_alloc.c drivers/android/binder_alloc.h+28 -280 replies
2/9binder: concurrent page installationdrivers/android/binder_alloc.c+41 -240 replies
3/9binder: select correct nid for pages in LRUdrivers/android/binder_alloc.c+12 -40 replies
4/9binder: store shrinker metadata under page->privatedrivers/android/binder_alloc.c drivers/android/binder_alloc.h drivers/android/binder_alloc_selftest.c+99 -700 replies
5/9binder: replace alloc->vma with alloc->mappeddrivers/android/binder_alloc.c drivers/android/binder_alloc.h drivers/android/binder_alloc_selftest.c+30 -260 replies
6/9binder: rename alloc->buffer to vm_startdrivers/android/binder.c drivers/android/binder_alloc.c drivers/android/binder_alloc.h +2 more+19 -190 replies
7/9binder: use per-vma lock in page installationdrivers/android/binder_alloc.c+50 -170 replies
8/9binder: propagate vm_insert_page() errorsdrivers/android/binder_alloc.c+0 -10 replies
9/9binder: use per-vma lock in page reclaimingdrivers/android/binder_alloc.c+22 -70 replies

Reviews trailers per patch

All 9 patches have a Reviewed-by or Acked-by.

PatchSuren Baghdasaryan
1/9R-b
2/9R-b
3/9R-b
4/9R-b
5/9R-b
6/9R-b
7/9R-b
8/9R-b
9/9R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v7 thread

Cover letter [PATCH v7 0/9] binder: faster page installations

The main focus of these patches is to improve the performance of binder page installations, primarily by reducing contention on the mmap_lock. The idea is to allow concurrent page insertion by leveraging per-vma locking and get_user_pages_remote().

Unfortunately, this required reverting the alloc->lock spinlock back into a mutex in order to serialize with the shrinker. At least until finding a better solution e.g. support page zapping with a spinlock. The trade off is still quite worth it though.

Other patches are also included that remove unsafe and redundant things such as the alloc->vma pointer or the struct binder_lru_page concept.

Note: I'll work on setting up a page fault handler for binder next. I believe an idea from Alice Ryhl to deferred the page insertions will make this finally feasible. I only need to figure out a few performance bits but if/when done most of the manual page insertion code in binder could be dropped. :)

Changelog:

v7:
* cast page->private to struct binder_shrinker_mdata before kfree()

v6:
https://lore.kernel.org/all/[email protected]/
* rework the usage of page->lru and page->index into only page->private
* expanded comments aobut vma validation using alloc->mapped per Suren

v5:
https://lore.kernel.org/all/[email protected]/
* rebase and resolve conflicts with commit da0c02516c50 ("mm/list_lru:
simplify the list_lru walk callback function")
* add comment to binder_alloc_is_mapped() about valid vma check
* add note to commit log about future page->lru removal
* collect Reviewed-by tags from Suren

v4:
https://lore.kernel.org/all/[email protected]/
* add explicit FOLL_NOFAULT to get_user_pages_remote()
* per-vma locking to shrinker path (per Liam)

v3:
https://lore.kernel.org/all/[email protected]/
* collect "Reviewed-by" tags from Suren
* use full commit subject in revert (not only sha1)
* add "goto unlock" label for vma_lookup() failures
* address -ENOMEM error override in separate patch
* squash "remove alloc->vma" patch into alloc->mapped patch
* pass 'struct binder_alloc *' to binder_page_lookup() too
* factor out individual mmget_not_zero()/mmput_async() calls
* cleanup binder_page_insert() to avoid using goto
* document only one mapping allowed per binder instance
* check binder_alloc_is_mapped() in binder_page_lookup()
* remove no longer need local page_to_free pointer

v2:
https://lore.kernel.org/all/[email protected]/
* fix locking order when upgrading from vma lock to mmap lock
* switch folio_walk_start() for get_user_pages_remote()
* release vma/mmap locks and mmput() right after vm_insert_page()
* add binder_page_alloc() helper for binder_install_single_page()

v1:
https://lore.kernel.org/all/[email protected]/

Cc Alice Ryhl <[email protected]>
Cc Barry Song <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Liam R. Howlett <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Nhat Pham <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Todd Kjos <[email protected]>
Cc Viktor Martensson <[email protected]>
Cc Hillf Danton <[email protected]>
Cc Lorenzo Stoakes <[email protected]>

Carlos Llamas (9):
Revert "binder: switch alloc->mutex to spinlock_t"
binder: concurrent page installation
binder: select correct nid for pages in LRU
binder: store shrinker metadata under page->private
binder: replace alloc->vma with alloc->mapped
binder: rename alloc->buffer to vm_start
binder: use per-vma lock in page installation
binder: propagate vm_insert_page() errors
binder: use per-vma lock in page reclaiming

 drivers/android/binder.c                |   2 +-
 drivers/android/binder_alloc.c          | 366 +++++++++++++++---------
 drivers/android/binder_alloc.h          |  45 +--
 drivers/android/binder_alloc_selftest.c |  18 +-
 drivers/android/binder_trace.h          |   2 +-
 5 files changed, 269 insertions(+), 164 deletions(-)
Signature · 1 line
2.47.0.338.g60cca15819-goog