Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp1514769imm; Fri, 6 Jul 2018 01:17:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpenhirYp8s5pOLwAvrG9njMKRM4+5X5tGJv17yzdpCW6P2MPNTfp6xEvLXv5ZzwF5CchCFB X-Received: by 2002:a62:e0d5:: with SMTP id d82-v6mr9642349pfm.59.1530865046215; Fri, 06 Jul 2018 01:17:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530865046; cv=none; d=google.com; s=arc-20160816; b=kIFZ3E8scisWIBuXD0ZX7GZ+RuBR+T5khA+74xhzcs2dWmZITsTIVENoDrVLsM4tLF ZMaKfo4KhK7EKpvzO8FmI4iqlE9+0Wj3Be1kAUxYc7delMNHlEgUoI5VDKkF3BtxTXUC ONrE8qderdG1CzOtlZrKD9RgompKcepNYOoQ1ANo1QJFj9LZEt3RDKhrjcZ8v4K69kvZ DHTU4jv8ZhZLMGQ7u54lOv67KJ6V3MSD3QBUuDVjl2xV2j9O+smSDkUdIgtlf9EX/m6+ O0TzePK1BmRl9Pdi3L9J8XO6wvtlQMMgyObW0jIFAqDarhj/J6f7oQPHe9J0mZUNZSnn KYxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=rtdc9EBZDt/OvCySy+SZxp4b3kXttIQe6tLhXTYwvQ4=; b=pxJYHF6VImerSRqzmlozLxl4OqW/bol22/dQbxL8UC5gWBNEjSetzCJRGeHbhg670n sK3rM3Z6ujJ3oZnur4btUb2Qs+JP3hbG35vZovke9VJvjmtQHTrerssVg0ZBqL8LmZoZ Z4WKr8K2Lwo6vDI/E5wd47MFks0YjL2/aO4DgaiRNCwmEIjJTzVe59IwTGUPI3qPydfk A1JjuikBBQEOzzH04hocZ9ELS1FMLfncFwNYOME7bihqzZk3XXHMpWGPeGgFbMDcafsr OG7ffzzbXwibpTg7bMYPm0AlInZogEu21W0F6VGpM91FH9xZESXisTN6YQOn4mQRrJwl 69ag== 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: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b1-v6si7262902pgb.465.2018.07.06.01.17.11; Fri, 06 Jul 2018 01:17:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="USCnp/ui"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754187AbeGFIP4 (ORCPT + 99 others); Fri, 6 Jul 2018 04:15:56 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36887 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754158AbeGFIPw (ORCPT ); Fri, 6 Jul 2018 04:15:52 -0400 Received: by mail-pf0-f196.google.com with SMTP id h20-v6so7791503pfn.4 for ; Fri, 06 Jul 2018 01:15:52 -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=USCnp/uiMzpHz4l7FUGRPnJQ5OJWgyq5jcRAcHMwK4VWF+Oy7NYUrSFewXeCCPYfFW PvL25wDKKUGzA+8J35GblymiB98Gqiad4zJtIQNVfq2/oOqQ1uBWX14Gw6LlLkSOnXaH wCs1exMdtnsmmaDWdDdNt4l9y9vebHpJ6NuK+8USXtUFJsJN343AmRwgyoMrt50FD1nX o8cRgL90cJeT9kQ+A3OFdEtTVVCzOkVtfQJWt78/TdmRoQnd28AuiLUTGUeRjKb2lNf6 46qXBbk/BT7VjBvKVRmicsKYzvvIVS6luFB19UeOJIdkvMS3vXEhrzPM0u5b6Htv2+vG +Vxg== 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=slE8o5REYQH2wNI9dr/DIVgJlGfTpwkuQtVKi5/qcvNM367h+DyL+t8B0Md4gCsfsR gQPqaVrqltC59l529YRLds2wny/XbYcLvuWYQq1173CMDnlYXf/zNvYgUo1y62bNdQgQ Kzccur+7CTinb4vAo43TA4U6CqZIDyU/ou8dkpsUEZn1FeKyPJsEoeDtxzP1IDhChhqm 1Ck9UpoPIK4MEOYHZ39VlzmfXRUjgLc8bu2J6OqKkh4qGcw0DlaZ9YteVDlWHK0Y4US1 /CRwT0/YI9FEMdjtIOOfCF3ucN5gZAJ35pVdyiG56B/SK7oFELZcllqdC7ai4EqQUBTs izGA== X-Gm-Message-State: APt69E0SnfRy63bUvCdYbZkGHbTZq32JtftznyguugrsgeSkODupPAyn gySbFDkvvvl2DC8y24VM/BY= 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, -- 1.8.3.1