Received: by 10.213.65.68 with SMTP id h4csp245565imn; Tue, 3 Apr 2018 19:58:42 -0700 (PDT) X-Google-Smtp-Source: AIpwx49xRd3FgGzO0zFAwP3ICZr2P1OMd6wUBwHlcSZ0Sev0X78lpzoY1f8IkeidzCrLatxUaKgU X-Received: by 10.101.96.200 with SMTP id r8mr10802159pgv.152.1522810722600; Tue, 03 Apr 2018 19:58:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522810722; cv=none; d=google.com; s=arc-20160816; b=ikb/NcyXNj1XA383cWA0ynd9euNtyOw3debjrcF20H5HFKAa5qzARl09OwyU51cOz9 HBVQRgvA7Hq9060LkGnkNNareSTGsJnPbffmpG+i3AwoL+5xYgw+4Ud35OQcRJJ3I9tC apERXfBoAxRpGroaQjY/hgdFEd+KA3uncH4dK5kVcTIRSQsPyTB2uCT7ZU06TNSiqoli 5YM0j4PaOwsOvy1FbGOtV0AnHjEtwFl9myemPu0VqdrYhN34Znrd9LexgMfiuf9x8cWW s143TVvHISpeGpOqAf9kxUH9t1ooUZ0ANH7uWr82DKghEe1l1LA/JTQA6VuDx8JZgH3u bMzQ== 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=dyMI+v3VoOQghzg/SFDaXUCaWcnyG1p6iYj3OzZ8sfg=; b=k1uSS5bFNwuomZa0IgAPpW/2Xb0HVwE6ByuG9VBmIjGn75Uz3G0yIrS1w/woqBERxZ 1T2MrnKazGkiZoTYlY+JxjZ9Y558ynidBlcwvX6fSwrmvMhUvCL/ypxg5MMFRQtedFiY 1TmBwh58Can6+InKXvXt+Xt8NOiwybzNBnIxDC8NwkYYzb+PwQTHl/rkMKfF4nS6jZ6Z oLvZu+GVa1oeFkD0LpZjjA0qobmbXe6w4p5EabYy/iwCrsS3B8emqRYNCnBOYPK52KFl 41kZ2XGFe9UgNol/g/Yzzvkck23zRcj6TPYhXQWfZc4K0w4dewtKa7CBOlocpdSJpoQl cOsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XzXjmbgj; 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 e6si3299561pfn.174.2018.04.03.19.58.28; Tue, 03 Apr 2018 19:58:42 -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=XzXjmbgj; 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 S1753356AbeDDC5K (ORCPT + 99 others); Tue, 3 Apr 2018 22:57:10 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:45166 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752750AbeDDC5J (ORCPT ); Tue, 3 Apr 2018 22:57:09 -0400 Received: by mail-pl0-f67.google.com with SMTP id v18-v6so10027055ply.12 for ; Tue, 03 Apr 2018 19:57: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=dyMI+v3VoOQghzg/SFDaXUCaWcnyG1p6iYj3OzZ8sfg=; b=XzXjmbgjcUoA0dJg7mhgRJYiW1F3yS4GaOpDyQYlGQSJRycMYzEE29IV8JdWYMbifo 0pngrJysxD/xq5jfAJuOgYaUlHYYlQoRk8/MvO6bloje1vEBCATsMmuy+Nxp48uICW+m X+XM2QSzW1XD9LnkYcx34uv+szrf/X48AwVkoTpXbKnxhciRBTCB5siONvyXf4jhwVhN F0tD91kKVmFBxYNnYPt4kb/6K1Q5auaLLc3YcivznoGUqYyz9uSPk5msQAZ5FCN0HldN sRRmDCwNHXWrfc8AZxyM8JHqV8qsoaPVy2vRzEV4BIJOEpmabbzw2k2U0sChV+y3c4vB dWaQ== 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=dyMI+v3VoOQghzg/SFDaXUCaWcnyG1p6iYj3OzZ8sfg=; b=AtWTn3Jv66wZ+Y0ueOEHGMcKlHwXfPV7Z4sQHKzUDzywU42gA78+opsaOdcEx6MZNg UJFHAPNSS1X5ho0RyakA/KHxx+dRXo+C9mJszrs3tvcmPzw23VZJHwH9DZ1UqT+J9sYQ opzgESgilCXTEm1GN6I8eWowm+wTg8J+uv5C7Gc8muenkBa0mPrtRVPMws/E19bykzCg c+4t7LdcXHTGTsW2imH9QTgFSOPR+x6XdQBZNkrgozeuu8Cay6es4eSzAe7CPEYdRlka JpESPYxCHTw8kR+MBaSqjwKHLHMfPMwsrEzWZmUpiLGgobutKuDHpMKfTS5163AchDaa 7BSA== X-Gm-Message-State: AElRT7EWyC+MCuhk1K9s1h0iNdYhtzFRBbLraso/IBOtHjTnADemrveM Zorkava8rXYc5uY70bw4iBI= X-Received: by 10.99.180.6 with SMTP id s6mr10540882pgf.81.1522810628553; Tue, 03 Apr 2018 19:57:08 -0700 (PDT) Received: from localhost.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id a4sm8020701pfj.107.2018.04.03.19.56.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Apr 2018 19:57:08 -0700 (PDT) From: Jia He To: Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , Andrew Morton , Michal Hocko Cc: 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 , Jia He Subject: [PATCH v6 2/5] arm: arm64: page_alloc: reduce unnecessary binary search in memblock_next_valid_pfn() Date: Tue, 3 Apr 2018 19:56:16 -0700 Message-Id: <1522810579-7466-3-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522810579-7466-1-git-send-email-hejianet@gmail.com> References: <1522810579-7466-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. 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. Signed-off-by: Jia He --- include/linux/arm96_common.h | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/include/linux/arm96_common.h b/include/linux/arm96_common.h index a6f68ea..2f4dea4 100644 --- a/include/linux/arm96_common.h +++ b/include/linux/arm96_common.h @@ -5,32 +5,47 @@ #ifndef __ARM96_COMMON_H #define __ARM96_COMMON_H #ifdef CONFIG_HAVE_ARCH_PFN_VALID +static int early_region_idx __init_memblock = -1; /* HAVE_MEMBLOCK is always enabled on arm and arm64 */ ulong __init_memblock memblock_next_valid_pfn(ulong pfn) { struct memblock_type *type = &memblock.memory; - unsigned int right = type->cnt; - unsigned int mid, left = 0; + struct memblock_region *regions = type->regions; + uint right = type->cnt; + uint mid, left = 0; + ulong start_pfn, end_pfn; phys_addr_t addr = PFN_PHYS(++pfn); + /* 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; + } + + /* slow path, do the binary searching */ do { mid = (right + left) / 2; - if (addr < type->regions[mid].base) + if (addr < regions[mid].base) right = mid; - else if (addr >= (type->regions[mid].base + - type->regions[mid].size)) + else if (addr >= (regions[mid].base + regions[mid].size)) left = mid + 1; else { - /* addr is within the region, so pfn is valid */ + early_region_idx = mid; return pfn; } } while (left < right); if (right == type->cnt) return -1UL; - else - return PHYS_PFN(type->regions[right].base); + + early_region_idx = right; + + return PHYS_PFN(regions[early_region_idx].base); } EXPORT_SYMBOL(memblock_next_valid_pfn); #endif /*CONFIG_HAVE_ARCH_PFN_VALID*/ -- 2.7.4