From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADAF5C04A95 for ; Fri, 23 Sep 2022 22:54:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232789AbiIWWyU (ORCPT ); Fri, 23 Sep 2022 18:54:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232726AbiIWWyQ (ORCPT ); Fri, 23 Sep 2022 18:54:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6455413EE9E for ; Fri, 23 Sep 2022 15:54:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0C59761D9C for ; Fri, 23 Sep 2022 22:54:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D548CC433C1; Fri, 23 Sep 2022 22:54:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1663973654; bh=gCJ8DR840inCdFEFB4zVuogQsDTiryXsoN5Cs3aTkmg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=raUysYcQlgcKkCEAXtNM5kTHYKgQujoGqIyUz8/cM6rL/oebYKznvjyMEy8KqlQaG 6+z3oy4Lq1TU9tNsJRyShPGIa4oU45HDrGB7VukzoNL07s2nEAnkFahOAPEfzdW5HP rw0ycj+7bxLEb8kMoZ2iMoTNqRRtQZypLVc/tZ8Y= Date: Fri, 23 Sep 2022 15:54:12 -0700 From: Andrew Morton To: "Jason A. Donenfeld" Cc: Andy Shevchenko , linux-kernel@vger.kernel.org, Kees Cook Subject: Re: [PATCH v2] minmax: clamp more efficiently by avoiding extra comparison Message-Id: <20220923155412.b0132fc62eca18817a023cd2@linux-foundation.org> In-Reply-To: <20220923154001.4074849-1-Jason@zx2c4.com> References: <20220923154001.4074849-1-Jason@zx2c4.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 23 Sep 2022 17:40:01 +0200 "Jason A. Donenfeld" wrote: > Currently the clamp algorithm does: > > if (val > hi) > val = hi; > if (val < lo) > val = lo; > > But since hi > lo by definition, this can be made more efficient with: > > if (val > hi) > val = hi; > else if (val < lo) > val = lo; > > So fix up the clamp and clamp_t functions to do this, adding the same > argument checking as for min and min_t. > The patch adds 140 bytes of text to mm/memblock.o, for example. Presumably from the additional branch. Larger text means larger cache footprint means slower. So where's the proof that this change gives us a more efficient kernel?