From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 216413126D1 for ; Fri, 7 Nov 2025 22:02:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762552938; cv=none; b=MvfRGL3t7gaNe6Ygf+1di8EgM5tQanoqmVffxX9Hw652MTW87BXA6xl0NieHkDW4NBlWeddZx3wteqwbbm8K9yFN7vfSy3QWhIR1IS5JWwC+fdqYeYvDIbN29At2IsErv/SOLiHc7OdOeTP53sDawUqJF3OL1ReV6lajxmzVMXc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762552938; c=relaxed/simple; bh=78h7gZjK2DnylzgjwC5RvW7XGitrHkh4zHw5oUqrXtQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VkDMhFCsdzZES7PKD6Qq0V+UzrZQUvAWPP9s5FZ2rraHyaFeBfhmDLHLq5D1jiZLPyw7HCsSbv6CCHgJ/zzdPF88rTKEYwWHCzXuPGipBoavB5JOriVlpu3uCbLzOLqiQP2SvHk3Xa+ufQEyAiuz9nDLTKSAuG38TiQ+BMpeo/E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OyjGf8ud; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OyjGf8ud" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-295c64cb951so55955ad.0 for ; Fri, 07 Nov 2025 14:02:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1762552936; x=1763157736; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Fk1g3IY/I26lAkkLzgmm3oJ8Y/bG9K9A/adrQZcZLLg=; b=OyjGf8uddzkjzKAUocFBRhMedIO4dx2j2LZmt9blNjf3mOEqnNctoGjHtdToDG1ZAO kRLFkF2tyjAS01SCMLA/8G7MLtNmIFzs/pM2PgNPYotEJUlpFV6YNOTrdggXBN5l4ZN9 1b6n9oco17op/ewACcNtQYbfrwHBU5URq8PpSENpsWOu53qPsOBNxVc3ux4QAj/ewwOF P/x/A/C3LuNf/d1bgNC3332wdrWVn7ujo5hMXKL95uobkRvvcvpS/WnMlWn/pdpi/Kr1 aqgRExgYCGQSnNgy44ZV180cfSMVmZMNVsd1YGuleWXKnqxKGukwE+RGyTUMxD1b7eI2 g+Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762552936; x=1763157736; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Fk1g3IY/I26lAkkLzgmm3oJ8Y/bG9K9A/adrQZcZLLg=; b=oQKbSVoSg0/FsAaeuWRAqq1j8ICvJwd9IcxsTtSSURNGKsWl41herHc1owA83loMN4 GQFvhi66u+4LiBR9Rn6wjDg6WSkpWhZtI7LDJGGyswkDI4bJBBJdM4EsVzdCNztC/yHx zi/1E3XbexbGPmI4zNNAU3YMjy+9hWhLCOHy9rYG5qvUVr/fFfTDpfaXu2xiVjYUiJYK n3rUwN8WqU3kGThOTKjc9XsgZRHi0EgKex26jM63f6s9UUdi+DhuH3wqcmmfCAwRpMu8 fGjxbi8csjYsUyScsR23b24exSiuC4q6IUTC4vtM2SR2gdkF4iamVupZ/n6VO5MxiaIQ K+qw== X-Forwarded-Encrypted: i=1; AJvYcCUz/GxRTDcJIQETSo0WAy6C9+d6GqB3g9bIl9VSvbMMUEjku+ZF9txaEexoTCGrduolb13Vr7N+Vv82pqeNiQ==@vger.kernel.org X-Gm-Message-State: AOJu0YxGG3CDKF6puoBqP0+JJqangCB7PsSf0qiznoQpbZHqhbHPRyNC T7R/AzAMri0ZoW4PHHkA3fMX2R2y6oBlhxm9Lt/qghxr78ZnzHGj/gbG8FJSi7FvTQ== X-Gm-Gg: ASbGncv9oaeFFAlEA5dBPy4ppK1BXRkp9ScWI4472tHX2UwlT+gTf2cA22+a5SfFrXY D8nf2T/f2MRtkHqWJ2zSTfddKsiZ4/WRUWVHI9sJTzvw5lYqwEpwN6dW43pXub/WKLAEw4yyj46 7Ftct/bfkCQOzUauRBiJfn7kdCMSMEtXk7ZWW9W4CUwxiCufkLdWY6BzTqnsnoYKVULXuYF7v2y FaDOxWrVTSBdW9oYeXw73L8kZoxTitjHzI2jto1ASY0qR9Vro2sBo591v/9EEFQ911uQoch49xy L2xYgsyw2VvOP/NFv536fD6pOwBnx+H7hFPtODOZ+YYUjPXLrxAH3UpU/JU9e4KPlBWWyMyNjBF tPN01TQfNYCk/mfPR/2yez2o7k3hkVpSEsEPfYeW08FJ+5ELl4ZbvqnvYxYtZHHLe5KeP7/GOEC EX6r41Lq95M5xg0w2GQ58MI5lru565sQeylV6Drznn37CeVWsZlMGWcwMMoKvGXKfsNKFNr+RE4 I3pJ/FZ5VGPEnzz2LY1NXkmKg== X-Google-Smtp-Source: AGHT+IE7LM/ftcbdlEIftAMc3LNqaSP97ukQV1UpBEOmW69D8muqPSdkZcVrRCXHkPez2e+AUj0Wfw== X-Received: by 2002:a17:903:190:b0:26a:8171:daf8 with SMTP id d9443c01a7336-297e567e77amr1470925ad.8.1762552935873; Fri, 07 Nov 2025 14:02:15 -0800 (PST) Received: from google.com (116.241.118.34.bc.googleusercontent.com. [34.118.241.116]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-297dacd1e93sm11822995ad.2.2025.11.07.14.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Nov 2025 14:02:14 -0800 (PST) Date: Fri, 7 Nov 2025 22:02:09 +0000 From: Carlos Llamas To: Alice Ryhl Cc: Greg Kroah-Hartman , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Suren Baghdasaryan , linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org Subject: Re: [PATCH] rust_binder: move BC_FREE_BUFFER drop inside if statement Message-ID: References: <20251029-binder-bcfreebuf-option-v1-1-4d282be0439f@google.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251029-binder-bcfreebuf-option-v1-1-4d282be0439f@google.com> On Wed, Oct 29, 2025 at 11:50:58AM +0000, Alice Ryhl wrote: > When looking at flamegraphs, there is a pretty large entry for the > function call drop_in_place::> which in turn calls > drop_in_place::. Combined with the looper_need_return > condition, this means that the generated code looks like this: > > if let Some(buffer) = buffer { > if buffer.looper_need_return_on_free() { > self.inner.lock().looper_need_return = true; > } > } > drop_in_place::>() { // not inlined > if let Some(buffer) = buffer { > drop_in_place::(buffer); > } > } > > This kind of situation where you check X and then check X again is > normally optimized into a single condition, but in this case due to the > non-inlined function call to drop_in_place::>, that > optimization does not happen. > > Furthermore, the drop_in_place:: call is only two-thirds of > the drop_in_place::> call in the flamegraph. This > indicates that this double condition is not performing well. Also, last > time I looked at Binder perf, I remember finding that the destructor of > Allocation was involved with many branch mispredictions. > > Thus, change this code to look like this: > > if let Some(buffer) = buffer { > if buffer.looper_need_return_on_free() { > self.inner.lock().looper_need_return = true; > } > drop_in_place::(buffer); > } > > by dropping the Allocation directly. Flamegraphs confirm that the > drop_in_place::> call disappears from this change. > > Signed-off-by: Alice Ryhl > --- LGTM, Acked-by: Carlos Llamas