mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-06 10:58:48 +09:00
UPSTREAM: binder: separate the no-space debugging logic
Move the no-space debugging logic into a separate function. Lets also mark this branch as unlikely in binder_alloc_new_buf_locked() as most requests will fit without issue. Also add a few cosmetic changes and suggestions from checkpatch. Reviewed-by: Alice Ryhl <aliceryhl@google.com> Signed-off-by: Carlos Llamas <cmllamas@google.com> Link: https://lore.kernel.org/r/20231201172212.1813387-14-cmllamas@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Bug: 254650075 (cherry picked from commit 9409af24e4503d14093b27db9425f7c99e64fef4) Change-Id: I4ff8ced5728a63815f7d47df9eb9ac85aa0a362d Signed-off-by: Carlos Llamas <cmllamas@google.com>
This commit is contained in:
@@ -319,6 +319,43 @@ static inline struct vm_area_struct *binder_alloc_get_vma(
|
|||||||
return smp_load_acquire(&alloc->vma);
|
return smp_load_acquire(&alloc->vma);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void debug_no_space_locked(struct binder_alloc *alloc)
|
||||||
|
{
|
||||||
|
size_t largest_alloc_size = 0;
|
||||||
|
struct binder_buffer *buffer;
|
||||||
|
size_t allocated_buffers = 0;
|
||||||
|
size_t largest_free_size = 0;
|
||||||
|
size_t total_alloc_size = 0;
|
||||||
|
size_t total_free_size = 0;
|
||||||
|
size_t free_buffers = 0;
|
||||||
|
size_t buffer_size;
|
||||||
|
struct rb_node *n;
|
||||||
|
|
||||||
|
for (n = rb_first(&alloc->allocated_buffers); n; n = rb_next(n)) {
|
||||||
|
buffer = rb_entry(n, struct binder_buffer, rb_node);
|
||||||
|
buffer_size = binder_alloc_buffer_size(alloc, buffer);
|
||||||
|
allocated_buffers++;
|
||||||
|
total_alloc_size += buffer_size;
|
||||||
|
if (buffer_size > largest_alloc_size)
|
||||||
|
largest_alloc_size = buffer_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (n = rb_first(&alloc->free_buffers); n; n = rb_next(n)) {
|
||||||
|
buffer = rb_entry(n, struct binder_buffer, rb_node);
|
||||||
|
buffer_size = binder_alloc_buffer_size(alloc, buffer);
|
||||||
|
free_buffers++;
|
||||||
|
total_free_size += buffer_size;
|
||||||
|
if (buffer_size > largest_free_size)
|
||||||
|
largest_free_size = buffer_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
|
||||||
|
"allocated: %zd (num: %zd largest: %zd), free: %zd (num: %zd largest: %zd)\n",
|
||||||
|
total_alloc_size, allocated_buffers,
|
||||||
|
largest_alloc_size, total_free_size,
|
||||||
|
free_buffers, largest_free_size);
|
||||||
|
}
|
||||||
|
|
||||||
static bool debug_low_async_space_locked(struct binder_alloc *alloc)
|
static bool debug_low_async_space_locked(struct binder_alloc *alloc)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -398,42 +435,14 @@ static struct binder_buffer *binder_alloc_new_buf_locked(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (best_fit == NULL) {
|
if (unlikely(!best_fit)) {
|
||||||
size_t allocated_buffers = 0;
|
|
||||||
size_t largest_alloc_size = 0;
|
|
||||||
size_t total_alloc_size = 0;
|
|
||||||
size_t free_buffers = 0;
|
|
||||||
size_t largest_free_size = 0;
|
|
||||||
size_t total_free_size = 0;
|
|
||||||
|
|
||||||
for (n = rb_first(&alloc->allocated_buffers); n != NULL;
|
|
||||||
n = rb_next(n)) {
|
|
||||||
buffer = rb_entry(n, struct binder_buffer, rb_node);
|
|
||||||
buffer_size = binder_alloc_buffer_size(alloc, buffer);
|
|
||||||
allocated_buffers++;
|
|
||||||
total_alloc_size += buffer_size;
|
|
||||||
if (buffer_size > largest_alloc_size)
|
|
||||||
largest_alloc_size = buffer_size;
|
|
||||||
}
|
|
||||||
for (n = rb_first(&alloc->free_buffers); n != NULL;
|
|
||||||
n = rb_next(n)) {
|
|
||||||
buffer = rb_entry(n, struct binder_buffer, rb_node);
|
|
||||||
buffer_size = binder_alloc_buffer_size(alloc, buffer);
|
|
||||||
free_buffers++;
|
|
||||||
total_free_size += buffer_size;
|
|
||||||
if (buffer_size > largest_free_size)
|
|
||||||
largest_free_size = buffer_size;
|
|
||||||
}
|
|
||||||
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
|
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
|
||||||
"%d: binder_alloc_buf size %zd failed, no address space\n",
|
"%d: binder_alloc_buf size %zd failed, no address space\n",
|
||||||
alloc->pid, size);
|
alloc->pid, size);
|
||||||
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
|
debug_no_space_locked(alloc);
|
||||||
"allocated: %zd (num: %zd largest: %zd), free: %zd (num: %zd largest: %zd)\n",
|
|
||||||
total_alloc_size, allocated_buffers,
|
|
||||||
largest_alloc_size, total_free_size,
|
|
||||||
free_buffers, largest_free_size);
|
|
||||||
return ERR_PTR(-ENOSPC);
|
return ERR_PTR(-ENOSPC);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n == NULL) {
|
if (n == NULL) {
|
||||||
buffer = rb_entry(best_fit, struct binder_buffer, rb_node);
|
buffer = rb_entry(best_fit, struct binder_buffer, rb_node);
|
||||||
buffer_size = binder_alloc_buffer_size(alloc, buffer);
|
buffer_size = binder_alloc_buffer_size(alloc, buffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user