FROMLIST: binder: add more debug info when allocation fails.
authorMartijn Coenen <maco@android.com>
Wed, 15 Mar 2017 17:22:52 +0000 (18:22 +0100)
committerDanny Wood <danwood76@gmail.com>
Tue, 8 Oct 2019 13:36:25 +0000 (14:36 +0100)
(from https://patchwork.kernel.org/patch/9817797/)

Bug: 36088202
Test: tested manually
Change-Id: Ib526a9c375e6136669b72f341e0b54d896fd1cec
Signed-off-by: Martijn Coenen <maco@android.com>
Signed-off-by: Siqi Lin <siqilin@google.com>
drivers/android/binder_alloc.c

index 8f79df3f3613e72ceacd3788fcb0a65d7af828a8..aabfebac6e57221ae27a9872e18cedb4a023a4ba 100644 (file)
@@ -337,8 +337,36 @@ struct binder_buffer *binder_alloc_new_buf_locked(struct binder_alloc *alloc,
                }
        }
        if (best_fit == NULL) {
+               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;
+               }
                pr_err("%d: binder_alloc_buf size %zd failed, no address space\n",
                        alloc->pid, size);
+               pr_err("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);
        }
        if (n == NULL) {
@@ -698,9 +726,10 @@ void binder_alloc_deferred_release(struct binder_alloc *alloc)
 static void print_binder_buffer(struct seq_file *m, const char *prefix,
                                struct binder_buffer *buffer)
 {
-       seq_printf(m, "%s %d: %pK size %zd:%zd %s\n",
+       seq_printf(m, "%s %d: %pK size %zd:%zd:%zd %s\n",
                   prefix, buffer->debug_id, buffer->data,
                   buffer->data_size, buffer->offsets_size,
+                  buffer->extra_buffers_size,
                   buffer->transaction ? "active" : "delivered");
 }