Received: by 10.213.65.68 with SMTP id h4csp1056768imn; Wed, 21 Mar 2018 01:12:45 -0700 (PDT) X-Google-Smtp-Source: AG47ELtepsRby8ov+dm/W0cWkwgHKcOkzKYMzVy328UjSpqg95aqpchI5d2fvJGdv0kSHUNG8hun X-Received: by 10.167.131.199 with SMTP id j7mr15951200pfn.99.1521619965508; Wed, 21 Mar 2018 01:12:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521619965; cv=none; d=google.com; s=arc-20160816; b=tVwymCPgAoMX0Uz0QkktEeXDkPbNwmFTbx6lo8/AAEX79TMdl3KZiHmI+OAv5grl03 E8AWcptstsgKSaEUzwxmNfjT15YulGoAB9NhX9HKOGLa/Iv3SrzIdjyWm3CZ4H5GD163 bUUPF2udbmhv1oRRgq1yLYC6zgW6rtqhztzpivGjYoxIt98/oG560IBp68XvvbvapD/S tmCBY3s1lY7SEwXsIPRsO5NsePvW9E9aUyWv9U+cFR29syg9WgQjDLQdu94OELiELegO gUgwXKp4w2QSoe0KNNnRoo0xteeO6vgL6NvI40DOEaeFL3+3OoOr6B1jOHgQgCTCzdQB FKHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=IllwNGbVSEyW44Dcu7drhaaIK6QU55n9PaAMLuzoo2Q=; b=f45B1kFkrZPr1aXgi19rq3LQ4576X+KBuyLf26zwO2Gpr52aqQlDkdaGcGjFXPNUtl XdaM3b+iRBv9MkA3sEfNTdWMdZZKzW4MCnDmHpOYhn5qPB+udIHzV9hfYw0N2SAJTa86 mSIABHvfuhfkF4oLFZB7oiD5g+t3I4NFlfSV0cKiWeWjcdxLubXU2r9Jt7uFGIHWmdRT JQuCkp8Y/8XkPwUjr9NiafTiNLdDjt3hlV3u22UkAp61HiEUOejK1q7G8nVtHrmlAdur olvCODcrIJEAcNPLmrinnWAEB3ClyN7160yxkt7NNePKklHtRLV7UbmeZ5cNKmGh/4Uj ncnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VH7QcpI4; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a77si2685107pfg.300.2018.03.21.01.12.31; Wed, 21 Mar 2018 01:12:45 -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=pass header.i=@gmail.com header.s=20161025 header.b=VH7QcpI4; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751931AbeCUILL (ORCPT + 99 others); Wed, 21 Mar 2018 04:11:11 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:43840 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751630AbeCUILJ (ORCPT ); Wed, 21 Mar 2018 04:11:09 -0400 Received: by mail-pf0-f194.google.com with SMTP id j2so1702921pff.10 for ; Wed, 21 Mar 2018 01:11:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IllwNGbVSEyW44Dcu7drhaaIK6QU55n9PaAMLuzoo2Q=; b=VH7QcpI48ixE0VlLO+HXX0UypUrABrUPerIJ8VACr0zcPC73BJ0X955VT3bCWLTJXb ddPY+KK0rwzAe/5D1sXWHDpB4Q9KAoL3m+bO6b3MXTDA+U4ucAZ8njocaMMdQaf4ems9 h6qUpV8E8+71r/tBsmNEUCJHn2f1TJih3vUy8+so8WZo3pQUumGaXbxGZuW+TKPZgqQE +lQu8McI0ZswISC0NDeK3EYNWFd6T4eAXoi31ngtuXbUt+19qFCt6IgIKlqVneU9p8xr AU8SOm8C8XuKi15SEdJrqQZ/hN4iysdi8ly+DKUwRKo5G9FHAcVr4Xs9Ckipv4FdYqJV lzBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IllwNGbVSEyW44Dcu7drhaaIK6QU55n9PaAMLuzoo2Q=; b=b2Vqln5zD9fyzzmtx1imEGJawbW6HgV6HPIcvAXphwbwM6tncSJRQB7BK13HjldAy+ Lior1V4WnpbNtTYrV1vQs8tiUjlVs60924FmDvTKJPnniRTVMyvXKCb3Zvbp1c1Pzwer QqwaRxozysfk8Z3f4u5BV8uZ+UK0tTYXH60ZJ9uyDRWK0owfQBZgA8XCV6WnQVxgJKcg By/Nfu1IRcA9okMIzoKG/oKuJB42WYGR+SuxSYxp7WDvZtOssslBdTe9bLdDV4fLCGy5 fh5XIFFU7fK9w55QMakZ3UkETL0vO+QSnwPn0E4ckv9giZWgsXIWZBn+23QRyve4ZD9q xfwg== X-Gm-Message-State: AElRT7HZTmosgIncftmIdtpXN/xmdJQaZ3eLReB5GUu2wFAw7pB8eN97 5v9cg+8+eq4liKnchmpd3Uk= X-Received: by 10.101.97.139 with SMTP id c11mr14307961pgv.443.1521619868582; Wed, 21 Mar 2018 01:11:08 -0700 (PDT) Received: from localhost.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id w10sm5950775pgr.57.2018.03.21.01.10.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Mar 2018 01:11:08 -0700 (PDT) From: Jia He To: Andrew Morton , Michal Hocko , Catalin Marinas , Mel Gorman , Will Deacon , Mark Rutland , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" Cc: Pavel Tatashin , Daniel Jordan , AKASHI Takahiro , Gioh Kim , Steven Sistare , Daniel Vacek , Eugeniu Rosca , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-mm@kvack.org, James Morse , Ard Biesheuvel , 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 , Jia He Subject: [PATCH 4/4] mm: page_alloc: reduce unnecessary binary search in early_pfn_valid() Date: Wed, 21 Mar 2018 01:09:56 -0700 Message-Id: <1521619796-3846-5-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521619796-3846-1-git-send-email-hejianet@gmail.com> References: <1521619796-3846-1-git-send-email-hejianet@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(), we can record the last returned memblock region index and check check pfn++ is still in the same region. Currently it only improves the performance on arm64 and has 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 f28c62c..215dc92 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5481,7 +5481,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)) { #ifdef CONFIG_HAVE_MEMBLOCK /* * Skip to the pfn preceding the next valid one (or -- 2.7.4