From patchwork Fri Jun 29 02:29:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 10495537 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 0B4BE60325 for ; Fri, 29 Jun 2018 02:31:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC9BD2A6B0 for ; Fri, 29 Jun 2018 02:31:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E09852A6E0; Fri, 29 Jun 2018 02:31:01 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F4E92A6B0 for ; Fri, 29 Jun 2018 02:31:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84DB06B0269; Thu, 28 Jun 2018 22:31:00 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 825686B026A; Thu, 28 Jun 2018 22:31:00 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73BF66B026B; Thu, 28 Jun 2018 22:31:00 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f200.google.com (mail-qk0-f200.google.com [209.85.220.200]) by kanga.kvack.org (Postfix) with ESMTP id 472996B0269 for ; Thu, 28 Jun 2018 22:31:00 -0400 (EDT) Received: by mail-qk0-f200.google.com with SMTP id f2-v6so8113211qkm.10 for ; Thu, 28 Jun 2018 19:31:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=djDu+PIa1upI/bAjFRM2i263LjHkgnzhYw9JJWjbmtY=; b=VOOWUp0oWrbbobwTcrv5P8N+dmypC3QA4dhH1petnu+3F1S/bhP93hxVbhgkFCblFP eYg2vM/AsYeLFiKMwsNuVruoYmIgxOzJvcpIXFLNhx1pteuNpmp4XOxBJOOOGQBzQVNG FGZkOAwEQ1yn00TIsipnB1bgV55nVmru6bnAzUrNVgAJfqPR3iQlusfzi9v+NluCL1En 9ErFUCPd5DrCuojX0qZsyhdzDzQdnYhavRH14w3QJtA3wI5JuqmoaMTh4hqg2w6S6E9P oQLmzNWqav78PudW0faNEcZ81YsHwdktAuKUf4h+2J/Flm32lARYHw1HR2Mg0ZcKt/R9 5fmw== X-Gm-Message-State: APt69E3iP942aoIqlD7K+3/1NaFgp5gBbqw6XrmEB+B3pMGomoSqAFCV AVWPzX9QWQ+GGrbJrf+L8jAnehTXUr/qQ9Fjm5N1dfMveARW/HBcn/gCBtp/NfvkTj9fiL0Oz7F JNKWtMA3tWFo4Cs9w5JCZUS5n1b5og2Fdc735LnL9756a0dnvmQt0WyS1tQzXrPbOgj3N3VvXEz L8sGCMxPWkztoJLRIMCHKAKeAsiNUb6uT/fAkPA/OWOQi8lyGhctQHxC+VjvLvommro4rqkqG/Q FINLR8Nf7SbMKpvaxxkiKHsncGHT86JT+RjCNF3wnIeVot1KXH77+V1Nyq92NqNiYEhieSHiENI dKZo+c1+dZkIzM2hugIKjyEVfa9YWJTwykW8Bp+oMWN63LTpd1xlgG8aiypWqS7ny3Wl5NmJ05A K X-Received: by 2002:a37:bf42:: with SMTP id p63-v6mr11290482qkf.240.1530239460087; Thu, 28 Jun 2018 19:31:00 -0700 (PDT) X-Received: by 2002:a37:bf42:: with SMTP id p63-v6mr11290455qkf.240.1530239459451; Thu, 28 Jun 2018 19:30:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530239459; cv=none; d=google.com; s=arc-20160816; b=j8fdijkUeHRHwUdUpNbMr47FBe/oFHihCsmb0uWe6MnYAUVM7CJc4LldLxXe1+mVeG Ixc0uuXKiB7zr0nJ4/8oCKwYAUGa4PSJa262PADYxt4mWpx9/jx8z9gdRH28zGutpPqZ 2o155xqic6sPnf85bDIBO7TPfBlcwTqbdytiKjdF++VCWhpEBu0EcepS+3Q/psFM1CEN JFK2NzYQ2KE69GqMZgKydAcnUBCMpvez9YX0zE8EBtmra5fc3YzoU6k8F07Jg4/x6T0J t41RN2q4xi0SR6hiksgFt68MMB1F2zeAZ942WUEOZC661yfNs7xE2Jjt7QBm2c9OwFoP 374A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=djDu+PIa1upI/bAjFRM2i263LjHkgnzhYw9JJWjbmtY=; b=vt4z5Qzt7TmRnPyTpxvYDZOo69FeAjnqTw5VOs/pPAYrHHYaTGBzz6TtxJ04iQAxyG LeL/14nFHjk9W0VNbF2AN62oVflY4WBgOXnw+17SkU71miw3CSCcQIn5TxOXcFA49SD0 kQ3s67g6CmyTneUfIUp6dzcGK2dVkStauxm2zwZS5C7zi8t76Cpvjr0KdXSp2EqsUaLy F0UIAk4z6IbWnilnzNOTueV58FmlgUMQXIX5JNpQyWs0O4PLYCgbVRLewsJCAroy8IiV J9QMrq0KoJAqc2mHbGZYw7CCVDXT4k9BCYGMSCslrOSUTI47WsbJWMcY1O0o3dVL6YR0 pzpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=k9w8Uoas; spf=pass (google.com: domain of hejianet@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=hejianet@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id o19-v6sor4651064qki.159.2018.06.28.19.30.59 for (Google Transport Security); Thu, 28 Jun 2018 19:30:59 -0700 (PDT) Received-SPF: pass (google.com: domain of hejianet@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=k9w8Uoas; spf=pass (google.com: domain of hejianet@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=hejianet@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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=djDu+PIa1upI/bAjFRM2i263LjHkgnzhYw9JJWjbmtY=; b=k9w8Uoas56o/7k1a6DbvlCedX3G0Nf50HUQpQwtKHxqTFO3HXjEVRKSiwKhGpA3pTo 0HJylj0h00QYT8cdQffYKC+1hdjPILfFYkvysBet1CefgKoD7RBvWczxEmF4hpjnLPMp l0jVQzOG3XGn9sCN2It8XP0gVWG1CL3sgOug4BQgELk1/4CZLW4wkZ4rw+Rd9nBGeXlm zEQ9ATXJt+3HRwGMlBScdCzBLdeEZZdCkHC7gxs7ZtTyxu6DTW5NL7hHlmIGmK0Q1R3J uWPtt0pX/2f68HDbOvtRcTgbZEG22fOet7kCeqrmGcBzTVI+Ekwty2cq2X3cCdEDX2EW sPYA== X-Google-Smtp-Source: AAOMgpfiutho23lmYXN4eaiiYCChQWv1fAMYnDZiD/V16f8Gxbjiwq9ag4dMv7HuyBuB3cZiy8V8cQ== X-Received: by 2002:a37:13e6:: with SMTP id 99-v6mr11106848qkt.252.1530239459275; Thu, 28 Jun 2018 19:30:59 -0700 (PDT) Received: from ct7host.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id y25-v6sm6390186qtc.48.2018.06.28.19.30.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jun 2018 19:30:58 -0700 (PDT) From: Jia He To: Russell King , Andrew Morton , Michal Hocko , Catalin Marinas , Mel Gorman , Will Deacon , Mark Rutland , "H. Peter Anvin" Cc: Pavel Tatashin , Daniel Jordan , AKASHI Takahiro , Gioh Kim , Steven Sistare , Daniel Vacek , Eugeniu Rosca , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-mm@kvack.org, James Morse , Ard Biesheuvel , Steve Capper , Thomas Gleixner , Ingo Molnar , Greg Kroah-Hartman , Kate Stewart , Philippe Ombredanne , Johannes Weiner , Kemi Wang , Petr Tesarik , YASUAKI ISHIMATSU , Andrey Ryabinin , Nikolay Borisov , richard.weiyang@gmail.com, Jia He , Jia He Subject: [PATCH v9 5/6] arm: arm64: introduce pfn_valid_region() Date: Fri, 29 Jun 2018 10:29:22 +0800 Message-Id: <1530239363-2356-6-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1530239363-2356-1-git-send-email-hejianet@gmail.com> References: <1530239363-2356-1-git-send-email-hejianet@gmail.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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. in early_pfn_valid(), we can record the last returned memblock region. If current pfn and last pfn are in the same memory region, we needn't do the unnecessary binary searches because memblock_is_nomap is the same result for whole memory region. Signed-off-by: Jia He --- include/linux/early_pfn.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/linux/early_pfn.h b/include/linux/early_pfn.h index f9e40c3..9609391 100644 --- a/include/linux/early_pfn.h +++ b/include/linux/early_pfn.h @@ -51,5 +51,29 @@ ulong __init_memblock memblock_next_valid_pfn(ulong pfn) return PHYS_PFN(regions[early_region_idx].base); } EXPORT_SYMBOL(memblock_next_valid_pfn); + +int pfn_valid_region(ulong pfn) +{ + ulong start_pfn, end_pfn; + struct memblock_type *type = &memblock.memory; + struct memblock_region *regions = type->regions; + + 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 !memblock_is_nomap( + ®ions[early_region_idx]); + } + + early_region_idx = memblock_search_pfn_regions(pfn); + if (early_region_idx == -1) + return false; + + return !memblock_is_nomap(®ions[early_region_idx]); +} +EXPORT_SYMBOL(pfn_valid_region); #endif /*CONFIG_HAVE_MEMBLOCK_PFN_VALID*/ #endif /*__EARLY_PFN_H*/