Received: by 10.213.65.68 with SMTP id h4csp902931imn; Tue, 27 Mar 2018 10:53:36 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/4ViYCdRbgmXHtLFEXRKCHyy/+zDRVRHb21/ct9mLgXuWngZ/YJ3hucMeFhJgHx4lTHF1Z X-Received: by 10.101.76.10 with SMTP id u10mr170435pgq.445.1522173216316; Tue, 27 Mar 2018 10:53:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522173216; cv=none; d=google.com; s=arc-20160816; b=GmF+6vsO8aomvVwcTz1lIoKxYLbpKdQWkNz3n+PfAQzhvqQpHhvszI5TwQe5PiTHKo xf7lEyRjQVa2qbLwq1wid43nbnX/0kKv9+/PffaZAbpRJFT4+JSPGECsbVhY4feC2TYn 5zfL0oehd0J7Jj5diXg7AumbzdhgeVn0Ts8ucrCC5GkP6K0VV8EJzMAeAmnQDkiR0hPx VuiFXQvieUsCpotoE7rhyiI7fT385rre3WTO305QdwMKyJ09OBhBwgbBO/+dUvEUa/wv EWsRrSUoMG/eHJu150Z8QryLM5EtHhBjtu5VgclyWVV10m2oX/j5u3UYhXCg01zWsdnu LSoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:arc-authentication-results; bh=PKnxID0WwC3bDqophEN8lxKzjNjdAxjBSOn7ndzxv8I=; b=Q9NZpMngtq6N828Ykn3sUL9nJjhVuNx4mf1FN4+GtaRe3IYRzB+zsZkGdsLVmc36AO Rkhqj2rAA21phqf41PB1dv2T/SVHIdece8M9Qye7H9eEnJ9/xNIB4CfeXG8U1c5+CsCQ WbzwIcpQqLe9NcAIzx5T1kqoDdEjO4ugVlpgT+CcxE0dkcYYeaqX5cjRR2kOwzetv8i3 +/fOcE3b2c+uuEUAHJSDvJP6lWzkCynW9FoOHhCHqkE6Wvp3ffpfM3w1g4EbjpFuQSLH XgRX91Zmuad/h7TYGtSsFx4Ms9IzxUSdKaA618dINunf7HzkZm6PeMnhGUCt3D3FmQ9U 0Xcw== ARC-Authentication-Results: i=1; mx.google.com; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l69si1232558pfk.180.2018.03.27.10.53.22; Tue, 27 Mar 2018 10:53:36 -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; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753814AbeC0RwA (ORCPT + 99 others); Tue, 27 Mar 2018 13:52:00 -0400 Received: from mail-ot0-f194.google.com ([74.125.82.194]:46592 "EHLO mail-ot0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753647AbeC0Rv5 (ORCPT ); Tue, 27 Mar 2018 13:51:57 -0400 Received: by mail-ot0-f194.google.com with SMTP id v64-v6so4313223otb.13 for ; Tue, 27 Mar 2018 10:51:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=PKnxID0WwC3bDqophEN8lxKzjNjdAxjBSOn7ndzxv8I=; b=a52OO8SIiCkO8p6WQItr8MwpnReEfV2vSmq1N/MMp3ukEv6S57LggnozRcBpl5UlOc a4HZAJCiivCqWU3EHz3ocK7Y4+6792SkN/DekgEylG4U1Ltj6Xk/whUIdpUUMdLu8ggC U+HUf9q2BXxIbABWIkg1inrn9vBvSHNo/PC/xyHhjDuhfSdWiz1SB2X+FAyd9WgGrBSe 3FwA1AccIJUX0dMbS7ZEWQyxs6q8pXAIF5Fo63xWeLBiiT+uxOxZhMjs6TA63i6/cQMR KQy0fpMzalP0DSMVli+nlUB2kFUiWvdB2BBs3zfaSlBOsEj1wb9u6c6kBOZnVJ27iSXq z4+g== X-Gm-Message-State: AElRT7EoIGK7+RJR4uVSARTIzPwBJheusTq8ZZb9fupA9T0HA9HE/cnT Gv5ttXOiY47+uzwBVT5vlShjRBkDG+xUFmAv7MAzVw== X-Received: by 2002:a9d:252b:: with SMTP id k40-v6mr201272otb.141.1522173116585; Tue, 27 Mar 2018 10:51:56 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:39f6:0:0:0:0:0 with HTTP; Tue, 27 Mar 2018 10:51:56 -0700 (PDT) In-Reply-To: <1522033340-6575-6-git-send-email-hejianet@gmail.com> References: <1522033340-6575-1-git-send-email-hejianet@gmail.com> <1522033340-6575-6-git-send-email-hejianet@gmail.com> From: Daniel Vacek Date: Tue, 27 Mar 2018 19:51:56 +0200 Message-ID: Subject: Re: [PATCH v3 5/5] mm: page_alloc: reduce unnecessary binary search in early_pfn_valid() To: Jia He Cc: Andrew Morton , Michal Hocko , Catalin Marinas , Mel Gorman , Will Deacon , Mark Rutland , Ard Biesheuvel , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Pavel Tatashin , Daniel Jordan , AKASHI Takahiro , Gioh Kim , Steven Sistare , Eugeniu Rosca , Vlastimil Babka , open list , linux-mm@kvack.org, James Morse , Steve Capper , x86@kernel.org, Greg Kroah-Hartman , Kate Stewart , Philippe Ombredanne , Johannes Weiner , Kemi Wang , Petr Tesarik , YASUAKI ISHIMATSU , Andrey Ryabinin , Nikolay Borisov , Jia He Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 26, 2018 at 5:02 AM, 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. in early_pfn_valid(), if pfn and > pfn+1 are in the same memblock region, we can record the last returned > memblock region index and check check pfn++ is still in the same region. > > Currently it only improve the performance on arm64 and will have no > impact on other arches. > > Signed-off-by: Jia He > --- > arch/x86/include/asm/mmzone_32.h | 2 +- > include/linux/mmzone.h | 12 +++++++++--- > mm/page_alloc.c | 2 +- > 3 files changed, 11 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/include/asm/mmzone_32.h b/arch/x86/include/asm/mmzone_32.h > index 73d8dd1..329d3ba 100644 > --- a/arch/x86/include/asm/mmzone_32.h > +++ b/arch/x86/include/asm/mmzone_32.h > @@ -49,7 +49,7 @@ static inline int pfn_valid(int pfn) > return 0; > } > > -#define early_pfn_valid(pfn) pfn_valid((pfn)) > +#define early_pfn_valid(pfn, last_region_idx) pfn_valid((pfn)) > > #endif /* CONFIG_DISCONTIGMEM */ > > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > index d797716..3a686af 100644 > --- a/include/linux/mmzone.h > +++ b/include/linux/mmzone.h > @@ -1267,9 +1267,15 @@ static inline int pfn_present(unsigned long pfn) > }) > #else > #define pfn_to_nid(pfn) (0) > -#endif > +#endif /*CONFIG_NUMA*/ > + > +#ifdef CONFIG_HAVE_ARCH_PFN_VALID > +#define early_pfn_valid(pfn, last_region_idx) \ > + pfn_valid_region(pfn, last_region_idx) > +#else > +#define early_pfn_valid(pfn, last_region_idx) pfn_valid(pfn) > +#endif /*CONFIG_HAVE_ARCH_PFN_VALID*/ > > -#define early_pfn_valid(pfn) pfn_valid(pfn) > void sparse_init(void); > #else > #define sparse_init() do {} while (0) > @@ -1288,7 +1294,7 @@ struct mminit_pfnnid_cache { > }; > > #ifndef early_pfn_valid > -#define early_pfn_valid(pfn) (1) > +#define early_pfn_valid(pfn, last_region_idx) (1) > #endif > > void memory_present(int nid, unsigned long start, unsigned long end); > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 0bb0274..debccf3 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -5484,7 +5484,7 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, > if (context != MEMMAP_EARLY) > goto not_early; > > - if (!early_pfn_valid(pfn)) { > + if (!early_pfn_valid(pfn, &idx)) { > #if (defined CONFIG_HAVE_MEMBLOCK) && (defined CONFIG_HAVE_ARCH_PFN_VALID) > /* > * Skip to the pfn preceding the next valid one (or > -- > 2.7.4 > Hmm, what about making index global variable instead of changing all the prototypes? Similar to early_pfnnid_cache for example. Something like: #ifdef CONFIG_HAVE_ARCH_PFN_VALID extern int early_region_idx __meminitdata; #define early_pfn_valid(pfn) \ pfn_valid_region(pfn, &early_region_idx) #else #define early_pfn_valid(pfn) pfn_valid(pfn) #endif /*CONFIG_HAVE_ARCH_PFN_VALID*/ And move this to arch/arm64/include/asm/page.h ? --nX