Received: by 10.213.65.68 with SMTP id h4csp974944imn; Sun, 25 Mar 2018 20:05:22 -0700 (PDT) X-Google-Smtp-Source: AG47ELt7mhJjkQp4NqdQDcXwJPHmqJIrJUNPZ+DhUVUow6Cv5il2Sr3mc7NJzywr/H9ahhXYCNan X-Received: by 10.98.212.80 with SMTP id u16mr31618577pfl.58.1522033522581; Sun, 25 Mar 2018 20:05:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522033522; cv=none; d=google.com; s=arc-20160816; b=d+tGIevuu/XsrUqRkQpevRL0KxyyCqnZC77qqBKqeq3DYCD1luUTmtbWmV1YBDTnAQ Dvqpi8GP/pRqDo2q92sXKcteBzrfF9ZiNifjTFcV2NAWd/8/0x697wXWmJnpwDgbmjnK 5AGz8HvVwRs0PZ+RF9ufYOZ1wqwY2JgHGmTFi0PXsVh1wd1s0eQNeCPowCGgj+PRLW2/ m3zO6OzyeQrMzt0afM1F1qUVQSt42QARmpLOaXRh3wvsx12n1SDgjgs1XWRloIixXVWv uhMnSmfuTPLAFYN8gpj2bsjpFII+mg1npHX2NL3bq6XCWmm3SMh1+e6xVNfWNM8g417k Pv0w== 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=fjoll5HQ7Oaam0IV/p4IkO61bSW7q+rwRDuYpnkLEwk=; b=QqZPlHnSEFxfJ16iDY8RvgXNuMNj1GqmGNjxhdSr90oZikWsfmMTV/siYy2ZIs7zLH abh8j57//7ootJH30i5k58nvgmkl+WqpUc1DDIfEaQnRSHCTd1w4mkdjy08VEAcIw+Tw cun6yPZiEicQKuEEgJySDWUO3m7wWUqudjc6M/62mbQPPg0qEnmPRTVjJjveOsAPjJf+ imA6DzapFVoNyAcPOfi9nS3ApKvfrnaXWgHGFGi/fFukUlY+h/2ICg94ZWIbah10vhjT Ud6LDXIp9ckS9LYS+5zBVCqzD6+63+vRoaK3r2OBm1dAaOIBOlcZY3fw3KNNQxC/FDRw RpDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iA8ZptUl; 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 v11si923468pgf.136.2018.03.25.20.05.08; Sun, 25 Mar 2018 20:05:22 -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=iA8ZptUl; 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 S1752180AbeCZDDx (ORCPT + 99 others); Sun, 25 Mar 2018 23:03:53 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:34440 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751074AbeCZDDv (ORCPT ); Sun, 25 Mar 2018 23:03:51 -0400 Received: by mail-pg0-f66.google.com with SMTP id m15so6781908pgc.1 for ; Sun, 25 Mar 2018 20:03:50 -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=fjoll5HQ7Oaam0IV/p4IkO61bSW7q+rwRDuYpnkLEwk=; b=iA8ZptUlDHlx/8jH9zAilfHbLqSxQqppBhDdJ93AN2WCXIXeUpccbDJWCzHvGoBDGS IyumSq33UTmjeqAhu09/SY0Msu2OG95eFHKvIi1zrJz0l3dOkL1uQr2w+NSD4KTfSdQq dOq+uAAvWRO8aPvIZ9bRmg1sKk0WhQExluCKcDD3tsOktebua8aB5YVaiGkjIMLBgTB5 0xawKyPT2hICT2ZvrqVdoKV3YZsiA50V/0rFHxx8BjllXYLAWjPxa1MFan4FQE4zWIhR Qi88Wnsz7gVBP10jy7dxJhFpIIskX7l3XYkiWVCbMJRtrt/oHn5TAY7tbsChVu7FrSxJ RmQg== 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=fjoll5HQ7Oaam0IV/p4IkO61bSW7q+rwRDuYpnkLEwk=; b=DGCtouwi9WQQii7Z/pMBfIrPS5t/Kz+UFkMgr5giBQgwQqU+X6UX6sQcjfW8p7i3J/ c7LoONjJHvxrqba5hPZWYodjFznl5wbdwL8dd9jj2WeN5iC+/8BFKZnLTRehZDw48phV ouOUJhf+70oHNkLHtkH6LBkDxd48Yv20O8ddTOQWCNboiZfkSisWHku7VoPgob+wwIJe 2y+Db0OYaSVwXNjCBAVKOrpGdtVdBfWDCU3ksHD1rQC2/b8ZJOl/13fZPDkclTXSw6S4 mdK5QYpWJmdmjIDpjx8prnLD7vKOH7uSN/6Div/Cy+QiQhu6LMIIopOvN6Lvbnh9OMRn UT5A== X-Gm-Message-State: AElRT7EA5pevkXuxffLGf3pOwfcIwmIO4gmXz537XKesZnT2jZYG7gcx CNgeoGxM6gWd0sYjN7LrG0k= X-Received: by 10.99.113.93 with SMTP id b29mr27309128pgn.243.1522033430643; Sun, 25 Mar 2018 20:03:50 -0700 (PDT) Received: from localhost.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id f19sm1634989pgv.39.2018.03.25.20.03.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 25 Mar 2018 20:03:50 -0700 (PDT) From: Jia He To: Andrew Morton , Michal Hocko , Catalin Marinas , Mel Gorman , Will Deacon , Mark Rutland , Ard Biesheuvel , 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 , 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 v3 5/5] mm: page_alloc: reduce unnecessary binary search in early_pfn_valid() Date: Sun, 25 Mar 2018 20:02:19 -0700 Message-Id: <1522033340-6575-6-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522033340-6575-1-git-send-email-hejianet@gmail.com> References: <1522033340-6575-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(), 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