[PATCH 13/21] binder: relocate low space calculation

Carlos Llamas posted 21 patches 2 years, 1 month ago
Only 19 patches received!
There is a newer version of this series
[PATCH 13/21] binder: relocate low space calculation
Posted by Carlos Llamas 2 years, 1 month ago
Move the low async space calculation to debug_low_async_space_locked().
This logic not only fits better here but also offloads some of the many
tasks currently done in binder_alloc_new_buf_locked().

No functional change in this patch.

Signed-off-by: Carlos Llamas <cmllamas@google.com>
---
 drivers/android/binder_alloc.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index 3fe5c734c3df..cc627c106a01 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -375,6 +375,15 @@ static bool debug_low_async_space_locked(struct binder_alloc *alloc)
 	size_t num_buffers = 0;
 	struct rb_node *n;
 
+	/*
+	 * Only start detecting spammers once we have less than 20% of async
+	 * space left (which is less than 10% of total buffer size).
+	 */
+	if (alloc->free_async_space >= alloc->buffer_size / 10) {
+		alloc->oneway_spam_detected = false;
+		return false;
+	}
+
 	for (n = rb_first(&alloc->allocated_buffers); n != NULL;
 		 n = rb_next(n)) {
 		buffer = rb_entry(n, struct binder_buffer, rb_node);
@@ -497,16 +506,8 @@ static struct binder_buffer *binder_alloc_new_buf_locked(
 		binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC_ASYNC,
 			     "%d: binder_alloc_buf size %zd async free %zd\n",
 			      alloc->pid, size, alloc->free_async_space);
-		if (alloc->free_async_space < alloc->buffer_size / 10) {
-			/*
-			 * Start detecting spammers once we have less than 20%
-			 * of async space left (which is less than 10% of total
-			 * buffer size).
-			 */
-			buffer->oneway_spam_suspect = debug_low_async_space_locked(alloc);
-		} else {
-			alloc->oneway_spam_detected = false;
-		}
+		if (debug_low_async_space_locked(alloc))
+			buffer->oneway_spam_suspect = true;
 	}
 
 	return buffer;
-- 
2.42.0.869.gea05f2083d-goog
Re: [PATCH 13/21] binder: relocate low space calculation
Posted by Alice Ryhl 2 years, 1 month ago
Carlos Llamas <cmllamas@google.com> writes:
> Move the low async space calculation to debug_low_async_space_locked().
> This logic not only fits better here but also offloads some of the many
> tasks currently done in binder_alloc_new_buf_locked().
> 
> No functional change in this patch.
> 
> Signed-off-by: Carlos Llamas <cmllamas@google.com>

One suggestion below, but I'm fine either way.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>


Carlos Llamas <cmllamas@google.com> writes:
> +		if (debug_low_async_space_locked(alloc))
> +			buffer->oneway_spam_suspect = true;

You could avoid a branch here like this:

buffer->oneway_spam_suspect = debug_low_async_space_locked(alloc);

Alice
Re: [PATCH 13/21] binder: relocate low space calculation
Posted by Carlos Llamas 2 years, 1 month ago
On Tue, Nov 07, 2023 at 09:08:26AM +0000, Alice Ryhl wrote:
> Carlos Llamas <cmllamas@google.com> writes:
> > Move the low async space calculation to debug_low_async_space_locked().
> > This logic not only fits better here but also offloads some of the many
> > tasks currently done in binder_alloc_new_buf_locked().
> > 
> > No functional change in this patch.
> > 
> > Signed-off-by: Carlos Llamas <cmllamas@google.com>
> 
> One suggestion below, but I'm fine either way.
> 
> Reviewed-by: Alice Ryhl <aliceryhl@google.com>
> 
> 
> Carlos Llamas <cmllamas@google.com> writes:
> > +		if (debug_low_async_space_locked(alloc))
> > +			buffer->oneway_spam_suspect = true;
> 
> You could avoid a branch here like this:
> 

Sure, sounds good to me.

--
Carlos Llamas