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: 10511141 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 4837D6024A for ; Fri, 6 Jul 2018 09:02:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AFCC2855C for ; Fri, 6 Jul 2018 09:02:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D53F2856D; Fri, 6 Jul 2018 09:02:43 +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 BD4832855C for ; Fri, 6 Jul 2018 09:02:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D54656B026B; Fri, 6 Jul 2018 05:02:41 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CDCD66B026C; Fri, 6 Jul 2018 05:02:41 -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 BCC746B026D; Fri, 6 Jul 2018 05:02:41 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f200.google.com (mail-pf0-f200.google.com [209.85.192.200]) by kanga.kvack.org (Postfix) with ESMTP id 7D4C96B026B for ; Fri, 6 Jul 2018 05:02:41 -0400 (EDT) Received: by mail-pf0-f200.google.com with SMTP id t10-v6so6737954pfh.0 for ; Fri, 06 Jul 2018 02:02:41 -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=rtdc9EBZDt/OvCySy+SZxp4b3kXttIQe6tLhXTYwvQ4=; b=lJf/eHJlKF2PRWN+VzapB8Zb4TQg5IwYAWMRP2zUksbOejaOQ+6TJLjs8J5JNVwr5N FPiOLiG5j13IdgRXZ8OgipbS5Wo5YPaVe315x3T1yMBDnpM4KI0vF+GLgDgB/ibyPump KdyeGa7Rl+T6qujEmahWi/d9xNGfdqIMfUkpf2fN5oY6Z8HquOEozHkRAFaZPqf4R/hc lNrrl0087MIFtyRmGl38Y5K0dPjo6yqJ0L9ZGZ9sB1Ijyi3IcrvFsDGFfpCoW5DxfsSs BLzTYPkYmrPhPhNA7hrHBs1QqjlgVcG//NE/WwsPt5mj5Xzp49ieygnVRKD8rYKZxR6V vOZQ== X-Gm-Message-State: APt69E2a9ygfmqCPTVQPKWQmML7ZXzTrEfDTTbYXwufiyWWon10cNiwB mzFQSxwN5SEOHOKhHYKJBjVQ+yuTEr17USkOrSvJF7w0Wf0tyF/ERd4j5cXwaCZtYlKZ7CbhNkQ 9tdHhrIHrhrXne5cYo9b55s26hefQpzYo0jmO2O2/e9t2WxNObtG4Eefz1BPLN18QK+AU2FrJ1t H7o+jFrp8tUG5nDypYrpMewrfbLNMudUycuHJN5XRdhwUOi1BT772z3GjsODAlCDISowI1k75Hb N5gXZjPY7ZT0PTCCHH9hiWBs5mUtVqntillBC3vip5AVDPW+vvta7n4xubP0rL1MJVRX5prJIW2 X1tIgWqH7rTEwAlaee3KD1iMKewU/Wft7hwZRJGjYPiahS2GR/XVXqOc2euN5QjkczSG1mVaHfl m X-Received: by 2002:a65:5c83:: with SMTP id a3-v6mr8710021pgt.164.1530867761219; Fri, 06 Jul 2018 02:02:41 -0700 (PDT) X-Received: by 2002:a65:5c83:: with SMTP id a3-v6mr8709977pgt.164.1530867760557; Fri, 06 Jul 2018 02:02:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530867760; cv=none; d=google.com; s=arc-20160816; b=kD2ldgVKbnT5XbYsR6RkgtcQzPeT81HBlhtPsUx6Gl62GeFNvEBZdrZD4jHYUv26K8 vmoCQrYJOLAH7aQSflAub5ZvJBmygDviLE37GBiXQ7E4hjUnqMY1fpUbynRHAZSujQ2m Re7J2Zji4CQjR5zaeBWxjQSKewpz27z1mqlCmBQunmPV9Dbv24jV/A1lCKuzBMYeNC+c qFw/VqFe2IkQ8gd32UWHRLOFYbPwxyDoYcUDzKuGU8Q1mNP0wLMAxh3kLR5y5X/NuaUD OxTiNMJZ1VFPQTUnKSZWEscpKHWSccs2XSuE908hfrWkva2uDc3Fl6XhFFJRq3Of+Nkr fnBA== 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=rtdc9EBZDt/OvCySy+SZxp4b3kXttIQe6tLhXTYwvQ4=; b=QZAx5z2aLgHEsM+Rui7ka5/VFOEN0K9AVrtJrPwZu7d4ed5CE64INBuZu4zYe2PWNc aymDMjUbaAeY73RwmRz4OlzbUSFHKubhHtpFqBSNrs2xPzbUKevnqcm4lwizzDzfpcfh EwxsG3AihpFQayMyEcjOaLY0qIzoPvEzwKC7W6suQtNaj8oyGWz6oaZgkwc78kznfVXM 4D3cvZ99VTbhZajKb52qUip3AM+HNSxp4DMGIHhgorUXuHgJFUq3j9ZmpUOG/bNoyWak Xwt2TAN+a/QOoU0vcdpNd2l2cKmhzNTx8EdxvNjjPUd+zemef1xMwwIg0RHP58lwElF2 Baeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DybZWRef; 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 j127-v6sor2104454pfb.151.2018.07.06.02.02.40 for (Google Transport Security); Fri, 06 Jul 2018 02:02:40 -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=DybZWRef; 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=rtdc9EBZDt/OvCySy+SZxp4b3kXttIQe6tLhXTYwvQ4=; b=DybZWRefHd8feD3InBNrJ8fiVAEN2N3lBwFabNSZI+ME6XZChaJ70PBBQSS+laghIn mp5OcpXmPvZNztETIeNjnHzEwsd/M9qpgZSsBR28IA/15OTeHmpktjSpcfvRf/iBtJRz HQps64EKg3yahvKKdwQV/komJvcrfEFBW/bbiY0n4BSrl+zC9FPbL6FUTRlPGpKK1sLf n9OaP/aFNy9NkXuX6Epjbo8aXqLEuOSD48dconuus86BzAhi6nt6/6ZJxE01ekHOis1h lrYAtY1jeGvdhml43tZHCKeeW8vOSdcbI089c2jo4V/G7X8P9zJitlZ9JGFwuI9iBGKx hQyw== 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 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 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-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 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,