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 X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EEE8C10F25 for ; Sat, 7 Mar 2020 23:15:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D1B3E20684 for ; Sat, 7 Mar 2020 23:15:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="HDOFwUXD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D1B3E20684 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7E0C96B0005; Sat, 7 Mar 2020 18:15:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 791B76B0006; Sat, 7 Mar 2020 18:15:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CCB96B0007; Sat, 7 Mar 2020 18:15:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0126.hostedemail.com [216.40.44.126]) by kanga.kvack.org (Postfix) with ESMTP id 56EC86B0005 for ; Sat, 7 Mar 2020 18:15:44 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 27691181AC9C6 for ; Sat, 7 Mar 2020 23:15:44 +0000 (UTC) X-FDA: 76570125408.01.honey53_8955ad6162f0d X-HE-Tag: honey53_8955ad6162f0d X-Filterd-Recvd-Size: 2847 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Sat, 7 Mar 2020 23:15:43 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 842FC20684; Sat, 7 Mar 2020 23:15:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583622942; bh=PQ1dJmyPmP9RuAp0Y48k7+4kdZe3kgJZTmHXrX4URZs=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=HDOFwUXDbu8m0PLMB596Ay74/Ju7AWtDzQ0JdQ/Lqnx264Rn/A2EvFZ0x+BTsNdrG U2mGGNQPx6Yl81L33rYIWiMiHKqPMlhPPFVR9z043LhQh0l1sfpvJ8a5vDuah7U8DD xXcRq6rVD0n5pO19BFgHhizEb2rXOtlr1M6Ts3IA= Date: Sat, 7 Mar 2020 15:15:42 -0800 From: Andrew Morton To: mateusznosek0@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] mm/page_alloc.c: Micro-optimisation Remove unnecessary branch Message-Id: <20200307151542.b14131037dc44a8edcb22cad@linux-foundation.org> In-Reply-To: <20200307225335.31300-1-mateusznosek0@gmail.com> References: <20200307225335.31300-1-mateusznosek0@gmail.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sat, 7 Mar 2020 23:53:35 +0100 mateusznosek0@gmail.com wrote: > From: Mateusz Nosek > > Previously if branch condition was false, the assignment was not executed. > The assignment can be safely executed even when the condition is false and > it is not incorrect as it assigns the value of 'nodemask' to 'ac.nodemask' > which already has the same value. > > So as the assignment can be executed unconditionally, the branch can be > removed. > > ... > > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -4819,8 +4819,7 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, int preferred_nid, > * Restore the original nodemask if it was potentially replaced with > * &cpuset_current_mems_allowed to optimize the fast-path attempt. > */ > - if (unlikely(ac.nodemask != nodemask)) > - ac.nodemask = nodemask; > + ac.nodemask = nodemask; > This will now unconditionally dirty the ac.nodemask cacheline, which means that cacheline will need to be written back. If it is truly unlikely that the write was needed then the thinking goes that the test-and-branch is worthwhile, by saving on memory traffic. At least, I assume that's why the code is the way it is. I don't know whether this optimisation is valid on a majority of modern platforms. But that's the thinking!