From patchwork Thu Apr 5 08:04:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 10323851 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 9353A6032A for ; Thu, 5 Apr 2018 08:07:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85E4E290B4 for ; Thu, 5 Apr 2018 08:07:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 798F6290B6; Thu, 5 Apr 2018 08:07:25 +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=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM 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 E8D70290B4 for ; Thu, 5 Apr 2018 08:07:24 +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=g08PnMVtZa4HmMHm/dODQ44eXN EDoFJQYVQRLSS/9aG38k+lQ+qYi/Yp2G6aW0ZTzGf1iA9cfHbvN/1Q26CCnVtsgPHjlxqDw/3IXPe 2r1azy/uBVH2PQd4VaE9fYiTyaa1uT7JOKYf+HuG+DFkbHeQD0ixbVw7PlwothjV4c1blpcNogPbQ WrVvNY7hdq8lxTleETBYtPY44PKkm4I7fKDGJlnLuLJzM4KmWjhvb6d3Ui9LW8Ecc0dbjA+vTjcNy TOh6iG6VXvS8ppdwyHaHvNd83PZcSeOpYFe/UMs0Ty9KzAXHAaHM21ZrT8BN2xpvej/ScDeMiA4do PGGlo8FA==; 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 1f3zvL-0004gI-U9; Thu, 05 Apr 2018 08:07:11 +0000 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f3zty-0003g9-Da for linux-arm-kernel@lists.infradead.org; Thu, 05 Apr 2018 08:06:01 +0000 Received: by mail-pl0-x241.google.com with SMTP id 61-v6so16086549plb.2 for ; Thu, 05 Apr 2018 01:05:38 -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=bAC8FCkYcyp0H/q2ONTsRMsWcFkKP6gm2BGG1uJYa34NUfki4AR900BhK+z9M1xpXi 0sOeGu6dt09uvnqZm6vd0c8iLG2Jem9zB3edxRXmNyBUUWCfV4yVjQxyJLBxtP3zq0nu 1zwe/Yi3zFiNmsAMiQDcAeuQKjBaXYXN/dL3uX3+ozHZ4mCNhCByDS0d9AjjUBbHOYmn k51fznn/rORZsBW/jL6xDlgOe2xEkBa9yl8AD7wyKCXaKMIIoz1pa2wNzcF6nm+Bog1S YpTjkxvezntJjRLZtiS70CbLuo3IPQK4+urOfV+pD9vgTQJuZ2wL7is1fVpJBMa/2nCG 6WTQ== X-Gm-Message-State: AElRT7H2ceqS/Bg+m5Y3t0+oKyZ9tILa7eqH/pVECj6ezLKaKKf3XmDh N78uw87vGMVRJzf83ytIhjI= X-Google-Smtp-Source: AIpwx4+JhxobxA01x8lUTgMZWMcXpAx9xPj56h56PxJX7aTdvFPEM/bMoS/uNjEp9B/BoYYuXM4WLw== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180405_010546_473208_1D117965 X-CRM114-Status: GOOD ( 15.38 ) 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;