From patchwork Wed Apr 11 07:21:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 10334949 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BE1DE6053C for ; Wed, 11 Apr 2018 07:26:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A460823B23 for ; Wed, 11 Apr 2018 07:26:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9905F28716; Wed, 11 Apr 2018 07:26:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0DF622871B for ; Wed, 11 Apr 2018 07:26:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=8JQunyzYUZNq7jCtocidkm+jC5Iog9S5v+p4zGOdEdQ=; b=CWtB67zfWDHdv+MMXfbL6fYGsw WAu7b1lt40OwfsE+EHOUDavPWDrHMkpVQMZ1Zt7UYrSCqSXKcdN76oaFXe2jIsPBBhOpxUQ4DUU2u h0c/3frCsjmY0lUhHyc5GqqL0r3Nsy3xbbKkppf1L3P0HuV6+drN0hhXYITgcvM3FA+NEdp0Tny/B FR/3l8UC5kGcAG/jEBi5xn4SyPnxmZgZMc311Z4cK+0OSNGKHqqcBO/KcnZUzV/lkxbp3JneJqiVK 9a8Yqlf7hHu+hneAdbffYFtgsf889wRgRSE5qpzDjAl2oYoTgS7dJ9y+ZWWNgi744ABCrPZDPBT03 jhyMG+dw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6A8o-0004eD-8v; Wed, 11 Apr 2018 07:26:02 +0000 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6A6q-0002Ik-9o for linux-arm-kernel@lists.infradead.org; Wed, 11 Apr 2018 07:24:14 +0000 Received: by mail-pg0-x243.google.com with SMTP id e2so369529pgv.8 for ; Wed, 11 Apr 2018 00:23: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=jTFtCeLVmOl3ejjpj9tektZLE59S/+31HoMFtsyWZgk=; b=VgEFCcx/aro7k73EHBLz//M3FDYkE62ukYEUXWv7w4FA/Kq0j5KwhgMeGm5W++bIVu 2jpZRw+S7rG4kHj4V2+lBA7fCxxI4EjweUP9oXm5ANk0d3xUaWYOFKbgMy6swCZBZajq iHOZQ75cvbmsibXV3nEa82PPu2hm4fAS4Mj6ianCEe8jiHWm43mxfdL1qDM9L5u0XpRG xMB/uJrwIMLu+21swYyPd3uv0lWAkOm2W4HMvOt+eZUY3rYVJuSbkBxD0+8oqpsUGR5q c4GdAbJ/5lRiWSmXfdZyve75yxVlyv6okY8UJPbhq2B3f4gFni9YU9kIcxBSe20+4Gg9 XXGQ== 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=LKLD25sLqNE6d9v25Uw+9gok75hmLnzMeOfZaBauiAQzW2js1X+RF0r9vNp2x4Bjz1 Tu+kuSvRjO6rVjuSShWYUIuJ1UB85qXOBMV5BiKVHqJIKSgICBbCoDhBiGyzQ36Cj6+9 WaqrRFix6oy2Hx+lmGqI4KJyqu0Zu8JEu8clleshggtM9WDXsM/xTd5sG6cNwgMBvGCI A8Z7/BMHIOtsSlojJ3AhNLIS6tloV8JeB/SXptil9+vY3ux9r0y0H7Su09TYHU/CEb2v 3XuYoTJRq6hMhur2YozlyuGquQ28Ybv7IW46ymPWQc1QtGanIH+o5KFPbFM25o/jsxuh 7A+Q== X-Gm-Message-State: ALQs6tDaA6JxDv9cGd0fxa0NyH7UL3/1f/4oc0kEpOHNpR972aq01Fd9 HZOIb4qWIdAYXhfr9HQtSLQ= X-Google-Smtp-Source: AIpwx49JB5WRYRXZtuptubBGW8r4+1PCbl9XVT1BkPL1K6FXafmVk1gGRYLdEStgKWnX///YxQjfhg== X-Received: by 10.98.80.145 with SMTP id g17mr3037856pfj.71.1523431429621; Wed, 11 Apr 2018 00:23:49 -0700 (PDT) Received: from localhost.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id o90sm1561898pfj.102.2018.04.11.00.23.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Apr 2018 00:23:49 -0700 (PDT) From: Jia He To: Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , Andrew Morton , Michal Hocko Subject: [PATCH v8 4/6] mm/memblock: introduce memblock_search_pfn_regions() Date: Wed, 11 Apr 2018 00:21:55 -0700 Message-Id: <1523431317-30612-5-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523431317-30612-1-git-send-email-hejianet@gmail.com> References: <1523431317-30612-1-git-send-email-hejianet@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180411_002400_379405_2ABC7DFD X-CRM114-Status: GOOD ( 14.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gioh Kim , Wei Yang , linux-mm@kvack.org, Eugeniu Rosca , Petr Tesarik , Nikolay Borisov , Jia He , Pavel Tatashin , Daniel Jordan , AKASHI Takahiro , Vlastimil Babka , Andrey Ryabinin , Laura Abbott , Daniel Vacek , Mel Gorman , Vladimir Murzin , Kees Cook , Philip Derrin , YASUAKI ISHIMATSU , Jia He , Kemi Wang , linux-arm-kernel@lists.infradead.org, Steve Capper , linux-kernel@vger.kernel.org, James Morse , Johannes Weiner MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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;