From patchwork Fri Jul 6 09:01:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 10511207 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 76D0D600CA for ; Fri, 6 Jul 2018 09:39:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 694152855D for ; Fri, 6 Jul 2018 09:39:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CD6A28563; Fri, 6 Jul 2018 09:39:16 +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 EE7542855D for ; Fri, 6 Jul 2018 09:39:15 +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=6gcFo7tcWYuIWlrA8Hw8cpHr4Hn6vilFluV7fMtMPD8=; b=j/wAHQA4zXAb2SPaMGP+3vRkcs MN5Eyzgfx7V/YdKUa8ZmGZAtZih8ffC2bOg5Pikcy32z1yL3MOrnAOPSW7eZ2NeDW2Lpxwjii/Ekc 3ywRTm6QrxXRJiId4H/0fDWVoNznabBbMOplZBrti5+K4pQ6P6/VvR8exHklLNVu9OCKflT5wld2I Y0hLTjJ5pL3ISNXVI7YW26WrgbAG/ydqe2c/Otfkhs5EoeDA+X5PupkJ2zhW6YHxkp6110FTv4hgW MSlYX+ex/+eAwQx98qQcrf7PHQgfPcEBzwjCk49RphbpDZkAPKHYwrIf3bgr6KmDODiHpJAGEuYUk zlT/g2kQ==; 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 1fbNCp-00075k-9J; Fri, 06 Jul 2018 09:39:11 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fbMjY-000671-D8 for linux-arm-kernel@bombadil.infradead.org; Fri, 06 Jul 2018 09:08:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=rtdc9EBZDt/OvCySy+SZxp4b3kXttIQe6tLhXTYwvQ4=; b=Lze0R+OHtoNRUTnV5OlevT1Q2 mJrnekYualF98cB6ZqXZkNy5Hzdrqt9IuRDwwCLDF8kPdstuxDBE1UPeCk/PRvVmxifrG+m8FPE36 9A2OHiuok6uJHMZyfdSrf5AJ0fMfKe7WDL6j21Z0XpM7OxtimhhaG+RJyRq39iQhrGTxcU07wL4Mm HyALHTfroY2YGh620pIBZQetBGK56SkEUf7WIgVbN4bX7IZzfhg2yFy5dUXFcsJzYt3rLOQEFaznY tRfUjaHE3ui8U85tj+h07+dTIaoxIeeGyp90ok42pC+lmf9rU8+bHNOxb61ZdJDJktfmsq9A8E0MI YwmHU3r/w==; Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fbMdh-00011I-JE for linux-arm-kernel@lists.infradead.org; Fri, 06 Jul 2018 09:03:01 +0000 Received: by mail-pf0-x242.google.com with SMTP id y24-v6so7883822pfe.12 for ; Fri, 06 Jul 2018 02:02:41 -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=rtdc9EBZDt/OvCySy+SZxp4b3kXttIQe6tLhXTYwvQ4=; b=DybZWRefHd8feD3InBNrJ8fiVAEN2N3lBwFabNSZI+ME6XZChaJ70PBBQSS+laghIn mp5OcpXmPvZNztETIeNjnHzEwsd/M9qpgZSsBR28IA/15OTeHmpktjSpcfvRf/iBtJRz HQps64EKg3yahvKKdwQV/komJvcrfEFBW/bbiY0n4BSrl+zC9FPbL6FUTRlPGpKK1sLf n9OaP/aFNy9NkXuX6Epjbo8aXqLEuOSD48dconuus86BzAhi6nt6/6ZJxE01ekHOis1h lrYAtY1jeGvdhml43tZHCKeeW8vOSdcbI089c2jo4V/G7X8P9zJitlZ9JGFwuI9iBGKx hQyw== 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=rtdc9EBZDt/OvCySy+SZxp4b3kXttIQe6tLhXTYwvQ4=; b=M4f9DxtVZSW5yD6PIWkLciZg1D9XUfhQSVaRIvlnTvWusaR3plIs8kk1rI8LrsRuM6 nJb/ZC/7YRB/aJvh0MIGH5crkMyV1lZZ8IM++tSYIoxLq5a9Wf4BgFVyaXu5bKWXNCHN KpktJZr/c2qRE5GC2+C1lJhXS7HwtNmiAUmRZux+sZu+R4pwwTkLXQCtLeywzfhNMEU1 S+WULgPPF4ge+aFyew8TQJbGWt4NsqHlzNVicamPGUU47PrLj8y2kTE/c7gaCQRLEdIb 8dvk2dJO442dyM9xNlQ5YgWXYbMs5CfRgp8aZu2asZoooWzhmJIkJIdhW1uHHeAwEbHR 3QPg== X-Gm-Message-State: APt69E0US4GEPo8XO37lQpP3ZoHZaTgNJbwiea7xY9kLUFItlfmmQ4t1 4xeeEpuOZZJy30TrGK815a8= X-Google-Smtp-Source: AAOMgpcocswtgjtHNdjqffq9MrloIRC3jLxZtQNd6r+gQ5OYDodQ1JD30tPWt+mweNwr/QsbWObb6Q== X-Received: by 2002:a62:20d8:: with SMTP id m85-v6mr2833555pfj.74.1530867760292; Fri, 06 Jul 2018 02:02:40 -0700 (PDT) Received: from ct7host.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id e5-v6sm10837092pgs.59.2018.07.06.02.02.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jul 2018 02:02:39 -0700 (PDT) From: Jia He To: Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , Andrew Morton , Michal Hocko Subject: [RESEND PATCH v10 5/6] mm/memblock: introduce pfn_valid_region() Date: Fri, 6 Jul 2018 17:01:14 +0800 Message-Id: <1530867675-9018-6-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1530867675-9018-1-git-send-email-hejianet@gmail.com> References: <1530867675-9018-1-git-send-email-hejianet@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180706_100257_564756_AC4BAA89 X-CRM114-Status: GOOD ( 14.76 ) 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 , 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 From: Jia He 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 --- mm/memblock.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mm/memblock.c b/mm/memblock.c index c783b1a..274bd9f 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1188,6 +1188,30 @@ 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*/ static phys_addr_t __init memblock_alloc_range_nid(phys_addr_t size,