From: Carlos Llamas <cmllamas@google.com>
To: Alice Ryhl <aliceryhl@google.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Arve Hjønnevåg" <arve@android.com>,
"Todd Kjos" <tkjos@android.com>,
"Martijn Coenen" <maco@android.com>,
"Joel Fernandes" <joel@joelfernandes.org>,
"Christian Brauner" <brauner@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
linux-kernel@vger.kernel.org, kernel-team@android.com,
"Matthew Wilcox" <willy@infradead.org>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>
Subject: Re: [PATCH v6 4/9] binder: store shrinker metadata under page->private
Date: Wed, 4 Dec 2024 13:55:12 +0000 [thread overview]
Message-ID: <Z1BfQE6IMI9nqUIB@google.com> (raw)
In-Reply-To: <CAH5fLgiarbw82R34Ct=GP3-6ophJOuhuRoerr427gHsEPy+Rcg@mail.gmail.com>
On Wed, Dec 04, 2024 at 10:39:58AM +0100, Alice Ryhl wrote:
> On Tue, Dec 3, 2024 at 10:56 PM Carlos Llamas <cmllamas@google.com> wrote:
> >
> > Instead of pre-allocating an entire array of struct binder_lru_page in
> > alloc->pages, install the shrinker metadata under page->private. This
> > ensures the memory is allocated and released as needed alongside pages.
> >
> > By converting the alloc->pages[] into an array of struct page pointers,
> > we can access these pages directly and only reference the shrinker
> > metadata where it's being used (e.g. inside the shrinker's callback).
>
> Using many allocations instead of a single array will increase the
> number of allocations a lot. Is it worth it?
It's not a lot, is as needed. Yes, there will be some transactions that
need to allocate a page and the metadata here and there. However, the
vast majority will find an existing page.
Another way to think about this is how userspace defines the mmap size:
It makes sense to leave some slack beyond the expected usage. This patch
avoids preallocating all that memory for the "slack" which will end up
unused most of the time.
>
> > Rename struct binder_lru_page to struct binder_shrinker_mdata to better
> > reflect its purpose. Add convenience functions that wrap the allocation
> > and freeing of pages along with their shrinker metadata.
> >
> > Note I've reworked this patch to avoid using page->lru and page->index
> > directly, as Matthew pointed out that these are being removed [1].
> >
> > Link: https://lore.kernel.org/all/ZzziucEm3np6e7a0@casper.infradead.org/ [1]
> > Cc: Matthew Wilcox <willy@infradead.org>
> > Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
> > Reviewed-by: Suren Baghdasaryan <surenb@google.com>
> > Signed-off-by: Carlos Llamas <cmllamas@google.com>
>
> [...]
>
> > +static void binder_free_page(struct page *page)
> > +{
> > + kfree((void *)page_private(page));
> > + __free_page(page);
>
> I would cast the page_private to a pointer of the right type here.
> There may be tools or future improvements to kfree that use the type
> information.
Ok, I'll change this. There is also us humans that might benefit from
using the explicit type for context.
--
Carlos Llamas
next prev parent reply other threads:[~2024-12-04 13:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-03 21:54 [PATCH v6 0/9] binder: faster page installations Carlos Llamas
2024-12-03 21:54 ` [PATCH v6 1/9] Revert "binder: switch alloc->mutex to spinlock_t" Carlos Llamas
2024-12-03 21:54 ` [PATCH v6 2/9] binder: concurrent page installation Carlos Llamas
2024-12-04 9:59 ` Alice Ryhl
2024-12-04 13:39 ` Carlos Llamas
2024-12-04 14:05 ` Alice Ryhl
2024-12-03 21:54 ` [PATCH v6 3/9] binder: select correct nid for pages in LRU Carlos Llamas
2024-12-03 21:54 ` [PATCH v6 4/9] binder: store shrinker metadata under page->private Carlos Llamas
2024-12-04 9:39 ` Alice Ryhl
2024-12-04 13:55 ` Carlos Llamas [this message]
2024-12-03 21:54 ` [PATCH v6 5/9] binder: replace alloc->vma with alloc->mapped Carlos Llamas
2024-12-03 21:54 ` [PATCH v6 6/9] binder: rename alloc->buffer to vm_start Carlos Llamas
2024-12-03 21:54 ` [PATCH v6 7/9] binder: use per-vma lock in page installation Carlos Llamas
2024-12-03 21:54 ` [PATCH v6 8/9] binder: propagate vm_insert_page() errors Carlos Llamas
2024-12-03 21:54 ` [PATCH v6 9/9] binder: use per-vma lock in page reclaiming Carlos Llamas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z1BfQE6IMI9nqUIB@google.com \
--to=cmllamas@google.com \
--cc=Liam.Howlett@oracle.com \
--cc=aliceryhl@google.com \
--cc=arve@android.com \
--cc=brauner@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=joel@joelfernandes.org \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maco@android.com \
--cc=surenb@google.com \
--cc=tkjos@android.com \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.