Re: [PATCH 17/21] binder: malloc new_buffer outside of locks

From: Alice Ryhl
Date: Tue Nov 07 2023 - 04:09:39 EST


Carlos Llamas <cmllamas@xxxxxxxxxx> writes:
> Preallocate new_buffer before acquiring the alloc->mutex and hand it
> down to binder_alloc_new_buf_locked(). The new buffer will be used in
> the vast majority of requests (measured at 98.2% in field data). The
> buffer is discarded otherwise. This change is required in preparation
> for transitioning alloc->mutex into a spinlock in subsequent commits.
>
> Signed-off-by: Carlos Llamas <cmllamas@xxxxxxxxxx>

You also need to free the new buffer here:

if (unlikely(!best_fit)) {
binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
"%d: binder_alloc_buf size %zd failed, no address space\n",
alloc->pid, size);
debug_no_space_locked(alloc);
return ERR_PTR(-ENOSPC);
}

Other than the above, this looks correct to me.

Alice