Received: by 10.213.65.68 with SMTP id h4csp403294imn; Fri, 6 Apr 2018 02:11:58 -0700 (PDT) X-Google-Smtp-Source: AIpwx48kSg9p0m1/56W3IB2OVfZp3tDajH7Lx4oiyLLBNjV1hqR1bTrRenqF4g1atd/TYI8wene0 X-Received: by 2002:a17:902:8d98:: with SMTP id v24-v6mr26421287plo.21.1523005918913; Fri, 06 Apr 2018 02:11:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523005918; cv=none; d=google.com; s=arc-20160816; b=JhPHXZ8VFhZ0YHACXozgv3H7bgP/TttlSYUzGIZSTYrMvcBj8SQ28U18LdHKN988ir uvQhFo0ksfKzcuY0kyW6mLaE6/z7IlD1OmDA3tb6rhLsVQCYrkg3aGoTlrSVIhL8mSfG /H86XhZ2l86creTOZpfx4c1NOKp2iCj6tJZirQ23vToJIKNKukByTmua+j1pL/684GMe Q0NknrEREqv0zr6N+A3eqRfSY1RRx2zulGe5uhGzxGbwPUxx3rv7rVIEsx2HFBAyu29b IVuQF25zKxfH+vXRm02skjgQSjH1thSnKFrFH2Wu7DlkTlJsKt/tzmpVxydhVDJQaYfV QjIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=kx7LnfGySD+d8l1VPptSaIDDt4WVaFbd3PAFv1H1U/c=; b=myEXuvCRXQI4iyS644bM/1Xs7flopPEqaX6Cfx8wgGdMYdBstntiIr1Mp/+suoBD/8 jbuknBVeNJxdGgcF74k6QTdio/vF84JRGSVJtHD8jH3ZYGIg7Lozanwi0MVnGwggiBbG t6zOSZNMmtWy3OkaTd/6t2uXS2wkoBFcImiWuN3NQyL4IHtbPthGrV1/A7VQZZyyr0/p 3R7U335d/WCNIdmgkN7cp+nM+LsSsh0SIQg7iPmKOCqQKtLeKTzTJ6P0TgdvyNX4fhCP D/q4WpNMiOZTUm/QzWWXpJSuu4A7CrauN/LN2P8bTazRyS89+qTqwggeUhkT1sKD/Lvz l7jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b=L+6yh1rb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o16si6803763pgc.832.2018.04.06.02.11.44; Fri, 06 Apr 2018 02:11:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b=L+6yh1rb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751896AbeDFJK2 (ORCPT + 99 others); Fri, 6 Apr 2018 05:10:28 -0400 Received: from pandora.armlinux.org.uk ([78.32.30.218]:47642 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751750AbeDFJK0 (ORCPT ); Fri, 6 Apr 2018 05:10:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=kx7LnfGySD+d8l1VPptSaIDDt4WVaFbd3PAFv1H1U/c=; b=L+6yh1rb/B0hGgiDNlhxj6vnG 2y5NVfoAasEdMiWKfOokSj0uUicOAI9Ocn1tTqgpYJApRvK85Egw3s3Rri7Rb1/5KUI5vqr2UC9XQ 6u9e/QHuUPjdJfuRh55hoDVCTMJyX7iIR4iOTTfO5gn2t3GTCMuwL/ltZPwdV9GDFBU5A=; Received: from n2100.armlinux.org.uk ([fd8f:7570:feb6:1:214:fdff:fe10:4f86]:53220) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) (envelope-from ) id 1f4NN7-0000yJ-1Z; Fri, 06 Apr 2018 10:09:25 +0100 Received: from linux by n2100.armlinux.org.uk with local (Exim 4.90_1) (envelope-from ) id 1f4NN3-0008BH-TU; Fri, 06 Apr 2018 10:09:21 +0100 Date: Fri, 6 Apr 2018 10:09:20 +0100 From: Russell King - ARM Linux To: Matthew Wilcox Cc: Jia He , Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , Andrew Morton , Michal Hocko , Wei Yang , Kees Cook , Laura Abbott , Vladimir Murzin , Philip Derrin , AKASHI Takahiro , James Morse , Steve Capper , Pavel Tatashin , Gioh Kim , Vlastimil Babka , Mel Gorman , Johannes Weiner , Kemi Wang , Petr Tesarik , YASUAKI ISHIMATSU , Andrey Ryabinin , Nikolay Borisov , Daniel Jordan , Daniel Vacek , Eugeniu Rosca , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Jia He Subject: Re: [PATCH v7 2/5] arm: arm64: page_alloc: reduce unnecessary binary search in memblock_next_valid_pfn() Message-ID: <20180406090920.GM16141@n2100.armlinux.org.uk> References: <1522915478-5044-1-git-send-email-hejianet@gmail.com> <1522915478-5044-3-git-send-email-hejianet@gmail.com> <20180405113444.GB2647@bombadil.infradead.org> <1f809296-e88d-1090-0027-890782b91d6e@gmail.com> <20180405125054.GC2647@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180405125054.GC2647@bombadil.infradead.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 05, 2018 at 05:50:54AM -0700, Matthew Wilcox wrote: > On Thu, Apr 05, 2018 at 08:44:12PM +0800, Jia He wrote: > > > > > > On 4/5/2018 7:34 PM, Matthew Wilcox Wrote: > > > On Thu, Apr 05, 2018 at 01:04:35AM -0700, Jia He wrote: > > > > Commit b92df1de5d28 ("mm: page_alloc: skip over regions of invalid pfns > > > > where possible") optimized the loop in memmap_init_zone(). But there is > > > > still some room for improvement. E.g. if pfn and pfn+1 are in the same > > > > memblock region, we can simply pfn++ instead of doing the binary search > > > > in memblock_next_valid_pfn. > > > Sure, but I bet if we are >end_pfn, we're almost certainly going to the > > > start_pfn of the next block, so why not test that as well? > > > > > > > + /* fast path, return pfn+1 if next pfn is in the same region */ > > > > + if (early_region_idx != -1) { > > > > + start_pfn = PFN_DOWN(regions[early_region_idx].base); > > > > + end_pfn = PFN_DOWN(regions[early_region_idx].base + > > > > + regions[early_region_idx].size); > > > > + > > > > + if (pfn >= start_pfn && pfn < end_pfn) > > > > + return pfn; > > > early_region_idx++; > > > start_pfn = PFN_DOWN(regions[early_region_idx].base); > > > if (pfn >= end_pfn && pfn <= start_pfn) > > > return start_pfn; > > Thanks, thus the binary search in next step can be discarded? > > I don't know all the circumstances in which this is called. Maybe a linear > search with memo is more appropriate than a binary search. That's been brought up before, and the reasoning appears to be something along the lines of... Academics and published wisdom is that on cached architectures, binary searches are bad because it doesn't operate efficiently due to the overhead from having to load cache lines. Consequently, there seems to be a knee-jerk reaction that "all binary searches are bad, we must eliminate them." What is failed to be grasped here, though, is that it is typical that the number of entries in this array tend to be small, so the entire array takes up one or two cache lines, maybe a maximum of four lines depending on your cache line length and number of entries. This means that the binary search expense is reduced, and is lower than a linear search for the majority of cases. What is key here as far as performance is concerned is whether the general usage of pfn_valid() by the kernel is optimal. We should not optimise only for the boot case, which means evaluating the effect of these changes with _real_ workloads, not just "does my machine boot a milliseconds faster". -- RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up According to speedtest.net: 8.21Mbps down 510kbps up