Received: by 10.213.65.68 with SMTP id h4csp1652739imn; Thu, 5 Apr 2018 01:08:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx49xCl54nciH5QeRDUZ/N6yvPqsdz2P2XuM5DpY7sRO6xtO4QOFlhsRqUi7+oYHo8KjvcMtV X-Received: by 10.98.72.205 with SMTP id q74mr16450645pfi.70.1522915713645; Thu, 05 Apr 2018 01:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522915713; cv=none; d=google.com; s=arc-20160816; b=BJT5mSjL0B0JGbAo+LojvV14qQq+wTBd6spUAKqpZCFFbCCDW7yA3vaDbnNDtnxKRf fPEpSUYTGUZ9gh5uvTsfHH7Fu6WZawvz1glZre6GXpAICmMjbgnrRRA4WX3rvsw3fqzr trzs0Dx5F7WbYwQriB7Iwfo0i/01uT/SXbbKCPrAX8pvrEiOngJGr0qxtYxk6gsBXBfF SBAg6jB4/bV3gyeqKNd7Fd39auLkCp0MXeC1cXSRDVKbOpxSXwqbR5QaHc4Y/AedxrH8 7iQojkZK3CG/Xjl/1pw2BhfrQUrrGtwa2FPQXYa3xGcfDXtYbvKN66J0O50PlNrDyoFc HZ0A== 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=jTFtCeLVmOl3ejjpj9tektZLE59S/+31HoMFtsyWZgk=; b=oT5zIrQSlyxgXvWUGwR8noF8buc8k6Kn739l13Vq8MjbHKjXktt0xNpcV56634LicK 20T62CQ9KfVkjdPoKC9TphPY37Gh8u57HJulvkYrlEiIe4ackK4gzcEpS7El6U3mWZLN h7mF8oKHl5wUbXLGLUfcMkz+7biOM3vqMWOl/21Ozdlk5U1Mt2iOVFLcAxbPWRkIyduU SEVaXODJ8FKEv4yKJn4PCp94Vo9gWJmM0czzeZsANxIoyK5N3umS7zLzJ8jzLKam8FgP EAp4xQVf+Q/kQbrQ42WwVyb4v07DqmtDcrBZzxZg0sg0SaZmyn/3gAT8i3GLrIUaMWTd dvhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cfjz2i/e; 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 t19-v6si4989029plo.102.2018.04.05.01.08.19; Thu, 05 Apr 2018 01:08:33 -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=cfjz2i/e; 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 S1751809AbeDEIFn (ORCPT + 99 others); Thu, 5 Apr 2018 04:05:43 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:36683 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751726AbeDEIFi (ORCPT ); Thu, 5 Apr 2018 04:05:38 -0400 Received: by mail-pl0-f68.google.com with SMTP id 91-v6so18063263pld.3 for ; Thu, 05 Apr 2018 01:05:37 -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=jTFtCeLVmOl3ejjpj9tektZLE59S/+31HoMFtsyWZgk=; b=cfjz2i/evlHl7ZcZzp0y3zK9lYRtcrbX1pr1f3Pdeju+vq3EjIDkcrcUhls1ukL7jF Bx6lTkYLIALqhvLQ5uDVkqZTykBnxkrsYSnU4WihIDIKTVpHS/z0sklHrjwA1Xv1u5Zj uAgAENue+IqLFpYgMfR1uMhPe1fiwerCBAOf8JgBlQgTCNB4Uzsw34jK7o2Q6yOyhuch +er6fisQm48Mu0l2C1PjsQyGi6G9FkBVj9m7yyDfEjIfW2Nx5pudIIliWFdTv0P4fUkt NnA2vlyNXhKodXKuHBbqdJKs9h7R5r6NrquKiPoQ+pZnYintpCaqjPTVl91P+LXWsMLo i/OQ== 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=jTFtCeLVmOl3ejjpj9tektZLE59S/+31HoMFtsyWZgk=; b=hl/c7BzhY2Fp28c+eVnCp5vUCJudJTA7Rs+FoaBUQGCb3y4kHQP+Pur59xU0ORaYf4 uLNWEL2Fm43zV9vVyDpCkOv5TZNE+t/lXqdxfqBdMJvuP4jpoZjYs6s6GEXCnUdwo2Ap WxekUe7zJqyEcglYSPfBAYq0+V3OG9jxEVjfrqCSkQ95Jo6y6hcbbE6zfUqSBWKoZ2v6 YODQ/dncmI9UHRIo4bvbQTULnra4lWB391dxGm3p3a4AXGNRDFUbgM/s/6j69ffSijjR +FOIHBFxtYoPlKR2/82qW9s4iR9Y7PnV2pgaKeDCUbBKdAZ1IUszDgHfQcw8i9FhoID7 EJlQ== X-Gm-Message-State: AElRT7HxhDXWfOqRNK0TReb8DWDV56JQoArEp99d2kDqFS0BTCv2M9K0 DxzX8H9h6ovFbPC5vzq0hsQ= X-Received: by 10.99.109.139 with SMTP id i133mr13614590pgc.194.1522915537641; Thu, 05 Apr 2018 01:05:37 -0700 (PDT) Received: from localhost.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id 2sm14983690pft.33.2018.04.05.01.05.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Apr 2018 01:05:37 -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 v7 3/5] mm/memblock: introduce memblock_search_pfn_regions() Date: Thu, 5 Apr 2018 01:04:36 -0700 Message-Id: <1522915478-5044-4-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522915478-5044-1-git-send-email-hejianet@gmail.com> References: <1522915478-5044-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 This api is to find the memory region index of input pfn. With this helper, we can improve the loop in early_pfn_valid by recording last region index. If current pfn and last pfn are in the same memory region, we needn't do the unnecessary binary searches because the result of memblock_is_nomap is the same for whole memory region. Signed-off-by: Jia He --- include/linux/memblock.h | 2 ++ mm/memblock.c | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 0257aee..a0127b3 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -203,6 +203,8 @@ void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn, i >= 0; __next_mem_pfn_range(&i, nid, p_start, p_end, p_nid)) #endif /* CONFIG_HAVE_MEMBLOCK_NODE_MAP */ +int memblock_search_pfn_regions(unsigned long pfn); + /** * for_each_free_mem_range - iterate through free memblock areas * @i: u64 used as loop variable diff --git a/mm/memblock.c b/mm/memblock.c index ba7c878..0f4004c 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1617,6 +1617,15 @@ static int __init_memblock memblock_search(struct memblock_type *type, phys_addr return -1; } +/* search memblock with the input pfn, return the region idx */ +int __init_memblock memblock_search_pfn_regions(unsigned long pfn) +{ + struct memblock_type *type = &memblock.memory; + int mid = memblock_search(type, PFN_PHYS(pfn)); + + return mid; +} + bool __init memblock_is_reserved(phys_addr_t addr) { return memblock_search(&memblock.reserved, addr) != -1; -- 2.7.4