Received: by 10.192.165.156 with SMTP id m28csp395107imm; Wed, 11 Apr 2018 00:27:48 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/5FbR0qHYFh0vqvs93L+yHUrry8ocSjp1OWWIDtFG76g8FFpfm8FuuyzQZCexILKkatcJj X-Received: by 2002:a17:902:7c82:: with SMTP id y2-v6mr3897975pll.103.1523431668680; Wed, 11 Apr 2018 00:27:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523431668; cv=none; d=google.com; s=arc-20160816; b=YrMDxySGpYQ+VUezmeK/0CuSP4tyEsSz5XtBOD+ufQVdbvKk+bisok9s2m4LuH/R4w Gc+kctzcKJLF2FUANRNKwmoXJY3jDM70QzM0JDEihKiTEc4avadGTHTF33/OYFZeRVQM Tr5WTrkIYQAdOSzgpmx9TbrjJhaB6oRpYq08GqkTN8BliZk1PA8YBQcQjD/OSdEizxoS 9boW4ob8T5ZHONcTMWvGD5VzlrGDRzZS9/0IE0SZap7yLgYx6UBtGznAKjrSc5RO7Jeq 5ZPaU3shrBzr33Zv7ZPC2oN/BjKMeWt1rsaWEBQvbh5EnooFN+JcQ3rWiUWGKIXx36hb dw4w== 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=bWEIwN9fKEYADtf8sYrehDaLqkTLk8VHlqvtXB1YhaRWOBHJZm9m0rZJWTbFzxyyM7 aCz5w37KirLztBYDRjr7rxDIFTOyWzRP8xxmtH6RKs1HjepjPT/BuzdJJFn54wTVeBNd CHSMbPuHHoBgTiQ5kH7bizta7XDl2vOyzBZ+j42EDVadMoAufLhyRE1aA66mJLUTMdKb N73RQvWbfU/D1HsFqxA8R0j30qXrF4R+xo6ySHk+B+Wjy1yKE0c5pnl3O9MP9MP6drJn mxGWRP2jyPTz8sjTRhLQVt7YTk9mEvO/q+OL5Gp+Hc8bUtnpgte8dvmPP9zTvu0xOIam eWQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VgEFCcx/; 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 a6-v6si559937pll.722.2018.04.11.00.27.12; Wed, 11 Apr 2018 00:27:48 -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=VgEFCcx/; 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 S1752604AbeDKHXw (ORCPT + 99 others); Wed, 11 Apr 2018 03:23:52 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:34088 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750801AbeDKHXu (ORCPT ); Wed, 11 Apr 2018 03:23:50 -0400 Received: by mail-pg0-f68.google.com with SMTP id p10so370443pgn.1 for ; Wed, 11 Apr 2018 00:23:49 -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=OttA7CbnSiGiQuy1/PzGYzFlc0mU2xMc7iJH0X1YM3Z3RcKY6e/mYXMYAwiavHSRtr WqNPgxmxIZ+K7murtrhvhpNVp+sAMBbo1HMX3LyP5ZPgl7ElxvDD8F2DiKXtF5XbLRb4 tUfn1ItdDQeFGIcKIq0HTcbZvYTboL2Gx9FYlimeHEjoY0YMqPgnm22+FBadEmTfzRhm NgBr9uaxLTP+zBTT8mXI4ocFWRN4YD4w0pKnbx8JjxXZUM4Pe+FG1dlrJAzQ6ih6Chrc x6M4Rvirv9URKLmACjlegD8BHQArRektTqdasHyrney2ih0mX4VbdNGzeXJVtmkP3HbT qIJg== X-Gm-Message-State: ALQs6tDJou0TmLv3ycAiFDECCQNFgveycMPkft3W/jn3pa/z6NYchWjD qiCgA4N+1BLed36jB5zfDfE= 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 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 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> 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