From patchwork Fri Jul 6 08:14:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 10511017 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 3B5C16024A for ; Fri, 6 Jul 2018 08:15:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CB6728161 for ; Fri, 6 Jul 2018 08:15:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 201F8284E9; Fri, 6 Jul 2018 08:15:55 +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 A28ED28161 for ; Fri, 6 Jul 2018 08:15:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B2E4B6B026B; Fri, 6 Jul 2018 04:15:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id ADDFA6B026C; Fri, 6 Jul 2018 04:15:53 -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 980656B026D; Fri, 6 Jul 2018 04:15:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f197.google.com (mail-pf0-f197.google.com [209.85.192.197]) by kanga.kvack.org (Postfix) with ESMTP id 53CA36B026B for ; Fri, 6 Jul 2018 04:15:53 -0400 (EDT) Received: by mail-pf0-f197.google.com with SMTP id u18-v6so6631786pfh.21 for ; Fri, 06 Jul 2018 01:15:53 -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=B1SK07ff3CEI37s8U2lF0AvwvfdraANybXyXRK0i/h9f/cHx01V/Lq+cd7D9+n1Aul /zTf/Xf7XHqRw0kvmhk3JYlMtiYjxgvyEBD5mRh+LTkDZolpjWJ0zGKw19BnWf9Jft/r 3eEP19gVRlIIVfrHxM6pmhfRCmBX1hu2XZ9cGohwNsR0+TgkDdA9psJ2/ds/gpXP29Os HrLHIEBF3s6nQHSXBUyQTpr5f7qZhJ5EMbAJP3mLXQKYA0YUmRv4z4lf2OhO7RvgLudY n6GqamuYzJVUiDSoQXrrxDn3TYZDt5O9hTHDGj8S3JKqo1uS4+XXROL+WoXRKhm4Sc1Z Y+/A== X-Gm-Message-State: APt69E27OOUEM8P6Ry+vljpdsIfsnXJqam9gpEzxwNTpHLe6yVPS+g+B ih64rIvZh13TdzXZ81r5bS61YPMeudzeMjYNIB2oJlOQmk6YiUopAcwlyHI4S5o88D4rPa/gp19 w/268NTFBxI+R+2bJFwEnmU/8RSltSSG+ORu7w0RWwUGPIu8b8ip/Q5m4GLW4MIXAyHpkj1+Z6V PYf6nZaiGb5gKlg1selY1FsxdF5AuVYhnoPap+zgB75wnMIE4O2aHUOZ2/qVHnpvge31QRjmZTv H8V16V2I78SmOW0bnIdfU04WMwl0AM87tMiyNBEeCLRS6xkx8mlfNGCH0xxsdSJzgdkVjAV+4z1 mxMN8HfQFBkCoMD6hu2TOzPDPnhCkPQ76fnbHXq0z/8nmLT0MmQTpWMVAzF6jq77hVJvlzrSHcR B X-Received: by 2002:a62:23d1:: with SMTP id q78-v6mr9586886pfj.179.1530864953011; Fri, 06 Jul 2018 01:15:53 -0700 (PDT) X-Received: by 2002:a62:23d1:: with SMTP id q78-v6mr9586842pfj.179.1530864952162; Fri, 06 Jul 2018 01:15:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530864952; cv=none; d=google.com; s=arc-20160816; b=NUEHOLy45KXLnZ00Mm7mGwvG0ezS2B5MOjgeYBq3NRq5QrO/GIseVNUutu0CsuNkrj n0gEWKdrpUAO9fPK8TRVVyBXqbjUDKrVpe15yfV5ijKMMh2kZkhSpQyiTsrbwgM+y9dv CFdTQ+hHn8zpCSzk6NvqrnMkATSaPq3ekDtl9pOfrJPjI1KgGZk783V+UzgEAzqCY8Zv O3dFV0aHMoKBSkz5N86WKvHezxDWst/E0LrzF7dWXUsC11iSszoAC3DtGAkn6ERIDxDX i426/gOJLz56zBHLEtusZZ218OA/GOBHJ7E/vp1SaH6SAzc2k9lEUshVQdgssZrkfcx+ VNJQ== 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=ur8Oy5x2ue5twRRv5yLYdOE8rRf4BXpml5xqFw5yk1DBhs/QCLfR6KySZPR01VVrZK tclj6dyE3YoEH1nUcongYrxl38K9izgh+diSRKAll083rjQUepDcj8cNM+ch7IHhmXOh E6YYRnCQLIKFC3wVjzll6in13E427T/BZDgtHJmgPBBolDRBWegYOPn5cwhV120Mi9x8 cpjSxEz3efbwz65tuTA7CG2SzQyYFNI/pZt64cmdfyacmkS+tRIPZmCRMrF/l8EoOmfG dkjNxUDV7a/HufIUWdYeqh8OJ5OMA9AJhxBelBkR1xRuXRCbnL34scVbBeM8pt6fQhfc UdUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="USCnp/ui"; 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 k64-v6sor2167639pge.208.2018.07.06.01.15.52 for (Google Transport Security); Fri, 06 Jul 2018 01:15:52 -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="USCnp/ui"; 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=USCnp/uiMzpHz4l7FUGRPnJQ5OJWgyq5jcRAcHMwK4VWF+Oy7NYUrSFewXeCCPYfFW PvL25wDKKUGzA+8J35GblymiB98Gqiad4zJtIQNVfq2/oOqQ1uBWX14Gw6LlLkSOnXaH wCs1exMdtnsmmaDWdDdNt4l9y9vebHpJ6NuK+8USXtUFJsJN343AmRwgyoMrt50FD1nX o8cRgL90cJeT9kQ+A3OFdEtTVVCzOkVtfQJWt78/TdmRoQnd28AuiLUTGUeRjKb2lNf6 46qXBbk/BT7VjBvKVRmicsKYzvvIVS6luFB19UeOJIdkvMS3vXEhrzPM0u5b6Htv2+vG +Vxg== X-Google-Smtp-Source: AAOMgpetk0FDPvS72S6nqxbW6IfAlLwxw7wyhiDHKOk1N3Mvxo+w23y+iZbuIoWbiTvIZG/JjWTWXw== X-Received: by 2002:a65:6689:: with SMTP id b9-v6mr8487588pgw.326.1530864951959; Fri, 06 Jul 2018 01:15:51 -0700 (PDT) Received: from ct7host.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id c141-v6sm4673049pfc.25.2018.07.06.01.15.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Jul 2018 01:15:51 -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 Subject: [PATCH v10 5/6] mm/memblock: introduce pfn_valid_region() Date: Fri, 6 Jul 2018 16:14:19 +0800 Message-Id: <1530864860-7671-6-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1530864860-7671-1-git-send-email-hejianet@gmail.com> References: <1530864860-7671-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,