Received: by 10.213.65.68 with SMTP id h4csp1172296imn; Sat, 24 Mar 2018 05:28:44 -0700 (PDT) X-Google-Smtp-Source: AG47ELsuAojDLLRHVz699myfiTtepDMJJ2VKyeo5T8lmj5mY9qxGQa835RAwJhCtumjBIU6pQxKB X-Received: by 2002:a17:902:6d0f:: with SMTP id s15-v6mr33855490plk.375.1521894524060; Sat, 24 Mar 2018 05:28:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521894524; cv=none; d=google.com; s=arc-20160816; b=BK80d6VDCo+podUMkUAkG9iHJkvi1RXpR318hxuHVQm6oI8BS0rklDAEAe2RVYk8BX dMHAy5/qrQB3ZJv+Smd0e1r+9FK3mO6Giz+bd5UzQKW22Hw3OEHFxIrC82wenOcN59ZA 5pUmbcfqu1wbyPUf5+jiahVhjmZG5dbQY5eGfadiRlwNgNpumpcyIZNszssXL4BU/Ma4 l8PcFOGTAaDm6NhyuLCxV+5BDwLeoL8Nc3LYo/wyumkeJbm0pdq0k44JRXBTnzrm/cD0 5boKgs6QVgF5SzSi/wcF0gD6RwhdX9cYpwaEWEVN1TRDxDNylZfPB9MAsXju6drzVAGB phqg== 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=ID/HHnJy8Od0sv4ugrwey4ueEG+z0zzevhay9oki3bU=; b=x3n8F/s78nlACNjMlJZrBdXZKbmLh+gwvw8mfnNrEPXz08EHZq/bKDvjh54VtqKP4R RadzpKWpbBr6/X+ckMb9oOfW+nVvalimyoptC0IMehouFi1P6fiU/xnT+Fx3QxCoxbiR vrh2wMjblaBrL/SPsl9S0mhQ8BHY/u1A55ptXa5Mh+6BEgLeWsBixOS2oV3xb3/yQgmB pSUSlJ1dhwIHAl6Ra9rvMrWwf63u37wWckcx9OXRDrJ5N0KRf1w5kQOJJP88Q/blyy1H xUmxLq93aZ5I8F1JNj0UVFnl2Oz/1HTfsfVfkAgtxuqw9qvyutyo8AVt7ZIezyZIrJhU ZeWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Jn4V0Stb; 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 y2-v6si10838835pli.242.2018.03.24.05.28.29; Sat, 24 Mar 2018 05:28:44 -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=Jn4V0Stb; 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 S1752218AbeCXM0M (ORCPT + 99 others); Sat, 24 Mar 2018 08:26:12 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:36696 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751879AbeCXM0K (ORCPT ); Sat, 24 Mar 2018 08:26:10 -0400 Received: by mail-pl0-f68.google.com with SMTP id 91-v6so1260227pld.3 for ; Sat, 24 Mar 2018 05:26:09 -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=ID/HHnJy8Od0sv4ugrwey4ueEG+z0zzevhay9oki3bU=; b=Jn4V0StbSFRBngJf+7VncmYZVW+mEH0uvwWWJO3/XPuNHpxWNgfSR1k3LdACrc5Wmc h8GgYTu4qx6kb0sDj9Fwdusm/LTrBvtStvyh6H5E3UkMoDLfyDQbP2ZtmlgGUGjtr0Ny 52f440rYfp7ykUD9MFd8GFpY2OHcUgmjN+2DQJ5fpyZkLjZuBj1XUfd41f2JTrlHr4/F itA/gsVptFP0xN54h+Ui6kLAgU0lrBArkoF7c9szhZq4ZBoUWdMfnPmdrvUbNWgJB1sk nUfj0rui/MntPi4sPjal7CU1SE3l0Eko5R6b23tMqHL42EzpNyiiFBYtttJFkJoAehz3 +/SQ== 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=ID/HHnJy8Od0sv4ugrwey4ueEG+z0zzevhay9oki3bU=; b=Hv7AyV7/0uYHEcK36+HcJFJuU/KKW1uuz+q0d7AB54muwhMd92N9yM/I5gGXY1Om98 sCB2PXbV7Z0/89WpeGqoMAmNC+V6pbHA9Uh835HPQCBGhtf3diIdiXNalvuZ3BByvqwG gtjdTSqubYPHjMkE2WzJjc8W9RV+FZBn+4ehCgAqQNiz+VpxjnIiujo5l7siiyRaAsuq mgMBXlyaarjcLY2TbnTbjsE2+3RUia8Ej4VyVyGLK9Bk4vS9keWiAtznpJli8YuH7AIt 5SKHxBVsk3cwIgxTYzBmgnmeDoJj+SJkl1Ad1J1GehU+a68jJCMuB7HJeWfiRLgxWvLc tlFw== X-Gm-Message-State: AElRT7EHiwZNUJ2Hbg1H0nuLIfOs+/jYaQtrMDFxpxdlDbvzCObTi5mr e1mnzvYXxBb4eCyW5saN8LQ= X-Received: by 2002:a17:902:2f81:: with SMTP id t1-v6mr1817331plb.290.1521894369704; Sat, 24 Mar 2018 05:26:09 -0700 (PDT) Received: from localhost.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id b6sm23152371pfm.160.2018.03.24.05.25.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 24 Mar 2018 05:26:09 -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 v2 5/5] mm: page_alloc: reduce unnecessary binary search in early_pfn_valid() Date: Sat, 24 Mar 2018 05:24:42 -0700 Message-Id: <1521894282-6454-6-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521894282-6454-1-git-send-email-hejianet@gmail.com> References: <1521894282-6454-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 if 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..68aef71 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5484,8 +5484,8 @@ 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 (defined CONFIG_HAVE_MEMBLOCK) && (defined CONFIG_HAVE_ARCH_PFN_VALID) + if (!early_pfn_valid(pfn, &idx)) { /* * Skip to the pfn preceding the next valid one (or * end_pfn), such that we hit a valid pfn (or end_pfn) -- 2.7.4